[v3,14/17] qemu: Support input model=virtio-{non-}transitional

Message ID 005ef112d40e58325485f47dcb86b58b4032a269.1549663397.git.crobinso@redhat.com
State Accepted
Commit 90fd9bd98972191d64ea201d86bab3eb7af54a1d
Headers show
Series
  • qemu: virtio-{non-}transitional support
Related show

Commit Message

Cole Robinson Feb. 8, 2019, 10:12 p.m.
Add <input> model handling for virtio transitional devices. Ex:

  <input type='passthrough' bus='virtio' model='virtio-transitional'>
    ...
  </input>

* "virtio-transitional" maps to qemu "virtio-input-host-pci-transitional"
* "virtio-non-transitional" maps to qemu "virtio-input-host-non-transitional"

Reviewed-by: Andrea Bolognani <abologna@redhat.com>

Signed-off-by: Cole Robinson <crobinso@redhat.com>

---
 src/qemu/qemu_command.c                             |  8 +++++++-
 src/qemu/qemu_domain_address.c                      | 13 ++++++++++++-
 .../virtio-non-transitional.x86_64-3.1.0.args       |  4 ++--
 .../virtio-non-transitional.x86_64-latest.args      |  4 ++--
 .../virtio-transitional.x86_64-3.1.0.args           |  7 +++----
 .../virtio-transitional.x86_64-latest.args          |  7 +++----
 tests/qemuxml2xmloutdata/virtio-transitional.xml    |  9 ++-------
 7 files changed, 31 insertions(+), 21 deletions(-)

-- 
2.20.1

--
libvir-list mailing list
libvir-list@redhat.com
https://www.redhat.com/mailman/listinfo/libvir-list

Patch

