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 C88031FF13E for ; Fri, 23 Jan 2026 14:26:08 +0100 (CET) Received: from firstgate.proxmox.com (localhost [127.0.0.1]) by firstgate.proxmox.com (Proxmox) with ESMTP id 998CED9DA; Fri, 23 Jan 2026 14:26:16 +0100 (CET) From: Dominik Csapak To: pve-devel@lists.proxmox.com Date: Fri, 23 Jan 2026 14:25:48 +0100 Message-ID: <20260123132611.974310-3-d.csapak@proxmox.com> X-Mailer: git-send-email 2.47.3 In-Reply-To: <20260123132611.974310-1-d.csapak@proxmox.com> References: <20260123132611.974310-1-d.csapak@proxmox.com> MIME-Version: 1.0 X-SPAM-LEVEL: Spam detection results: 0 AWL -0.970 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 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 Subject: [pve-devel] [PATCH qemu-server v2 1/2] pci: factor 'prepare_pci_devices' out to PVE::QemuServer::PCI module 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" only slight change to the logic here was to return a uuid from an mdev in any case if we need it, and overwrite it in vm_start_nolock with the one from smbios1 if possible, instead of doing it the other way round. This was necessary since we don't have access to parse_smbios1 in the PCI module. Signed-off-by: Dominik Csapak --- new in v2 src/PVE/QemuServer.pm | 45 +++++++-------------------------------- src/PVE/QemuServer/PCI.pm | 45 +++++++++++++++++++++++++++++++++++++++ 2 files changed, 53 insertions(+), 37 deletions(-) diff --git a/src/PVE/QemuServer.pm b/src/PVE/QemuServer.pm index 7a0a2606..6c9fd22a 100644 --- a/src/PVE/QemuServer.pm +++ b/src/PVE/QemuServer.pm @@ -5633,45 +5633,16 @@ sub vm_start_nolock { push $cmd->@*, $state_cmdline->@*; - for my $device (values $pci_devices->%*) { - next if $device->{mdev}; # we don't reserve for mdev devices - push $pci_reserve_list->@*, map { $_->{id} } $device->{ids}->@*; - } - - # reserve all PCI IDs before actually doing anything with them - PVE::QemuServer::PCI::reserve_pci_usage($pci_reserve_list, $vmid, $start_timeout); - - my $uuid; - for my $id (sort keys %$pci_devices) { - my $d = $pci_devices->{$id}; - my ($index) = ($id =~ m/^hostpci(\d+)$/); - - my $chosen_mdev; - for my $dev ($d->{ids}->@*) { - my $info = - eval { PVE::QemuServer::PCI::prepare_pci_device($vmid, $dev->{id}, $index, $d) }; - if ($d->{mdev} || $d->{nvidia}) { - warn $@ if $@; - $chosen_mdev = $info; - last if $chosen_mdev; # if successful, we're done - } else { - die $@ if $@; - } - } - - next if !$d->{mdev} && !$d->{nvidia}; - die "could not create mediated device\n" if !defined($chosen_mdev); + ($pci_reserve_list, my $uuid) = + PVE::QemuServer::PCI::prepare_pci_devices($conf, $vmid, $pci_devices, $start_timeout); - # nvidia grid needs the uuid of the mdev as qemu parameter - if (!defined($uuid) && $chosen_mdev->{vendor} =~ m/^(0x)?10de$/) { - if (defined($conf->{smbios1})) { - my $smbios_conf = parse_smbios1($conf->{smbios1}); - $uuid = $smbios_conf->{uuid} if defined($smbios_conf->{uuid}); - } - $uuid = PVE::QemuServer::PCI::generate_mdev_uuid($vmid, $index) - if !defined($uuid); - } + # uuid for nvidia vgpu + # prefer the smbios1 uuid if we have and need it + if (defined($uuid) && defined($conf->{smbios1})) { + my $smbios_conf = parse_smbios1($conf->{smbios1}); + $uuid = $smbios_conf->{uuid} if defined($smbios_conf->{uuid}); } + push @$cmd, '-uuid', $uuid if defined($uuid); }; if (my $err = $@) { diff --git a/src/PVE/QemuServer/PCI.pm b/src/PVE/QemuServer/PCI.pm index c9cf8de0..f778c60f 100644 --- a/src/PVE/QemuServer/PCI.pm +++ b/src/PVE/QemuServer/PCI.pm @@ -736,6 +736,51 @@ sub print_hostpci_devices { return ($kvm_off, $gpu_passthrough, $legacy_igd, $pci_devices); } +sub prepare_pci_devices { + my ($conf, $vmid, $pci_devices, $start_timeout) = @_; + + my $pci_reserve_list = []; + my $uuid; + + for my $device (values $pci_devices->%*) { + next if $device->{mdev}; # we don't reserve for mdev devices + push $pci_reserve_list->@*, map { $_->{id} } $device->{ids}->@*; + } + + # reserve all PCI IDs before actually doing anything with them + reserve_pci_usage($pci_reserve_list, $vmid, $start_timeout); + + for my $id (sort keys %$pci_devices) { + my $d = $pci_devices->{$id}; + my ($index) = ($id =~ m/^hostpci(\d+)$/); + + my $chosen_mdev; + for my $dev ($d->{ids}->@*) { + my $info = + eval { prepare_pci_device($vmid, $dev->{id}, $index, $d) }; + if ($d->{mdev} || $d->{nvidia}) { + warn $@ if $@; + $chosen_mdev = $info; + last if $chosen_mdev; # if successful, we're done + } else { + die $@ if $@; + } + } + + next if !$d->{mdev} && !$d->{nvidia}; + die "could not create mediated device\n" if !defined($chosen_mdev); + + # nvidia vgpu need a uuid parameter, we want the smbios one but we can't parse + # that here, so returnt any mdev uuid to signal we want one and as a fallback, + # in case there is not smbios uuid + if (!defined($uuid) && $chosen_mdev->{vendor} =~ m/^(0x)?10de$/) { + $uuid = generate_mdev_uuid($vmid, $index) if !defined($uuid); + } + } + + return ($pci_reserve_list, $uuid); +} + sub prepare_pci_device { my ($vmid, $pciid, $index, $device) = @_; -- 2.47.3 _______________________________________________ pve-devel mailing list pve-devel@lists.proxmox.com https://lists.proxmox.com/cgi-bin/mailman/listinfo/pve-devel