]> git.ipfire.org Git - thirdparty/libvirt.git/commitdiff
qemu: Format rom.enabled attribute for PCI devices
authorAndrea Bolognani <abologna@redhat.com>
Fri, 20 Apr 2018 15:17:11 +0000 (17:17 +0200)
committerAndrea Bolognani <abologna@redhat.com>
Mon, 23 Apr 2018 13:20:54 +0000 (15:20 +0200)
The attribute can be used to disable ROM loading completely
for a device.

This might be needed because, even when the guest is configured
such that the PCI ROM will not be loaded in the PCI BAR, some
hypervisors (eg. QEMU) might still make it available to the
guest in a form (eg. fw_cfg) that some firmwares (eg. SeaBIOS)
will consume, thus not achieving the desired result.

Resolves: https://bugzilla.redhat.com/show_bug.cgi?id=1425058

Signed-off-by: Andrea Bolognani <abologna@redhat.com>
src/qemu/qemu_command.c
tests/qemuxml2argvdata/pci-rom-disabled.args [new file with mode: 0644]
tests/qemuxml2argvdata/pci-rom-disabled.xml [new file with mode: 0644]
tests/qemuxml2argvtest.c
tests/qemuxml2xmloutdata/pci-rom-disabled.xml [new file with mode: 0644]
tests/qemuxml2xmltest.c

