From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from gate001.proxmox.com (gate001.proxmox.com [45.144.208.40]) by lore.proxmox.com (Postfix) with ESMTPS id 215F11FF09F for ; Thu, 03 Sep 2026 10:41:44 +0200 (CEST) Received: from gate001.proxmox.com (localhost.localdomain [127.0.0.1]) by gate001.proxmox.com (Proxmox) with ESMTP id CD5472158D; Thu, 03 Sep 2026 10:41:43 +0200 (CEST) Content-Type: text/plain; charset=UTF-8 Date: Thu, 03 Sep 2026 10:41:40 +0200 Message-Id: Subject: Re: [PATCH qemu-server v4 6/7] pci: call hookscript for each prepared pci device From: "Elias Huhsovitz" To: "Dominik Csapak" , Content-Transfer-Encoding: quoted-printable Mime-Version: 1.0 X-Mailer: aerc 0.20.0 References: <20260825135502.3971930-1-d.csapak@proxmox.com> <20260825135502.3971930-7-d.csapak@proxmox.com> In-Reply-To: <20260825135502.3971930-7-d.csapak@proxmox.com> X-Bm-Milter-Handled: 55990f41-d878-4baa-be0a-ee34c49e34d2 X-Bm-Transport-Timestamp: 1788424898465 X-SPAM-LEVEL: Spam detection results: 0 AWL 0.695 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: 6PB6NOIBRCGFAYHGH7MFWB5HE33RAS33 X-Message-ID-Hash: 6PB6NOIBRCGFAYHGH7MFWB5HE33RAS33 X-MailFrom: e.huhsovitz@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: One comment inline. On Tue Aug 25, 2026 at 3:54 PM CEST, Dominik Csapak wrote: > 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; > =20 > use IO::File; > =20 > +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 =3D $info; > - last if $chosen_mdev; # if successful, we're done > } else { > die $@ if $@; > } > + > + next if !defined($info); > + > + my $params =3D { id =3D> $id, pciid =3D> $info->{name} }; > + $params->{mdev_uuid} =3D $info->{uuid} if defined($info->{uu= id}); > + PVE::GuestHelpers::exec_hookscript($conf, $vmid, 'post-pci-p= repare', 1, $params); Passing $stop_on_error=3D1 might causes existing hookscripts do 'die'. The current example hookscript found under /usr/share/pve-docs/examples/guest-example-hookscript.pl recommends a pattern of dying, if an unknown hookscript-phase is used. I would assume that most users are currently using such a pattern. We now call exec_hookscript with `$stop_on_error=3D1`. Users that have an active hookscript and an active PCI device will experience the following error on VM startup: GUEST HOOK: 202 post-pci-prepare got unknown phase 'post-pci-prepare' TASK ERROR: hookscript error for 202 on post-pci-prepare: command '/var/lib/vz/snippets/guest-example-hookscript-old.pl 202 post-pci-= prepare' failed: exit code 255 See my review for patch 7/7 for my suggestions of handling this. > + > + last if defined($chosen_mdev); > } > =20 > next if !$d->{mdev} && !$d->{nvidia};