]> git.ipfire.org Git - thirdparty/libvirt.git/commitdiff
qemu: caps: add virCPUFeaturePolicy param to virQEMUCapsUpdateCPUDeprecatedFeatures
authorCollin Walling <walling@linux.ibm.com>
Mon, 30 Jun 2025 03:19:27 +0000 (23:19 -0400)
committerJiri Denemark <jdenemar@redhat.com>
Fri, 25 Jul 2025 13:36:21 +0000 (15:36 +0200)
Currently, virQEMUCapsUpdateCPUDeprecatedFeatures only allows for
disabling deprecated features.  This locks the deprecated_features
attribute to only do something if set to 'off'.

Let's add a virCPUFeaturePolicy to the function's parameters which will
allow the caller to decide what happens to these features.

Add a test with guest XML using deprecated_features='on' to ensure the
API is working properly.

Signed-off-by: Collin Walling <walling@linux.ibm.com>
Reviewed-by: Boris Fiuczynski <fiuczy@linux.ibm.com>
Acked-by: Thomas Huth <thuth@redhat.com>
src/qemu/qemu_capabilities.c
src/qemu/qemu_capabilities.h
src/qemu/qemu_driver.c
src/qemu/qemu_process.c
tests/qemuxmlconfdata/cpu-model-deprecated-features-on.s390x-latest.args [new file with mode: 0644]
tests/qemuxmlconfdata/cpu-model-deprecated-features-on.s390x-latest.xml [new file with mode: 0644]
tests/qemuxmlconfdata/cpu-model-deprecated-features-on.xml [new file with mode: 0644]
tests/qemuxmlconftest.c

index d2b59ba1f40ba912ccdff7d74d487e9224212da4..af238894b57325104781617212768a0b2141ef04 100644 (file)
@@ -3368,7 +3368,8 @@ virQEMUCapsGetCPUFeatures(virQEMUCaps *qemuCaps,
 void
 virQEMUCapsUpdateCPUDeprecatedFeatures(virQEMUCaps *qemuCaps,
                                        virDomainVirtType virtType,
-                                       virCPUDef *cpu)
+                                       virCPUDef *cpu,
+                                       virCPUFeaturePolicy policy)
 {
     qemuMonitorCPUModelInfo *modelInfo;
     size_t i;
@@ -3379,8 +3380,7 @@ virQEMUCapsUpdateCPUDeprecatedFeatures(virQEMUCaps *qemuCaps,
         return;
 
     for (i = 0; i < g_strv_length(modelInfo->deprecated_props); i++) {
-        virCPUDefUpdateFeature(cpu, modelInfo->deprecated_props[i],
-                               VIR_CPU_FEATURE_DISABLE);
+        virCPUDefUpdateFeature(cpu, modelInfo->deprecated_props[i], policy);
     }
 }
 
index 2c78ea14f3107083bc93380db831775e50d76a2e..55b05bea84e0311bf4d894c9abb9b36248f0650c 100644 (file)
@@ -788,7 +788,8 @@ int virQEMUCapsGetCPUFeatures(virQEMUCaps *qemuCaps,
                               char ***features);
 void virQEMUCapsUpdateCPUDeprecatedFeatures(virQEMUCaps *qemuCaps,
                                             virDomainVirtType virtType,
-                                            virCPUDef *cpu);
+                                            virCPUDef *cpu,
+                                            virCPUFeaturePolicy policy);
 
 virDomainVirtType virQEMUCapsGetVirtType(virQEMUCaps *qemuCaps);
 
index 8204c72d2fee57c5736162b2c1f2407c0816bbef..ac72ea5cb0471a0890034a500bc81d595e59f20c 100644 (file)
@@ -16742,7 +16742,8 @@ qemuConnectGetDomainCapabilities(virConnectPtr conn,
 
     if (flags & VIR_CONNECT_GET_DOMAIN_CAPABILITIES_DISABLE_DEPRECATED_FEATURES) {
         virQEMUCapsUpdateCPUDeprecatedFeatures(qemuCaps, virttype,
-                                               domCaps->cpu.hostModel);
+                                               domCaps->cpu.hostModel,
+                                               VIR_CPU_FEATURE_DISABLE);
     }
 
     return virDomainCapsFormat(domCaps);
