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 0550B1FF141 for ; Fri, 27 Feb 2026 13:07:12 +0100 (CET) Received: from firstgate.proxmox.com (localhost [127.0.0.1]) by firstgate.proxmox.com (Proxmox) with ESMTP id 797CEFE6F; Fri, 27 Feb 2026 13:08:04 +0100 (CET) From: Dominik Csapak To: pve-devel@lists.proxmox.com Subject: [PATCH qemu-server v3 2/2] pci: call hookscript for each prepared pci device Date: Fri, 27 Feb 2026 13:06:53 +0100 Message-ID: <20260227120728.2152303-4-d.csapak@proxmox.com> X-Mailer: git-send-email 2.47.3 In-Reply-To: <20260227120728.2152303-1-d.csapak@proxmox.com> References: <20260227120728.2152303-1-d.csapak@proxmox.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-SPAM-LEVEL: Spam detection results: 0 AWL 0.034 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 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: DY7O3VU3NCLVWIEECZTJREEAFCJZ3ZNK X-Message-ID-Hash: DY7O3VU3NCLVWIEECZTJREEAFCJZ3ZNK 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). Include the generated mdev uuid in the return value of `prepare_pci_device`, to avoid having to generate that multiple times. With that we can get rid of one extra generation here too. Signed-off-by: Dominik Csapak --- src/PVE/QemuServer/PCI.pm | 24 ++++++++++++++++++++++-- 1 file changed, 22 insertions(+), 2 deletions(-) diff --git a/src/PVE/QemuServer/PCI.pm b/src/PVE/QemuServer/PCI.pm index f778c60f..5d9c7ab2 100644 --- a/src/PVE/QemuServer/PCI.pm +++ b/src/PVE/QemuServer/PCI.pm @@ -761,9 +761,28 @@ sub prepare_pci_devices { if ($d->{mdev} || $d->{nvidia}) { warn $@ if $@; $chosen_mdev = $info; - last if $chosen_mdev; # if successful, we're done + if (defined($chosen_mdev)) { + my $params = { id => $id, pciid => $chosen_mdev->{name} }; + $params->{mdev_uuid} = $chosen_mdev->{uuid}; + PVE::GuestHelpers::exec_hookscript( + $conf, $vmid, 'post-pci-prepare', 1, $params, + ); + last; + } } else { die $@ if $@; + if (defined($info)) { + PVE::GuestHelpers::exec_hookscript( + $conf, + $vmid, + 'post-pci-prepare', + 1, + { + id => $id, + pciid => $info->{name}, + }, + ); + } } } @@ -774,7 +793,7 @@ sub prepare_pci_devices { # 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); + $uuid = $chosen_mdev->{uuid} if !defined($uuid); } } @@ -795,6 +814,7 @@ sub prepare_pci_device { } elsif (my $mdev = $device->{mdev}) { my $uuid = generate_mdev_uuid($vmid, $index); PVE::SysFSTools::pci_create_mdev_device($pciid, $uuid, $mdev); + $info->{uuid} = $uuid; } else { die "can't unbind/bind PCI group to VFIO '$pciid'\n" if !PVE::SysFSTools::pci_dev_group_bind_to_vfio($pciid); -- 2.47.3