From 8121cb08f854b8199485bff5b6875e7fbf3cf6a1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marek=20Marczykowski-G=C3=B3recki?= Date: Sat, 20 Apr 2024 04:19:56 +0200 Subject: [PATCH] Improve checking for memory hotplug support 1. Fix handling HVM to match the intention described in the comment. 2. Fix distinguishing dom0-provided and vm-provided kernels - the actual "kernel" property value depends on the virt_mode QubesOS/qubes-issues#7956 --- qubes/vm/qubesvm.py | 19 ++++++++++++++++--- 1 file changed, 16 insertions(+), 3 deletions(-) diff --git a/qubes/vm/qubesvm.py b/qubes/vm/qubesvm.py index d117b0b76..56b67ad81 100644 --- a/qubes/vm/qubesvm.py +++ b/qubes/vm/qubesvm.py @@ -1642,6 +1642,17 @@ def is_memory_balancing_possible(self): return False return True + def is_kernel_from_vm(self): + """Does the kernel is really a bootloader loading the kernel + from within the VM?""" + if self.virt_mode == 'hvm': + return self.kernel is None + if self.virt_mode == 'pvh': + return self.kernel == 'pvgrub2-pvh' + if self.virt_mode == 'pv': + return self.kernel == 'pvgrub2' + assert False + @property def use_memory_hotplug(self): """Use memory hotplug for memory balancing. @@ -1655,9 +1666,11 @@ def use_memory_hotplug(self): # if not explicitly set, check if support is advertised # for dom0-provided kernel - check there # Do not enable automatically for HVM, as qemu isn't happy about that - - # emulated devices wont work (DMA issues?); but still allow enabling - # manually in that case. - if self.kernel and self.virt_mode != 'hvm': + # emulated devices won't work (DMA issues?); but still allow enabling + # manually in that case (with the feature above). + if self.virt_mode == 'hvm': + return False + if not self.is_kernel_from_vm(): return (pathlib.Path(self.storage.kernels_dir) / 'memory-hotplug-supported').exists() # otherwise - check advertised VM's features