index 313667ef9f93fa1fe5ec2543c608aff9260e967e..da87ae609ba78c6462df391ab622dfcf466a03f3 100644 (file)
@@ -6543,8 +6543,13 @@ qemuProcessUpdateGuestCPU(virDomainDef *def,
         return -1;
     }
 
-    if (def->cpu->deprecated_feats == VIR_TRISTATE_SWITCH_OFF) {
-        virQEMUCapsUpdateCPUDeprecatedFeatures(qemuCaps, def->virtType, def->cpu);
+    if (def->cpu->deprecated_feats) {
+        virCPUFeaturePolicy policy = VIR_CPU_FEATURE_REQUIRE;
+        if (def->cpu->deprecated_feats == VIR_TRISTATE_SWITCH_OFF)
+            policy = VIR_CPU_FEATURE_DISABLE;
+
+        virQEMUCapsUpdateCPUDeprecatedFeatures(qemuCaps, def->virtType,
+                                               def->cpu, policy);
     }
 
     return 0;
diff --git a/tests/qemuxmlconfdata/cpu-model-deprecated-features-on.s390x-latest.args b/tests/qemuxmlconfdata/cpu-model-deprecated-features-on.s390x-latest.args
new file mode 100644 (file)
index 0000000..8cdb2a2
--- /dev/null
@@ -0,0 +1,32 @@
+LC_ALL=C \
+PATH=/bin \
+HOME=/var/lib/libvirt/qemu/domain--1-guest \
+USER=test \
+LOGNAME=test \
+XDG_DATA_HOME=/var/lib/libvirt/qemu/domain--1-guest/.local/share \
+XDG_CACHE_HOME=/var/lib/libvirt/qemu/domain--1-guest/.cache \
+XDG_CONFIG_HOME=/var/lib/libvirt/qemu/domain--1-guest/.config \
+/usr/bin/qemu-system-s390x \
+-name guest=guest,debug-threads=on \
+-S \
+-object '{"qom-type":"secret","id":"masterKey0","format":"raw","file":"/var/lib/libvirt/qemu/domain--1-guest/master-key.aes"}' \
+-machine s390-ccw-virtio,usb=off,dump-guest-core=off,memory-backend=s390.ram \
+-accel kvm \
+-cpu gen16a-base,nnpa=on,aen=on,cmmnt=on,vxpdeh=on,aefsi=on,diag318=on,csske=on,mepoch=on,msa9=on,msa8=on,msa7=on,msa6=on,msa5=on,msa4=on,msa3=on,msa2=on,msa1=on,sthyi=on,edat=on,ri=on,deflate=on,edat2=on,etoken=on,vx=on,ipter=on,pai=on,paie=on,mepochptff=on,ap=on,vxeh=on,vxpd=on,esop=on,msa9_pckmo=on,vxeh2=on,esort=on,appv=on,apqi=on,apft=on,els=on,iep=on,appvi=on,apqci=on,cte=on,ais=on,bpb=on,ctop=on,gs=on,ppa15=on,zpci=on,rdp=on,sea_esop2=on,beareh=on,te=on,cmm=on,vxpdeh2=on \
+-m size=219136k \
+-object '{"qom-type":"memory-backend-ram","id":"s390.ram","size":224395264}' \
+-overcommit mem-lock=off \
+-smp 1,sockets=1,cores=1,threads=1 \
+-uuid 22782664-6b93-46bf-9595-317220dd2d1c \
+-display none \
+-no-user-config \
+-nodefaults \
+-chardev socket,id=charmonitor,fd=1729,server=on,wait=off \
+-mon chardev=charmonitor,id=monitor,mode=control \
+-rtc base=utc \
+-no-shutdown \
+-boot strict=on \
+-audiodev '{"id":"audio1","driver":"none"}' \
+-device '{"driver":"virtio-balloon-ccw","id":"balloon0","devno":"fe.0.0000"}' \
+-sandbox on,obsolete=deny,elevateprivileges=deny,spawn=deny,resourcecontrol=deny \
+-msg timestamp=on
diff --git a/tests/qemuxmlconfdata/cpu-model-deprecated-features-on.s390x-latest.xml b/tests/qemuxmlconfdata/cpu-model-deprecated-features-on.s390x-latest.xml
new file mode 100644 (file)
index 0000000..3bea664
--- /dev/null
@@ -0,0 +1,25 @@
+<domain type='kvm'>
+  <name>guest</name>
+  <uuid>22782664-6b93-46bf-9595-317220dd2d1c</uuid>
+  <memory unit='KiB'>219100</memory>
+  <currentMemory unit='KiB'>219100</currentMemory>
+  <vcpu placement='static'>1</vcpu>
+  <os>
+    <type arch='s390x' machine='s390-ccw-virtio'>hvm</type>
+    <boot dev='hd'/>
+  </os>
+  <cpu mode='host-model' check='partial' deprecated_features='on'/>
+  <clock offset='utc'/>
+  <on_poweroff>destroy</on_poweroff>
+  <on_reboot>restart</on_reboot>
+  <on_crash>destroy</on_crash>
+  <devices>
+    <emulator>/usr/bin/qemu-system-s390x</emulator>
+    <controller type='pci' index='0' model='pci-root'/>
+    <audio id='1' type='none'/>
+    <memballoon model='virtio'>
+      <address type='ccw' cssid='0xfe' ssid='0x0' devno='0x0000'/>
+    </memballoon>
+    <panic model='s390'/>
+  </devices>
+</domain>
diff --git a/tests/qemuxmlconfdata/cpu-model-deprecated-features-on.xml b/tests/qemuxmlconfdata/cpu-model-deprecated-features-on.xml
new file mode 100644 (file)
index 0000000..a5b11a4
--- /dev/null
@@ -0,0 +1,15 @@
+<domain type='kvm'>
+  <name>guest</name>
+  <uuid>22782664-6b93-46bf-9595-317220dd2d1c</uuid>
+  <memory unit='KiB'>219100</memory>
+  <currentMemory unit='KiB'>219100</currentMemory>
+  <vcpu placement='static'>1</vcpu>
+  <os>
+    <type arch='s390x' machine='s390-ccw-virtio'>hvm</type>
+  </os>
+  <cpu mode='host-model' check='partial' deprecated_features='on'/>
+  <clock offset='utc'/>
+  <devices>
+    <emulator>/usr/bin/qemu-system-s390x</emulator>
+  </devices>
+</domain>
index 773f7d9e4212e8685b89b69af9286073e012df7d..7387eb69873d14e2cfe77c76a47bf74fb622c023 100644 (file)
@@ -2304,6 +2304,7 @@ mymain(void)
 
     DO_TEST_CAPS_ARCH_VER_FAILURE("cpu-model-deprecated-features-off", "s390x", "8.2.0");
     DO_TEST_CAPS_ARCH_LATEST("cpu-model-deprecated-features-off", "s390x");
+    DO_TEST_CAPS_ARCH_LATEST("cpu-model-deprecated-features-on", "s390x");
 
     DO_TEST_CAPS_ARCH_LATEST_FULL("cpu-Haswell", "x86_64", ARG_CAPS_HOST_CPU_MODEL, QEMU_CPU_DEF_HASWELL);
     DO_TEST_CAPS_ARCH_LATEST_FULL("cpu-Haswell2", "x86_64", ARG_CAPS_HOST_CPU_MODEL, QEMU_CPU_DEF_HASWELL);