sched: Do not copy user_cpus_ptr when parent is reset_on_fork
RFC PATCH 1/1 sched: Do not copy user_cpus_ptr when parent is reset_on_fork
Now, the task's user_cpus_ptr would dup from parent's user_cpus_ptr. It is better reset the user_cpus_ptr when parent's reset_on_fork is set.
--- kernel/sched/core.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
kernel/sched/core.c +1 -1
@@ -2666,7 +2666,7 @@ int dup_user_cpus_ptr(struct task_struct *dst, struct task_struct *src,* do_set_cpus_allowed(). */ raw_spin_lock_irqsave (&src->pi_lock, flags); -if (src->user_cpus_ptr) { +if (src->user_cpus_ptr && !src->sched_reset_on_fork) {swap (dst->user_cpus_ptr, user_mask);cpumask_copy (dst->user_cpus_ptr, src->user_cpus_ptr); }
Signature · 1 line
2.25.1
Quoted 3 lines · Xuewen Yan
Now, the task's
user_cpus_ptrwould dup from parent'suser_cpus_ptr. It is better reset theuser_cpus_ptrwhen parent'sreset_on_forkis set.
According to sched(7):
Each thread has a reset-on-fork scheduling flag. When this flag is set, children created by fork(2) do not inherit privileged scheduling policies.
It can be argued what are considered privileged scheduling policies. AFAICS, a restricted affinity doesn't seem to be a "privileged" scheduling policy. That is my own opinion strictly from the definition point of view, I will let others weigh in on that and I am OK to go either way.
Cheers,
Longman
Quoted 19 lines
Signed-off-by Xuewen Yan <[email protected]>--- kernel/sched/core.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)kernel/sched/core.c +1
-1@@ -2666,7 +2666,7 @@ int dup_user_cpus_ptr(struct task_struct *dst, struct task_struct *src,* do_set_cpus_allowed(). */ raw_spin_lock_irqsave (&src->pi_lock, flags); -if (src->user_cpus_ptr) { +if (src->user_cpus_ptr && !src->sched_reset_on_fork) {swap (dst->user_cpus_ptr, user_mask);cpumask_copy (dst->user_cpus_ptr, src->user_cpus_ptr); }
Quoted 7 lines · On Thu, Sep 05, 2024 at 08:42:33AM -0400 Waiman Long wrote:
Quoted 3 lines · Xuewen Yan
Now, the task's
user_cpus_ptrwould dup from parent'suser_cpus_ptr. It is better reset theuser_cpus_ptrwhen parent'sreset_on_forkis set.According to sched(7):
Quoted 9 lines
Each thread has a reset-on-fork scheduling flag. When this flag is set, children created by fork(2) do not inherit privileged scheduling policies.
It can be argued what are considered privileged scheduling policies. AFAICS, a restricted affinity doesn't seem to be a "privileged" scheduling policy. That is my own opinion strictly from the definition point of view, I will let others weigh in on that and I am OK to go either way.
I think that one could argue that clearing a restricted affinity is increasing the privilege and not preventing inheritence of same. i.e. it would be the opposite of what reset-on-fork means.
I'd say NAK to this one if I had that power.
Cheers,
Phil
Quoted 24 lines
Cheers,
LongmanQuoted 19 lines
Signed-off-by Xuewen Yan <[email protected]>--- kernel/sched/core.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)kernel/sched/core.c +1
-1@@ -2666,7 +2666,7 @@ int dup_user_cpus_ptr(struct task_struct *dst, struct task_struct *src,* do_set_cpus_allowed(). */ raw_spin_lock_irqsave (&src->pi_lock, flags); -if (src->user_cpus_ptr) { +if (src->user_cpus_ptr && !src->sched_reset_on_fork) {swap (dst->user_cpus_ptr, user_mask);cpumask_copy (dst->user_cpus_ptr, src->user_cpus_ptr); }
Quoted 16 lines · Phil Auld
Quoted 6 lines · On Thu, Sep 05, 2024 at 08:42:33AM -0400 Waiman Long wrote:
Quoted 3 lines · Xuewen Yan
Now, the task's
user_cpus_ptrwould dup from parent'suser_cpus_ptr. It is better reset theuser_cpus_ptrwhen parent'sreset_on_forkis set.According to sched(7):
Quoted 9 lines
Each thread has a reset-on-fork scheduling flag. When this flag is set, children created by fork(2) do not inherit privileged scheduling policies.
It can be argued what are considered privileged scheduling policies. AFAICS, a restricted affinity doesn't seem to be a "privileged" scheduling policy. That is my own opinion strictly from the definition point of view, I will let others weigh in on that and I am OK to go either way.
Quoted 5 lines
I think that one could argue that clearing a restricted affinity is increasing the privilege and not preventing inheritence of same. i.e. it would be the opposite of what reset-on-fork means.
I'd say NAK to this one if I had that power.
Maybe I am not clear enough in my previous mail. My position is the same as yours. I think this patch is not necessary. More reasons should be provided as to why it is right to not inherited the restricted affinity when reset-on-fork flag is reset.
Cheers,
Longman
Quoted 22 lines · On Thu, Sep 05, 2024 at 10:00:36AM -0400 Waiman Long wrote:
Quoted 20 lines · Phil Auld
Quoted 6 lines · On Thu, Sep 05, 2024 at 08:42:33AM -0400 Waiman Long wrote:
Quoted 3 lines · Xuewen Yan
Now, the task's
user_cpus_ptrwould dup from parent'suser_cpus_ptr. It is better reset theuser_cpus_ptrwhen parent'sreset_on_forkis set.According to sched(7):
Quoted 9 lines
Each thread has a reset-on-fork scheduling flag. When this flag is set, children created by fork(2) do not inherit privileged scheduling policies.
It can be argued what are considered privileged scheduling policies. AFAICS, a restricted affinity doesn't seem to be a "privileged" scheduling policy. That is my own opinion strictly from the definition point of view, I will let others weigh in on that and I am OK to go either way.
I think that one could argue that clearing a restricted affinity is increasing the privilege and not preventing inheritence of same. i.e. it would be the opposite of what reset-on-fork means.
Quoted 7 lines
Quoted 1 line
I'd say NAK to this one if I had that power.
Maybe I am not clear enough in my previous mail. My position is the same as yours. I think this patch is not necessary. More reasons should be provided as to why it is right to not inherited the restricted affinity when reset-on-fork flag is reset.
No, you were clear. I was just providing my opinion, weighing in :)
Cheers,
Phil
Quoted 3 lines
Cheers,
Longman