25aafc
From ba8699bf038f3fe588cc0e40bf484260c08e6f48 Mon Sep 17 00:00:00 2001
25aafc
Message-Id: <ba8699bf038f3fe588cc0e40bf484260c08e6f48@dist-git>
25aafc
From: Pavel Hrdina <phrdina@redhat.com>
25aafc
Date: Mon, 25 Nov 2019 11:02:21 +0100
25aafc
Subject: [PATCH] qemu_process: fix starting VMs if machine group has limited
25aafc
 cpuset.cpus
25aafc
25aafc
Commit <f136b83139c63f20de0df3285d9e82df2fb97bfc> reworked process
25aafc
affinity setting but did not take cgroups into account which introduced
25aafc
an issue when starting VM with custom cpuset.cpus for the whole machine
25aafc
group.
25aafc
25aafc
If the machine group is limited to some pCPUs libvirt should not try to
25aafc
set a VM to run on all pCPUs as it will result in permission denied when
25aafc
writing to cpuset.cpus.
25aafc
25aafc
To fix this the affinity has to be set separately from cgroups cpuset.
25aafc
25aafc
Resolves: <https://bugzilla.redhat.com/show_bug.cgi?id=1746517>
25aafc
25aafc
Signed-off-by: Pavel Hrdina <phrdina@redhat.com>
25aafc
Reviewed-by: Michal Privoznik <mprivozn@redhat.com>
25aafc
(cherry picked from commit 4c0398b5284d14c55eca51095673b6fadbbd85fb)
25aafc
25aafc
Conflicts:
25aafc
    src/qemu/qemu_process.c - upstream commit that introduced this
25aafc
            issue was modified to not use VIR_AUTOFREE
25aafc
25aafc
Signed-off-by: Pavel Hrdina <phrdina@redhat.com>
25aafc
Message-Id: <86eec31e53a4d061e098919d145e6a89cc8740c4.1574676123.git.phrdina@redhat.com>
25aafc
Reviewed-by: Jiri Denemark <jdenemar@redhat.com>
25aafc
---
25aafc
 src/qemu/qemu_process.c | 8 ++++++--
25aafc
 1 file changed, 6 insertions(+), 2 deletions(-)
25aafc
25aafc
diff --git a/src/qemu/qemu_process.c b/src/qemu/qemu_process.c
25aafc
index 307098cd63..4a2864af27 100644
25aafc
--- a/src/qemu/qemu_process.c
25aafc
+++ b/src/qemu/qemu_process.c
25aafc
@@ -2476,6 +2476,7 @@ qemuProcessSetupPid(virDomainObjPtr vm,
25aafc
     virDomainNumatuneMemMode mem_mode;
25aafc
     virCgroupPtr cgroup = NULL;
25aafc
     virBitmapPtr use_cpumask = NULL;
25aafc
+    virBitmapPtr afinity_cpumask = NULL;
25aafc
     virBitmapPtr hostcpumap = NULL;
25aafc
     char *mem_mask = NULL;
25aafc
     int ret = -1;
25aafc
@@ -2501,7 +2502,7 @@ qemuProcessSetupPid(virDomainObjPtr vm,
25aafc
          * its config file */
25aafc
         if (qemuProcessGetAllCpuAffinity(&hostcpumap) < 0)
25aafc
             goto cleanup;
25aafc
-        use_cpumask = hostcpumap;
25aafc
+        afinity_cpumask = hostcpumap;
25aafc
     }
25aafc
 
25aafc
     /*
25aafc
@@ -2542,8 +2543,11 @@ qemuProcessSetupPid(virDomainObjPtr vm,
25aafc
 
25aafc
     }
25aafc
 
25aafc
+    if (!afinity_cpumask)
25aafc
+        afinity_cpumask = use_cpumask;
25aafc
+
25aafc
     /* Setup legacy affinity. */
25aafc
-    if (use_cpumask && virProcessSetAffinity(pid, use_cpumask) < 0)
25aafc
+    if (afinity_cpumask && virProcessSetAffinity(pid, afinity_cpumask) < 0)
25aafc
         goto cleanup;
25aafc
 
25aafc
     /* Set scheduler type and priority. */
25aafc
-- 
25aafc
2.24.0
25aafc