[Devel] [PATCH RHEL COMMIT] sched: Return only virtual cpus in sched_getaffinity()

Konstantin Khorenko khorenko at virtuozzo.com
Fri Sep 24 14:49:35 MSK 2021


The commit is pushed to "branch-rh9-5.14.vz9.1.x-ovz" and will appear at https://src.openvz.org/scm/ovz/vzkernel.git
after ark-5.14
------>
commit 97f2bc2f34fd34f0d3ba6c30bd240ce85c05a463
Author: Kirill Tkhai <ktkhai at virtuozzo.com>
Date:   Fri Sep 24 14:49:35 2021 +0300

    sched: Return only virtual cpus in sched_getaffinity()
    
    Fill mask using virtual cpus which are enumerated
    from 0 to num_online_vcpus()-1.
    
    Just in pair to /proc/cpuinfo and sched_setaffinity().
    
    https://jira.sw.ru/browse/PSBM-25367
    
    Signed-off-by: Kirill Tkhai <ktkhai at parallels.com>
    
    Acked-by: Vladimir Davydov <vdavydov at parallels.com>
    An addition by khorenko@:
    "nproc" utility works via sched_getaffinity().
    Acked-by: Cyrill Gorcunov <gorcunov at openvz.org>
    Signed-off-by: Kirill Tkhai <ktkhai at virtuozzo.com>
    
    https://jira.sw.ru/browse/PSBM-133986
    
    (cherry picked from commit 83352c7f8f4b98fd4dbf5f0de00681b6cdc11d7c)
    Signed-off-by: Alexander Mikhalitsyn <alexander.mikhalitsyn at virtuozzo.com>
---
 kernel/sched/core.c | 6 ++++++
 1 file changed, 6 insertions(+)

diff --git a/kernel/sched/core.c b/kernel/sched/core.c
index 064482744ac7..291f293fb00a 100644
--- a/kernel/sched/core.c
+++ b/kernel/sched/core.c
@@ -7848,6 +7848,12 @@ long sched_getaffinity(pid_t pid, struct cpumask *mask)
 	if (retval)
 		goto out_unlock;
 
+	if (!ve_is_super(get_exec_env())) {
+		cpumask_clear(mask);
+		bitmap_fill(cpumask_bits(mask), num_online_vcpus());
+		goto out_unlock;
+	}
+
 	raw_spin_lock_irqsave(&p->pi_lock, flags);
 	cpumask_and(mask, &p->cpus_mask, cpu_active_mask);
 	raw_spin_unlock_irqrestore(&p->pi_lock, flags);


More information about the Devel mailing list