From: Dominik Csapak <d.csapak@proxmox.com>
To: pve-devel@lists.proxmox.com
Subject: [PATCH qemu-server 2/2] pci: mdev: use PVE::RS::NVML for nvidia mdev information
Date: Thu, 5 Mar 2026 10:16:55 +0100 [thread overview]
Message-ID: <20260305091711.1221589-12-d.csapak@proxmox.com> (raw)
In-Reply-To: <20260305091711.1221589-1-d.csapak@proxmox.com>
This gets us the missing description that used to be in sysfs.
In case this is an SR-IOV virtual function, we have to get the physical
device first since only that is a valid device for querying with NVML.
'pci_dev_physfn_id' is only used here currently so it's a local sub, but
if we need it in more places, a good place could be 'PVE::SysFSTools' or
'PVE::QemuServer::PCI'.
Signed-off-by: Dominik Csapak <d.csapak@proxmox.com>
---
src/PVE/QemuServer/PCI/Mdev.pm | 45 ++++++++++++++++++++++++----------
1 file changed, 32 insertions(+), 13 deletions(-)
diff --git a/src/PVE/QemuServer/PCI/Mdev.pm b/src/PVE/QemuServer/PCI/Mdev.pm
index 3b42ce2d..51dca474 100644
--- a/src/PVE/QemuServer/PCI/Mdev.pm
+++ b/src/PVE/QemuServer/PCI/Mdev.pm
@@ -2,11 +2,28 @@ package PVE::QemuServer::PCI::Mdev;
use v5.36;
+use File::Basename;
+
+use PVE::RS::NVML;
use PVE::SysFSTools;
use PVE::File qw(file_read_first_line dir_glob_foreach file_get_contents);
my $pcisysfs = "/sys/bus/pci";
+# 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.
+my sub pci_dev_physfn_id($id) {
+ $id = PVE::SysFSTools::normalize_pci_id($id);
+ my $devpath = "$pcisysfs/devices/$id";
+
+ if (-d "$devpath/physfn") {
+ return basename(readlink("$devpath/physfn"));
+ } else {
+ return $id;
+ }
+}
+
sub generate_mdev_uuid($vmid, $index) {
return sprintf("%08d-0000-0000-0000-%012d", $index, $vmid);
}
@@ -18,6 +35,7 @@ sub generate_mdev_uuid($vmid, $index) {
# type => 'FooType_1',
# description => "a longer description with custom format\nand newlines",
# available => 5,
+# name => "human readable name for the type",
# },
# ...
# ]
@@ -55,19 +73,20 @@ sub get_mdev_types($id) {
},
);
} 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;
-
- push $types->@*, {
- type => "nvidia-$id", # backwards compatibility
- description => "", # TODO, read from xml/nvidia-smi ?
- available => 1,
- name => $name,
- };
+ my $physfn = pci_dev_physfn_id($id);
+ my $creatable = eval { PVE::RS::NVML::creatable_vgpu_types_for_dev($physfn) };
+ die "failed to query NVIDIA vGPU types for $id - $@\n" if $@;
+
+ for my $type ($creatable->@*) {
+ my $nvidia_id = $type->{id};
+ my $name = $type->{name};
+ push $types->@*,
+ {
+ type => "nvidia-$nvidia_id",
+ description => $type->{description},
+ available => 1,
+ name => $name,
+ };
}
}
--
2.47.3
next prev parent reply other threads:[~2026-03-05 9:17 UTC|newest]
Thread overview: 14+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-03-05 9:16 [PATCH common/debcargo-conf/manager/proxmox-perl-rs/qemu-server 00/13] use NVML for vGPU info querying Dominik Csapak
2026-03-05 9:16 ` [PATCH debcargo-conf 1/8] nvml-wrapper-sys: Update to 0.9.0 Dominik Csapak
2026-03-05 9:16 ` [PATCH debcargo-conf 2/8] nvml-wrapper-sys: release 0.9.0-1 Dominik Csapak
2026-03-05 9:16 ` [PATCH debcargo-conf 3/8] nvml-wrapper: Update to 0.11.0 Dominik Csapak
2026-03-05 9:16 ` [PATCH debcargo-conf 4/8] nvml-wrapper: release 0.11.0-1 Dominik Csapak
2026-03-05 9:16 ` [PATCH debcargo-conf 5/8] nvml-wrapper: Update to 0.12.0 Dominik Csapak
2026-03-05 9:16 ` [PATCH debcargo-conf 6/8] nvml-wrapper: add patch for vgpu ids Dominik Csapak
2026-03-05 9:16 ` [PATCH debcargo-conf 7/8] backport nvml-wrapper-sys 0.9.0-1 Dominik Csapak
2026-03-05 9:16 ` [PATCH debcargo-conf 8/8] backport nvml-wrapper 0.12.0-1 Dominik Csapak
2026-03-05 9:16 ` [PATCH proxmox-perl-rs 1/1] pve: add binding for accessing vgpu info Dominik Csapak
2026-03-05 9:16 ` [PATCH qemu-server 1/2] pci: move mdev related code to own module Dominik Csapak
2026-03-05 9:16 ` Dominik Csapak [this message]
2026-03-05 9:16 ` [PATCH manager 1/1] api: hardware: pci: use NVML for querying mdev information Dominik Csapak
2026-03-05 9:16 ` [PATCH common 1/1] sysfs tools: remove moved code Dominik Csapak
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=20260305091711.1221589-12-d.csapak@proxmox.com \
--to=d.csapak@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.