From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from gate001.proxmox.com (gate001.proxmox.com [IPv6:2a0f:8001:1:32::40]) by lore.proxmox.com (Postfix) with ESMTPS id 09E3D1FF0AB for ; Wed, 23 Sep 2026 09:06:19 +0200 (CEST) Received: from gate001.proxmox.com (localhost.localdomain [127.0.0.1]) by gate001.proxmox.com (Proxmox) with ESMTP id E488521662; Wed, 23 Sep 2026 09:05:31 +0200 (CEST) From: Dominik Csapak To: pve-devel@lists.proxmox.com Subject: [PATCH qemu-server v5 7/9] pci: call hookscript for each prepared pci device Date: Wed, 23 Sep 2026 09:05:00 +0200 Message-ID: <20260923070522.434715-8-d.csapak@proxmox.com> X-Mailer: git-send-email 2.47.3 In-Reply-To: <20260923070522.434715-1-d.csapak@proxmox.com> References: <20260923070522.434715-1-d.csapak@proxmox.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-SPAM-LEVEL: Spam detection results: 0 AWL 0.450 Adjusted score from AWL reputation of From: address DMARC_MISSING 0.1 Missing DMARC policy KAM_DMARC_STATUS 0.01 Test Rule for DKIM or SPF Failure with Strict Alignment (newer systems) RCVD_IN_DNSWL_MED -2.3 Sender listed at https://www.dnswl.org/, medium trust 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: KKSZWEORP6KLCVGJASCQMTTCEBNZ7I3U X-Message-ID-Hash: KKSZWEORP6KLCVGJASCQMTTCEBNZ7I3U 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: There are situations where a user might want to do extra things for a passed through PCI device after it has been prepared/created (e.g. in case of vGPU/mdev) but before the actual QEMU process is started. Two examples are (both are used with NVIDIA vGPUs): * setting 'vgpu_params' such as removing the frame-rate-limiter * setting the gpu_instance_id for MIG devices So instead of creating (nvidia-specific) interfaces for these, give a user the ability to do it themselves via the hookscript as a first step. Call it for each prepared device, so that we can give the hookscript the 'hostpciX' id, and the used uuid (in case of mdevs) or the pci id (in case of regular or modern vGPU passthrough). A failing hookscript aborts, and blocks the VM start. Signed-off-by: Dominik Csapak Reviewed-by: Elias Huhsovitz Tested-by: Elias Huhsovitz Reviewed-by: Jakob Klocker Tested-by: Jakob Klocker --- src/PVE/QemuServer/PCI.pm | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/src/PVE/QemuServer/PCI.pm b/src/PVE/QemuServer/PCI.pm index 7bfe1791..8a7328b0 100644 --- a/src/PVE/QemuServer/PCI.pm +++ b/src/PVE/QemuServer/PCI.pm @@ -5,6 +5,7 @@ use strict; use IO::File; +use PVE::GuestHelpers; use PVE::JSONSchema; use PVE::Mapping::PCI; use PVE::SysFSTools; @@ -738,10 +739,17 @@ sub prepare_pci_devices { if ($pci_device->{mdev} || $pci_device->{nvidia}) { warn $@ if $@; $chosen_mdev = $info; - last if $chosen_mdev; # if successful, we're done } else { die $@ if $@; } + + next if !defined($info); + + my $params = { id => $id, pciid => $info->{name} }; + $params->{mdev_uuid} = $info->{uuid} if defined($info->{uuid}); + PVE::GuestHelpers::exec_hookscript($conf, $vmid, 'post-pci-prepare', 1, $params); + + last if defined($chosen_mdev); } next if !$pci_device->{mdev} && !$pci_device->{nvidia}; -- 2.47.3