index b666f3715f5561fb4aff158bf6be2589d158b48e..418729b9881ec6548d04adf008c9210785466e5f 100644 (file)
@@ -442,13 +442,20 @@ static int
 qemuBuildRomStr(virBufferPtr buf,
                 virDomainDeviceInfoPtr info)
 {
-    if (info->rombar || info->romfile) {
+    if (info->romenabled || info->rombar || info->romfile) {
         if (info->type != VIR_DOMAIN_DEVICE_ADDRESS_TYPE_PCI) {
             virReportError(VIR_ERR_CONFIG_UNSUPPORTED,
-                           "%s", _("rombar and romfile are supported only for PCI devices"));
+                           "%s", _("ROM tuning is only supported for PCI devices"));
             return -1;
         }
 
+        /* Passing an empty romfile= tells QEMU to disable ROM entirely for
+         * this device, and makes other settings irrelevant */
+        if (info->romenabled == VIR_TRISTATE_BOOL_NO) {
+            virBufferAddLit(buf, ",romfile=");
+            return 0;
+        }
+
         switch (info->rombar) {
         case VIR_TRISTATE_SWITCH_OFF:
             virBufferAddLit(buf, ",rombar=0");
@@ -464,6 +471,7 @@ qemuBuildRomStr(virBufferPtr buf,
            virQEMUBuildBufferEscapeComma(buf, info->romfile);
         }
     }
+
     return 0;
 }
 
diff --git a/tests/qemuxml2argvdata/pci-rom-disabled.args b/tests/qemuxml2argvdata/pci-rom-disabled.args
new file mode 100644 (file)
index 0000000..8c9dc2f
--- /dev/null
@@ -0,0 +1,26 @@
+LC_ALL=C \
+PATH=/bin \
+HOME=/home/test \
+USER=test \
+LOGNAME=test \
+QEMU_AUDIO_DRV=none \
+/usr/bin/qemu-system-x86_64 \
+-name guest \
+-S \
+-machine pc,accel=tcg,usb=off,dump-guest-core=off \
+-m 214 \
+-smp 1,sockets=1,cores=1,threads=1 \
+-uuid c7a5fdbd-edaf-9466-926a-d65c16db1809 \
+-display none \
+-no-user-config \
+-nodefaults \
+-chardev socket,id=charmonitor,path=/tmp/lib/domain--1-guest/monitor.sock,\
+server,nowait \
+-mon chardev=charmonitor,id=monitor,mode=control \
+-rtc base=utc \
+-no-shutdown \
+-no-acpi \
+-boot c \
+-netdev user,id=hostnet0 \
+-device virtio-net-pci,netdev=hostnet0,id=net0,mac=52:54:00:24:a5:9f,bus=pci.0,\
+addr=0x3,romfile=
diff --git a/tests/qemuxml2argvdata/pci-rom-disabled.xml b/tests/qemuxml2argvdata/pci-rom-disabled.xml
new file mode 100644 (file)
index 0000000..1c12052
--- /dev/null
@@ -0,0 +1,20 @@
+<domain type='qemu'>
+  <name>guest</name>
+  <uuid>c7a5fdbd-edaf-9466-926a-d65c16db1809</uuid>
+  <memory unit='KiB'>219100</memory>
+  <vcpu placement='static'>1</vcpu>
+  <os>
+    <type arch='x86_64' machine='pc'>hvm</type>
+  </os>
+  <devices>
+    <emulator>/usr/bin/qemu-system-x86_64</emulator>
+    <controller type='pci' model='pci-root'/>
+    <controller type='usb' model='none'/>
+    <interface type='user'>
+      <mac address='52:54:00:24:a5:9f'/>
+      <model type='virtio'/>
+      <rom enabled='no'/>
+    </interface>
+    <memballoon model='none'/>
+  </devices>
+</domain>
index 74d930ebe2518d638ac7bce7625c586d0d1c0094..ae9893a84ea8374aa6835459f8bf105e4078ca74 100644 (file)
@@ -1554,6 +1554,7 @@ mymain(void)
     DO_TEST_PARSE_ERROR("hostdev-mdev-invalid-target-address",
             QEMU_CAPS_DEVICE_VFIO_PCI);
     DO_TEST("pci-rom", NONE);
+    DO_TEST("pci-rom-disabled", NONE);
 
     DO_TEST_FULL("restore-v2", "exec:cat", 7, 0, 0, GIC_NONE, NONE);
     DO_TEST_FULL("restore-v2-fd", "stdio", 7, 0, 0, GIC_NONE, NONE);
diff --git a/tests/qemuxml2xmloutdata/pci-rom-disabled.xml b/tests/qemuxml2xmloutdata/pci-rom-disabled.xml
new file mode 100644 (file)
index 0000000..6a95064
--- /dev/null
@@ -0,0 +1,29 @@
+<domain type='qemu'>
+  <name>guest</name>
+  <uuid>c7a5fdbd-edaf-9466-926a-d65c16db1809</uuid>
+  <memory unit='KiB'>219100</memory>
+  <currentMemory unit='KiB'>219100</currentMemory>
+  <vcpu placement='static'>1</vcpu>
+  <os>
+    <type arch='x86_64' machine='pc'>hvm</type>
+    <boot dev='hd'/>
+  </os>
+  <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='pci' index='0' model='pci-root'/>
+    <controller type='usb' index='0' model='none'/>
+    <interface type='user'>
+      <mac address='52:54:00:24:a5:9f'/>
+      <model type='virtio'/>
+      <rom enabled='no'/>
+      <address type='pci' domain='0x0000' bus='0x00' slot='0x03' function='0x0'/>
+    </interface>
+    <input type='mouse' bus='ps2'/>
+    <input type='keyboard' bus='ps2'/>
+    <memballoon model='none'/>
+  </devices>
+</domain>
index 9e77b9fb13cff82236c525c0ebd1fbdc9418cb4b..6c1f0b0fa62f1fe8a8504997c37e69619b9c1bfd 100644 (file)
@@ -474,6 +474,7 @@ mymain(void)
     DO_TEST("hostdev-vfio", NONE);
     DO_TEST("hostdev-mdev-precreated", NONE);
     DO_TEST("pci-rom", NONE);
+    DO_TEST("pci-rom-disabled", NONE);
     DO_TEST("pci-serial-dev-chardev", NONE);
 
     DO_TEST("encrypted-disk", NONE);