SysFSTools: allow longer pci domains

by default, there is only one pci domain ('0000'), but there are systems
where there are more, and they don't need to be exactly 4 characters
long (see [0]), so extend that regex to allow domains 4 characters or
longer

0: https://forum.proxmox.com/threads/problem-with-gpu-passthrough-in-a-virtual-machine.105720/

Signed-off-by: Dominik Csapak <d.csapak@proxmox.com>
This commit is contained in:
Dominik Csapak 2022-02-28 14:48:19 +01:00 committed by Thomas Lamprecht
parent b863860407
commit 6ac98ad562

View File

@ -8,7 +8,7 @@ use IO::File;
use PVE::Tools qw(file_read_firstline dir_glob_foreach); use PVE::Tools qw(file_read_firstline dir_glob_foreach);
my $pcisysfs = "/sys/bus/pci"; my $pcisysfs = "/sys/bus/pci";
my $pciregex = "([a-f0-9]{4}):([a-f0-9]{2}):([a-f0-9]{2})\.([a-f0-9])"; my $pciregex = "([a-f0-9]{4,}):([a-f0-9]{2}):([a-f0-9]{2})\.([a-f0-9])";
my $parse_pci_ids = sub { my $parse_pci_ids = sub {
my $ids = {}; my $ids = {};
@ -149,7 +149,7 @@ sub get_mdev_types {
my ($id) = @_; my ($id) = @_;
my $fullid = $id; my $fullid = $id;
if ($id !~ m/^[0-9a-fA-f]{4}:/) { if ($id !~ m/^[0-9a-fA-f]{4,}:/) {
$fullid = "0000:$id"; $fullid = "0000:$id";
} }
@ -300,11 +300,11 @@ sub pci_dev_group_bind_to_vfio {
} }
die "Cannot find vfio-pci module!\n" if !-d $vfio_basedir; die "Cannot find vfio-pci module!\n" if !-d $vfio_basedir;
$pciid = "0000:$pciid" if $pciid !~ m/^[0-9a-f]{4}:/; $pciid = "0000:$pciid" if $pciid !~ m/^[0-9a-f]{4,}:/;
# get IOMMU group devices # get IOMMU group devices
opendir(my $D, "$pcisysfs/devices/$pciid/iommu_group/devices/") || die "Cannot open iommu_group: $!\n"; opendir(my $D, "$pcisysfs/devices/$pciid/iommu_group/devices/") || die "Cannot open iommu_group: $!\n";
my @devs = grep /^[0-9a-f]{4}:/, readdir($D); my @devs = grep /^[0-9a-f]{4,}:/, readdir($D);
closedir($D); closedir($D);
foreach my $pciid (@devs) { foreach my $pciid (@devs) {
@ -323,7 +323,7 @@ sub pci_dev_group_bind_to_vfio {
sub pci_create_mdev_device { sub pci_create_mdev_device {
my ($pciid, $uuid, $type) = @_; my ($pciid, $uuid, $type) = @_;
$pciid = "0000:$pciid" if $pciid !~ m/^[0-9a-f]{4}:/; $pciid = "0000:$pciid" if $pciid !~ m/^[0-9a-f]{4,}:/;
my $basedir = "$pcisysfs/devices/$pciid"; my $basedir = "$pcisysfs/devices/$pciid";
my $mdev_dir = "$basedir/mdev_supported_types"; my $mdev_dir = "$basedir/mdev_supported_types";
@ -360,7 +360,7 @@ sub pci_create_mdev_device {
sub pci_cleanup_mdev_device { sub pci_cleanup_mdev_device {
my ($pciid, $uuid) = @_; my ($pciid, $uuid) = @_;
$pciid = "0000:$pciid" if $pciid !~ m/^[0-9a-f]{4}:/; $pciid = "0000:$pciid" if $pciid !~ m/^[0-9a-f]{4,}:/;
my $basedir = "$pcisysfs/devices/$pciid/$uuid"; my $basedir = "$pcisysfs/devices/$pciid/$uuid";