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 0E9751FF17A for ; Tue, 6 Aug 2024 14:22:07 +0200 (CEST) Received: from firstgate.proxmox.com (localhost [127.0.0.1]) by firstgate.proxmox.com (Proxmox) with ESMTP id 340691CEBD; Tue, 6 Aug 2024 14:22:08 +0200 (CEST) From: Dominik Csapak To: pve-devel@lists.proxmox.com Date: Tue, 6 Aug 2024 14:21:58 +0200 Message-Id: <20240806122203.2266054-2-d.csapak@proxmox.com> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20240806122203.2266054-1-d.csapak@proxmox.com> References: <20240806122203.2266054-1-d.csapak@proxmox.com> MIME-Version: 1.0 X-SPAM-LEVEL: Spam detection results: 0 AWL 0.014 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 RCVD_IN_VALIDITY_CERTIFIED_BLOCKED 0.001 ADMINISTRATOR NOTICE: The query to Validity was blocked. See https://knowledge.validity.com/hc/en-us/articles/20961730681243 for more information. RCVD_IN_VALIDITY_RPBL_BLOCKED 0.001 ADMINISTRATOR NOTICE: The query to Validity was blocked. See https://knowledge.validity.com/hc/en-us/articles/20961730681243 for more information. RCVD_IN_VALIDITY_SAFE_BLOCKED 0.001 ADMINISTRATOR NOTICE: The query to Validity was blocked. See https://knowledge.validity.com/hc/en-us/articles/20961730681243 for more information. SPF_HELO_NONE 0.001 SPF: HELO does not publish an SPF Record SPF_PASS -0.001 SPF: sender matches SPF record URIBL_BLOCKED 0.001 ADMINISTRATOR NOTICE: The query to URIBL was blocked. See http://wiki.apache.org/spamassassin/DnsBlocklists#dnsbl-block for more information. [sysfstools.pm] Subject: [pve-devel] [PATCH common 1/2] SysFSTools: handle new nvidia syfsapi as mdev 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" with kernel 6.8 NVIDIAs vGPU driver has a different api than the previous 'mediated devices'. Adapt our sysfcode to also recognize this for the 'mdev' paths and add another 'nvidia' property so we can detect this. Also parse the new api when they exist instead of the mediated devices. The biggest difference to the existing mdev api for our use is that the devices don't report all generally available devices, only the createable ones. So if a user wants to configure a VM, the selection is restricted by what may currently run on the GPU (depending ont the exact settings, e.g. mixed mode gpus where different models can be mixed on a single GPU; not the default though) We could overcome this, when we'd parse the general info from the 'nvidia-smi' tool, though I'm currently unsure if that interface is stable and intended to be parsed (there is no json output or similar AFAIK) Signed-off-by: Dominik Csapak --- best viewed with '-w' src/PVE/SysFSTools.pm | 65 ++++++++++++++++++++++++++++--------------- 1 file changed, 42 insertions(+), 23 deletions(-) diff --git a/src/PVE/SysFSTools.pm b/src/PVE/SysFSTools.pm index 8eb9f2e..25b2f31 100644 --- a/src/PVE/SysFSTools.pm +++ b/src/PVE/SysFSTools.pm @@ -112,6 +112,10 @@ sub lspci { if (-d "$devdir/mdev_supported_types") { $res->{mdev} = 1; + } elsif (-d "$devdir/nvidia") { + # nvidia driver for kernel 6.8 or higher + $res->{mdev} = 1; # for api compatibility + $res->{nvidia} = 1; } my $device_hash = $ids->{$vendor}->{devices}->{$device} // {}; @@ -159,31 +163,46 @@ sub get_mdev_types { my $types = []; - my $mdev_path = "$pcisysfs/devices/$id/mdev_supported_types"; - if (!-d $mdev_path) { - return $types; + my $dev_path = "$pcisysfs/devices/$id"; + my $mdev_path = "$dev_path/mdev_supported_types"; + my $nvidia_path = "$dev_path/nvidia/creatable_vgpu_types"; + if (-d $mdev_path) { + dir_glob_foreach($mdev_path, '[^\.].*', sub { + my ($type) = @_; + + my $type_path = "$mdev_path/$type"; + + my $available = int(file_read_firstline("$type_path/available_instances")); + my $description = PVE::Tools::file_get_contents("$type_path/description"); + + my $entry = { + type => $type, + description => $description, + available => $available, + }; + + my $name = file_read_firstline("$type_path/name"); + $entry->{name} = $name if defined($name); + + 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; + + push $types->@*, { + type => "nvidia-$id", # backwards compatibility + description => "", # TODO, read from xml/nvidia-smi ? + available => 1, + name => $name, + } + } } - dir_glob_foreach($mdev_path, '[^\.].*', sub { - my ($type) = @_; - - my $type_path = "$mdev_path/$type"; - - my $available = int(file_read_firstline("$type_path/available_instances")); - my $description = PVE::Tools::file_get_contents("$type_path/description"); - - my $entry = { - type => $type, - description => $description, - available => $available, - }; - - my $name = file_read_firstline("$type_path/name"); - $entry->{name} = $name if defined($name); - - push @$types, $entry; - }); - return $types; } -- 2.39.2 _______________________________________________ pve-devel mailing list pve-devel@lists.proxmox.com https://lists.proxmox.com/cgi-bin/mailman/listinfo/pve-devel