From: "Jakob Klocker" <j.klocker@proxmox.com>
To: "Dominik Csapak" <d.csapak@proxmox.com>, <pve-devel@lists.proxmox.com>
Subject: Re: [PATCH qemu-server v4 4/7] pci: factor 'prepare_pci_devices' out to PVE::QemuServer::PCI module
Date: Thu, 03 Sep 2026 10:53:12 +0200 [thread overview]
Message-ID: <DL5JYN74YFKA.4RGQYCFAIASU@proxmox.com> (raw)
In-Reply-To: <20260825135502.3971930-5-d.csapak@proxmox.com>
nit inline
On Tue Aug 25, 2026 at 3:54 PM CEST, Dominik Csapak wrote:
> no functional change intended.
>
> Note: $conf is unused in `prepare_pci_devices` for now, but will be used
> later.
>
> Signed-off-by: Dominik Csapak <d.csapak@proxmox.com>
> ---
> src/PVE/QemuServer.pm | 36 ++-------------------------------
> src/PVE/QemuServer/PCI.pm | 42 +++++++++++++++++++++++++++++++++++++++
> 2 files changed, 44 insertions(+), 34 deletions(-)
>
> diff --git a/src/PVE/QemuServer.pm b/src/PVE/QemuServer.pm
> index 9c4c13b9..3eeea871 100644
> --- a/src/PVE/QemuServer.pm
> +++ b/src/PVE/QemuServer.pm
> @@ -5697,40 +5697,8 @@ sub vm_start_nolock {
>
> push $cmd->@*, $state_cmdline->@*;
>
> - for my $device (values $pci_devices->%*) {
> - next if $device->{mdev}; # we don't reserve for mdev devices
> - push $pci_reserve_list->@*, map { $_->{id} } $device->{ids}->@*;
> - }
> -
> - # reserve all PCI IDs before actually doing anything with them
> - PVE::QemuServer::PCI::reserve_pci_usage($pci_reserve_list, $vmid, $start_timeout);
> -
> - my $uuid;
> - for my $id (sort keys %$pci_devices) {
> - my $d = $pci_devices->{$id};
> - my ($index) = ($id =~ m/^hostpci(\d+)$/);
> -
> - my $chosen_mdev;
> - for my $dev ($d->{ids}->@*) {
> - my $info =
> - eval { PVE::QemuServer::PCI::prepare_pci_device($vmid, $dev->{id}, $index, $d) };
> - if ($d->{mdev} || $d->{nvidia}) {
> - warn $@ if $@;
> - $chosen_mdev = $info;
> - last if $chosen_mdev; # if successful, we're done
> - } else {
> - die $@ if $@;
> - }
> - }
> -
> - next if !$d->{mdev} && !$d->{nvidia};
> - die "could not create mediated device\n" if !defined($chosen_mdev);
> -
> - # nvidia vgpu needs a uuid as qemu parameter
> - if (!defined($uuid) && $chosen_mdev->{vendor} =~ m/^(0x)?10de$/) {
> - $uuid = PVE::QemuServer::PCI::Mdev::generate_mdev_uuid($vmid, $index);
> - }
> - }
> + ($pci_reserve_list, my $uuid) =
> + PVE::QemuServer::PCI::prepare_pci_devices($conf, $vmid, $pci_devices, $start_timeout);
>
> # uuid for nvidia vgpu
> # prefer the smbios1 uuid if we have and need it
> diff --git a/src/PVE/QemuServer/PCI.pm b/src/PVE/QemuServer/PCI.pm
> index 0b67943c..f7167dcc 100644
> --- a/src/PVE/QemuServer/PCI.pm
> +++ b/src/PVE/QemuServer/PCI.pm
> @@ -704,6 +704,48 @@ sub print_hostpci_devices {
> return ($kvm_off, $gpu_passthrough, $legacy_igd, $pci_devices);
> }
>
> +sub prepare_pci_devices {
> + my ($conf, $vmid, $pci_devices, $start_timeout) = @_;
> +
> + my $pci_reserve_list = [];
> + my $uuid;
> +
> + for my $device (values $pci_devices->%*) {
> + next if $device->{mdev}; # we don't reserve for mdev devices
> + push $pci_reserve_list->@*, map { $_->{id} } $device->{ids}->@*;
> + }
> +
> + # reserve all PCI IDs before actually doing anything with them
> + reserve_pci_usage($pci_reserve_list, $vmid, $start_timeout);
> +
> + for my $id (sort keys %$pci_devices) {
> + my $d = $pci_devices->{$id};
Since this code is being moved anyway, it might be a good opportunity
to give $d a more descriptive name. Since $device is already in use,
maybe $pci_device?
> + my ($index) = ($id =~ m/^hostpci(\d+)$/);
> +
> + my $chosen_mdev;
> + for my $dev ($d->{ids}->@*) {
> + my $info = eval { prepare_pci_device($vmid, $dev->{id}, $index, $d) };
> + if ($d->{mdev} || $d->{nvidia}) {
> + warn $@ if $@;
> + $chosen_mdev = $info;
> + last if $chosen_mdev; # if successful, we're done
> + } else {
> + die $@ if $@;
> + }
> + }
> +
> + next if !$d->{mdev} && !$d->{nvidia};
> + die "could not create mediated device\n" if !defined($chosen_mdev);
> +
> + # nvidia vgpu needs a uuid as qemu parameter
> + if (!defined($uuid) && $chosen_mdev->{vendor} =~ m/^(0x)?10de$/) {
> + $uuid = PVE::QemuServer::PCI::Mdev::generate_mdev_uuid($vmid, $index);
> + }
> + }
> +
> + return ($pci_reserve_list, $uuid);
> +}
> +
> sub prepare_pci_device {
> my ($vmid, $pciid, $index, $device) = @_;
>
next prev parent reply other threads:[~2026-09-03 8:53 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 [this message]
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
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=DL5JYN74YFKA.4RGQYCFAIASU@proxmox.com \
--to=j.klocker@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