SysFSTools: handle new nvidia syfsapi as mdev

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 <d.csapak@proxmox.com>
Tested-by: Christoph Heiss <c.heiss@proxmox.com>
Reviewed-by: Christoph Heiss <c.heiss@proxmox.com>
This commit is contained in:
Dominik Csapak 2024-08-06 14:21:58 +02:00 committed by Thomas Lamprecht
parent eff59571be
commit dc023d60c5

View File

@ -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,11 +163,10 @@ 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) = @_;
@ -183,6 +186,22 @@ 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;
push $types->@*, {
type => "nvidia-$id", # backwards compatibility
description => "", # TODO, read from xml/nvidia-smi ?
available => 1,
name => $name,
}
}
}
return $types;
}