From b98d29e022a8c96bfc3acdd9ae7448aae337e93e Mon Sep 17 00:00:00 2001 From: Michal Privoznik Date: Tue, 2 Dec 2025 12:26:28 +0100 Subject: [PATCH] qemu: Treat memory device source nodemask as strict NUMA policy MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit A memory device can have which specifies which host NUMA nodes the memory should be allocated from (currently supported for dimm, virtio-mem and sgx-epc models). But when generating corresponding command line for the device, the NUMA policy is taken from the guest NUMA node that corresponds to the memory device (as defined by target/node) or overall domain NUMA policy (as defined by ). This may lead to memory being allocated from unexpected NUMA node. For instance, if the memory device has 0 and domain has then the cmd line for the memory device also has just "policy":"preferred". Treat as mode='strict'. But I agree that this is kind of nonsense configuration. Why would somebody want to prefer one NUMA node but then configure memory device to allocate NUMA from the other? Resolves: https://issues.redhat.com/browse/RHEL-114415 Signed-off-by: Michal Privoznik Reviewed-by: Ján Tomko --- src/qemu/qemu_command.c | 6 ++++++ .../memory-hotplug-numa-preferred.x86_64-latest.args | 2 +- 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/src/qemu/qemu_command.c b/src/qemu/qemu_command.c index fb89dbec27..98229d7cf9 100644 --- a/src/qemu/qemu_command.c +++ b/src/qemu/qemu_command.c @@ -3497,6 +3497,12 @@ qemuBuildMemoryBackendProps(virJSONValue **backendProps, if (!virNumaNodesetIsAvailable(nodemask)) return -1; + /* Treat source nodes as strict mode, regardless of the target guest + * NUMA node mode. */ + if (hasSourceNodes) { + mode = VIR_DOMAIN_NUMATUNE_MEM_STRICT; + } + /* If mode is "restrictive", we should only use cgroups setting allowed memory * nodes, and skip passing the host-nodes and policy parameters to QEMU command * line which means we will use system default memory policy. */ diff --git a/tests/qemuxmlconfdata/memory-hotplug-numa-preferred.x86_64-latest.args b/tests/qemuxmlconfdata/memory-hotplug-numa-preferred.x86_64-latest.args index 23a5f76af2..cc318977b3 100644 --- a/tests/qemuxmlconfdata/memory-hotplug-numa-preferred.x86_64-latest.args +++ b/tests/qemuxmlconfdata/memory-hotplug-numa-preferred.x86_64-latest.args @@ -34,7 +34,7 @@ XDG_CONFIG_HOME=/var/lib/libvirt/qemu/domain--1-QEMUGuest1/.config \ -device '{"driver":"pcie-root-port","port":10,"chassis":3,"id":"pci.3","bus":"pcie.0","addr":"0x1.0x2"}' \ -device '{"driver":"qemu-xhci","id":"usb","bus":"pci.1","addr":"0x0"}' \ -object '{"qom-type":"thread-context","id":"tc-memdimm0","node-affinity":[0]}' \ --object '{"qom-type":"memory-backend-file","id":"memdimm0","mem-path":"/dev/hugepages1G/libvirt/qemu/-1-QEMUGuest1","prealloc":true,"size":1073741824,"host-nodes":[0],"policy":"preferred","prealloc-context":"tc-memdimm0"}' \ +-object '{"qom-type":"memory-backend-file","id":"memdimm0","mem-path":"/dev/hugepages1G/libvirt/qemu/-1-QEMUGuest1","prealloc":true,"size":1073741824,"host-nodes":[0],"policy":"bind","prealloc-context":"tc-memdimm0"}' \ -device '{"driver":"pc-dimm","node":0,"memdev":"memdimm0","id":"dimm0","slot":0}' \ -audiodev '{"id":"audio1","driver":"none"}' \ -global ICH9-LPC.noreboot=off \ -- 2.47.3