]> git.ipfire.org Git - thirdparty/libvirt.git/commitdiff
qemuBuildThreadContextProps: Prune .node-affinity wrt <emulatorpin/>
authorMichal Privoznik <mprivozn@redhat.com>
Tue, 7 Mar 2023 13:05:54 +0000 (14:05 +0100)
committerMichal Privoznik <mprivozn@redhat.com>
Wed, 15 Mar 2023 11:46:55 +0000 (12:46 +0100)
When a thread-context object is specified on the cmd line, then
QEMU spawns a thread and sets its affinity to the list of NUMA
nodes specified in .node-affinity attribute. And this works just
fine, until the main QEMU thread itself is not restricted.

Because of v5.3.0-rc1~18 we restrict the main emulator thread
even before QEMU is executed and thus then it tries to set
affinity of a thread-context thread, it inevitably fails with:

  Setting CPU affinity failed: Invalid argument

Now, we could lift the pinning temporarily, let QEMU spawn all
thread-context threads, and enforce pinning again, but that would
require some form of communication with QEMU (maybe -preconfig?).
But that would still be wrong, because it would circumvent
<emulatorpin/>.

Technically speaking, thread-context is an internal
implementation detail of QEMU, and if it weren't for it, the main
emulator thread would be doing the allocation. Therefore, we
should honor the pinning and prune the list of node so that
inaccessible ones are dropped.

Resolves: https://bugzilla.redhat.com/show_bug.cgi?id=2154750
Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
Reviewed-by: Kristina Hanicova <khanicov@redhat.com>
Reviewed-by: Andrea Bolognani <abologna@redhat.com>
src/qemu/qemu_command.c
src/qemu/qemu_command.h
tests/qemuxml2argvdata/memory-hotplug-dimm-addr.x86_64-latest.args

index 6de3b549a05bd153d79629e9a312adb5737e4fce..7027da329439167d1c9bd291b6fe571cdc4d0110 100644 (file)
@@ -3539,7 +3539,7 @@ qemuBuildMemoryDimmBackendStr(virCommand *cmd,
                                     def, mem, true, false, &nodemask) < 0)
         return -1;
 
-    if (qemuBuildThreadContextProps(&tcProps, &props, priv, nodemask) < 0)
+    if (qemuBuildThreadContextProps(&tcProps, &props, def, priv, nodemask) < 0)
         return -1;
 
     if (tcProps &&
@@ -3636,10 +3636,13 @@ qemuBuildMemoryDeviceProps(virQEMUDriverConfig *cfg,
 int
 qemuBuildThreadContextProps(virJSONValue **tcProps,
                             virJSONValue **memProps,
+                            const virDomainDef *def,
                             qemuDomainObjPrivate *priv,
                             virBitmap *nodemask)
 {
     g_autoptr(virJSONValue) props = NULL;
+    virBitmap *emulatorpin = NULL;
+    g_autoptr(virBitmap) emulatorNodes = NULL;
     g_autofree char *tcAlias = NULL;
     const char *memalias = NULL;
     bool prealloc = false;
@@ -3656,6 +3659,22 @@ qemuBuildThreadContextProps(virJSONValue **tcProps,
         !prealloc)
         return 0;
 
+    emulatorpin = qemuDomainEvaluateCPUMask(def,
+                                            def->cputune.emulatorpin,
+                                            priv->autoNodeset);
+
+    if (emulatorpin && virNumaIsAvailable()) {
+        if (virNumaCPUSetToNodeset(emulatorpin, &emulatorNodes) < 0)
+            return -1;
+
+        virBitmapIntersect(emulatorNodes, nodemask);
+
+        if (virBitmapIsAllClear(emulatorNodes))
+            return 0;
+
+        nodemask = emulatorNodes;
+    }
+
     memalias = virJSONValueObjectGetString(*memProps, "id");
     if (!memalias) {
         virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
@@ -7188,7 +7207,7 @@ qemuBuildMemCommandLineMemoryDefaultBackend(virCommand *cmd,
                                     def, &mem, false, true, &nodemask) < 0)
         return -1;
 
-    if (qemuBuildThreadContextProps(&tcProps, &props, priv, nodemask) < 0)
+    if (qemuBuildThreadContextProps(&tcProps, &props, def, priv, nodemask) < 0)
         return -1;
 
     if (tcProps &&
@@ -7517,7 +7536,7 @@ qemuBuildNumaCommandLine(virQEMUDriverConfig *cfg,
             g_autoptr(virJSONValue) tcProps = NULL;
 
             if (qemuBuildThreadContextProps(&tcProps, &nodeBackends[i],
-                                            priv, nodemask[i]) < 0)
+                                            def, priv, nodemask[i]) < 0)
                 goto cleanup;
 
             if (tcProps &&
index 17f326d13b37dd18b6ddf0e72cc8d8e0f4c79b47..5fdb138030f662a1804969b6f9689d614badcb62 100644 (file)
@@ -153,6 +153,7 @@ qemuBuildMemoryDeviceProps(virQEMUDriverConfig *cfg,
 int
 qemuBuildThreadContextProps(virJSONValue **tcProps,
                             virJSONValue **memProps,
+                            const virDomainDef *def,
                             qemuDomainObjPrivate *priv,
                             virBitmap *nodemask);
 
index 84360843fbb324a912119593cc14dc4f75ca2b90..6ae1fd1b989c4c047057449c808cd96e1ae6edeb 100644 (file)
@@ -28,7 +28,7 @@ XDG_CONFIG_HOME=/var/lib/libvirt/qemu/domain--1-QEMUGuest1/.config \
 -no-shutdown \
 -boot strict=on \
 -device '{"driver":"piix3-usb-uhci","id":"usb","bus":"pci.0","addr":"0x1.0x2"}' \
--object '{"qom-type":"thread-context","id":"tc-memdimm0","node-affinity":[1,2,3]}' \
+-object '{"qom-type":"thread-context","id":"tc-memdimm0","node-affinity":[1,2]}' \
 -object '{"qom-type":"memory-backend-file","id":"memdimm0","mem-path":"/dev/hugepages2M/libvirt/qemu/-1-QEMUGuest1","prealloc":true,"size":536870912,"host-nodes":[1,2,3],"policy":"bind","prealloc-context":"tc-memdimm0"}' \
 -device '{"driver":"pc-dimm","node":0,"memdev":"memdimm0","id":"dimm0","slot":0,"addr":4294967296}' \
 -object '{"qom-type":"memory-backend-ram","id":"memdimm2","size":536870912}' \