sched/core: Fix a missed update of user_cpus_ptr
PATCH 1/1 sched/core: Fix a missed update of user_cpus_ptr
Since commit 8f9ea86fdf99 ("sched: Always preserve the user requested cpumask"), a successful call to sched_setaffinity() should always save the user requested cpu affinity mask in a task's user_cpus_ptr. However, when the given cpu mask is the same as the current one, user_cpus_ptr is not updated. Fix this by saving the user mask in this case too.
--- kernel/sched/core.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-)
kernel/sched/core.c +4 -1
@@ -2951,8 +2951,11 @@ static int __set_cpus_allowed_ptr_locked(struct task_struct *p, }if (!(ctx->flags &SCA_MIGRATE_ENABLE )) { -if (cpumask_equal (&p->cpus_mask, ctx->new_mask)) +if (cpumask_equal (&p->cpus_mask, ctx->new_mask)) { +if (ctx->flags &SCA_USER ) +swap (p->user_cpus_ptr, ctx->user_mask); goto out; + } if (WARN_ON_ONCE(p == current && is_migration_disabled(p) &&
Signature · 1 line
2.31.1
Quoted 19 lines · Waiman Long
Since commit
8f9ea86fdf99("sched: Always preserve the user requested cpumask"), a successful call tosched_setaffinity()should always save the user requested cpu affinity mask in a task'suser_cpus_ptr. However, when the given cpu mask is the same as the current one,user_cpus_ptris not updated. Fix this by saving the user mask in this case too.Fixes 8f9ea86fdf99 ("sched: Always preserve the user requested cpumask")Signed-off-by Waiman Long <[email protected]>--- kernel/sched/core.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-)kernel/sched/core.c +0
-0@@ -2951,8 +2951,11 @@ static int __set_cpus_allowed_ptr_locked(struct task_struct *p, }
kernel/sched/core.c static int __set_cpus_allowed_ptr_locked(struct task_struct *p, · line 2961
Quoted 10 lines
kernel/sched/core.c +4
-1if (!(ctx->flags &SCA_MIGRATE_ENABLE )) { -if (cpumask_equal (&p->cpus_mask, ctx->new_mask)) +if (cpumask_equal (&p->cpus_mask, ctx->new_mask)) { +if (ctx->flags &SCA_USER ) +swap (p->user_cpus_ptr, ctx->user_mask); goto out; + } if (WARN_ON_ONCE(p == current && is_migration_disabled(p) &&
and this is for a separate bug and should go through the scheduler tree.
Thanks.
Signature · 1 line
tejun
Quoted 28 lines · Tejun Heo
Quoted 27 lines · Waiman Long
Since commit
8f9ea86fdf99("sched: Always preserve the user requested cpumask"), a successful call tosched_setaffinity()should always save the user requested cpu affinity mask in a task'suser_cpus_ptr. However, when the given cpu mask is the same as the current one,user_cpus_ptris not updated. Fix this by saving the user mask in this case too.Fixes 8f9ea86fdf99 ("sched: Always preserve the user requested cpumask")Signed-off-by Waiman Long <[email protected]>--- kernel/sched/core.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-)kernel/sched/core.c +4
-1@@ -2951,8 +2951,11 @@ static int __set_cpus_allowed_ptr_locked(struct task_struct *p, }if (!(ctx->flags &SCA_MIGRATE_ENABLE )) { -if (cpumask_equal (&p->cpus_mask, ctx->new_mask)) +if (cpumask_equal (&p->cpus_mask, ctx->new_mask)) { +if (ctx->flags &SCA_USER ) +swap (p->user_cpus_ptr, ctx->user_mask); goto out; + }
Quoted 3 lines
kernel/sched/core.c static int __set_cpus_allowed_ptr_locked(struct task_struct *p, · line 2961
Quoted 2 lines
kernel/sched/core.c +0
-0if (WARN_ON_ONCE(p == current && is_migration_disabled(p) &&and this is for a separate bug and should go through the scheduler tree.
Yes, this is for Peter to pick up.
Cheers,
Longman
Peter Zijlstra
maintainerQuoted 19 lines · Waiman Long
Since commit
8f9ea86fdf99("sched: Always preserve the user requested cpumask"), a successful call tosched_setaffinity()should always save the user requested cpu affinity mask in a task'suser_cpus_ptr. However, when the given cpu mask is the same as the current one,user_cpus_ptris not updated. Fix this by saving the user mask in this case too.Fixes 8f9ea86fdf99 ("sched: Always preserve the user requested cpumask")Signed-off-by Waiman Long <[email protected]>--- kernel/sched/core.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-)kernel/sched/core.c +0
-0@@ -2951,8 +2951,11 @@ static int __set_cpus_allowed_ptr_locked(struct task_struct *p, }
kernel/sched/core.c static int __set_cpus_allowed_ptr_locked(struct task_struct *p, · line 2961
Quoted 10 lines
kernel/sched/core.c +4
-1if (!(ctx->flags &SCA_MIGRATE_ENABLE )) { -if (cpumask_equal (&p->cpus_mask, ctx->new_mask)) +if (cpumask_equal (&p->cpus_mask, ctx->new_mask)) { +if (ctx->flags &SCA_USER ) +swap (p->user_cpus_ptr, ctx->user_mask); goto out; + } if (WARN_ON_ONCE(p == current && is_migration_disabled(p) &&
Indeed. Thanks!
The following commit has been merged into the sched/urgent branch of tip:
The following commit has been merged into the sched/urgent branch of tip:
Commit-ID: df14b7f9efcda35e59bb6f50351aac25c50f6e24 Gitweb: https://git.kernel.org/tip/df14b7f9efcda35e59bb6f50351aac25c50f6e24 Author: Waiman Long <[email protected]> AuthorDate: Fri, 03 Feb 2023 13:18:49 -05:00 Committer: Peter Zijlstra <[email protected]> CommitterDate: Mon, 13 Feb 2023 16:36:14 +01:00
sched/core: Fix a missed update of user_cpus_ptr
Since commit 8f9ea86fdf99 ("sched: Always preserve the user requested cpumask"), a successful call to sched_setaffinity() should always save the user requested cpu affinity mask in a task's user_cpus_ptr. However, when the given cpu mask is the same as the current one, user_cpus_ptr is not updated. Fix this by saving the user mask in this case too.
--- kernel/sched/core.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-)
kernel/sched/core.c +4 -1
@@ -2951,8 +2951,11 @@ static int __set_cpus_allowed_ptr_locked(struct task_struct *p, }if (!(ctx->flags &SCA_MIGRATE_ENABLE )) { -if (cpumask_equal (&p->cpus_mask, ctx->new_mask)) +if (cpumask_equal (&p->cpus_mask, ctx->new_mask)) { +if (ctx->flags &SCA_USER ) +swap (p->user_cpus_ptr, ctx->user_mask); goto out; + } if (WARN_ON_ONCE(p == current && is_migration_disabled(p) &&