From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from firstgate.proxmox.com (firstgate.proxmox.com [212.224.123.68]) by lore.proxmox.com (Postfix) with ESMTPS id EE9AE1FF13C for ; Thu, 05 Mar 2026 10:17:27 +0100 (CET) Received: from firstgate.proxmox.com (localhost [127.0.0.1]) by firstgate.proxmox.com (Proxmox) with ESMTP id 880D01EC23; Thu, 5 Mar 2026 10:17:52 +0100 (CET) From: Dominik Csapak 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 Message-ID: <20260305091711.1221589-12-d.csapak@proxmox.com> X-Mailer: git-send-email 2.47.3 In-Reply-To: <20260305091711.1221589-1-d.csapak@proxmox.com> References: <20260305091711.1221589-1-d.csapak@proxmox.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-SPAM-LEVEL: Spam detection results: 0 AWL -0.963 Adjusted score from AWL reputation of From: address BAYES_00 -1.9 Bayes spam probability is 0 to 1% DMARC_MISSING 0.1 Missing DMARC policy KAM_DMARC_STATUS 0.01 Test Rule for DKIM or SPF Failure with Strict Alignment KAM_MAILER 2 Automated Mailer Tag Left in Email SPF_HELO_NONE 0.001 SPF: HELO does not publish an SPF Record SPF_PASS -0.001 SPF: sender matches SPF record Message-ID-Hash: MW6S2HJ5OXUMPGV57GLIHSQWR3XOXUUF X-Message-ID-Hash: MW6S2HJ5OXUMPGV57GLIHSQWR3XOXUUF X-MailFrom: d.csapak@proxmox.com X-Mailman-Rule-Misses: dmarc-mitigation; no-senders; approved; loop; banned-address; emergency; member-moderation; nonmember-moderation; administrivia; implicit-dest; max-recipients; max-size; news-moderation; no-subject; digests; suspicious-header X-Mailman-Version: 3.3.10 Precedence: list List-Id: Proxmox VE development discussion List-Help: List-Owner: List-Post: List-Subscribe: List-Unsubscribe: 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 --- 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