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 447561FF0B7 for ; Tue, 25 Aug 2026 15:55:43 +0200 (CEST) Received: from gate001.proxmox.com (localhost.localdomain [127.0.0.1]) by gate001.proxmox.com (Proxmox) with ESMTP id 5AC0A216B7; Tue, 25 Aug 2026 15:55:08 +0200 (CEST) From: Dominik Csapak To: pve-devel@lists.proxmox.com Subject: [PATCH qemu-server v4 6/7] pci: call hookscript for each prepared pci device Date: Tue, 25 Aug 2026 15:54:51 +0200 Message-ID: <20260825135502.3971930-7-d.csapak@proxmox.com> X-Mailer: git-send-email 2.47.3 In-Reply-To: <20260825135502.3971930-1-d.csapak@proxmox.com> References: <20260825135502.3971930-1-d.csapak@proxmox.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-SPAM-LEVEL: Spam detection results: 0 AWL 0.724 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: FNUXQVF7VJ5GXMYH422G7EISLU3RMH4Z X-Message-ID-Hash: FNUXQVF7VJ5GXMYH422G7EISLU3RMH4Z 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 --- 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 5d2fdabb..755945a9 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; @@ -728,10 +729,17 @@ sub prepare_pci_devices { if ($d->{mdev} || $d->{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 !$d->{mdev} && !$d->{nvidia}; -- 2.47.3