]> git.proxmox.com Git - qemu-server.git/commitdiff
fix #2510: hostpci: always check if device exists
authorDominik Csapak <d.csapak@proxmox.com>
Mon, 9 Dec 2019 09:10:04 +0000 (10:10 +0100)
committerThomas Lamprecht <t.lamprecht@proxmox.com>
Mon, 9 Dec 2019 10:30:14 +0000 (11:30 +0100)
if the user set a device as hostpci with the 'shorthand' syntax:

hostpciX: 00:12

we ignored it on starting and showcmd and continued.
Since the user explicitly wanted to passthrough a device, we now check
if there is actually a device with that id

for explicitly configured devices (00:12.1), we did not check if it exists,
but the kvm call failed with a non-obvious error message

now we always call 'lspci' from SysFSTools to check if it actually exists,
and fail if not. With this, we can drop the workaround for adding
'0000' if no domain was given, since lspci does it already for us

this fixes #2510, an issue with using mediated devices where the users did not have
the domain in the config, since we forgot to add the default domain there

the only issue with this patch is that it changes the behaviour of
'showcmd' slightly, as in now, we die if the device was explicitly
given, but did not exists (we showed the commandline, now we fail)

this also slightly changes the commandline for qemu (adding always
the domain), which is not a problem since we cannot live migrate
or snapshot such vms, but we have to adapt the tests

Signed-off-by: Dominik Csapak <d.csapak@proxmox.com>
PVE/QemuServer.pm
test/cfg2cmd/i440fx-win10-hostpci.conf.cmd
test/cfg2cmd/q35-linux-hostpci.conf.cmd
test/cfg2cmd/q35-win10-hostpci.conf.cmd

