[OLK-6.6] sched/ebpf: Fix bpf_sched_set_task_prefer_nid()
hulk inclusion category: bugfix bugzilla: https://atomgit.com/openeuler/kernel/issues/9010 ---------------------------------------- The current bpf_sched_set_task_prefer_nid() passes the full node mask directly to set_prefer_cpus_ptr(), which may result in preferred CPUs being outside of task->cpus_ptr. In such cases, the scheduler will ignore the preferred CPUs completely, causing the preferred node setting to NOT work at all. Fix this by computing the intersection between task->cpus_ptr and cpumask_of_node(nid), ensuring the resulting preferred mask is a subset of the task's allowed CPUs. Fixes: 4e47cb331dc0b ("sched/ebpf: Add kfunc to set the preferred...") Signed-off-by: Hui Tang <tanghui20@huawei.com> --- kernel/sched/bpf_sched.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/kernel/sched/bpf_sched.c b/kernel/sched/bpf_sched.c index 6849a58439b2..ffe13eed601c 100644 --- a/kernel/sched/bpf_sched.c +++ b/kernel/sched/bpf_sched.c @@ -212,13 +212,16 @@ __bpf_kfunc long bpf_sched_tag_of_entity(struct sched_entity *se) __bpf_kfunc int bpf_sched_set_task_prefer_nid(struct task_struct *task, int nid) { + cpumask_t mask; + if (!task) return -EINVAL; if ((unsigned int)nid >= nr_node_ids) return -EINVAL; - return set_prefer_cpus_ptr(task, cpumask_of_node(nid)); + cpumask_and(&mask, task->cpus_ptr, cpumask_of_node(nid)); + return set_prefer_cpus_ptr(task, &mask); } BTF_SET8_START(sched_task_kfunc_btf_ids) -- 2.34.1
participants (1)
-
Hui Tang