diff --git a/src/qemu/qemu_command.c b/src/qemu/qemu_command.c
index 022d5a5d90..946bc8b0b3 100644
--- a/src/qemu/qemu_command.c
+++ b/src/qemu/qemu_command.c
@@ -512,8 +512,14 @@  qemuBuildVirtioDevStr(virBufferPtr buf,
             has_ntmodel = device.data.vsock->model == VIR_DOMAIN_VSOCK_MODEL_VIRTIO_NON_TRANSITIONAL;
             break;
 
-        case VIR_DOMAIN_DEVICE_LEASE:
         case VIR_DOMAIN_DEVICE_INPUT:
+            if (device.data.input->type != VIR_DOMAIN_INPUT_TYPE_PASSTHROUGH)
+                return 0;
+            has_tmodel = device.data.input->model == VIR_DOMAIN_INPUT_MODEL_VIRTIO_TRANSITIONAL;
+            has_ntmodel = device.data.input->model == VIR_DOMAIN_INPUT_MODEL_VIRTIO_NON_TRANSITIONAL;
+            break;
+
+        case VIR_DOMAIN_DEVICE_LEASE:
         case VIR_DOMAIN_DEVICE_SOUND:
         case VIR_DOMAIN_DEVICE_VIDEO:
         case VIR_DOMAIN_DEVICE_WATCHDOG:
diff --git a/src/qemu/qemu_domain_address.c b/src/qemu/qemu_domain_address.c
index badf237333..8f505c90fd 100644
--- a/src/qemu/qemu_domain_address.c
+++ b/src/qemu/qemu_domain_address.c
@@ -949,7 +949,18 @@  qemuDomainDeviceCalculatePCIConnectFlags(virDomainDeviceDefPtr dev,
     case VIR_DOMAIN_DEVICE_INPUT:
         switch ((virDomainInputBus) dev->data.input->bus) {
         case VIR_DOMAIN_INPUT_BUS_VIRTIO:
-            return virtioFlags;
+            switch ((virDomainInputModel) dev->data.input->model) {
+            case VIR_DOMAIN_INPUT_MODEL_VIRTIO_TRANSITIONAL:
+                /* Transitional devices only work in conventional PCI slots */
+                return pciFlags;
+            case VIR_DOMAIN_INPUT_MODEL_VIRTIO:
+            case VIR_DOMAIN_INPUT_MODEL_VIRTIO_NON_TRANSITIONAL:
+            case VIR_DOMAIN_INPUT_MODEL_DEFAULT:
+                return virtioFlags;
+            case VIR_DOMAIN_INPUT_MODEL_LAST:
+                break;
+            }
+            return 0;
 
         case VIR_DOMAIN_INPUT_BUS_PS2:
         case VIR_DOMAIN_INPUT_BUS_USB:
diff --git a/tests/qemuxml2argvdata/virtio-non-transitional.x86_64-3.1.0.args b/tests/qemuxml2argvdata/virtio-non-transitional.x86_64-3.1.0.args
index 9130572abe..0f5de86315 100644
--- a/tests/qemuxml2argvdata/virtio-non-transitional.x86_64-3.1.0.args
+++ b/tests/qemuxml2argvdata/virtio-non-transitional.x86_64-3.1.0.args
@@ -42,8 +42,8 @@  fsdev=fsdev-fs0,mount_tag=fs1,bus=pci.1,addr=0x0 \
 -netdev user,id=hostnet0 \
 -device virtio-net-pci,disable-legacy=on,disable-modern=off,netdev=hostnet0,\
 id=net0,mac=00:11:22:33:44:55,bus=pci.2,addr=0x0 \
--device virtio-input-host-pci,id=input0,evdev=/dev/input/event1234,bus=pci.7,\
-addr=0x0 \
+-device virtio-input-host-pci,disable-legacy=on,disable-modern=off,id=input0,\
+evdev=/dev/input/event1234,bus=pci.7,addr=0x0 \
 -device vhost-scsi-pci,disable-legacy=on,disable-modern=off,\
 wwpn=naa.5123456789abcde0,vhostfd=3,id=hostdev0,bus=pci.4,addr=0x0 \
 -device virtio-balloon-pci,disable-legacy=on,disable-modern=off,id=balloon0,\
diff --git a/tests/qemuxml2argvdata/virtio-non-transitional.x86_64-latest.args b/tests/qemuxml2argvdata/virtio-non-transitional.x86_64-latest.args
index 8e0709816b..383b29f629 100644
--- a/tests/qemuxml2argvdata/virtio-non-transitional.x86_64-latest.args
+++ b/tests/qemuxml2argvdata/virtio-non-transitional.x86_64-latest.args
@@ -42,8 +42,8 @@  bus=pci.1,addr=0x0 \
 -netdev user,id=hostnet0 \
 -device virtio-net-pci-non-transitional,netdev=hostnet0,id=net0,\
 mac=00:11:22:33:44:55,bus=pci.2,addr=0x0 \
--device virtio-input-host-pci,id=input0,evdev=/dev/input/event1234,bus=pci.7,\
-addr=0x0 \
+-device virtio-input-host-pci-non-transitional,id=input0,\
+evdev=/dev/input/event1234,bus=pci.7,addr=0x0 \
 -device vhost-scsi-pci-non-transitional,wwpn=naa.5123456789abcde0,vhostfd=3,\
 id=hostdev0,bus=pci.4,addr=0x0 \
 -device virtio-balloon-pci-non-transitional,id=balloon0,bus=pci.5,addr=0x0 \
diff --git a/tests/qemuxml2argvdata/virtio-transitional.x86_64-3.1.0.args b/tests/qemuxml2argvdata/virtio-transitional.x86_64-3.1.0.args
index 0286b98ece..1c851b5ec4 100644
--- a/tests/qemuxml2argvdata/virtio-transitional.x86_64-3.1.0.args
+++ b/tests/qemuxml2argvdata/virtio-transitional.x86_64-3.1.0.args
@@ -27,7 +27,6 @@  file=/tmp/lib/domain--1-QEMUGuest1/master-key.aes \
 addr=0x1 \
 -device pcie-pci-bridge,id=pci.2,bus=pci.1,addr=0x0 \
 -device pcie-root-port,port=0x9,chassis=3,id=pci.3,bus=pcie.0,addr=0x1.0x1 \
--device pcie-root-port,port=0xa,chassis=4,id=pci.4,bus=pcie.0,addr=0x1.0x2 \
 -drive file=/dev/HostVG/QEMUGuest1,format=raw,if=none,id=drive-virtio-disk0 \
 -device virtio-blk-pci,disable-legacy=off,disable-modern=off,scsi=off,\
 bus=pci.2,addr=0x3,drive=drive-virtio-disk0,id=virtio-disk0,bootindex=1 \
@@ -37,8 +36,8 @@  fsdev=fsdev-fs0,mount_tag=fs1,bus=pci.2,addr=0x1 \
 -netdev user,id=hostnet0 \
 -device virtio-net-pci,disable-legacy=off,disable-modern=off,netdev=hostnet0,\
 id=net0,mac=00:11:22:33:44:55,bus=pci.2,addr=0x2 \
--device virtio-input-host-pci,id=input0,evdev=/dev/input/event1234,bus=pci.3,\
-addr=0x0 \
+-device virtio-input-host-pci,disable-legacy=off,disable-modern=off,id=input0,\
+evdev=/dev/input/event1234,bus=pci.2,addr=0x7 \
 -device vhost-scsi-pci,disable-legacy=off,disable-modern=off,\
 wwpn=naa.5123456789abcde0,vhostfd=3,id=hostdev0,bus=pci.2,addr=0x4 \
 -device virtio-balloon-pci,disable-legacy=off,disable-modern=off,id=balloon0,\
@@ -49,5 +48,5 @@  id=rng0,bus=pci.2,addr=0x6 \
 -sandbox on,obsolete=deny,elevateprivileges=deny,spawn=deny,\
 resourcecontrol=deny \
 -device vhost-vsock-pci,disable-legacy=off,disable-modern=off,id=vsock0,\
-guest-cid=4,vhostfd=6789,bus=pci.2,addr=0x7 \
+guest-cid=4,vhostfd=6789,bus=pci.2,addr=0x8 \
 -msg timestamp=on
diff --git a/tests/qemuxml2argvdata/virtio-transitional.x86_64-latest.args b/tests/qemuxml2argvdata/virtio-transitional.x86_64-latest.args
index 24b49e6009..410eb28f0a 100644
--- a/tests/qemuxml2argvdata/virtio-transitional.x86_64-latest.args
+++ b/tests/qemuxml2argvdata/virtio-transitional.x86_64-latest.args
@@ -27,7 +27,6 @@  file=/tmp/lib/domain--1-QEMUGuest1/master-key.aes \
 addr=0x1 \
 -device pcie-pci-bridge,id=pci.2,bus=pci.1,addr=0x0 \
 -device pcie-root-port,port=0x9,chassis=3,id=pci.3,bus=pcie.0,addr=0x1.0x1 \
--device pcie-root-port,port=0xa,chassis=4,id=pci.4,bus=pcie.0,addr=0x1.0x2 \
 -drive file=/dev/HostVG/QEMUGuest1,format=raw,if=none,id=drive-virtio-disk0 \
 -device virtio-blk-pci-transitional,scsi=off,bus=pci.2,addr=0x3,\
 drive=drive-virtio-disk0,id=virtio-disk0,bootindex=1 \
@@ -37,8 +36,8 @@  bus=pci.2,addr=0x1 \
 -netdev user,id=hostnet0 \
 -device virtio-net-pci-transitional,netdev=hostnet0,id=net0,\
 mac=00:11:22:33:44:55,bus=pci.2,addr=0x2 \
--device virtio-input-host-pci,id=input0,evdev=/dev/input/event1234,bus=pci.3,\
-addr=0x0 \
+-device virtio-input-host-pci-transitional,id=input0,\
+evdev=/dev/input/event1234,bus=pci.2,addr=0x7 \
 -device vhost-scsi-pci-transitional,wwpn=naa.5123456789abcde0,vhostfd=3,\
 id=hostdev0,bus=pci.2,addr=0x4 \
 -device virtio-balloon-pci-transitional,id=balloon0,bus=pci.2,addr=0x5 \
@@ -47,5 +46,5 @@  id=hostdev0,bus=pci.2,addr=0x4 \
 -sandbox on,obsolete=deny,elevateprivileges=deny,spawn=deny,\
 resourcecontrol=deny \
 -device vhost-vsock-pci-transitional,id=vsock0,guest-cid=4,vhostfd=6789,\
-bus=pci.2,addr=0x7 \
+bus=pci.2,addr=0x8 \
 -msg timestamp=on
diff --git a/tests/qemuxml2xmloutdata/virtio-transitional.xml b/tests/qemuxml2xmloutdata/virtio-transitional.xml
index 490b28368a..9fa9732c2d 100644
--- a/tests/qemuxml2xmloutdata/virtio-transitional.xml
+++ b/tests/qemuxml2xmloutdata/virtio-transitional.xml
@@ -39,11 +39,6 @@ 
       <target chassis='3' port='0x9'/>
       <address type='pci' domain='0x0000' bus='0x00' slot='0x01' function='0x1'/>
     </controller>
-    <controller type='pci' index='4' model='pcie-root-port'>
-      <model name='pcie-root-port'/>
-      <target chassis='4' port='0xa'/>
-      <address type='pci' domain='0x0000' bus='0x00' slot='0x01' function='0x2'/>
-    </controller>
     <filesystem type='mount' accessmode='passthrough' model='virtio-transitional'>
       <source dir='/export/fs1'/>
       <target dir='fs1'/>
@@ -56,7 +51,7 @@ 
     </interface>
     <input type='passthrough' bus='virtio' model='virtio-transitional'>
       <source evdev='/dev/input/event1234'/>
-      <address type='pci' domain='0x0000' bus='0x03' slot='0x00' function='0x0'/>
+      <address type='pci' domain='0x0000' bus='0x02' slot='0x07' function='0x0'/>
     </input>
     <input type='mouse' bus='ps2'/>
     <input type='keyboard' bus='ps2'/>
@@ -73,7 +68,7 @@ 
     </rng>
     <vsock model='virtio-transitional'>
       <cid auto='no' address='4'/>
-      <address type='pci' domain='0x0000' bus='0x02' slot='0x07' function='0x0'/>
+      <address type='pci' domain='0x0000' bus='0x02' slot='0x08' function='0x0'/>
     </vsock>
   </devices>
 </domain>