[libvirt PATCH] conf: ensure only one vgpu has ramfb enabled

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Validate the domain configuration to ensure that if there are more than
one vgpu assigned to a domain, only one of them has 'ramfb' enabled.

This was never a supported configuration. QEMU failed confusingly when
attempting to start a domain with this configuration. This change
attempts to provide better information about the error.

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

Signed-off-by: Jonathon Jongsma <jjongsma@xxxxxxxxxx>
---
 src/conf/domain_validate.c                    | 19 ++++++++--
 ...v-display-ramfb-multiple.x86_64-latest.err |  1 +
 .../hostdev-mdev-display-ramfb-multiple.xml   | 38 +++++++++++++++++++
 tests/qemuxml2argvtest.c                      |  1 +
 4 files changed, 56 insertions(+), 3 deletions(-)
 create mode 100644 tests/qemuxml2argvdata/hostdev-mdev-display-ramfb-multiple.x86_64-latest.err
 create mode 100644 tests/qemuxml2argvdata/hostdev-mdev-display-ramfb-multiple.xml

diff --git a/src/conf/domain_validate.c b/src/conf/domain_validate.c
index 68190fc3e2..f4d6e6e0c5 100644
--- a/src/conf/domain_validate.c
+++ b/src/conf/domain_validate.c
@@ -1194,20 +1194,33 @@ virDomainDefDuplicateDiskInfoValidate(const virDomainDef *def)
 }
 
 static int
-virDomainDefDuplicateHostdevInfoValidate(const virDomainDef *def)
+virDomainDefHostdevValidate(const virDomainDef *def)
 {
     size_t i;
     size_t j;
+    bool ramfbEnabled = false;
 
     for (i = 0; i < def->nhostdevs; i++) {
+        virDomainHostdevDef *dev = def->hostdevs[i];
+
         for (j = i + 1; j < def->nhostdevs; j++) {
-            if (virDomainHostdevMatch(def->hostdevs[i],
+            if (virDomainHostdevMatch(dev,
                                       def->hostdevs[j])) {
                 virReportError(VIR_ERR_XML_ERROR, "%s",
                     _("Hostdev already exists in the domain configuration"));
                 return -1;
             }
         }
+
+        if (dev->source.subsys.type == VIR_DOMAIN_HOSTDEV_SUBSYS_TYPE_MDEV &&
+            dev->source.subsys.u.mdev.ramfb == VIR_TRISTATE_SWITCH_ON) {
+            if (ramfbEnabled) {
+                virReportError(VIR_ERR_CONFIG_UNSUPPORTED, "%s",
+                               _("Only one vgpu device can have 'ramfb' enabled"));
+                return -1;
+            }
+            ramfbEnabled = true;
+        }
     }
 
     return 0;
@@ -1664,7 +1677,7 @@ virDomainDefValidateInternal(const virDomainDef *def,
     if (virDomainDefDuplicateDiskInfoValidate(def) < 0)
         return -1;
 
-    if (virDomainDefDuplicateHostdevInfoValidate(def) < 0)
+    if (virDomainDefHostdevValidate(def) < 0)
         return -1;
 
     if (virDomainDefDuplicateDriveAddressesValidate(def) < 0)
diff --git a/tests/qemuxml2argvdata/hostdev-mdev-display-ramfb-multiple.x86_64-latest.err b/tests/qemuxml2argvdata/hostdev-mdev-display-ramfb-multiple.x86_64-latest.err
new file mode 100644
index 0000000000..07ce47abf7
--- /dev/null
+++ b/tests/qemuxml2argvdata/hostdev-mdev-display-ramfb-multiple.x86_64-latest.err
@@ -0,0 +1 @@
+unsupported configuration: Only one vgpu device can have 'ramfb' enabled
diff --git a/tests/qemuxml2argvdata/hostdev-mdev-display-ramfb-multiple.xml b/tests/qemuxml2argvdata/hostdev-mdev-display-ramfb-multiple.xml
new file mode 100644
index 0000000000..1fe53726b5
--- /dev/null
+++ b/tests/qemuxml2argvdata/hostdev-mdev-display-ramfb-multiple.xml
@@ -0,0 +1,38 @@
+<domain type='qemu'>
+  <name>QEMUGuest2</name>
+  <uuid>c7a5fdbd-edaf-9455-926a-d65c16db1809</uuid>
+  <memory unit='KiB'>219136</memory>
+  <currentMemory unit='KiB'>219136</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='usb' index='0'>
+    </controller>
+    <controller type='pci' index='0' model='pci-root'/>
+    <controller type='ide' index='0'>
+    </controller>
+    <graphics type='vnc'/>
+    <hostdev mode='subsystem' type='mdev' model='vfio-pci' display='on' ramfb='on'>
+      <source>
+        <address uuid='53764d0e-85a0-42b4-af5c-2046b460b1dc'/>
+      </source>
+    </hostdev>
+    <hostdev mode='subsystem' type='mdev' model='vfio-pci' display='on' ramfb='on'>
+      <source>
+        <address uuid='53764d0e-85a0-42b4-af5c-2046b460b1dd'/>
+      </source>
+    </hostdev>
+    <video>
+      <model type='qxl' heads='1'/>
+    </video>
+    <memballoon model='none'/>
+  </devices>
+</domain>
diff --git a/tests/qemuxml2argvtest.c b/tests/qemuxml2argvtest.c
index 41fd032f19..e334c59eb7 100644
--- a/tests/qemuxml2argvtest.c
+++ b/tests/qemuxml2argvtest.c
@@ -1896,6 +1896,7 @@ mymain(void)
             QEMU_CAPS_DEVICE_VFIO_PCI,
             QEMU_CAPS_VFIO_PCI_DISPLAY);
     DO_TEST_CAPS_LATEST("hostdev-mdev-display-ramfb");
+    DO_TEST_CAPS_LATEST_PARSE_ERROR("hostdev-mdev-display-ramfb-multiple");
     DO_TEST_PARSE_ERROR("hostdev-vfio-zpci-wrong-arch",
                         QEMU_CAPS_DEVICE_VFIO_PCI);
     DO_TEST("hostdev-vfio-zpci",
-- 
2.35.1




[Index of Archives]     [Virt Tools]     [Libvirt Users]     [Lib OS Info]     [Fedora Users]     [Fedora Desktop]     [Fedora SELinux]     [Big List of Linux Books]     [Yosemite News]     [KDE Users]     [Fedora Tools]

  Powered by Linux