From: Christoph Heiss <c.heiss@proxmox.com>
To: pve-devel@lists.proxmox.com
Subject: [pve-devel] [PATCH common 4/4] sysfs: use new PVE::RS::VFIO::Nvidia module to retrieve vGPU info
Date: Tue, 20 Jan 2026 14:13:12 +0100 [thread overview]
Message-ID: <20260120131319.949986-5-c.heiss@proxmox.com> (raw)
In-Reply-To: <20260120131319.949986-1-c.heiss@proxmox.com>
pci_dev_physfn_id() is used to obtain the parent device of a virtual
function, i.e. the physical function.
Needed for retrieving information about Nvidia vGPU devices via
proxmox-ve-vfio, as libnvidia-ml functions only work with physical
functions.
Signed-off-by: Christoph Heiss <c.heiss@proxmox.com>
---
src/PVE/SysFSTools.pm | 45 ++++++++++++++++++++++++++++++-------------
1 file changed, 32 insertions(+), 13 deletions(-)
diff --git a/src/PVE/SysFSTools.pm b/src/PVE/SysFSTools.pm
index a00fbcb..89e57b9 100644
--- a/src/PVE/SysFSTools.pm
+++ b/src/PVE/SysFSTools.pm
@@ -4,8 +4,10 @@ use strict;
use warnings;
use IO::File;
+use File::Basename;
use PVE::Tools qw(file_read_firstline dir_glob_foreach);
+use PVE::RS::VFIO::Nvidia;
my $pcisysfs = "/sys/bus/pci";
my $domainregex = "[a-f0-9]{4,}";
@@ -157,6 +159,7 @@ sub lspci {
# type => 'FooType_1',
# description => "a longer description with custom format\nand newlines",
# available => 5,
+# name => "human-readable name of mdev"
# },
# ...
# ]
@@ -170,7 +173,7 @@ sub get_mdev_types {
my $dev_path = "$pcisysfs/devices/$id";
my $mdev_path = "$dev_path/mdev_supported_types";
- my $nvidia_path = "$dev_path/nvidia/creatable_vgpu_types";
+ my $nvidia_path = "$dev_path/nvidia";
if (-d $mdev_path) {
dir_glob_foreach(
$mdev_path,
@@ -195,20 +198,20 @@ sub get_mdev_types {
push @$types, $entry;
},
);
- } elsif (-f $nvidia_path) {
- my $creatable = PVE::Tools::file_get_contents($nvidia_path);
- for my $line (split("\n", $creatable)) {
- next if $line =~ m/^ID/; # header
- next if $line !~ m/^(.*?)\s*:\s*(.*)$/;
- my $id = $1;
- my $name = $2;
+ } elsif (-d $nvidia_path) {
+ $id = pci_dev_physfn_id($id);
+ my $nvtypes = eval { PVE::RS::VFIO::Nvidia::creatable_vgpu_types_for_dev($id); };
- push $types->@*, {
- type => "nvidia-$id", # backwards compatibility
- description => "", # TODO, read from xml/nvidia-smi ?
+ if (my $err = $@) {
+ die "failed to get creatable Nvidia vGPU types for $id: $err\n";
+ } else {
+ my @mapped = map { {
+ type => "nvidia-$_->{id}", # backwards compatibility
available => 1,
- name => $name,
- };
+ description => $_->{description},
+ name => $_->{name},
+ } } @$nvtypes;
+ $types = \@mapped;
}
}
@@ -409,6 +412,22 @@ sub pci_create_mdev_device {
return undef;
}
+# Returns the PCI bus id of the physical function (IOW, parent device) of the
+# given device. If the device does not have a parent physical function, returns
+# the given ID unchanged.
+sub pci_dev_physfn_id {
+ my ($id) = @_;
+
+ $id = normalize_pci_id($id);
+ my $devpath = "$pcisysfs/devices/$id";
+
+ if (-d "$devpath/physfn") {
+ return basename(readlink("$devpath/physfn"));
+ } else {
+ return $id;
+ }
+}
+
# encode the hostpci index and vmid into the uuid
sub generate_mdev_uuid {
my ($vmid, $index) = @_;
--
2.52.0
_______________________________________________
pve-devel mailing list
pve-devel@lists.proxmox.com
https://lists.proxmox.com/cgi-bin/mailman/listinfo/pve-devel
next prev parent reply other threads:[~2026-01-20 13:13 UTC|newest]
Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-01-20 13:13 [pve-devel] [PATCH proxmox-{ve, perl}-rs/common 0/4] use native libnvidia-ml library for " Christoph Heiss
2026-01-20 13:13 ` [pve-devel] [PATCH proxmox-ve-rs 1/4] vfio: add crate for interacting with vfio host devices Christoph Heiss
2026-01-20 13:13 ` [pve-devel] [PATCH proxmox-ve-rs 2/4] vfio: add rust-native interface for accessing NVIDIA vGPU info Christoph Heiss
2026-01-20 13:13 ` [pve-devel] [PATCH proxmox-perl-rs 3/4] pve: add bindings for proxmox-ve-vfio Christoph Heiss
2026-01-20 13:13 ` Christoph Heiss [this message]
2026-01-20 15:00 ` [pve-devel] [PATCH common 4/4] sysfs: use new PVE::RS::VFIO::Nvidia module to retrieve vGPU info Thomas Lamprecht
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20260120131319.949986-5-c.heiss@proxmox.com \
--to=c.heiss@proxmox.com \
--cc=pve-devel@lists.proxmox.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.