From: "Elias Huhsovitz" <e.huhsovitz@proxmox.com>
To: "Dominik Csapak" <d.csapak@proxmox.com>, <pve-devel@lists.proxmox.com>
Subject: Re: [PATCH qemu-server v4 6/7] pci: call hookscript for each prepared pci device
Date: Thu, 03 Sep 2026 10:41:40 +0200 [thread overview]
Message-ID: <DL5JPT7OMQQQ.2T2M1Y1C2OUTB@proxmox.com> (raw)
In-Reply-To: <20260825135502.3971930-7-d.csapak@proxmox.com>
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 <d.csapak@proxmox.com>
> ---
> 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);
Passing $stop_on_error=1 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=1`. 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);
> }
>
> next if !$d->{mdev} && !$d->{nvidia};
next prev parent reply other threads:[~2026-09-03 8:41 UTC|newest]
Thread overview: 15+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-08-25 13:54 [PATCH docs/guest-common/qemu-server v4 0/7] add new pci passthrough specific hookscript phase Dominik Csapak
2026-08-25 13:54 ` [PATCH guest-common v4 1/7] helpers: exec hookscript: add optional parameters Dominik Csapak
2026-09-03 8:40 ` Elias Huhsovitz
2026-09-03 8:52 ` Jakob Klocker
2026-08-25 13:54 ` [PATCH qemu-server v4 2/7] pci: mdev preparation: always generate local uuid first Dominik Csapak
2026-08-25 13:54 ` [PATCH qemu-server v4 3/7] pci: nvidia vgpu: correct wrong comment about uuid Dominik Csapak
2026-08-25 13:54 ` [PATCH qemu-server v4 4/7] pci: factor 'prepare_pci_devices' out to PVE::QemuServer::PCI module Dominik Csapak
2026-09-03 8:53 ` Jakob Klocker
2026-08-25 13:54 ` [PATCH qemu-server v4 5/7] pci: preparation: mdev: only generate uuid once Dominik Csapak
2026-08-25 13:54 ` [PATCH qemu-server v4 6/7] pci: call hookscript for each prepared pci device Dominik Csapak
2026-09-03 8:41 ` Elias Huhsovitz [this message]
2026-08-25 13:54 ` [PATCH docs v4 7/7] examples: add new hookscript phase to example hookscript Dominik Csapak
2026-09-03 8:41 ` Elias Huhsovitz
2026-08-26 6:10 ` [PATCH docs/guest-common/qemu-server v4 0/7] add new pci passthrough specific hookscript phase Dominik Csapak
2026-09-03 8:54 ` Jakob Klocker
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=DL5JPT7OMQQQ.2T2M1Y1C2OUTB@proxmox.com \
--to=e.huhsovitz@proxmox.com \
--cc=d.csapak@proxmox.com \
--cc=pve-devel@lists.proxmox.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox