[libvirt PATCH 0/3] conf: Fix handling of SMM feature

Andrea Bolognani (3): tests: Update smm=on test tests: Introduce smm=off test conf: Fix smm=off handling src/conf/domain_conf.c | 9 +++++--- ...rgs => machine-smm-off.x86_64-latest.args} | 16 ++++++-------- tests/qemuxml2argvdata/machine-smm-off.xml | 17 +++++++++++++++ ...args => machine-smm-on.x86_64-latest.args} | 16 ++++++-------- tests/qemuxml2argvdata/machine-smm-on.xml | 17 +++++++++++++++ tests/qemuxml2argvtest.c | 8 ++----- .../machine-smm-off.x86_64-latest.xml} | 21 ++++++++++++------- .../machine-smm-on.x86_64-latest.xml} | 19 ++++++++++------- tests/qemuxml2xmltest.c | 2 ++ 9 files changed, 81 insertions(+), 44 deletions(-) copy tests/qemuxml2argvdata/{machine-smm-opt.args => machine-smm-off.x86_64-latest.args} (52%) create mode 100644 tests/qemuxml2argvdata/machine-smm-off.xml rename tests/qemuxml2argvdata/{machine-smm-opt.args => machine-smm-on.x86_64-latest.args} (52%) create mode 100644 tests/qemuxml2argvdata/machine-smm-on.xml copy tests/{qemuxml2argvdata/machine-smm-opt.xml => qemuxml2xmloutdata/machine-smm-off.x86_64-latest.xml} (51%) rename tests/{qemuxml2argvdata/machine-smm-opt.xml => qemuxml2xmloutdata/machine-smm-on.x86_64-latest.xml} (53%) -- 2.35.3

