From 1e768f4d5d7e2ec7e764c06d62c111272b0c64b8 Mon Sep 17 00:00:00 2001 From: Wai Yee Wong Date: Mon, 12 Apr 2021 12:16:05 -0400 Subject: [PATCH] Get the correct XML record for a PIC device if it is one of the devices in an iommuGroup --- xCAT-server/lib/xcat/plugins/kvm.pm | 41 ++++++++++++++++++++++++++++- 1 file changed, 40 insertions(+), 1 deletion(-) diff --git a/xCAT-server/lib/xcat/plugins/kvm.pm b/xCAT-server/lib/xcat/plugins/kvm.pm index 89be54d85..8f5851ff0 100755 --- a/xCAT-server/lib/xcat/plugins/kvm.pm +++ b/xCAT-server/lib/xcat/plugins/kvm.pm @@ -814,13 +814,52 @@ sub build_xmldesc { } my $devhash = XMLin($devxml); + if (defined $devhash->{capability}->{type} and $devhash->{capability}->{type} =~ /pci/i) { my %tmphash; $tmphash{mode} = 'subsystem'; $tmphash{type} = $devhash->{capability}->{type}; $tmphash{managed} = "yes"; $tmphash{driver}->{name} = "vfio"; - $tmphash{source}->{address}->[0] = \%{ $devhash->{'capability'}->{'iommuGroup'}->{'address'} }; + + if (ref $devhash->{'capability'}->{'iommuGroup'}->{'address'} ne 'ARRAY') + { + # There is only one record of address. + + $tmphash{source}->{address}->[0] = \%{ $devhash->{'capability'}->{'iommuGroup'}->{'address'} }; + } + else + { + # There are multiple records of address. Extract the function portion of the PCI devname. + + my $numaddr; + my $tmpval; + my $devfunction; + my $tmpfunction; + + $devname =~ /pci_([0-9]*)_([0-9]*)_([0-9]*)_([0-9]*)/; + + $devfunction = $4; + + $numaddr = length (ref $devhash->{'capability'}->{'iommuGroup'}->{'address'}); + + for (my $i = 0; $i < $numaddr; $i++) + { + $tmpval = $devhash->{'capability'}->{'iommuGroup'}->{'address'}->[$i]->{'function'}; + + $tmpval =~ /0x([0-9]*)/; + + $tmpfunction = $1; + + # Compare the function portion of the PCI devname against that of the XML structure.:w + if ($devfunction eq $tmpfunction) + { + $tmphash{source}->{address}->[0] = \%{ $devhash->{'capability'}->{'iommuGroup'}->{'address'}->[$i] }; + last; + } + } + } + push(@prdevarray, \%tmphash); }