index 76146ca22f43d5ae31e60d9aa77d02d53f8625cd..6267cae09538413f2b014c8a80d94e9c508e5da3 100644 (file)
@@ -2246,13 +2246,11 @@ sub parse_hostpci {
     my @idlist = split(/;/, $res->{host});
     delete $res->{host};
     foreach my $id (@idlist) {
-       if ($id =~ m/\./) { # full id 00:00.1
-           push @{$res->{pciid}}, {
-               id => $id,
-           };
-       } else { # partial id 00:00
-           $res->{pciid} = PVE::SysFSTools::lspci($id);
+       my $devs = PVE::SysFSTools::lspci($id);
+       if (!scalar(@$devs)) {
+           die "no pci device found for '$id'\n";
        }
+       push @{$res->{pciid}}, @$devs;
     }
     return $res;
 }
@@ -5369,7 +5367,6 @@ sub vm_start {
          my $pcidevices = $d->{pciid};
          foreach my $pcidevice (@$pcidevices) {
                my $pciid = $pcidevice->{id};
-               $pciid = "0000:$pciid" if $pciid !~ m/^[0-9a-f]{4}:/;
 
                my $info = PVE::SysFSTools::pci_device_info("$pciid");
                die "IOMMU not present\n" if !PVE::SysFSTools::check_iommu_support();
index 2bc1eefab7d077ba86afdd2b63ccf56fee9ba9c5..bda7f630902b9ccbe75cf9d2fa91dfaa857faa42 100644 (file)
@@ -26,7 +26,7 @@
   -device 'vmgenid,guid=54d1c06c-8f5b-440f-b5b2-6eab1380e13d' \
   -device 'piix3-usb-uhci,id=uhci,bus=pci.0,addr=0x1.0x2' \
   -device 'usb-tablet,id=tablet,bus=uhci.0,port=1' \
-  -device 'vfio-pci,host=0f:f2.0,id=hostpci0,bus=pci.0,addr=0x10' \
+  -device 'vfio-pci,host=0000:0f:f2.0,id=hostpci0,bus=pci.0,addr=0x10' \
   -device 'VGA,id=vga,bus=pci.0,addr=0x2' \
   -device 'virtio-balloon-pci,id=balloon0,bus=pci.0,addr=0x3' \
   -iscsi 'initiator-name=iqn.1993-08.org.debian:01:aabbccddeeff' \
index 6fde1c6f2c45d5edce172b1170dbb96a0a455bf9..ca5dfac6bcb43584a04b3daa1b434bd544220b38 100644 (file)
   -device 'vmgenid,guid=54d1c06c-8f5b-440f-b5b2-6eab1380e13d' \
   -readconfig /usr/share/qemu-server/pve-q35-4.0.cfg \
   -device 'usb-tablet,id=tablet,bus=ehci.0,port=1' \
-  -device 'vfio-pci,host=00:ff.1,id=hostpci0,bus=pci.0,addr=0x10' \
-  -device 'vfio-pci,host=d0:13.0,id=hostpci1,bus=ich9-pcie-port-2,addr=0x0' \
-  -device 'vfio-pci,host=00:f4.0,id=hostpci2,bus=pci.0,addr=0x1b' \
-  -device 'vfio-pci,host=d0:15.1,id=hostpci3,bus=ich9-pcie-port-4,addr=0x0' \
+  -device 'vfio-pci,host=0000:00:ff.1,id=hostpci0,bus=pci.0,addr=0x10' \
+  -device 'vfio-pci,host=0000:d0:13.0,id=hostpci1,bus=ich9-pcie-port-2,addr=0x0' \
+  -device 'vfio-pci,host=0000:00:f4.0,id=hostpci2,bus=pci.0,addr=0x1b' \
+  -device 'vfio-pci,host=0000:d0:15.1,id=hostpci3,bus=ich9-pcie-port-4,addr=0x0' \
   -device 'pcie-root-port,id=ich9-pcie-port-5,addr=10.0,x-speed=16,x-width=32,multifunction=on,bus=pcie.0,port=5,chassis=5' \
-  -device 'vfio-pci,host=d0:17.0,id=hostpci4,bus=ich9-pcie-port-5,addr=0x0,rombar=0' \
+  -device 'vfio-pci,host=0000:d0:17.0,id=hostpci4,bus=ich9-pcie-port-5,addr=0x0,rombar=0' \
   -device 'pcie-root-port,id=ich9-pcie-port-8,addr=10.3,x-speed=16,x-width=32,multifunction=on,bus=pcie.0,port=8,chassis=8' \
-  -device 'vfio-pci,host=d0:15.1,id=hostpci7,bus=ich9-pcie-port-8,addr=0x0' \
+  -device 'vfio-pci,host=0000:d0:15.1,id=hostpci7,bus=ich9-pcie-port-8,addr=0x0' \
   -device 'VGA,id=vga,bus=pcie.0,addr=0x1' \
   -device 'virtio-balloon-pci,id=balloon0,bus=pci.0,addr=0x3' \
   -iscsi 'initiator-name=iqn.1993-08.org.debian:01:aabbccddeeff' \
index cd004d95031352790786123538e4df2b5984b1e0..9531d7d92917f2182cb15ac484cdb25d26376068 100644 (file)
   -device 'vmgenid,guid=54d1c06c-8f5b-440f-b5b2-6eab1380e13d' \
   -readconfig /usr/share/qemu-server/pve-q35-4.0.cfg \
   -device 'usb-tablet,id=tablet,bus=ehci.0,port=1' \
-  -device 'vfio-pci,host=f0:42.0,id=hostpci0,bus=pci.0,addr=0x10' \
-  -device 'vfio-pci,host=f0:43.0,id=hostpci1,bus=ich9-pcie-port-2,addr=0x0' \
+  -device 'vfio-pci,host=0000:f0:42.0,id=hostpci0,bus=pci.0,addr=0x10' \
+  -device 'vfio-pci,host=0000:f0:43.0,id=hostpci1,bus=ich9-pcie-port-2,addr=0x0' \
   -device 'pcie-root-port,id=ich9-pcie-port-5,addr=10.0,x-speed=16,x-width=32,multifunction=on,bus=pcie.0,port=5,chassis=5' \
-  -device 'vfio-pci,host=00:43.1,id=hostpci4,bus=ich9-pcie-port-5,addr=0x0' \
+  -device 'vfio-pci,host=0000:00:43.1,id=hostpci4,bus=ich9-pcie-port-5,addr=0x0' \
   -device 'VGA,id=vga,bus=pcie.0,addr=0x1' \
   -device 'virtio-balloon-pci,id=balloon0,bus=pci.0,addr=0x3' \
   -iscsi 'initiator-name=iqn.1993-08.org.debian:01:aabbccddeeff' \