KCSAN: data-race in exit_signals / prepare_signal
Subsystems (2)
syzbot
syzbotHello,
syzbot found the following crash on:
HEAD commit: d724f94f x86, kcsan: Enable KCSAN for x86 git tree: https://github.com/google/ktsan.git kcsan console output: https://syzkaller.appspot.com/x/log.txt?x=13eab79f600000 kernel config: https://syzkaller.appspot.com/x/.config?x=c0906aa620713d80 dashboard link: https://syzkaller.appspot.com/bug?extid=492a4acccd8fc75ddfd0 compiler: gcc (GCC) 9.0.0 20181231 (experimental)
Unfortunately, I don't have any reproducer for this crash yet.
IMPORTANT: if you fix the bug, please add the following tag to the commit:
==================================================================
BUG: KCSAN: data-race in exit_signals / prepare_signal
read to 0xffff888103566064 of 4 bytes by interrupt on cpu 0:
sig_task_ignored kernel/signal.c:94 [inline] sig_ignored kernel/signal.c:119 [inline] prepare_signal+0x1f5/0x790 kernel/signal.c:956 send_sigqueue+0xc1/0x4b0 kernel/signal.c:1859 posix_timer_event kernel/time/posix-timers.c:328 [inline] posix_timer_fn+0x10d/0x230 kernel/time/posix-timers.c:354 __run_hrtimer kernel/time/hrtimer.c:1389 [inline] __hrtimer_run_queues+0x288/0x600 kernel/time/hrtimer.c:1451 hrtimer_interrupt+0x22a/0x480 kernel/time/hrtimer.c:1509 local_apic_timer_interrupt arch/x86/kernel/apic/apic.c:1110 [inline] smp_apic_timer_interrupt+0xdc/0x280 arch/x86/kernel/apic/apic.c:1135 apic_timer_interrupt+0xf/0x20 arch/x86/entry/entry_64.S:830 arch_local_irq_enable arch/x86/include/asm/paravirt.h:778 [inline] __raw_spin_unlock_irq include/linux/spinlock_api_smp.h:168 [inline] _raw_spin_unlock_irq+0x4e/0x80 kernel/locking/spinlock.c:199 spin_unlock_irq include/linux/spinlock.h:388 [inline] get_signal+0x1f4/0x1320 kernel/signal.c:2707 do_signal+0x3b/0xc00 arch/x86/kernel/signal.c:815 exit_to_usermode_loop+0x250/0x2c0 arch/x86/entry/common.c:159 prepare_exit_to_usermode arch/x86/entry/common.c:194 [inline] syscall_return_slowpath arch/x86/entry/common.c:274 [inline] do_syscall_64+0x2d7/0x2f0 arch/x86/entry/common.c:299 entry_SYSCALL_64_after_hwframe+0x44/0xa9
write to 0xffff888103566064 of 4 bytes by task 7604 on cpu 1:
exit_signals+0x13b/0x490 kernel/signal.c:2822 do_exit+0x1af/0x18e0 kernel/exit.c:825 do_group_exit+0xb4/0x1c0 kernel/exit.c:983 __do_sys_exit_group kernel/exit.c:994 [inline] __se_sys_exit_group kernel/exit.c:992 [inline] __x64_sys_exit_group+0x2e/0x30 kernel/exit.c:992 do_syscall_64+0xcf/0x2f0 arch/x86/entry/common.c:296 entry_SYSCALL_64_after_hwframe+0x44/0xa9
Reported by Kernel Concurrency Sanitizer on:
CPU: 1 PID: 7604 Comm: syz-executor.4 Not tainted 5.3.0+ #0 Hardware name: Google Google Compute Engine/Google Compute Engine, BIOS Google 01/01/2011 ==================================================================
---
This bug is generated by a bot. It may contain errors. See https://goo.gl/tpsmEJ for more information about syzbot. syzbot engineers can be reached at [email protected].
syzbot will keep track of this bug report. See:
https://goo.gl/tpsmEJ#status for how to communicate with syzbot.
[+Cc Will]
Quoted 11 lines · syzbot
Hello,
syzbot found the following crash on:
HEAD commit: d724f94f x86, kcsan: Enable KCSAN for x86 git tree: https://github.com/google/ktsan.git kcsan console output: https://syzkaller.appspot.com/x/log.txt?x=13eab79f600000 kernel config: https://syzkaller.appspot.com/x/.config?x=c0906aa620713d80 dashboard link: https://syzkaller.appspot.com/bug?extid=492a4acccd8fc75ddfd0 compiler: gcc (GCC) 9.0.0 20181231 (experimental)
Quoted 7 lines
Unfortunately, I don't have any reproducer for this crash yet.
IMPORTANT: if you fix the bug, please add the following tag to the commit:
Reported-by [email protected]==================================================================
BUG: KCSAN: data-race in exit_signals / prepare_signal
This traces back to Oleg fixing a race between a group stop and a thread exiting before it notices that it has a pending signal or is in the middle of do_exit() already, causing group stop to get wacky.
The original commit to fix this race is
commit d12619b5ff56 ("fix group stop with exit race") which took sighand lock before setting PF_EXITING on the thread.
Later on in
commit 5dee1707dfbf ("move the related code from exit_notify() to exit_signals()") an improvement was made for the single-threaded case and the
case where the group stop is already in progress. This removed the sighand lock around the PF_EXITING assignment.
If the race really matters and given how tsk->flags is currently accessed everywhere the simple fix for now might be:
kernel/signal.c +2 -0
@@ -2819,7 +2819,9 @@ void exit_signals(struct task_struct *tsk)cgroup_threadgroup_change_begin (tsk);if (thread_group_empty (tsk) ||signal_group_exit (tsk->signal)) { +spin_lock_irq (&tsk->sighand->siglock); tsk->flags |=PF_EXITING ; +spin_unlock_irq (&tsk->sighand->siglock);cgroup_threadgroup_change_end (tsk);return ; }
Christian
Quoted 7 lines · Christian Brauner
This traces back to Oleg fixing a race between a group stop and a thread exiting before it notices that it has a pending signal or is in the middle of
do_exit()already, causing group stop to get wacky.
The original commit to fix this race is
commitd12619b5ff56("fix group stop with exit race") which took sighand lock before settingPF_EXITINGon the thread.
Not really... sig_task_ignored() didn't check task->flags until the recent 33da8e7c81 ("signal: Allow cifs and drbd to receive their terminating signals"). But I think this doesn't matter, see below.
Quoted 8 lines
If the race really matters and given how
tsk->flagsis currently accessed everywhere the simple fix for now might be:kernel/signal.c +0
-0
kernel/signal.c void exit_signals(struct task_struct *tsk) · line 2824
Quoted 6 lines
kernel/signal.c +2
-0@@ -2819,7 +2819,9 @@ void exit_signals(struct task_struct *tsk)cgroup_threadgroup_change_begin (tsk);if (thread_group_empty (tsk) ||signal_group_exit (tsk->signal)) { +spin_lock_irq (&tsk->sighand->siglock); tsk->flags |=PF_EXITING ; +spin_unlock_irq (&tsk->sighand->siglock);
Well, exit_signals() tries to avoid ->siglock in this case....
But this doesn't matter. IIUC the problem is not that exit_signals() sets PF_EXITING, the problem is that it writes to tsk->flags and kasan detects the data race.
For example, freezable_schedule() which sets PF_FREEZER_SKIP can equally "race" with sig_task_ignored() or with ANY other code which checks this task's flags.
I think this is WONTFIX.
Oleg.
Quoted 35 lines · Oleg Nesterov
Quoted 7 lines · Christian Brauner
This traces back to Oleg fixing a race between a group stop and a thread exiting before it notices that it has a pending signal or is in the middle of
do_exit()already, causing group stop to get wacky.
The original commit to fix this race is
commitd12619b5ff56("fix group stop with exit race") which took sighand lock before settingPF_EXITINGon the thread.Not really...
sig_task_ignored()didn't checktask->flagsuntil the recent33da8e7c81("signal: Allow cifs and drbd to receive their terminating signals"). But I think this doesn't matter, see below.Quoted 8 lines
If the race really matters and given how
tsk->flagsis currently accessed everywhere the simple fix for now might be:kernel/signal.c +0
-0kernel/signal.c void exit_signals(struct task_struct *tsk) · line 2824
Quoted 6 lines
kernel/signal.c +2
-0@@ -2819,7 +2819,9 @@ void exit_signals(struct task_struct *tsk)cgroup_threadgroup_change_begin (tsk);if (thread_group_empty (tsk) ||signal_group_exit (tsk->signal)) { +spin_lock_irq (&tsk->sighand->siglock); tsk->flags |=PF_EXITING ; +spin_unlock_irq (&tsk->sighand->siglock);Well,
exit_signals()tries to avoid ->siglock in this case....But this doesn't matter. IIUC the problem is not that
exit_signals()setsPF_EXITING, the problem is that it writes totsk->flagsand kasan detects the data race.
Quoted 5 lines
For example,
freezable_schedule()which setsPF_FREEZER_SKIPcan equally "race" withsig_task_ignored()or with ANY other code which checks this task's flags.I think this is WONTFIX.
If taking the spinlock is unnecessary (which AFAIK it probably is) and there are no other writers to this flag, you will still need a WRITE_ONCE(tsk->flags, tsk->flags | PF_EXITING) to avoid the data-race.
However, if it is possible that there are concurrent writers setting other bits in flags, you need to ensure that the bits are set atomically (unless it's ok to lose some bits here). This can only be done via 1) taking siglock, or 2) via e.g. atomic_or(...), however, flags is not atomic_t ...
-- Marco
Quoted 9 lines · Marco Elver
Quoted 2 lines · Oleg Nesterov
I think this is WONTFIX.
If taking the spinlock is unnecessary (which AFAIK it probably is) and there are no other writers to this flag, you will still need a
WRITE_ONCE(tsk->flags, tsk->flags | PF_EXITING)to avoid the data-race.
Or even WRITE_ONCE(tsk->flags, READ_ONCE(tsk->flags) | PF_EXITING) in theory. But in practice, I do not think compiler can turn
curent->flags |= PF_EXITING;
into something which temporary clears another flag, say, PF_KTHREAD.
Quoted 2 lines
However, if it is possible that there are concurrent writers setting other bits in flags,
No, only current taks should change its ->flags.
Oleg.
Quoted 30 lines · Oleg Nesterov
Quoted 7 lines · Christian Brauner
This traces back to Oleg fixing a race between a group stop and a thread exiting before it notices that it has a pending signal or is in the middle of
do_exit()already, causing group stop to get wacky.
The original commit to fix this race is
commitd12619b5ff56("fix group stop with exit race") which took sighand lock before settingPF_EXITINGon the thread.Not really...
sig_task_ignored()didn't checktask->flagsuntil the recent33da8e7c81("signal: Allow cifs and drbd to receive their terminating signals"). But I think this doesn't matter, see below.Quoted 8 lines
If the race really matters and given how
tsk->flagsis currently accessed everywhere the simple fix for now might be:kernel/signal.c +0
-0kernel/signal.c void exit_signals(struct task_struct *tsk) · line 2824
Quoted 6 lines
kernel/signal.c +2
-0@@ -2819,7 +2819,9 @@ void exit_signals(struct task_struct *tsk)cgroup_threadgroup_change_begin (tsk);if (thread_group_empty (tsk) ||signal_group_exit (tsk->signal)) { +spin_lock_irq (&tsk->sighand->siglock); tsk->flags |=PF_EXITING ; +spin_unlock_irq (&tsk->sighand->siglock);Well,
exit_signals()tries to avoid ->siglock in this case....
Quoted 3 lines
But this doesn't matter. IIUC the problem is not that
exit_signals()setsPF_EXITING, the problem is that it writes totsk->flagsand kasan detects the data race.
Right, that's the reason I said "If the race really matters". I thought that other writers/readers always take sighand lock. So the easy fix would have been to take sighand lock too.
The alternative is that we need to fiddle with task_struct itself and replace flags with an atomic_t or sm which is more invasive and probably more controversial.
Christian
cgroup_enable_task_cg_lists && PF_EXITING (Was: KCSAN: data-race in exit_signals / prepare_signal)
In reply to syzbotcould you explain the usage of siglock/PF_EXITING in cgroup_enable_task_cg_lists() ?
PF_EXITING is protected by cgroup_threadgroup_rwsem, not by sighand->siglock.
Oleg.
Tejun Heo
maintainerRe: cgroup_enable_task_cg_lists && PF_EXITING (Was: KCSAN: data-race in exit_signals / prepare_signal)
Hello, Oleg.
Quoted 5 lines · Oleg Nesterov
could you explain the usage of siglock/PF_EXITING in
cgroup_enable_task_cg_lists()?
PF_EXITINGis protected bycgroup_threadgroup_rwsem, not bysighand->siglock.
Yeah, the optimization was added a really long time ago and I'm not sure it was ever correct. I'm removing it. If this ever becomes a problem (pretty unlikely), I think the right thing to do is adding a boot param instead of trying to do this dynamically.
Thanks.
Signature · 1 line
tejun
Tejun Heo
maintainerPATCH 1/1 cgroup: remove cgroup_enable_task_cg_lists() optimization
In reply to Oleg Nesterovcgroup_enable_task_cg_lists() is used to lazyily initialize task cgroup associations on the first use to reduce fork / exit overheads on systems which don't use cgroup. Unfortunately, locking around it has never been actually correct and its value is dubious given how the vast majority of systems use cgroup right away from boot.
This patch removes the optimization. For now, replace the cg_list based branches with WARN_ON_ONCE()'s to be on the safe side. We can simplify the logic further in the future.
--- include/linux/cgroup.h | 1 kernel/cgroup/cgroup.c | 184 ++++++++++--------------------------------------- kernel/cgroup/cpuset.c | 2 3 files changed, 39 insertions(+), 148 deletions(-)
include/linux/cgroup.h +0 -1
@@ -150,7 +150,6 @@ struct task_struct *cgroup_taskset_first(struct cgroup_taskset *tset,struct task_struct *cgroup_taskset_next (struct cgroup_taskset *tset,struct cgroup_subsys_state **dst_cssp); -void cgroup_enable_task_cg_lists (void );void css_task_iter_start (struct cgroup_subsys_state *css,unsigned int flags,struct css_task_iter *it);struct task_struct *css_task_iter_next (struct css_task_iter *it);
kernel/cgroup/cgroup.c +39 -145
238 lines not on this page · raw message
kernel/cgroup/cpuset.c +0 -2
@@ -928,8 +928,6 @@ static void rebuild_root_domains(void)lockdep_assert_cpus_held ();lockdep_assert_held (&sched_domains_mutex); -cgroup_enable_task_cg_lists (); -rcu_read_lock ();/*
Tejun Heo
maintainerRe: [PATCH cgroup/for-5.5] cgroup: remove cgroup_enable_task_cg_lists() optimization
Quoted 6 lines · Tejun Heo
cgroup_enable_task_cg_lists()is used to lazyily initialize task cgroup associations on the first use to reduce fork / exit overheads on systems which don't use cgroup. Unfortunately, locking around it has never been actually correct and its value is dubious given how the vast majority of systems use cgroup right away from boot.
Quoted 6 lines
This patch removes the optimization. For now, replace the
cg_listbased branches with WARN_ON_ONCE()'s to be on the safe side. We can simplify the logic further in the future.Signed-off-by Tejun Heo <[email protected]>Reported-by Oleg Nesterov <[email protected]>
Applying to cgroup/for-5.5.
Thanks.
Signature · 1 line
tejun
Re: [PATCH cgroup/for-5.5] cgroup: remove cgroup_enable_task_cg_lists() optimization
[+Dmitry]
Quoted 7 lines · Tejun Heo
Quoted 6 lines · Tejun Heo
cgroup_enable_task_cg_lists()is used to lazyily initialize task cgroup associations on the first use to reduce fork / exit overheads on systems which don't use cgroup. Unfortunately, locking around it has never been actually correct and its value is dubious given how the vast majority of systems use cgroup right away from boot.
Quoted 8 lines
Quoted 6 lines
This patch removes the optimization. For now, replace the
cg_listbased branches with WARN_ON_ONCE()'s to be on the safe side. We can simplify the logic further in the future.Signed-off-by Tejun Heo <[email protected]>Reported-by Oleg Nesterov <[email protected]>Applying to cgroup/for-5.5.
The code you removed was the only place where task->flags was set from !current. So I think this fixes the syzbot data-race report in:
https://lore.kernel.org/r/[email protected]
Thanks!
Christian
Re: [PATCH cgroup/for-5.5] cgroup: remove cgroup_enable_task_cg_lists() optimization
Quoted 15 lines · Christian Brauner
[+Dmitry]
Quoted 11 lines · Tejun Heo
Quoted 10 lines · Tejun Heo
cgroup_enable_task_cg_lists()is used to lazyily initialize task cgroup associations on the first use to reduce fork / exit overheads on systems which don't use cgroup. Unfortunately, locking around it has never been actually correct and its value is dubious given how the vast majority of systems use cgroup right away from boot.This patch removes the optimization. For now, replace the
cg_listbased branches with WARN_ON_ONCE()'s to be on the safe side. We can simplify the logic further in the future.
Quoted 7 lines
Quoted 4 lines
Quoted 2 lines
Signed-off-by Tejun Heo <[email protected]>Reported-by Oleg Nesterov <[email protected]>Applying to cgroup/for-5.5.
The code you removed was the only place where
task->flagswas set from !current.
No, that code doesn't modify task->flags. It checks PF_EXITING under siglock but this makes no sense and can't avoid the race with cgroup_exit().
Quoted 2 lines
So I think this fixes the syzbot data-race report in:
https://lore.kernel.org/r/[email protected]
No.
Almost every usage of task->flags (load or sore) can be reported as "data race".
Say, you do
if (task->flags & PF_KTHREAD)
while this task does
current->flags |= PF_FREEZER_SKIP; schedule().
this is data race.
Oleg.
Re: [PATCH cgroup/for-5.5] cgroup: remove cgroup_enable_task_cg_lists() optimization
Quoted 19 lines · Oleg Nesterov
Quoted 18 lines · Christian Brauner
[+Dmitry]
Quoted 14 lines · Tejun Heo
Quoted 12 lines · Tejun Heo
cgroup_enable_task_cg_lists()is used to lazyily initialize task cgroup associations on the first use to reduce fork / exit overheads on systems which don't use cgroup. Unfortunately, locking around it has never been actually correct and its value is dubious given how the vast majority of systems use cgroup right away from boot.This patch removes the optimization. For now, replace the
cg_listbased branches with WARN_ON_ONCE()'s to be on the safe side. We can simplify the logic further in the future.Signed-off-by Tejun Heo <[email protected]>Reported-by Oleg Nesterov <[email protected]>
Quoted 7 lines
Quoted 4 lines
Quoted 1 line
Applying to cgroup/for-5.5.
The code you removed was the only place where
task->flagswas set from !current.No, that code doesn't modify
task->flags. It checksPF_EXITINGunder siglock but this makes no sense and can't avoid the race withcgroup_exit().
Sorry, you are right. I misread
Ah right, sorry I misremembered this from the prior thread where we discussed where ->flags is set from [1].
Quoted 10 lines
Quoted 3 lines
So I think this fixes the syzbot data-race report in:
https://lore.kernel.org/r/[email protected]No.
Almost every usage of
task->flags(load or sore) can be reported as "data race".Say, you do
Quoted 8 lines
if (task->flags & PF_KTHREAD)while this task does
current->flags |= PF_FREEZER_SKIP; schedule().this is data race.
Right, but I thought we agreed on WONTFIX in those scenarios? The alternative is to READ_ONCE()/WRITE_ONCE() all of these.
[1]: https://lore.kernel.org/r/[email protected]
Anyway, accidental noise on my part.
Christian
Re: [PATCH cgroup/for-5.5] cgroup: remove cgroup_enable_task_cg_lists() optimization
Quoted 10 lines · Christian Brauner
Quoted 8 lines · Oleg Nesterov
Almost every usage of
task->flags(load or sore) can be reported as "data race".Say, you do
if (task->flags & PF_KTHREAD)while this task does
Quoted 7 lines
Quoted 4 lines
current->flags |= PF_FREEZER_SKIP; schedule().this is data race.
Right, but I thought we agreed on WONTFIX in those scenarios? The alternative is to READ_ONCE()/WRITE_ONCE() all of these.
Well, in my opinion this is WONTFIX, but I won't argue if someone adds _ONCE to all of these. Same for task->state, exit_state, and more.
Oleg.
Re: [PATCH cgroup/for-5.5] cgroup: remove cgroup_enable_task_cg_lists() optimization
[Removing a few people from Cc to avoid spamming the whole world]
Quoted 14 lines · Oleg Nesterov
Quoted 13 lines · Christian Brauner
Quoted 11 lines · Oleg Nesterov
Almost every usage of
task->flags(load or sore) can be reported as "data race".Say, you do
if (task->flags & PF_KTHREAD)while this task does
current->flags |= PF_FREEZER_SKIP; schedule().
Quoted 8 lines
Quoted 4 lines
Quoted 1 line
this is data race.
Right, but I thought we agreed on WONTFIX in those scenarios? The alternative is to READ_ONCE()/WRITE_ONCE() all of these.
Well, in my opinion this is WONTFIX, but I won't argue if someone adds
_ONCEto all of these. Same fortask->state,exit_state, and more.
Well, I honestly think that state and exit_state would make sense. There already were issues that got fixed for example in 3245d6acab98 ("exit: fix race between wait_consider_task() and wait_task_zombie()") and as far as I understand this would also help kcsan to better detect races.
Christian
Re: [PATCH cgroup/for-5.5] cgroup: remove cgroup_enable_task_cg_lists() optimization
Quoted 18 lines · Christian Brauner
Quoted 16 lines · Oleg Nesterov
Quoted 15 lines · Christian Brauner
Quoted 12 lines · Oleg Nesterov
Almost every usage of
task->flags(load or sore) can be reported as "data race".Say, you do
if (task->flags & PF_KTHREAD)while this task does
current->flags |= PF_FREEZER_SKIP; schedule().this is data race.
Quoted 8 lines
Quoted 6 lines
Quoted 2 lines
Right, but I thought we agreed on WONTFIX in those scenarios? The alternative is to READ_ONCE()/WRITE_ONCE() all of these.
Well, in my opinion this is WONTFIX, but I won't argue if someone adds
_ONCEto all of these. Same fortask->state,exit_state, and more.Well, I honestly think that state and
exit_statewould make sense.
Heh. Again, I am not arguing, but...
OK, lets suppose we blindly add READ_ONCE() to every access of task->state/exit_state.
Yes, this won't hurt and possibly can fix some bugs we are not aware of.
However,
Quoted 2 lines
There already were issues that got fixed for example in
3245d6acab98("exit: fix race betweenwait_consider_task()andwait_task_zombie()")
The change above can't fix the problem like this.
It is not that this code lacked READ_ONCE(). I am sure me and others understood that this code can read ->exit_state more than once, just nobody noticed that in this case this is really wrong.
IOW, if we simply change the code before 3245d6acab98 to use READ_ONCE() the code will be equally wrong, and
Quoted 2 lines
and as far as I understand this would also help kcsan to better detect races.
this change will simply hide the problem from kcsan.
Oleg.
Re: [PATCH cgroup/for-5.5] cgroup: remove cgroup_enable_task_cg_lists() optimization
Quoted 26 lines · Oleg Nesterov
Quoted 25 lines · Christian Brauner
Quoted 22 lines · Oleg Nesterov
Quoted 10 lines · Christian Brauner
Quoted 8 lines · Oleg Nesterov
Almost every usage of
task->flags(load or sore) can be reported as "data race".Say, you do
if (task->flags & PF_KTHREAD)while this task does
Quoted 7 lines
Quoted 4 lines
current->flags |= PF_FREEZER_SKIP; schedule().this is data race.
Right, but I thought we agreed on WONTFIX in those scenarios? The alternative is to READ_ONCE()/WRITE_ONCE() all of these.
Well, in my opinion this is WONTFIX, but I won't argue if someone adds
_ONCEto all of these. Same fortask->state,exit_state, and more.
Quoted 8 lines
Quoted 1 line
Well, I honestly think that state and
exit_statewould make sense.Heh. Again, I am not arguing, but...
OK, lets suppose we blindly add
READ_ONCE()to every access of task->state/exit_state.Yes, this won't hurt and possibly can fix some bugs we are not aware of.
I wasn't planning or working on adding *_ONCE everywhere. ;) I just think it makes sense as a preemptive strike since they are shared (though mostly protected by locks anyway).
Quoted 7 lines
However,
Quoted 2 lines
There already were issues that got fixed for example in
3245d6acab98("exit: fix race betweenwait_consider_task()andwait_task_zombie()")The change above can't fix the problem like this.
No argument about the code we discussed right here, for sure!
Quoted 5 lines
It is not that this code lacked
READ_ONCE(). I am sure me and others understood that this code can read ->exit_state more than once, just nobody noticed that in this case this is really wrong.
Quoted 7 lines
IOW, if we simply change the code before
3245d6acab98to useREAD_ONCE()the code will be equally wrong, andQuoted 2 lines
and as far as I understand this would also help kcsan to better detect races.
this change will simply hide the problem from kcsan.
I can't speak to that since the claim that read_once() helps them even if it's not really doing anything. But maybe I misunderstood the k{c,t}san manpage.
Christian
Re: [PATCH cgroup/for-5.5] cgroup: remove cgroup_enable_task_cg_lists() optimization
Quoted 10 lines · Christian Brauner
Quoted 9 lines · Oleg Nesterov
On 10/25, Christian Brauner wrote:
It is not that this code lacked
READ_ONCE(). I am sure me and others understood that this code can read ->exit_state more than once, just nobody noticed that in this case this is really wrong.IOW, if we simply change the code before
3245d6acab98to useREAD_ONCE()the code will be equally wrong, and
Quoted 8 lines
Quoted 4 lines
Quoted 2 lines
and as far as I understand this would also help kcsan to better detect races.
this change will simply hide the problem from kcsan.
I can't speak to that since the claim that
read_once()helps them even if it's not really doing anything. But maybe I misunderstood the k{c,t}san manpage.
What Oleg said is right: marking things _ONCE will make these accesses no longer be data races, and KCSAN would then no longer report these as data race, even if the code is still buggy due to there being a race condition. In this case, the race condition would stop also being a data race, and we'd no longer find it.
Thanks,
-- Marco