Use DO_TEST_CAPS_LATEST() instead of hardcoding capabilities and add the xml2xml part, which was missing; finally, rename it to accomodate the complementary smm=off test that we're about to introduce. Signed-off-by: Andrea Bolognani <abologna@redhat.com> --- ...args => machine-smm-on.x86_64-latest.args} | 16 ++++++---------- tests/qemuxml2argvdata/machine-smm-on.xml | 17 +++++++++++++++++ tests/qemuxml2argvtest.c | 7 +------ .../machine-smm-on.x86_64-latest.xml} | 19 ++++++++++++------- tests/qemuxml2xmltest.c | 1 + 5 files changed, 37 insertions(+), 23 deletions(-) rename tests/qemuxml2argvdata/{machine-smm-opt.args => machine-smm-on.x86_64-latest.args} (52%) create mode 100644 tests/qemuxml2argvdata/machine-smm-on.xml rename tests/{qemuxml2argvdata/machine-smm-opt.xml => qemuxml2xmloutdata/machine-smm-on.x86_64-latest.xml} (53%) diff --git a/tests/qemuxml2argvdata/machine-smm-opt.args b/tests/qemuxml2argvdata/machine-smm-on.x86_64-latest.args similarity index 52% rename from tests/qemuxml2argvdata/machine-smm-opt.args rename to tests/qemuxml2argvdata/machine-smm-on.x86_64-latest.args index 39fb447320..6fde375523 100644 --- a/tests/qemuxml2argvdata/machine-smm-opt.args +++ b/tests/qemuxml2argvdata/machine-smm-on.x86_64-latest.args @@ -6,14 +6,15 @@ LOGNAME=test \ XDG_DATA_HOME=/tmp/lib/domain--1-QEMUGuest1/.local/share \ XDG_CACHE_HOME=/tmp/lib/domain--1-QEMUGuest1/.cache \ XDG_CONFIG_HOME=/tmp/lib/domain--1-QEMUGuest1/.config \ -QEMU_AUDIO_DRV=none \ /usr/bin/qemu-system-x86_64 \ -name guest=QEMUGuest1,debug-threads=on \ -S \ --object secret,id=masterKey0,format=raw,file=/tmp/lib/domain--1-QEMUGuest1/master-key.aes \ --machine q35,usb=off,smm=on,dump-guest-core=off \ +-object '{"qom-type":"secret","id":"masterKey0","format":"raw","file":"/tmp/lib/domain--1-QEMUGuest1/master-key.aes"}' \ +-machine q35,usb=off,smm=on,dump-guest-core=off,memory-backend=pc.ram \ -accel tcg \ +-cpu qemu64 \ -m 214 \ +-object '{"qom-type":"memory-backend-ram","id":"pc.ram","size":224395264}' \ -overcommit mem-lock=off \ -smp 1,sockets=1,cores=1,threads=1 \ -uuid c7a5fdbd-edaf-9455-926a-d65c16db1809 \ @@ -26,11 +27,6 @@ QEMU_AUDIO_DRV=none \ -no-shutdown \ -no-acpi \ -boot strict=on \ --device i82801b11-bridge,id=pci.1,bus=pcie.0,addr=0x1e \ --device pci-bridge,chassis_nr=2,id=pci.2,bus=pci.1,addr=0x0 \ --device ioh3420,port=8,chassis=3,id=pci.3,bus=pcie.0,addr=0x1 \ --device virtio-scsi-pci,id=scsi0,bus=pci.2,addr=0x1 \ --drive file=/dev/HostVG/QEMUGuest1,format=raw,if=none,id=drive-scsi0-0-0-0 \ --device scsi-hd,bus=scsi0.0,channel=0,scsi-id=0,lun=0,drive=drive-scsi0-0-0-0,id=scsi0-0-0-0,bootindex=1 \ --device virtio-balloon-pci,id=balloon0,bus=pci.2,addr=0x2 \ +-audiodev '{"id":"audio1","driver":"none"}' \ +-sandbox on,obsolete=deny,elevateprivileges=deny,spawn=deny,resourcecontrol=deny \ -msg timestamp=on diff --git a/tests/qemuxml2argvdata/machine-smm-on.xml b/tests/qemuxml2argvdata/machine-smm-on.xml new file mode 100644 index 0000000000..e24608343a --- /dev/null +++ b/tests/qemuxml2argvdata/machine-smm-on.xml @@ -0,0 +1,17 @@ +<domain type='qemu'> + <name>QEMUGuest1</name> + <uuid>c7a5fdbd-edaf-9455-926a-d65c16db1809</uuid> + <memory unit='KiB'>219100</memory> + <vcpu placement='static'>1</vcpu> + <os> + <type arch='x86_64' machine='q35'>hvm</type> + </os> + <features> + <smm state='on'/> + </features> + <devices> + <emulator>/usr/bin/qemu-system-x86_64</emulator> + <controller type='usb' model='none'/> + <memballoon model='none'/> + </devices> +</domain> diff --git a/tests/qemuxml2argvtest.c b/tests/qemuxml2argvtest.c index 829550fbfe..c0c18ef1dc 100644 --- a/tests/qemuxml2argvtest.c +++ b/tests/qemuxml2argvtest.c @@ -1061,12 +1061,7 @@ mymain(void) driver.config->dumpGuestCore = true; DO_TEST_NOCAPS("machine-core-off"); driver.config->dumpGuestCore = false; - DO_TEST("machine-smm-opt", - QEMU_CAPS_DEVICE_DMI_TO_PCI_BRIDGE, - QEMU_CAPS_DEVICE_PCI_BRIDGE, - QEMU_CAPS_DEVICE_IOH3420, - QEMU_CAPS_ICH9_AHCI, - QEMU_CAPS_VIRTIO_SCSI); + DO_TEST_CAPS_LATEST("machine-smm-on"); DO_TEST("machine-vmport-opt", QEMU_CAPS_MACHINE_VMPORT_OPT); DO_TEST_NOCAPS("default-kvm-host-arch"); diff --git a/tests/qemuxml2argvdata/machine-smm-opt.xml b/tests/qemuxml2xmloutdata/machine-smm-on.x86_64-latest.xml similarity index 53% rename from tests/qemuxml2argvdata/machine-smm-opt.xml rename to tests/qemuxml2xmloutdata/machine-smm-on.x86_64-latest.xml index 053bb5c25f..7c7df9e06d 100644 --- a/tests/qemuxml2argvdata/machine-smm-opt.xml +++ b/tests/qemuxml2xmloutdata/machine-smm-on.x86_64-latest.xml @@ -11,18 +11,23 @@ <features> <smm state='on'/> </features> + <cpu mode='custom' match='exact' check='none'> + <model fallback='forbid'>qemu64</model> + </cpu> <clock offset='utc'/> <on_poweroff>destroy</on_poweroff> <on_reboot>restart</on_reboot> <on_crash>destroy</on_crash> <devices> <emulator>/usr/bin/qemu-system-x86_64</emulator> - <disk type='block' device='disk'> - <source dev='/dev/HostVG/QEMUGuest1'/> - <target dev='sda' bus='scsi'/> - <address type='drive' controller='0' bus='0' target='0' unit='0'/> - </disk> - <controller type='scsi' index='0'/> - <memballoon model='virtio'/> + <controller type='usb' index='0' model='none'/> + <controller type='sata' index='0'> + <address type='pci' domain='0x0000' bus='0x00' slot='0x1f' function='0x2'/> + </controller> + <controller type='pci' index='0' model='pcie-root'/> + <input type='mouse' bus='ps2'/> + <input type='keyboard' bus='ps2'/> + <audio id='1' type='none'/> + <memballoon model='none'/> </devices> </domain> diff --git a/tests/qemuxml2xmltest.c b/tests/qemuxml2xmltest.c index 8b655874d1..02d8a66f3c 100644 --- a/tests/qemuxml2xmltest.c +++ b/tests/qemuxml2xmltest.c @@ -243,6 +243,7 @@ mymain(void) DO_TEST_CAPS_LATEST("genid-auto"); DO_TEST_NOCAPS("machine-core-on"); DO_TEST_NOCAPS("machine-core-off"); + DO_TEST_CAPS_LATEST("machine-smm-on"); DO_TEST("machine-loadparm-multiple-disks-nets-s390", QEMU_CAPS_CCW); DO_TEST_NOCAPS("default-kvm-host-arch"); DO_TEST_NOCAPS("default-qemu-host-arch"); -- 2.35.3

