From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from firstgate.proxmox.com (firstgate.proxmox.com [IPv6:2a01:7e0:0:424::9]) by lore.proxmox.com (Postfix) with ESMTPS id A950B1FF15E for ; Tue, 20 Jan 2026 14:13:39 +0100 (CET) Received: from firstgate.proxmox.com (localhost [127.0.0.1]) by firstgate.proxmox.com (Proxmox) with ESMTP id B16FEFFBB; Tue, 20 Jan 2026 14:13:47 +0100 (CET) From: Christoph Heiss To: pve-devel@lists.proxmox.com Date: Tue, 20 Jan 2026 14:13:12 +0100 Message-ID: <20260120131319.949986-5-c.heiss@proxmox.com> X-Mailer: git-send-email 2.52.0 In-Reply-To: <20260120131319.949986-1-c.heiss@proxmox.com> References: <20260120131319.949986-1-c.heiss@proxmox.com> MIME-Version: 1.0 X-Bm-Milter-Handled: 55990f41-d878-4baa-be0a-ee34c49e34d2 X-Bm-Transport-Timestamp: 1768914769844 X-SPAM-LEVEL: Spam detection results: 0 AWL -0.948 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 Subject: [pve-devel] [PATCH common 4/4] sysfs: use new PVE::RS::VFIO::Nvidia module to retrieve vGPU info X-BeenThere: pve-devel@lists.proxmox.com X-Mailman-Version: 2.1.29 Precedence: list List-Id: Proxmox VE development discussion List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Reply-To: Proxmox VE development discussion Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Errors-To: pve-devel-bounces@lists.proxmox.com Sender: "pve-devel" 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 --- 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