[nvmdev] fix bug in construction of parent PCI device

When constructing NvidiaPCIDevice objects for each 'parent' device in the
'/sys/class/mdev_bus' directory, use the default PCI devices root
'/sys/bus/pci/devices'. All devices in '/sys/class/mdev_bus' will have
a corresponding directory at '/sys/bus/pci/devices'.

Starting with bf3f431fc8
the construction of the NvidiaPCIDevice object will fail when attempting to detect the physfn.
When SRIOV is used, all the VFs will show up under '/sys/class/mdev_bus', but the physfn will
only show up under '/sys/bus/pci/devices'.

Signed-off-by: Christopher Desiniotis <cdesiniotis@nvidia.com>
This commit is contained in:
Christopher Desiniotis 2024-07-15 12:06:52 -07:00
parent 167d4d5546
commit 44a5440a0a
No known key found for this signature in database
GPG Key ID: 603C8E544D789A89

View File

@ -242,7 +242,8 @@ func (m mdev) iommuGroup() (int, error) {
// NewParentDevice constructs a ParentDevice.
func NewParentDevice(devicePath string) (*ParentDevice, error) {
nvdevice, err := newNvidiaPCIDeviceFromPath(devicePath)
address := filepath.Base(devicePath)
nvdevice, err := nvpci.New().GetGPUByPciBusID(address)
if err != nil {
return nil, fmt.Errorf("failed to construct NVIDIA PCI device: %v", err)
}
@ -370,12 +371,3 @@ func (p *ParentDevice) GetAvailableMDEVInstances(mdevType string) (int, error) {
return availableInstances, nil
}
// newNvidiaPCIDeviceFromPath constructs an NvidiaPCIDevice for the specified device path.
func newNvidiaPCIDeviceFromPath(devicePath string) (*nvpci.NvidiaPCIDevice, error) {
root := filepath.Dir(devicePath)
address := filepath.Base(devicePath)
return nvpci.New(
nvpci.WithPCIDevicesRoot(root),
).GetGPUByPciBusID(address)
}