This complements the existing smm=on tests. Looking at the output files, one can immediately see how this case is currently not being handled correctly. We're going to fix that in the next commit. Signed-off-by: Andrea Bolognani <abologna@redhat.com> --- .../machine-smm-off.x86_64-latest.args | 32 +++++++++++++++++++ tests/qemuxml2argvdata/machine-smm-off.xml | 17 ++++++++++ tests/qemuxml2argvtest.c | 1 + .../machine-smm-off.x86_64-latest.xml | 30 +++++++++++++++++ tests/qemuxml2xmltest.c | 1 + 5 files changed, 81 insertions(+) create mode 100644 tests/qemuxml2argvdata/machine-smm-off.x86_64-latest.args create mode 100644 tests/qemuxml2argvdata/machine-smm-off.xml create mode 100644 tests/qemuxml2xmloutdata/machine-smm-off.x86_64-latest.xml diff --git a/tests/qemuxml2argvdata/machine-smm-off.x86_64-latest.args b/tests/qemuxml2argvdata/machine-smm-off.x86_64-latest.args new file mode 100644 index 0000000000..b5a685524e --- /dev/null +++ b/tests/qemuxml2argvdata/machine-smm-off.x86_64-latest.args @@ -0,0 +1,32 @@ +LC_ALL=C \ +PATH=/bin \ +HOME=/tmp/lib/domain--1-QEMUGuest1 \ +USER=test \ +LOGNAME=test \ +XDG_DATA_HOME=/tmp/lib/domain--1-QEMUGuest1/.local/share \ +XDG_CACHE_HOME=/tmp/lib/domain--1-QEMUGuest1/.cache \ +XDG_CONFIG_HOME=/tmp/lib/domain--1-QEMUGuest1/.config \ +/usr/bin/qemu-system-x86_64 \ +-name guest=QEMUGuest1,debug-threads=on \ +-S \ +-object '{"qom-type":"secret","id":"masterKey0","format":"raw","file":"/tmp/lib/domain--1-QEMUGuest1/master-key.aes"}' \ +-machine q35,usb=off,dump-guest-core=off,memory-backend=pc.ram \ +-accel tcg \ +-cpu qemu64 \ +-m 214 \ +-object '{"qom-type":"memory-backend-ram","id":"pc.ram","size":224395264}' \ +-overcommit mem-lock=off \ +-smp 1,sockets=1,cores=1,threads=1 \ +-uuid c7a5fdbd-edaf-9455-926a-d65c16db1809 \ +-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 \ +-no-acpi \ +-boot strict=on \ +-audiodev '{"id":"audio1","driver":"none"}' \ +-sandbox on,obsolete=deny,elevateprivileges=deny,spawn=deny,resourcecontrol=deny \ +-msg timestamp=on diff --git a/tests/qemuxml2argvdata/machine-smm-off.xml b/tests/qemuxml2argvdata/machine-smm-off.xml new file mode 100644 index 0000000000..c7857ec46a --- /dev/null +++ b/tests/qemuxml2argvdata/machine-smm-off.xml @@ -0,0 +1,17 @@ +<domain type='qemu'> + <name>QEMUGuest1</name> + <uuid>c7a5fdbd-edaf-9455-926a-d65c16db1809</uuid> + <memory unit='KiB'>219100</memory> + <vcpu placement='static'>1</vcpu> + <os> + <type arch='x86_64' machine='q35'>hvm</type> + </os> + <features> + <smm state='off'/> + </features> + <devices> + <emulator>/usr/bin/qemu-system-x86_64</emulator> + <controller type='usb' model='none'/> + <memballoon model='none'/> + </devices> +</domain> diff --git a/tests/qemuxml2argvtest.c b/tests/qemuxml2argvtest.c index c0c18ef1dc..7708e3ba3e 100644 --- a/tests/qemuxml2argvtest.c +++ b/tests/qemuxml2argvtest.c @@ -1062,6 +1062,7 @@ mymain(void) DO_TEST_NOCAPS("machine-core-off"); driver.config->dumpGuestCore = false; DO_TEST_CAPS_LATEST("machine-smm-on"); + DO_TEST_CAPS_LATEST("machine-smm-off"); DO_TEST("machine-vmport-opt", QEMU_CAPS_MACHINE_VMPORT_OPT); DO_TEST_NOCAPS("default-kvm-host-arch"); diff --git a/tests/qemuxml2xmloutdata/machine-smm-off.x86_64-latest.xml b/tests/qemuxml2xmloutdata/machine-smm-off.x86_64-latest.xml new file mode 100644 index 0000000000..1d58c22892 --- /dev/null +++ b/tests/qemuxml2xmloutdata/machine-smm-off.x86_64-latest.xml @@ -0,0 +1,30 @@ +<domain type='qemu'> + <name>QEMUGuest1</name> + <uuid>c7a5fdbd-edaf-9455-926a-d65c16db1809</uuid> + <memory unit='KiB'>219100</memory> + <currentMemory unit='KiB'>219100</currentMemory> + <vcpu placement='static'>1</vcpu> + <os> + <type arch='x86_64' machine='q35'>hvm</type> + <boot dev='hd'/> + </os> + <cpu mode='custom' match='exact' check='none'> + <model fallback='forbid'>qemu64</model> + </cpu> + <clock offset='utc'/> + <on_poweroff>destroy</on_poweroff> + <on_reboot>restart</on_reboot> + <on_crash>destroy</on_crash> + <devices> + <emulator>/usr/bin/qemu-system-x86_64</emulator> + <controller type='usb' index='0' model='none'/> + <controller type='sata' index='0'> + <address type='pci' domain='0x0000' bus='0x00' slot='0x1f' function='0x2'/> + </controller> + <controller type='pci' index='0' model='pcie-root'/> + <input type='mouse' bus='ps2'/> + <input type='keyboard' bus='ps2'/> + <audio id='1' type='none'/> + <memballoon model='none'/> + </devices> +</domain> diff --git a/tests/qemuxml2xmltest.c b/tests/qemuxml2xmltest.c index 02d8a66f3c..a8e1cb2400 100644 --- a/tests/qemuxml2xmltest.c +++ b/tests/qemuxml2xmltest.c @@ -244,6 +244,7 @@ mymain(void) DO_TEST_NOCAPS("machine-core-on"); DO_TEST_NOCAPS("machine-core-off"); DO_TEST_CAPS_LATEST("machine-smm-on"); + DO_TEST_CAPS_LATEST("machine-smm-off"); DO_TEST("machine-loadparm-multiple-disks-nets-s390", QEMU_CAPS_CCW); DO_TEST_NOCAPS("default-kvm-host-arch"); DO_TEST_NOCAPS("default-qemu-host-arch"); -- 2.35.3

