From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from firstgate.proxmox.com (firstgate.proxmox.com [212.224.123.68]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits)) (No client certificate requested) by lists.proxmox.com (Postfix) with ESMTPS id 6F35993DC3 for ; Tue, 20 Sep 2022 14:51:31 +0200 (CEST) Received: from firstgate.proxmox.com (localhost [127.0.0.1]) by firstgate.proxmox.com (Proxmox) with ESMTP id DC2C91BF86 for ; Tue, 20 Sep 2022 14:50:59 +0200 (CEST) Received: from proxmox-new.maurer-it.com (proxmox-new.maurer-it.com [94.136.29.106]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits)) (No client certificate requested) by firstgate.proxmox.com (Proxmox) with ESMTPS for ; Tue, 20 Sep 2022 14:50:54 +0200 (CEST) Received: from proxmox-new.maurer-it.com (localhost.localdomain [127.0.0.1]) by proxmox-new.maurer-it.com (Proxmox) with ESMTP id 67825444A0 for ; Tue, 20 Sep 2022 14:50:45 +0200 (CEST) From: Dominik Csapak To: pve-devel@lists.proxmox.com Date: Tue, 20 Sep 2022 14:50:19 +0200 Message-Id: <20220920125041.3636561-14-d.csapak@proxmox.com> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20220920125041.3636561-1-d.csapak@proxmox.com> References: <20220920125041.3636561-1-d.csapak@proxmox.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-SPAM-LEVEL: Spam detection results: 0 AWL 0.079 Adjusted score from AWL reputation of From: address BAYES_00 -1.9 Bayes spam probability is 0 to 1% 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 URIBL_BLOCKED 0.001 ADMINISTRATOR NOTICE: The query to URIBL was blocked. See http://wiki.apache.org/spamassassin/DnsBlocklists#dnsbl-block for more information. [qemuserver.pm, pci.pm] Subject: [pve-devel] [PATCH qemu-server v3 04/13] PCI: reuse parsed info from print_hostpci_devices X-BeenThere: pve-devel@lists.proxmox.com X-Mailman-Version: 2.1.29 Precedence: list List-Id: Proxmox VE development discussion List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Tue, 20 Sep 2022 12:51:31 -0000 instead of parsing the config again when trying to reserver/prepare the pci devices. also split the preparing into non-mdev devices and mdev devices, this will come in handy later. Signed-off-by: Dominik Csapak --- PVE/QemuServer.pm | 20 +++++--------------- PVE/QemuServer/PCI.pm | 8 +++++++- 2 files changed, 12 insertions(+), 16 deletions(-) diff --git a/PVE/QemuServer.pm b/PVE/QemuServer.pm index b3c3ce0..0a573de 100644 --- a/PVE/QemuServer.pm +++ b/PVE/QemuServer.pm @@ -3687,7 +3687,7 @@ sub config_to_command { my $bootorder = device_bootorder($conf); # host pci device passthrough - my ($kvm_off, $gpu_passthrough, $legacy_igd) = PVE::QemuServer::PCI::print_hostpci_devices( + my ($kvm_off, $gpu_passthrough, $legacy_igd, $pci_devices) = PVE::QemuServer::PCI::print_hostpci_devices( $vmid, $conf, $devices, $vga, $winversion, $q35, $bridges, $arch, $machine_type, $bootorder); # usb devices @@ -4103,7 +4103,7 @@ sub config_to_command { push @$cmd, @$aa; } - return wantarray ? ($cmd, $vollist, $spice_port) : $cmd; + return wantarray ? ($cmd, $vollist, $spice_port, $pci_devices) : $cmd; } sub check_rng_source { @@ -5493,7 +5493,7 @@ sub vm_start_nolock { print "Resuming suspended VM\n"; } - my ($cmd, $vollist, $spice_port) = config_to_command($storecfg, $vmid, + my ($cmd, $vollist, $spice_port, $pci_devices) = config_to_command($storecfg, $vmid, $conf, $defaults, $forcemachine, $forcecpu, $params->{'pbs-backing'}); my $migration_ip; @@ -5578,17 +5578,7 @@ sub vm_start_nolock { my $start_timeout = $params->{timeout} // config_aware_timeout($conf, $resume); - my $pci_devices = {}; # host pci devices - for (my $i = 0; $i < $PVE::QemuServer::PCI::MAX_HOSTPCI_DEVICES; $i++) { - my $dev = $conf->{"hostpci$i"} or next; - $pci_devices->{$i} = parse_hostpci($dev); - } - - # do not reserve pciid for mediated devices, sysfs will error out for duplicate assignment - my $real_pci_devices = [ grep { !(defined($_->{mdev}) && scalar($_->{pciid}->@*) == 1) } values $pci_devices->%* ]; - - # map to a flat list of pci ids - my $pci_id_list = [ map { $_->{id} } map { $_->{pciid}->@* } $real_pci_devices->@* ]; + my $pci_id_list = [ map { $_->{id} } map { $_->{used}->@* } values %$pci_devices ]; # reserve all PCI IDs before actually doing anything with them PVE::QemuServer::PCI::reserve_pci_usage($pci_id_list, $vmid, $start_timeout); @@ -5596,7 +5586,7 @@ sub vm_start_nolock { eval { my $uuid; for my $id (sort keys %$pci_devices) { - my $d = $pci_devices->{$id}; + my $d = $pci_devices->{$id}->{device}; for my $dev ($d->{pciid}->@*) { my $info = PVE::QemuServer::PCI::prepare_pci_device($vmid, $dev->{id}, $id, $d->{mdev}); diff --git a/PVE/QemuServer/PCI.pm b/PVE/QemuServer/PCI.pm index 7406246..b5284ef 100644 --- a/PVE/QemuServer/PCI.pm +++ b/PVE/QemuServer/PCI.pm @@ -422,12 +422,17 @@ sub print_hostpci_devices { my $kvm_off = 0; my $gpu_passthrough = 0; my $legacy_igd = 0; + my $parsed_devices = {}; my $pciaddr; for (my $i = 0; $i < $MAX_HOSTPCI_DEVICES; $i++) { my $id = "hostpci$i"; my $d = parse_hostpci($conf->{$id}); next if !$d; + $parsed_devices->{$i} = { + device => $d, + used => [], + }; if (my $pcie = $d->{pcie}) { die "q35 machine model is not enabled" if !$q35; @@ -449,6 +454,7 @@ sub print_hostpci_devices { } my $pcidevices = $d->{pciid}; + $parsed_devices->{$i}->{used} = $pcidevices; my $multifunction = @$pcidevices > 1; if ($d->{'legacy-igd'}) { @@ -503,7 +509,7 @@ sub print_hostpci_devices { } } - return ($kvm_off, $gpu_passthrough, $legacy_igd); + return ($kvm_off, $gpu_passthrough, $legacy_igd, $parsed_devices); } sub prepare_pci_device { -- 2.30.2