From b86d32dcb2f0977941ac515d956c485c9c528da9 Mon Sep 17 00:00:00 2001 From: Dominik Csapak Date: Tue, 11 Mar 2025 14:20:43 +0100 Subject: [PATCH] pci passthrough: enable live-migration for capable mapped-devices Set the 'enable-migration' QEMU command-line flag to on for live-migration marked mapped devices, as the default is 'auto', but for those which are marked as capable for live-migration, we want to explicitly enable that, so that we get an early error on start if the driver does not support live-migration. With that we can drop such devices from being a migration blocker. Signed-off-by: Dominik Csapak [TL: squash and re-order similar changes together] Signed-off-by: Thomas Lamprecht --- PVE/QemuServer.pm | 6 ++++++ PVE/QemuServer/PCI.pm | 8 +++++++- 2 files changed, 13 insertions(+), 1 deletion(-) diff --git a/PVE/QemuServer.pm b/PVE/QemuServer.pm index 2e72e2d6..c7ca484d 100644 --- a/PVE/QemuServer.pm +++ b/PVE/QemuServer.pm @@ -2519,6 +2519,12 @@ sub check_local_resources { my $mapped_device = { name => $name }; $mapped_res->{$k} = $mapped_device; + if ($pci_map->{ids}->{$name}->{'live-migration-capable'}) { + $mapped_device->{'live-migration'} = 1; + # don't add mapped device with live migration as blocker + next; + } + # don't add mapped devices as blocker for offline migration but still iterate over # all mappings above to collect on which nodes they are available. next if !$state; diff --git a/PVE/QemuServer/PCI.pm b/PVE/QemuServer/PCI.pm index a0d99692..afb60ad2 100644 --- a/PVE/QemuServer/PCI.pm +++ b/PVE/QemuServer/PCI.pm @@ -433,9 +433,11 @@ sub parse_hostpci { die "PCI device mapping not found for '$mapping'\n" if !$devices || !scalar($devices->@*); my $config = PVE::Mapping::PCI::config(); + my $mapping_cfg = $config->{ids}->{$mapping}; + $res->{'live-migration-capable'} = 1 if $mapping_cfg->{'live-migration-capable'}; for my $device ($devices->@*) { - eval { PVE::Mapping::PCI::assert_valid($mapping, $device, $config->{ids}->{$mapping}) }; + eval { PVE::Mapping::PCI::assert_valid($mapping, $device, $mapping_cfg) }; die "PCI device mapping invalid (hardware probably changed): $@\n" if $@; push $alternatives->@*, [split(/;/, $device->{path})]; } @@ -692,6 +694,10 @@ sub print_hostpci_devices { $devicestr .= ",host=$pcidevice->{id}"; } + if ($d->{'live-migration-capable'}) { + $devicestr .= ",enable-migration=on"; + } + my $mf_addr = $multifunction ? ".$j" : ''; $devicestr .= ",id=${id}${mf_addr}${pciaddr}${mf_addr}";