[libvirt] [PATCH] qemu_process: fix starting VMs if machine group has limited cpuset.cpus

Pavel Hrdina posted 1 patch 4 years, 5 months ago
Test syntax-check passed
Patches applied successfully (tree, apply log)
git fetch https://github.com/patchew-project/libvirt tags/patchew/7f88e4c9a8fae3196f10964eb6a5bc4b18027505.1573208385.git.phrdina@redhat.com
src/qemu/qemu_process.c | 8 ++++++--
1 file changed, 6 insertions(+), 2 deletions(-)
[libvirt] [PATCH] qemu_process: fix starting VMs if machine group has limited cpuset.cpus
Posted by Pavel Hrdina 4 years, 5 months ago
Commit <f136b83139c63f20de0df3285d9e82df2fb97bfc> reworked process
affinity setting but did not take cgroups into account which introduced
an issue when starting VM with custom cpuset.cpus for the whole machine
group.

If the machine group is limited to some pCPUs libvirt should not try to
set a VM to run on all pCPUs as it will result in permission denied when
writing to cpuset.cpus.

To fix this the affinity has to be set separately from cgroups cpuset.

Resolves: <https://bugzilla.redhat.com/show_bug.cgi?id=1746517>

Signed-off-by: Pavel Hrdina <phrdina@redhat.com>
---
 src/qemu/qemu_process.c | 8 ++++++--
 1 file changed, 6 insertions(+), 2 deletions(-)

diff --git a/src/qemu/qemu_process.c b/src/qemu/qemu_process.c
index ed8666e9d1..355b740caf 100644
--- a/src/qemu/qemu_process.c
+++ b/src/qemu/qemu_process.c
@@ -2636,6 +2636,7 @@ qemuProcessSetupPid(virDomainObjPtr vm,
     virDomainNumatuneMemMode mem_mode;
     virCgroupPtr cgroup = NULL;
     virBitmapPtr use_cpumask = NULL;
+    virBitmapPtr afinity_cpumask = NULL;
     g_autoptr(virBitmap) hostcpumap = NULL;
     char *mem_mask = NULL;
     int ret = -1;
@@ -2661,7 +2662,7 @@ qemuProcessSetupPid(virDomainObjPtr vm,
          * its config file */
         if (qemuProcessGetAllCpuAffinity(&hostcpumap) < 0)
             goto cleanup;
-        use_cpumask = hostcpumap;
+        afinity_cpumask = hostcpumap;
     }
 
     /*
@@ -2702,8 +2703,11 @@ qemuProcessSetupPid(virDomainObjPtr vm,
 
     }
 
+    if (!afinity_cpumask)
+        afinity_cpumask = use_cpumask;
+
     /* Setup legacy affinity. */
-    if (use_cpumask && virProcessSetAffinity(pid, use_cpumask) < 0)
+    if (afinity_cpumask && virProcessSetAffinity(pid, afinity_cpumask) < 0)
         goto cleanup;
 
     /* Set scheduler type and priority, but not for the main thread. */
-- 
2.23.0

--
libvir-list mailing list
libvir-list@redhat.com
https://www.redhat.com/mailman/listinfo/libvir-list

Re: [libvirt] [PATCH] qemu_process: fix starting VMs if machine group has limited cpuset.cpus
Posted by Michal Privoznik 4 years, 5 months ago
On 11/8/19 11:20 AM, Pavel Hrdina wrote:
> Commit <f136b83139c63f20de0df3285d9e82df2fb97bfc> reworked process
> affinity setting but did not take cgroups into account which introduced
> an issue when starting VM with custom cpuset.cpus for the whole machine
> group.
> 
> If the machine group is limited to some pCPUs libvirt should not try to
> set a VM to run on all pCPUs as it will result in permission denied when
> writing to cpuset.cpus.
> 
> To fix this the affinity has to be set separately from cgroups cpuset.
> 
> Resolves: <https://bugzilla.redhat.com/show_bug.cgi?id=1746517>
> 
> Signed-off-by: Pavel Hrdina <phrdina@redhat.com>
> ---
>   src/qemu/qemu_process.c | 8 ++++++--
>   1 file changed, 6 insertions(+), 2 deletions(-)

Reviewed-by: Michal Privoznik <mprivozn@redhat.com>

Michal

--
libvir-list mailing list
libvir-list@redhat.com
https://www.redhat.com/mailman/listinfo/libvir-list