Commit bdb0cca0 authored by Paul E. McKenney's avatar Paul E. McKenney

rcu-tasks: Mark ->trc_reader_nesting data races

There are several ->trc_reader_nesting data races that are too
low-probability for KCSAN to notice, but which will happen sooner or
later.  This commit therefore marks these accesses, and comments one
that cannot race.
Signed-off-by: default avatarPaul E. McKenney <paulmck@kernel.org>
parent 45f4b4a2
...@@ -897,7 +897,7 @@ static void trc_read_check_handler(void *t_in) ...@@ -897,7 +897,7 @@ static void trc_read_check_handler(void *t_in)
// If the task is not in a read-side critical section, and // If the task is not in a read-side critical section, and
// if this is the last reader, awaken the grace-period kthread. // if this is the last reader, awaken the grace-period kthread.
if (likely(!t->trc_reader_nesting)) { if (likely(!READ_ONCE(t->trc_reader_nesting))) {
if (WARN_ON_ONCE(atomic_dec_and_test(&trc_n_readers_need_end))) if (WARN_ON_ONCE(atomic_dec_and_test(&trc_n_readers_need_end)))
wake_up(&trc_wait); wake_up(&trc_wait);
// Mark as checked after decrement to avoid false // Mark as checked after decrement to avoid false
...@@ -906,7 +906,7 @@ static void trc_read_check_handler(void *t_in) ...@@ -906,7 +906,7 @@ static void trc_read_check_handler(void *t_in)
goto reset_ipi; goto reset_ipi;
} }
// If we are racing with an rcu_read_unlock_trace(), try again later. // If we are racing with an rcu_read_unlock_trace(), try again later.
if (unlikely(t->trc_reader_nesting < 0)) { if (unlikely(READ_ONCE(t->trc_reader_nesting) < 0)) {
if (WARN_ON_ONCE(atomic_dec_and_test(&trc_n_readers_need_end))) if (WARN_ON_ONCE(atomic_dec_and_test(&trc_n_readers_need_end)))
wake_up(&trc_wait); wake_up(&trc_wait);
goto reset_ipi; goto reset_ipi;
...@@ -953,6 +953,7 @@ static bool trc_inspect_reader(struct task_struct *t, void *arg) ...@@ -953,6 +953,7 @@ static bool trc_inspect_reader(struct task_struct *t, void *arg)
n_heavy_reader_ofl_updates++; n_heavy_reader_ofl_updates++;
in_qs = true; in_qs = true;
} else { } else {
// The task is not running, so C-language access is safe.
in_qs = likely(!t->trc_reader_nesting); in_qs = likely(!t->trc_reader_nesting);
} }
...@@ -985,7 +986,7 @@ static void trc_wait_for_one_reader(struct task_struct *t, ...@@ -985,7 +986,7 @@ static void trc_wait_for_one_reader(struct task_struct *t,
// The current task had better be in a quiescent state. // The current task had better be in a quiescent state.
if (t == current) { if (t == current) {
t->trc_reader_checked = true; t->trc_reader_checked = true;
WARN_ON_ONCE(t->trc_reader_nesting); WARN_ON_ONCE(READ_ONCE(t->trc_reader_nesting));
return; return;
} }
...@@ -1101,7 +1102,7 @@ static void show_stalled_task_trace(struct task_struct *t, bool *firstreport) ...@@ -1101,7 +1102,7 @@ static void show_stalled_task_trace(struct task_struct *t, bool *firstreport)
".I"[READ_ONCE(t->trc_ipi_to_cpu) > 0], ".I"[READ_ONCE(t->trc_ipi_to_cpu) > 0],
".i"[is_idle_task(t)], ".i"[is_idle_task(t)],
".N"[cpu > 0 && tick_nohz_full_cpu(cpu)], ".N"[cpu > 0 && tick_nohz_full_cpu(cpu)],
t->trc_reader_nesting, READ_ONCE(t->trc_reader_nesting),
" N"[!!t->trc_reader_special.b.need_qs], " N"[!!t->trc_reader_special.b.need_qs],
cpu); cpu);
sched_show_task(t); sched_show_task(t);
...@@ -1196,7 +1197,7 @@ static void rcu_tasks_trace_postgp(struct rcu_tasks *rtp) ...@@ -1196,7 +1197,7 @@ static void rcu_tasks_trace_postgp(struct rcu_tasks *rtp)
static void exit_tasks_rcu_finish_trace(struct task_struct *t) static void exit_tasks_rcu_finish_trace(struct task_struct *t)
{ {
WRITE_ONCE(t->trc_reader_checked, true); WRITE_ONCE(t->trc_reader_checked, true);
WARN_ON_ONCE(t->trc_reader_nesting); WARN_ON_ONCE(READ_ONCE(t->trc_reader_nesting));
WRITE_ONCE(t->trc_reader_nesting, 0); WRITE_ONCE(t->trc_reader_nesting, 0);
if (WARN_ON_ONCE(READ_ONCE(t->trc_reader_special.b.need_qs))) if (WARN_ON_ONCE(READ_ONCE(t->trc_reader_special.b.need_qs)))
rcu_read_unlock_trace_special(t, 0); rcu_read_unlock_trace_special(t, 0);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment