[pve-devel] [PATCH qemu-server 2/2] hostpci: always check if device exists
Dominik Csapak
d.csapak at proxmox.com
Fri Dec 6 14:29:30 CET 2019
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 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 at proxmox.com>
---
PVE/QemuServer.pm | 11 ++++-------
test/cfg2cmd/i440fx-win10-hostpci.conf.cmd | 2 +-
test/cfg2cmd/q35-linux-hostpci.conf.cmd | 12 ++++++------
test/cfg2cmd/q35-win10-hostpci.conf.cmd | 6 +++---
4 files changed, 14 insertions(+), 17 deletions(-)
diff --git a/PVE/QemuServer.pm b/PVE/QemuServer.pm
index 0d0e610..82613aa 100644
--- a/PVE/QemuServer.pm
+++ b/PVE/QemuServer.pm
@@ -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();
diff --git a/test/cfg2cmd/i440fx-win10-hostpci.conf.cmd b/test/cfg2cmd/i440fx-win10-hostpci.conf.cmd
index 2bc1eef..bda7f63 100644
--- a/test/cfg2cmd/i440fx-win10-hostpci.conf.cmd
+++ b/test/cfg2cmd/i440fx-win10-hostpci.conf.cmd
@@ -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' \
diff --git a/test/cfg2cmd/q35-linux-hostpci.conf.cmd b/test/cfg2cmd/q35-linux-hostpci.conf.cmd
index 6fde1c6..ca5dfac 100644
--- a/test/cfg2cmd/q35-linux-hostpci.conf.cmd
+++ b/test/cfg2cmd/q35-linux-hostpci.conf.cmd
@@ -23,14 +23,14 @@
-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' \
diff --git a/test/cfg2cmd/q35-win10-hostpci.conf.cmd b/test/cfg2cmd/q35-win10-hostpci.conf.cmd
index cd004d9..9531d7d 100644
--- a/test/cfg2cmd/q35-win10-hostpci.conf.cmd
+++ b/test/cfg2cmd/q35-win10-hostpci.conf.cmd
@@ -24,10 +24,10 @@
-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' \
--
2.20.1
More information about the pve-devel
mailing list