We have to always store the state of the feature in the virDomainDef struct, otherwise <smm state='off'/> will incorrectly be interpreted as if the <smm> element was not present. Fixes: eeb94215b074a71b3c8932d5fcaf657f269b2c82 Signed-off-by: Andrea Bolognani <abologna@redhat.com> --- src/conf/domain_conf.c | 9 ++++++--- .../qemuxml2argvdata/machine-smm-off.x86_64-latest.args | 2 +- .../qemuxml2xmloutdata/machine-smm-off.x86_64-latest.xml | 3 +++ 3 files changed, 10 insertions(+), 4 deletions(-) diff --git a/src/conf/domain_conf.c b/src/conf/domain_conf.c index d9b55c80aa..70562cc993 100644 --- a/src/conf/domain_conf.c +++ b/src/conf/domain_conf.c @@ -17676,8 +17676,12 @@ virDomainFeaturesDefParse(virDomainDef *def, VIR_XML_PROP_NONE, &state) < 0) return -1; - if ((state == VIR_TRISTATE_SWITCH_ABSENT) || - (state == VIR_TRISTATE_SWITCH_ON)) { + if (state == VIR_TRISTATE_SWITCH_ABSENT) + state = VIR_TRISTATE_SWITCH_ON; + + def->features[val] = state; + + if (state == VIR_TRISTATE_SWITCH_ON) { int rv = virParseScaledValue("string(./features/smm/tseg)", "string(./features/smm/tseg/@unit)", ctxt, @@ -17688,7 +17692,6 @@ virDomainFeaturesDefParse(virDomainDef *def, if (rv < 0) return -1; - def->features[val] = VIR_TRISTATE_SWITCH_ON; def->tseg_specified = rv != 0; } break; diff --git a/tests/qemuxml2argvdata/machine-smm-off.x86_64-latest.args b/tests/qemuxml2argvdata/machine-smm-off.x86_64-latest.args index b5a685524e..46f6a4a70c 100644 --- a/tests/qemuxml2argvdata/machine-smm-off.x86_64-latest.args +++ b/tests/qemuxml2argvdata/machine-smm-off.x86_64-latest.args @@ -10,7 +10,7 @@ XDG_CONFIG_HOME=/tmp/lib/domain--1-QEMUGuest1/.config \ -name guest=QEMUGuest1,debug-threads=on \ -S \ -object '{"qom-type":"secret","id":"masterKey0","format":"raw","file":"/tmp/lib/domain--1-QEMUGuest1/master-key.aes"}' \ --machine q35,usb=off,dump-guest-core=off,memory-backend=pc.ram \ +-machine q35,usb=off,smm=off,dump-guest-core=off,memory-backend=pc.ram \ -accel tcg \ -cpu qemu64 \ -m 214 \ diff --git a/tests/qemuxml2xmloutdata/machine-smm-off.x86_64-latest.xml b/tests/qemuxml2xmloutdata/machine-smm-off.x86_64-latest.xml index 1d58c22892..77b0b39750 100644 --- a/tests/qemuxml2xmloutdata/machine-smm-off.x86_64-latest.xml +++ b/tests/qemuxml2xmloutdata/machine-smm-off.x86_64-latest.xml @@ -8,6 +8,9 @@ <type arch='x86_64' machine='q35'>hvm</type> <boot dev='hd'/> </os> + <features> + <smm state='off'/> + </features> <cpu mode='custom' match='exact' check='none'> <model fallback='forbid'>qemu64</model> </cpu> -- 2.35.3

On a Friday in 2022, Andrea Bolognani wrote:
Andrea Bolognani (3): tests: Update smm=on test tests: Introduce smm=off test conf: Fix smm=off handling
src/conf/domain_conf.c | 9 +++++--- ...rgs => machine-smm-off.x86_64-latest.args} | 16 ++++++-------- tests/qemuxml2argvdata/machine-smm-off.xml | 17 +++++++++++++++ ...args => machine-smm-on.x86_64-latest.args} | 16 ++++++-------- tests/qemuxml2argvdata/machine-smm-on.xml | 17 +++++++++++++++ tests/qemuxml2argvtest.c | 8 ++----- .../machine-smm-off.x86_64-latest.xml} | 21 ++++++++++++------- .../machine-smm-on.x86_64-latest.xml} | 19 ++++++++++------- tests/qemuxml2xmltest.c | 2 ++ 9 files changed, 81 insertions(+), 44 deletions(-) copy tests/qemuxml2argvdata/{machine-smm-opt.args => machine-smm-off.x86_64-latest.args} (52%) create mode 100644 tests/qemuxml2argvdata/machine-smm-off.xml rename tests/qemuxml2argvdata/{machine-smm-opt.args => machine-smm-on.x86_64-latest.args} (52%) create mode 100644 tests/qemuxml2argvdata/machine-smm-on.xml copy tests/{qemuxml2argvdata/machine-smm-opt.xml => qemuxml2xmloutdata/machine-smm-off.x86_64-latest.xml} (51%) rename tests/{qemuxml2argvdata/machine-smm-opt.xml => qemuxml2xmloutdata/machine-smm-on.x86_64-latest.xml} (53%)
Reviewed-by: Ján Tomko <jtomko@redhat.com> Jano
participants (2)
-
Andrea Bolognani
-
Ján Tomko