[pve-devel] [PATCH qemu-server 2/2] vm start: warn if using ballooning and PCI(e) passthrough

Friedrich Weber f.weber at proxmox.com
Mon Nov 13 18:09:16 CET 2023

If a VM uses PCI(e) passthrough, ballooning does not work as expected:
The QEMU process will always consume the full memory amount given in
`memory`, even if `balloon` is set to a smaller (non-zero) amount. The
reason is that the PCI device might use DMA, so QEMU needs to map the
complete guest memory on startup. However, users may not be aware of
that (see e.g. [0]).

To make users aware of the limitation, warn on VM start if at least
one PCI device is passed through and ballooning is enabled (and
`balloon` != `memory`).

[0] https://forum.proxmox.com/threads/134202/

Signed-off-by: Friedrich Weber <f.weber at proxmox.com>

    I did not test this on a "real" PCI passthrough setup as I don't have
    one at hand, but Markus tested (an earlier version) of this patch on
    his machine.

 PVE/QemuServer.pm | 10 ++++++++++
 1 file changed, 10 insertions(+)

diff --git a/PVE/QemuServer.pm b/PVE/QemuServer.pm
index dbcd568..70983a4 100644
--- a/PVE/QemuServer.pm
+++ b/PVE/QemuServer.pm
@@ -5789,6 +5789,16 @@ sub vm_start_nolock {
 	die $err;
+    if (
+	scalar(%$pci_devices)
+	&& defined($conf->{balloon})
+	&& $conf->{balloon} != 0
+	&& $conf->{balloon} != $memory
+    ) {
+	log_warn("Ballooning is not possible when using PCI(e) passthrough, "
+		."VM will use maximum configured memory ($memory MiB).\n");
+    }
     PVE::Storage::activate_volumes($storecfg, $vollist);

More information about the pve-devel mailing list