From 227a298f7fc5702c7d7b911b3c62e94d61998b86 Mon Sep 17 00:00:00 2001 From: Dominik Csapak Date: Tue, 21 Jun 2022 16:07:04 +0200 Subject: [PATCH] fix #3577: prevent suspension for VMs with pci passthrough Prevent the user from suspending the vm at all, as while suspension itself may finish, the saved state is incomplete as we can neither save nor restore PCIe device state in any generic fashion, so resuming will almost certainly break. The single case when it could work is when the guest OS didn't uses the passed through device at all, so there's no state, but that's really odd (as why bother passing through then), and the user should rather remove the hostpci entry in that case. Signed-off-by: Dominik Csapak [ T: reword commit message slightly ] Signed-off-by: Thomas Lamprecht --- PVE/API2/Qemu.pm | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/PVE/API2/Qemu.pm b/PVE/API2/Qemu.pm index 99b426ec..24d0f591 100644 --- a/PVE/API2/Qemu.pm +++ b/PVE/API2/Qemu.pm @@ -2977,10 +2977,17 @@ __PACKAGE__->register_method({ # early check for storage permission, for better user feedback if ($todisk) { $rpcenv->check_vm_perm($authuser, $vmid, undef, ['VM.Config.Disk']); + my $conf = PVE::QemuConfig->load_config($vmid); + + # check for hostpci devices (suspend will maybe work, resume won't), + # so prevent users from suspending in the first place + for my $key (keys %$conf) { + next if $key !~ /^hostpci\d+/; + die "Cannot suspend VM to disk with assigned PCI devices\n"; + } if (!$statestorage) { # get statestorage from config if none is given - my $conf = PVE::QemuConfig->load_config($vmid); my $storecfg = PVE::Storage::config(); $statestorage = PVE::QemuServer::find_vmstate_storage($conf, $storecfg); }