Skip to content

Add SubsystemVendor and SubsystemDevice fields to NvidiaPCIDevice - #90

Merged
karthikvetrivel merged 2 commits into
NVIDIA:mainfrom
karthikvetrivel:nvpci-subsystem-ids
Jun 29, 2026
Merged

Add SubsystemVendor and SubsystemDevice fields to NvidiaPCIDevice#90
karthikvetrivel merged 2 commits into
NVIDIA:mainfrom
karthikvetrivel:nvpci-subsystem-ids

Conversation

@karthikvetrivel

@karthikvetrivel karthikvetrivel commented May 28, 2026

Copy link
Copy Markdown
Member

Description

Adds SubsystemVendor and SubsystemDevice (uint16) to NvidiaPCIDevice.

These fields are populated during PCI discovery from:

  • /sys/bus/pci/devices/<addr>/subsystem_vendor
  • /sys/bus/pci/devices/<addr>/subsystem_device

Problem

Some NVIDIA devices share the same PCI vendor/device IDs but differ by subsystem IDs. Exposing these fields allows downstream consumers to disambiguate devices during matching/filtering.

Unblocks NVIDIA/mig-parted#343.

Tested

I added two new tests.

  1. TestNvpciSubsystem creates a mock A100 device at 0000:80:05.1, calls GetGPUs(), and verifies the new fields are populated from the mock sysfs files:
SubsystemVendor == 0x10de
SubsystemDevice == 0x16c0
  1. TestNvpciSubsystemMissing creates the same mock device, then removes the mock subsystem_vendor and subsystem_device files. It calls GetGPUs() and verifies discovery still succeeds, with both new fields left at 0.

Signed-off-by: Karthik Vetrivel <kvetrivel@nvidia.com>
@karthikvetrivel
karthikvetrivel marked this pull request as ready for review June 22, 2026 13:53
Comment thread pkg/nvpci/nvpci.go Outdated
Comment thread pkg/nvpci/nvpci_test.go

@JunAr7112 JunAr7112 left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM Karthik. Is the device filter matching mentioned in the original issue part of the scope for this PR?

Signed-off-by: Karthik Vetrivel <kvetrivel@nvidia.com>
@karthikvetrivel

Copy link
Copy Markdown
Member Author

@JunAr7112 Thanks! This PR needs to land before integrating this change in mig-parted.

@rajathagasthya rajathagasthya left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM!

@karthikvetrivel
karthikvetrivel merged commit fce45db into NVIDIA:main Jun 29, 2026
4 checks passed
Comment thread pkg/nvpci/nvpci.go
case os.IsNotExist(err):
p.logger.Warningf("subsystem_device file not found for %s", address)
default:
return nil, fmt.Errorf("unable to read PCI subsystem device id for %s: %v", address, err)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
return nil, fmt.Errorf("unable to read PCI subsystem device id for %s: %v", address, err)
return nil, fmt.Errorf("unable to read PCI subsystem device id for %s: %w", address, err)

Comment thread pkg/nvpci/nvpci.go
subsystemDeviceStr := strings.TrimSpace(string(subsystemDevice))
subsystemDeviceID, err = strconv.ParseUint(subsystemDeviceStr, 0, 16)
if err != nil {
return nil, fmt.Errorf("unable to convert subsystem device string to uint16: %v", subsystemDeviceStr)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
return nil, fmt.Errorf("unable to convert subsystem device string to uint16: %v", subsystemDeviceStr)
return nil, fmt.Errorf("unable to convert subsystem device string %s to uint16: %w", subsystemDeviceStr, err)

Comment thread pkg/nvpci/nvpci.go
subsystemVendorStr := strings.TrimSpace(string(subsystemVendor))
subsystemVendorID, err = strconv.ParseUint(subsystemVendorStr, 0, 16)
if err != nil {
return nil, fmt.Errorf("unable to convert subsystem vendor string to uint16: %v", subsystemVendorStr)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
return nil, fmt.Errorf("unable to convert subsystem vendor string to uint16: %v", subsystemVendorStr)
return nil, fmt.Errorf("unable to convert subsystem vendor string %s to uint16: %w", subsystemVendorStr, err)

Comment thread pkg/nvpci/nvpci.go
case os.IsNotExist(err):
p.logger.Warningf("subsystem_vendor file not found for %s", address)
default:
return nil, fmt.Errorf("unable to read PCI subsystem vendor id for %s: %v", address, err)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
return nil, fmt.Errorf("unable to read PCI subsystem vendor id for %s: %v", address, err)
return nil, fmt.Errorf("unable to read PCI subsystem vendor id for %s: %w", address, err)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants