]> git.ipfire.org Git - thirdparty/libvirt.git/commitdiff
qemu: Improve validation for virtio input devices
authorAndrea Bolognani <abologna@redhat.com>
Wed, 6 Mar 2019 11:30:25 +0000 (12:30 +0100)
committerAndrea Bolognani <abologna@redhat.com>
Mon, 11 Mar 2019 08:53:40 +0000 (09:53 +0100)
While the parser and schema have to accept all possible models,
virtio-(non-)transitional models are only applicable to
type=passthrough and should be otherwise rejected.

Signed-off-by: Andrea Bolognani <abologna@redhat.com>
Reviewed-by: Cole Robinson <crobinso@redhat.com>
src/libvirt_private.syms
src/qemu/qemu_domain.c
tests/qemuxml2argvdata/virtio-transitional-not-supported.xml [new file with mode: 0644]
tests/qemuxml2argvtest.c

index f568933055a7e336f121d2fb4136137f8064f5d3..86f639a9c13a835f039e2eb594dbee1bedf3ab0d 100644 (file)
@@ -420,6 +420,7 @@ virDomainInputBusTypeToString;
 virDomainInputDefFind;
 virDomainInputDefFree;
 virDomainInputDefGetPath;
+virDomainInputTypeToString;
 virDomainIOMMUModelTypeFromString;
 virDomainIOMMUModelTypeToString;
 virDomainIOThreadIDAdd;
index 44453a5a7a90a9c741c801e118e6fc448c2da673..5cb5ac801f5f791ff2d3d681c4ec39d35645ad6e 100644 (file)
@@ -5971,6 +5971,38 @@ qemuDomainDeviceDefValidateInput(const virDomainInputDef *input,
     if (input->bus != VIR_DOMAIN_INPUT_BUS_VIRTIO)
         return 0;
 
+    /* Only type=passthrough supports model=virtio-(non-)transitional */
+    switch ((virDomainInputModel)input->model) {
+    case VIR_DOMAIN_INPUT_MODEL_VIRTIO_TRANSITIONAL:
+    case VIR_DOMAIN_INPUT_MODEL_VIRTIO_NON_TRANSITIONAL:
+        switch ((virDomainInputType)input->type) {
+        case VIR_DOMAIN_INPUT_TYPE_MOUSE:
+        case VIR_DOMAIN_INPUT_TYPE_TABLET:
+        case VIR_DOMAIN_INPUT_TYPE_KBD:
+            virReportError(VIR_ERR_CONFIG_UNSUPPORTED,
+                           _("virtio (non-)transitional models are not "
+                             "supported for input type=%s"),
+                           virDomainInputTypeToString(input->type));
+            return -1;
+        case VIR_DOMAIN_INPUT_TYPE_PASSTHROUGH:
+            break;
+        case VIR_DOMAIN_INPUT_TYPE_LAST:
+        default:
+            virReportEnumRangeError(virDomainInputType,
+                                    input->type);
+            return -1;
+        }
+        break;
+    case VIR_DOMAIN_INPUT_MODEL_VIRTIO:
+    case VIR_DOMAIN_INPUT_MODEL_DEFAULT:
+        break;
+    case VIR_DOMAIN_INPUT_MODEL_LAST:
+    default:
+        virReportEnumRangeError(virDomainInputModel,
+                                input->model);
+        return -1;
+    }
+
     switch ((virDomainInputType)input->type) {
     case VIR_DOMAIN_INPUT_TYPE_MOUSE:
         baseName = "virtio-mouse";
diff --git a/tests/qemuxml2argvdata/virtio-transitional-not-supported.xml b/tests/qemuxml2argvdata/virtio-transitional-not-supported.xml
new file mode 100644 (file)
index 0000000..881d91d
--- /dev/null
@@ -0,0 +1,11 @@
+<domain type='qemu'>
+  <name>QEMUGuest1</name>
+  <uuid>c7a5fdbd-edaf-9455-926a-d65c16db1809</uuid>
+  <memory unit='KiB'>219136</memory>
+  <os>
+    <type arch='x86_64' machine='q35'>hvm</type>
+  </os>
+  <devices>
+    <input type='keyboard' bus='virtio' model='virtio-non-transitional'/>
+  </devices>
+</domain>
index de9eb6abdba183c40f032aa14fc50e44160b7f00..113ad54b9c226a455885ace055e6ee19f5c54e4e 100644 (file)
@@ -3001,6 +3001,10 @@ mymain(void)
     DO_TEST_CAPS_VER("virtio-non-transitional", "3.1.0");
     DO_TEST_CAPS_LATEST("virtio-transitional");
     DO_TEST_CAPS_LATEST("virtio-non-transitional");
+    DO_TEST_PARSE_ERROR("virtio-transitional-not-supported",
+                        QEMU_CAPS_DEVICE_DMI_TO_PCI_BRIDGE,
+                        QEMU_CAPS_DEVICE_PCI_BRIDGE,
+                        QEMU_CAPS_DEVICE_IOH3420);
 
     /* Simple headless guests for various architectures */
     DO_TEST_CAPS_ARCH_LATEST("aarch64-virt-headless", "aarch64");