Tasks-RCU updates for v5.7
Subsystems (2)
Paul E. McKenney
maintainercover Tasks-RCU updates for v5.7
Hello!
This series contains Tasks-RCU updates.
1. Add *_ONCE() for rcu_tasks_cbs_head.
2. Add missing annotation for exit_tasks_rcu_start(), courtesy
of Jules Irenge.
3. Add missing annotation for exit_tasks_rcu_finish(), courtesy
of Jules Irenge.
Thanx, Paul
------------------------------------------------------------------------
update.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-)
[email protected]
maintainerPATCH 1/3 rcu-tasks: *_ONCE() for rcu_tasks_cbs_head
From: "Paul E. McKenney" <[email protected]>
The RCU tasks list of callbacks, rcu_tasks_cbs_head, is sampled locklessly by rcu_tasks_kthread() when waiting for work to do. This commit therefore applies READ_ONCE() to that lockless sampling and WRITE_ONCE() to the single potential store outside of rcu_tasks_kthread.
This data race was reported by KCSAN. Not appropriate for backporting due to failure being unlikely.
--- kernel/rcu/update.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
kernel/rcu/update.c +2 -2
@@ -528,7 +528,7 @@ void call_rcu_tasks(struct rcu_head *rhp, rcu_callback_t func) rhp->func = func;raw_spin_lock_irqsave (&rcu_tasks_cbs_lock, flags); needwake = !rcu_tasks_cbs_head; - *rcu_tasks_cbs_tail = rhp; +WRITE_ONCE (*rcu_tasks_cbs_tail, rhp); rcu_tasks_cbs_tail = &rhp->next;raw_spin_unlock_irqrestore (&rcu_tasks_cbs_lock, flags);/* We can't create the thread unless interrupts are enabled. */
@@ -658,7 +658,7 @@ static int __noreturn rcu_tasks_kthread(void *arg)/* If there were none, wait a bit and start over. */ if (!list) {wait_event_interruptible (rcu_tasks_cbs_wq, - rcu_tasks_cbs_head); +READ_ONCE (rcu_tasks_cbs_head));if (!rcu_tasks_cbs_head) {WARN_ON (signal_pending (current));schedule_timeout_interruptible (HZ /10 );
Signature · 1 line
2.9.5
Re: [PATCH tip/core/rcu 1/3] rcu-tasks: *_ONCE() for rcu_tasks_cbs_head
Quoted 9 lines · On Fri, Feb 14, 2020 at 04:25:18PM -0800, [email protected] wrote:
From: "Paul E. McKenney" <[email protected]>
The RCU tasks list of callbacks,
rcu_tasks_cbs_head, is sampled locklessly byrcu_tasks_kthread()when waiting for work to do. This commit therefore appliesREAD_ONCE()to that lockless sampling andWRITE_ONCE()to the single potential store outside ofrcu_tasks_kthread.This data race was reported by KCSAN. Not appropriate for backporting due to failure being unlikely.
What failure is possible here? AFAICT this is (again) one of them load-complare-against-constant-discard patterns that are impossible to mess up.
Quoted 30 lines
Signed-off-by Paul E. McKenney <[email protected]>--- kernel/rcu/update.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)kernel/rcu/update.c +2
-2@@ -528,7 +528,7 @@ void call_rcu_tasks(struct rcu_head *rhp, rcu_callback_t func) rhp->func = func;raw_spin_lock_irqsave (&rcu_tasks_cbs_lock, flags); needwake = !rcu_tasks_cbs_head; - *rcu_tasks_cbs_tail = rhp; +WRITE_ONCE (*rcu_tasks_cbs_tail, rhp); rcu_tasks_cbs_tail = &rhp->next;raw_spin_unlock_irqrestore (&rcu_tasks_cbs_lock, flags);/* We can't create the thread unless interrupts are enabled. */ @@ -658,7 +658,7 @@ static int __noreturn rcu_tasks_kthread(void *arg)/* If there were none, wait a bit and start over. */ if (!list) {wait_event_interruptible (rcu_tasks_cbs_wq, - rcu_tasks_cbs_head); +READ_ONCE (rcu_tasks_cbs_head));if (!rcu_tasks_cbs_head) {WARN_ON (signal_pending (current));schedule_timeout_interruptible (HZ /10 );Signature · 1 line
2.9.5
Paul E. McKenney
maintainerRe: [PATCH tip/core/rcu 1/3] rcu-tasks: *_ONCE() for rcu_tasks_cbs_head
Quoted 8 lines · Peter Zijlstra
Quoted 7 lines · On Fri, Feb 14, 2020 at 04:25:18PM -0800, [email protected] wrote:
From: "Paul E. McKenney" <[email protected]>
The RCU tasks list of callbacks,
rcu_tasks_cbs_head, is sampled locklessly byrcu_tasks_kthread()when waiting for work to do. This commit therefore appliesREAD_ONCE()to that lockless sampling andWRITE_ONCE()to the single potential store outside ofrcu_tasks_kthread.
Quoted 6 lines
Quoted 2 lines
This data race was reported by KCSAN. Not appropriate for backporting due to failure being unlikely.
What failure is possible here? AFAICT this is (again) one of them load-complare-against-constant-discard patterns that are impossible to mess up.
First, please keep in mind that this is RCU code. Rather uncomplicated for RCU, to be sure, but still RCU code.
The failure modes are thus as follows:
o I produce a patch for which KCSAN gives a legitimate warning,
but this warning is obscured by a pile of other warnings. Yes, we should continue improving KCSAN's ability to adapt to the users desired compiler-optimization risk level, but in RCU's case that risk level is set quite low.
In RCU, what others are calling false positives are therefore addressed. Yes, this does cost me a bit of work, but it is trivial compared to the work required to track down a real bug.
o Someone optimizes or otherwise changes the wait/wakeup code,
which inadvertently gives the compiler more scope for mischief.
In short, within RCU, I am handling all KCSAN complaints. This is looking to be an extremely inexpensive insurance policy for RCU. Other subsystems are of course free to make their own tradeoffs, and subsystems having less-aggressive concurrency control might be well-advised to take a different path than the one I am taking.
Thanx, Paul
Quoted 30 lines
Quoted 30 lines
Signed-off-by Paul E. McKenney <[email protected]>--- kernel/rcu/update.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)kernel/rcu/update.c +2
-2@@ -528,7 +528,7 @@ void call_rcu_tasks(struct rcu_head *rhp, rcu_callback_t func) rhp->func = func;raw_spin_lock_irqsave (&rcu_tasks_cbs_lock, flags); needwake = !rcu_tasks_cbs_head; - *rcu_tasks_cbs_tail = rhp; +WRITE_ONCE (*rcu_tasks_cbs_tail, rhp); rcu_tasks_cbs_tail = &rhp->next;raw_spin_unlock_irqrestore (&rcu_tasks_cbs_lock, flags);/* We can't create the thread unless interrupts are enabled. */ @@ -658,7 +658,7 @@ static int __noreturn rcu_tasks_kthread(void *arg)/* If there were none, wait a bit and start over. */ if (!list) {wait_event_interruptible (rcu_tasks_cbs_wq, - rcu_tasks_cbs_head); +READ_ONCE (rcu_tasks_cbs_head));if (!rcu_tasks_cbs_head) {WARN_ON (signal_pending (current));schedule_timeout_interruptible (HZ /10 );Signature · 1 line
2.9.5
Re: [PATCH tip/core/rcu 1/3] rcu-tasks: *_ONCE() for rcu_tasks_cbs_head
Quoted 31 lines · Paul E. McKenney
Quoted 8 lines · Peter Zijlstra
Quoted 7 lines · On Fri, Feb 14, 2020 at 04:25:18PM -0800, [email protected] wrote:
From: "Paul E. McKenney" <[email protected]>
The RCU tasks list of callbacks,
rcu_tasks_cbs_head, is sampled locklessly byrcu_tasks_kthread()when waiting for work to do. This commit therefore appliesREAD_ONCE()to that lockless sampling andWRITE_ONCE()to the single potential store outside ofrcu_tasks_kthread.Quoted 6 lines
Quoted 2 lines
This data race was reported by KCSAN. Not appropriate for backporting due to failure being unlikely.
What failure is possible here? AFAICT this is (again) one of them load-complare-against-constant-discard patterns that are impossible to mess up.
First, please keep in mind that this is RCU code. Rather uncomplicated for RCU, to be sure, but still RCU code.
The failure modes are thus as follows:
o I produce a patch for which KCSAN gives a legitimate warning,
but this warning is obscured by a pile of other warnings. Yes, we should continue improving KCSAN's ability to adapt to the users desired compiler-optimization risk level, but in RCU's case that risk level is set quite low.In RCU, what others are calling false positives are therefore addressed. Yes, this does cost me a bit of work, but it is trivial compared to the work required to track down a real bug.
Quoted 8 lines
o Someone optimizes or otherwise changes the wait/wakeup code,
which inadvertently gives the compiler more scope for mischief.In short, within RCU, I am handling all KCSAN complaints. This is looking to be an extremely inexpensive insurance policy for RCU. Other subsystems are of course free to make their own tradeoffs, and subsystems having less-aggressive concurrency control might be well-advised to take a different path than the one I am taking.
I just took offence at the Changelog wording. It seems to suggest there actually is a problem, there is not.
Paul E. McKenney
maintainerRe: [PATCH tip/core/rcu 1/3] rcu-tasks: *_ONCE() for rcu_tasks_cbs_head
Quoted 35 lines · Peter Zijlstra
Quoted 34 lines · Paul E. McKenney
Quoted 8 lines · Peter Zijlstra
Quoted 7 lines · On Fri, Feb 14, 2020 at 04:25:18PM -0800, [email protected] wrote:
From: "Paul E. McKenney" <[email protected]>
The RCU tasks list of callbacks,
rcu_tasks_cbs_head, is sampled locklessly byrcu_tasks_kthread()when waiting for work to do. This commit therefore appliesREAD_ONCE()to that lockless sampling andWRITE_ONCE()to the single potential store outside ofrcu_tasks_kthread.Quoted 6 lines
Quoted 2 lines
This data race was reported by KCSAN. Not appropriate for backporting due to failure being unlikely.
What failure is possible here? AFAICT this is (again) one of them load-complare-against-constant-discard patterns that are impossible to mess up.
First, please keep in mind that this is RCU code. Rather uncomplicated for RCU, to be sure, but still RCU code.
The failure modes are thus as follows:
o I produce a patch for which KCSAN gives a legitimate warning,
but this warning is obscured by a pile of other warnings. Yes, we should continue improving KCSAN's ability to adapt to the users desired compiler-optimization risk level, but in RCU's case that risk level is set quite low.In RCU, what others are calling false positives are therefore addressed. Yes, this does cost me a bit of work, but it is trivial compared to the work required to track down a real bug.
o Someone optimizes or otherwise changes the wait/wakeup code,
which inadvertently gives the compiler more scope for mischief.
Quoted 8 lines
Quoted 5 lines
In short, within RCU, I am handling all KCSAN complaints. This is looking to be an extremely inexpensive insurance policy for RCU. Other subsystems are of course free to make their own tradeoffs, and subsystems having less-aggressive concurrency control might be well-advised to take a different path than the one I am taking.
I just took offence at the Changelog wording. It seems to suggest there actually is a problem, there is not.
Quoting the changelog: "Not appropriate for backporting due to failure being unlikely."
Good enough?
Thanx, Paul
Re: [PATCH tip/core/rcu 1/3] rcu-tasks: *_ONCE() for rcu_tasks_cbs_head
Quoted 7 lines · Paul E. McKenney
Quoted 2 lines · Peter Zijlstra
I just took offence at the Changelog wording. It seems to suggest there actually is a problem, there is not.
Quoting the changelog: "Not appropriate for backporting due to failure being unlikely."
That implies there is failure, however unlikely.
In this particular case there is absolutely no failure, except perhaps in KCSAN. This patch is a pure annotation such that KCSAN can understand the code.
Like said, I don't object to the actual patch, but I do think it is important to call out false negatives or to describe the actual problem found.
Paul E. McKenney
maintainerRe: [PATCH tip/core/rcu 1/3] rcu-tasks: *_ONCE() for rcu_tasks_cbs_head
Quoted 11 lines · Peter Zijlstra
Quoted 7 lines · Paul E. McKenney
Quoted 2 lines · Peter Zijlstra
I just took offence at the Changelog wording. It seems to suggest there actually is a problem, there is not.
Quoting the changelog: "Not appropriate for backporting due to failure being unlikely."
That implies there is failure, however unlikely.
Quoted 7 lines
In this particular case there is absolutely no failure, except perhaps in KCSAN. This patch is a pure annotation such that KCSAN can understand the code.
Like said, I don't object to the actual patch, but I do think it is important to call out false negatives or to describe the actual problem found.
I don't feel at all comfortable declaring that there is absolutely no possibility of failure.
Thanx, Paul
Steven Rostedt
reviewerRe: [PATCH tip/core/rcu 1/3] rcu-tasks: *_ONCE() for rcu_tasks_cbs_head
Quoted 16 lines · On Tue, 18 Feb 2020 12:22:26 -0800 "Paul E. McKenney" <[email protected]>…
Quoted 15 lines · Peter Zijlstra
Quoted 7 lines · Paul E. McKenney
Quoted 2 lines · Peter Zijlstra
I just took offence at the Changelog wording. It seems to suggest there actually is a problem, there is not.
Quoting the changelog: "Not appropriate for backporting due to failure being unlikely."
That implies there is failure, however unlikely.
In this particular case there is absolutely no failure, except perhaps in KCSAN. This patch is a pure annotation such that KCSAN can understand the code.
Quoted 6 lines
Quoted 3 lines
Like said, I don't object to the actual patch, but I do think it is important to call out false negatives or to describe the actual problem found.
I don't feel at all comfortable declaring that there is absolutely no possibility of failure.
Perhaps wording it like so:
"There's know known issue with the current code, but the *_ONCE() annotations here makes KCSAN happy, allowing us to focus on KCSAN warnings that can help bring about known issues in other code that we can fix, without being distracted by KCSAN warnings that we do not see a problem with."
?
-- Steve
Paul E. McKenney
maintainerRe: [PATCH tip/core/rcu 1/3] rcu-tasks: *_ONCE() for rcu_tasks_cbs_head
Quoted 28 lines · Steven Rostedt
Quoted 16 lines · On Tue, 18 Feb 2020 12:22:26 -0800 "Paul E. McKenney" <[email protected]>…
Quoted 15 lines · Peter Zijlstra
Quoted 7 lines · Paul E. McKenney
Quoted 2 lines · Peter Zijlstra
I just took offence at the Changelog wording. It seems to suggest there actually is a problem, there is not.
Quoting the changelog: "Not appropriate for backporting due to failure being unlikely."
That implies there is failure, however unlikely.
In this particular case there is absolutely no failure, except perhaps in KCSAN. This patch is a pure annotation such that KCSAN can understand the code.
Quoted 6 lines
Quoted 3 lines
Like said, I don't object to the actual patch, but I do think it is important to call out false negatives or to describe the actual problem found.
I don't feel at all comfortable declaring that there is absolutely no possibility of failure.
Perhaps wording it like so:
Quoted 7 lines
"There's know known issue with the current code, but the
*_ONCE()annotations here makes KCSAN happy, allowing us to focus on KCSAN warnings that can help bring about known issues in other code that we can fix, without being distracted by KCSAN warnings that we do not see a problem with."?
That sounds more like something I might put in rcutodo.html as a statement of the RCU approach to KCSAN reports.
But switching to a different situation (for variety, if nothing else), what about the commit shown below?
Thanx, Paul
------------------------------------------------------------------------
commit 35bc02b04a041f32470ae6d959c549bcce8483db
Author: Paul E. McKenney <[email protected]> Date: Tue Feb 18 13:41:02 2020 -0800
rcutorture: Mark data-race potential for rcu_barrier() test statistics
The n_barrier_successes, n_barrier_attempts, and n_rcu_torture_barrier_error variables are updated (without access markings) by the main rcu_barrier() test kthread, and accessed (also without access markings) by the rcu_torture_stats() kthread. This of course can result in KCSAN complaints.
Because the accesses are in diagnostic prints, this commit uses data_race() to excuse the diagnostic prints from the data race. If this were to ever cause bogus statistics prints (for example, due to store tearing), any misleading information would be disambiguated by the presence or absence of an rcutorture splat.
This data race was reported by KCSAN. Not appropriate for backporting due to failure being unlikely and due to the mild consequences of the failure, namely a confusing rcutorture console message.
kernel/rcu/rcutorture.c +3 -3
@@ -1444,9 +1444,9 @@ rcu_torture_stats_print(void) atomic_long_read(&n_rcu_torture_timers));torture_onoff_stats ();pr_cont ("barrier: %ld/%ld:%ld\n" , - n_barrier_successes, - n_barrier_attempts, - n_rcu_torture_barrier_error); +data_race (n_barrier_successes), +data_race (n_barrier_attempts), +data_race (n_rcu_torture_barrier_error));pr_alert ("%s%s " , torture_type,TORTURE_FLAG ); if (atomic_read(&n_rcu_torture_mberror) ||
Steven Rostedt
reviewerRe: [PATCH tip/core/rcu 1/3] rcu-tasks: *_ONCE() for rcu_tasks_cbs_head
Quoted 4 lines · On Tue, 18 Feb 2020 14:54:55 -0800 "Paul E. McKenney" <[email protected]>…
This data race was reported by KCSAN. Not appropriate for backporting due to failure being unlikely and due to the mild consequences of the failure, namely a confusing rcutorture console message.
I've seen patches backported for less. :-/
Really, any statement that says something may go awry with the code, will be an argument to backport it.
-- Steve
Paul E. McKenney
maintainerRe: [PATCH tip/core/rcu 1/3] rcu-tasks: *_ONCE() for rcu_tasks_cbs_head
Quoted 8 lines · Steven Rostedt
Quoted 4 lines · On Tue, 18 Feb 2020 14:54:55 -0800 "Paul E. McKenney" <[email protected]>…
This data race was reported by KCSAN. Not appropriate for backporting due to failure being unlikely and due to the mild consequences of the failure, namely a confusing rcutorture console message.
Quoted 4 lines
I've seen patches backported for less. :-/
Really, any statement that says something may go awry with the code, will be an argument to backport it.
You aren't kidding! Rumor has it that someone tried backporting the RCU flavor-consolidation work, for but one example. Though I cannot help but salute the level of insanity represented by that attempt. ;-)
Thanx, Paul
Re: [PATCH tip/core/rcu 1/3] rcu-tasks: *_ONCE() for rcu_tasks_cbs_head
In reply to Paul E. McKenneyQuoted 76 lines · Paul E. McKenney
Quoted 28 lines · Steven Rostedt
Quoted 16 lines · On Tue, 18 Feb 2020 12:22:26 -0800 "Paul E. McKenney" <[email protected]>…
Quoted 15 lines · Peter Zijlstra
Quoted 7 lines · Paul E. McKenney
Quoted 2 lines · Peter Zijlstra
I just took offence at the Changelog wording. It seems to suggest there actually is a problem, there is not.
Quoting the changelog: "Not appropriate for backporting due to failure being unlikely."
That implies there is failure, however unlikely.
In this particular case there is absolutely no failure, except perhaps in KCSAN. This patch is a pure annotation such that KCSAN can understand the code.
Quoted 6 lines
Quoted 3 lines
Like said, I don't object to the actual patch, but I do think it is important to call out false negatives or to describe the actual problem found.
I don't feel at all comfortable declaring that there is absolutely no possibility of failure.
Perhaps wording it like so:
Quoted 7 lines
"There's know known issue with the current code, but the
*_ONCE()annotations here makes KCSAN happy, allowing us to focus on KCSAN warnings that can help bring about known issues in other code that we can fix, without being distracted by KCSAN warnings that we do not see a problem with."?
That sounds more like something I might put in rcutodo.html as a statement of the RCU approach to KCSAN reports.
But switching to a different situation (for variety, if nothing else), what about the commit shown below?
Thanx, Paul
------------------------------------------------------------------------
commit
35bc02b04a041f32470ae6d959c549bcce8483dbAuthor: Paul E. McKenney <[email protected]> Date: Tue Feb 18 13:41:02 2020 -0800rcutorture: Mark data-race potential for
rcu_barrier()test statisticsThe
n_barrier_successes,n_barrier_attempts, andn_rcu_torture_barrier_errorvariables are updated (without access markings) by the mainrcu_barrier()test kthread, and accessed (also without access markings) by thercu_torture_stats()kthread. This of course can result in KCSAN complaints.Because the accesses are in diagnostic prints, this commit uses
data_race()to excuse the diagnostic prints from the data race. If this were to ever cause bogus statistics prints (for example, due to store tearing), any misleading information would be disambiguated by the presence or absence of an rcutorture splat.This data race was reported by KCSAN. Not appropriate for backporting due to failure being unlikely and due to the mild consequences of the failure, namely a confusing rcutorture console message.
Signed-off-by Paul E. McKenney <[email protected]>kernel/rcu/rcutorture.c +0
-0
kernel/rcu/rcutorture.c rcu_torture_stats_print(void) · line 1449
Quoted 9 lines
kernel/rcu/rcutorture.c +3
-3@@ -1444,9 +1444,9 @@ rcu_torture_stats_print(void) atomic_long_read(&n_rcu_torture_timers));torture_onoff_stats ();pr_cont ("barrier: %ld/%ld:%ld\n" , - n_barrier_successes, - n_barrier_attempts, - n_rcu_torture_barrier_error); +data_race (n_barrier_successes), +data_race (n_barrier_attempts), +data_race (n_rcu_torture_barrier_error));
Would it be not worth just fixing the data-race within rcutorture itself?
thanks,
- Joel
Paul E. McKenney
maintainerRe: [PATCH tip/core/rcu 1/3] rcu-tasks: *_ONCE() for rcu_tasks_cbs_head
Quoted 72 lines · Joel Fernandes
Quoted 71 lines · Paul E. McKenney
Quoted 28 lines · Steven Rostedt
Quoted 16 lines · On Tue, 18 Feb 2020 12:22:26 -0800 "Paul E. McKenney" <[email protected]>…
Quoted 15 lines · Peter Zijlstra
Quoted 7 lines · Paul E. McKenney
Quoted 2 lines · Peter Zijlstra
I just took offence at the Changelog wording. It seems to suggest there actually is a problem, there is not.
Quoting the changelog: "Not appropriate for backporting due to failure being unlikely."
That implies there is failure, however unlikely.
In this particular case there is absolutely no failure, except perhaps in KCSAN. This patch is a pure annotation such that KCSAN can understand the code.
Quoted 6 lines
Quoted 3 lines
Like said, I don't object to the actual patch, but I do think it is important to call out false negatives or to describe the actual problem found.
I don't feel at all comfortable declaring that there is absolutely no possibility of failure.
Perhaps wording it like so:
Quoted 7 lines
"There's know known issue with the current code, but the
*_ONCE()annotations here makes KCSAN happy, allowing us to focus on KCSAN warnings that can help bring about known issues in other code that we can fix, without being distracted by KCSAN warnings that we do not see a problem with."?
That sounds more like something I might put in rcutodo.html as a statement of the RCU approach to KCSAN reports.
But switching to a different situation (for variety, if nothing else), what about the commit shown below?
Thanx, Paul
------------------------------------------------------------------------
commit
35bc02b04a041f32470ae6d959c549bcce8483dbAuthor: Paul E. McKenney <[email protected]> Date: Tue Feb 18 13:41:02 2020 -0800rcutorture: Mark data-race potential for
rcu_barrier()test statisticsThe
n_barrier_successes,n_barrier_attempts, andn_rcu_torture_barrier_errorvariables are updated (without access markings) by the mainrcu_barrier()test kthread, and accessed (also without access markings) by thercu_torture_stats()kthread. This of course can result in KCSAN complaints.Because the accesses are in diagnostic prints, this commit uses
data_race()to excuse the diagnostic prints from the data race. If this were to ever cause bogus statistics prints (for example, due to store tearing), any misleading information would be disambiguated by the presence or absence of an rcutorture splat.This data race was reported by KCSAN. Not appropriate for backporting due to failure being unlikely and due to the mild consequences of the failure, namely a confusing rcutorture console message.
Signed-off-by Paul E. McKenney <[email protected]>
Quoted 16 lines
Quoted 5 lines
kernel/rcu/rcutorture.c +0
-0kernel/rcu/rcutorture.c rcu_torture_stats_print(void) · line 1449
Quoted 9 lines
kernel/rcu/rcutorture.c +3
-3@@ -1444,9 +1444,9 @@ rcu_torture_stats_print(void) atomic_long_read(&n_rcu_torture_timers));torture_onoff_stats ();pr_cont ("barrier: %ld/%ld:%ld\n" , - n_barrier_successes, - n_barrier_attempts, - n_rcu_torture_barrier_error); +data_race (n_barrier_successes), +data_race (n_barrier_attempts), +data_race (n_rcu_torture_barrier_error));Would it be not worth just fixing the data-race within rcutorture itself?
I could use WRITE_ONCE() for updates and READ_ONCE() for statistics. However, my current rule is that diagnostic code that is not participating in the core synchronization uses data_race(). That way, if I do a typo and write to (say) n_barrier_attempts in some other thread, KCSAN will know to yell at me.
Thanx, Paul
Joel Fernandes
Reviewed-byRe: [PATCH tip/core/rcu 1/3] rcu-tasks: *_ONCE() for rcu_tasks_cbs_head
Quoted 90 lines · Paul E. McKenney
Quoted 72 lines · Joel Fernandes
Quoted 71 lines · Paul E. McKenney
Quoted 28 lines · Steven Rostedt
Quoted 16 lines · On Tue, 18 Feb 2020 12:22:26 -0800 "Paul E. McKenney" <[email protected]>…
Quoted 15 lines · Peter Zijlstra
Quoted 7 lines · Paul E. McKenney
Quoted 2 lines · Peter Zijlstra
I just took offence at the Changelog wording. It seems to suggest there actually is a problem, there is not.
Quoting the changelog: "Not appropriate for backporting due to failure being unlikely."
That implies there is failure, however unlikely.
In this particular case there is absolutely no failure, except perhaps in KCSAN. This patch is a pure annotation such that KCSAN can understand the code.
Quoted 6 lines
Quoted 3 lines
Like said, I don't object to the actual patch, but I do think it is important to call out false negatives or to describe the actual problem found.
I don't feel at all comfortable declaring that there is absolutely no possibility of failure.
Perhaps wording it like so:
Quoted 7 lines
"There's know known issue with the current code, but the
*_ONCE()annotations here makes KCSAN happy, allowing us to focus on KCSAN warnings that can help bring about known issues in other code that we can fix, without being distracted by KCSAN warnings that we do not see a problem with."?
That sounds more like something I might put in rcutodo.html as a statement of the RCU approach to KCSAN reports.
But switching to a different situation (for variety, if nothing else), what about the commit shown below?
Thanx, Paul
------------------------------------------------------------------------
commit
35bc02b04a041f32470ae6d959c549bcce8483dbAuthor: Paul E. McKenney <[email protected]> Date: Tue Feb 18 13:41:02 2020 -0800rcutorture: Mark data-race potential for
rcu_barrier()test statisticsThe
n_barrier_successes,n_barrier_attempts, andn_rcu_torture_barrier_errorvariables are updated (without access markings) by the mainrcu_barrier()test kthread, and accessed (also without access markings) by thercu_torture_stats()kthread. This of course can result in KCSAN complaints.Because the accesses are in diagnostic prints, this commit uses
data_race()to excuse the diagnostic prints from the data race. If this were to ever cause bogus statistics prints (for example, due to store tearing), any misleading information would be disambiguated by the presence or absence of an rcutorture splat.This data race was reported by KCSAN. Not appropriate for backporting due to failure being unlikely and due to the mild consequences of the failure, namely a confusing rcutorture console message.
Signed-off-by Paul E. McKenney <[email protected]>Quoted 16 lines
Quoted 5 lines
kernel/rcu/rcutorture.c +0
-0kernel/rcu/rcutorture.c rcu_torture_stats_print(void) · line 1449
Quoted 9 lines
kernel/rcu/rcutorture.c +3
-3@@ -1444,9 +1444,9 @@ rcu_torture_stats_print(void) atomic_long_read(&n_rcu_torture_timers));torture_onoff_stats ();pr_cont ("barrier: %ld/%ld:%ld\n" , - n_barrier_successes, - n_barrier_attempts, - n_rcu_torture_barrier_error); +data_race (n_barrier_successes), +data_race (n_barrier_attempts), +data_race (n_rcu_torture_barrier_error));Would it be not worth just fixing the data-race within rcutorture itself?
Quoted 5 lines
I could use
WRITE_ONCE()for updates andREAD_ONCE()for statistics. However, my current rule is that diagnostic code that is not participating in the core synchronization usesdata_race(). That way, if I do a typo and write to (say)n_barrier_attemptsin some other thread, KCSAN will know to yell at me.
Oh, ok. That makes sense.
thanks,
- Joel
Re: [PATCH tip/core/rcu 1/3] rcu-tasks: *_ONCE() for rcu_tasks_cbs_head
Quoted 97 lines · Joel Fernandes
Quoted 90 lines · Paul E. McKenney
Quoted 72 lines · Joel Fernandes
Quoted 71 lines · Paul E. McKenney
Quoted 28 lines · Steven Rostedt
Quoted 16 lines · On Tue, 18 Feb 2020 12:22:26 -0800 "Paul E. McKenney" <[email protected]>…
Quoted 15 lines · Peter Zijlstra
Quoted 7 lines · Paul E. McKenney
Quoted 2 lines · Peter Zijlstra
I just took offence at the Changelog wording. It seems to suggest there actually is a problem, there is not.
Quoting the changelog: "Not appropriate for backporting due to failure being unlikely."
That implies there is failure, however unlikely.
In this particular case there is absolutely no failure, except perhaps in KCSAN. This patch is a pure annotation such that KCSAN can understand the code.
Quoted 6 lines
Quoted 3 lines
Like said, I don't object to the actual patch, but I do think it is important to call out false negatives or to describe the actual problem found.
I don't feel at all comfortable declaring that there is absolutely no possibility of failure.
Perhaps wording it like so:
Quoted 7 lines
"There's know known issue with the current code, but the
*_ONCE()annotations here makes KCSAN happy, allowing us to focus on KCSAN warnings that can help bring about known issues in other code that we can fix, without being distracted by KCSAN warnings that we do not see a problem with."?
That sounds more like something I might put in rcutodo.html as a statement of the RCU approach to KCSAN reports.
But switching to a different situation (for variety, if nothing else), what about the commit shown below?
Thanx, Paul
------------------------------------------------------------------------
commit
35bc02b04a041f32470ae6d959c549bcce8483dbAuthor: Paul E. McKenney <[email protected]> Date: Tue Feb 18 13:41:02 2020 -0800rcutorture: Mark data-race potential for
rcu_barrier()test statisticsThe
n_barrier_successes,n_barrier_attempts, andn_rcu_torture_barrier_errorvariables are updated (without access markings) by the mainrcu_barrier()test kthread, and accessed (also without access markings) by thercu_torture_stats()kthread. This of course can result in KCSAN complaints.Because the accesses are in diagnostic prints, this commit uses
data_race()to excuse the diagnostic prints from the data race. If this were to ever cause bogus statistics prints (for example, due to store tearing), any misleading information would be disambiguated by the presence or absence of an rcutorture splat.This data race was reported by KCSAN. Not appropriate for backporting due to failure being unlikely and due to the mild consequences of the failure, namely a confusing rcutorture console message.
Signed-off-by Paul E. McKenney <[email protected]>Quoted 16 lines
Quoted 5 lines
kernel/rcu/rcutorture.c +0
-0kernel/rcu/rcutorture.c rcu_torture_stats_print(void) · line 1449
Quoted 9 lines
kernel/rcu/rcutorture.c +3
-3@@ -1444,9 +1444,9 @@ rcu_torture_stats_print(void) atomic_long_read(&n_rcu_torture_timers));torture_onoff_stats ();pr_cont ("barrier: %ld/%ld:%ld\n" , - n_barrier_successes, - n_barrier_attempts, - n_rcu_torture_barrier_error); +data_race (n_barrier_successes), +data_race (n_barrier_attempts), +data_race (n_rcu_torture_barrier_error));Would it be not worth just fixing the data-race within rcutorture itself?
Quoted 5 lines
I could use
WRITE_ONCE()for updates andREAD_ONCE()for statistics. However, my current rule is that diagnostic code that is not participating in the core synchronization usesdata_race(). That way, if I do a typo and write to (say)n_barrier_attemptsin some other thread, KCSAN will know to yell at me.
Quoted 3 lines
Oh, ok. That makes sense.
Reviewed-by Joel Fernandes (Google) <[email protected]>
Applied, thank you!
Thanx, Paul
Re: [PATCH tip/core/rcu 1/3] rcu-tasks: *_ONCE() for rcu_tasks_cbs_head
In reply to Peter ZijlstraQuoted 8 lines · Peter Zijlstra
Quoted 7 lines · On Fri, Feb 14, 2020 at 04:25:18PM -0800, [email protected] wrote:
From: "Paul E. McKenney" <[email protected]>
The RCU tasks list of callbacks,
rcu_tasks_cbs_head, is sampled locklessly byrcu_tasks_kthread()when waiting for work to do. This commit therefore appliesREAD_ONCE()to that lockless sampling andWRITE_ONCE()to the single potential store outside ofrcu_tasks_kthread.
Quoted 6 lines
Quoted 2 lines
This data race was reported by KCSAN. Not appropriate for backporting due to failure being unlikely.
What failure is possible here? AFAICT this is (again) one of them load-complare-against-constant-discard patterns that are impossible to mess up.
You mean that because we are only testing for NULL, so load/store tearing of rcu_tasks_cbs_head is not an issue right?
I agree. Even with invented stores, worst case we have a false-wakeup and go right back to sleep. Or, we read a partial rcu_tasks_cbs_head, and then go acquire the lock and read the whole thing correctly under lock.
I wonder if we can teach KCSAN to actually ignore this kind of situation so we don't need to employ READ_ONCE() for no reason. Basically ask it to not bother if the read was only NULL-testing. +Marco since it is KCSAN related.
thanks,
- Joel
Quoted 30 lines
Quoted 30 lines
Signed-off-by Paul E. McKenney <[email protected]>--- kernel/rcu/update.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)kernel/rcu/update.c +2
-2@@ -528,7 +528,7 @@ void call_rcu_tasks(struct rcu_head *rhp, rcu_callback_t func) rhp->func = func;raw_spin_lock_irqsave (&rcu_tasks_cbs_lock, flags); needwake = !rcu_tasks_cbs_head; - *rcu_tasks_cbs_tail = rhp; +WRITE_ONCE (*rcu_tasks_cbs_tail, rhp); rcu_tasks_cbs_tail = &rhp->next;raw_spin_unlock_irqrestore (&rcu_tasks_cbs_lock, flags);/* We can't create the thread unless interrupts are enabled. */ @@ -658,7 +658,7 @@ static int __noreturn rcu_tasks_kthread(void *arg)/* If there were none, wait a bit and start over. */ if (!list) {wait_event_interruptible (rcu_tasks_cbs_wq, - rcu_tasks_cbs_head); +READ_ONCE (rcu_tasks_cbs_head));if (!rcu_tasks_cbs_head) {WARN_ON (signal_pending (current));schedule_timeout_interruptible (HZ /10 );Signature · 1 line
2.9.5
Re: [PATCH tip/core/rcu 1/3] rcu-tasks: *_ONCE() for rcu_tasks_cbs_head
Quoted 20 lines · Joel Fernandes
Quoted 8 lines · Peter Zijlstra
Quoted 7 lines · On Fri, Feb 14, 2020 at 04:25:18PM -0800, [email protected] wrote:
From: "Paul E. McKenney" <[email protected]>
The RCU tasks list of callbacks,
rcu_tasks_cbs_head, is sampled locklessly byrcu_tasks_kthread()when waiting for work to do. This commit therefore appliesREAD_ONCE()to that lockless sampling andWRITE_ONCE()to the single potential store outside ofrcu_tasks_kthread.Quoted 6 lines
Quoted 2 lines
This data race was reported by KCSAN. Not appropriate for backporting due to failure being unlikely.
What failure is possible here? AFAICT this is (again) one of them load-complare-against-constant-discard patterns that are impossible to mess up.
You mean that because we are only testing for NULL, so load/store tearing of
rcu_tasks_cbs_headis not an issue right?
Quoted 7 lines
I agree. Even with invented stores, worst case we have a false-wakeup and go right back to sleep. Or, we read a partial
rcu_tasks_cbs_head, and then go acquire the lock and read the whole thing correctly under lock.I wonder if we can teach KCSAN to actually ignore this kind of situation so we don't need to employ
READ_ONCE()for no reason. Basically ask it to not bother if the read was only NULL-testing. +Marco since it is KCSAN related.
This came up before. It requires somehow making the compiler tell us what type of operation we're doing and in what context:
https://lore.kernel.org/lkml/CANpmjNNZQsatHexXHm4dXvA0na6r9xMgVD5R+-8d7VXEBRi32w@mail.gmail.com/
In particular:
Quoted 6 lines
Quoted 6 lines
This particular rule relies on semantic analysis that is beyond what the TSAN instrumentation currently supports. Right now we support GCC and Clang; changing the compiler probably means we'd end up with only one (probably Clang), and many more years before the change has propagated to the majority of used compiler versions. It'd be good if we can do this purely as a change in the kernel's codebase.
Load/store tearing might not be an issue, but we also have to be aware of things like load fusing, e.g. in a loop.
That being said, there may be ways to get similar results without yet changing the compiler.
Thanks,
-- Marco
Quoted 35 lines
thanks,
- Joel
Quoted 30 lines
Quoted 30 lines
Signed-off-by Paul E. McKenney <[email protected]>--- kernel/rcu/update.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)kernel/rcu/update.c +2
-3@@ -528,7 +528,7 @@ void call_rcu_tasks(struct rcu_head *rhp, rcu_callback_t func) rhp->func = func;raw_spin_lock_irqsave (&rcu_tasks_cbs_lock, flags); needwake = !rcu_tasks_cbs_head; - *rcu_tasks_cbs_tail = rhp; +WRITE_ONCE (*rcu_tasks_cbs_tail, rhp); rcu_tasks_cbs_tail = &rhp->next;raw_spin_unlock_irqrestore (&rcu_tasks_cbs_lock, flags);/* We can't create the thread unless interrupts are enabled. */ @@ -658,7 +658,7 @@ static int __noreturn rcu_tasks_kthread(void *arg)/* If there were none, wait a bit and start over. */ if (!list) {wait_event_interruptible (rcu_tasks_cbs_wq, - rcu_tasks_cbs_head); +READ_ONCE (rcu_tasks_cbs_head));if (!rcu_tasks_cbs_head) {WARN_ON (signal_pending (current));schedule_timeout_interruptible (HZ /10 ); --2.9.5
Re: [PATCH tip/core/rcu 1/3] rcu-tasks: *_ONCE() for rcu_tasks_cbs_head
Quoted 25 lines · Marco Elver
Quoted 24 lines · Joel Fernandes
Quoted 8 lines · Peter Zijlstra
Quoted 7 lines · On Fri, Feb 14, 2020 at 04:25:18PM -0800, [email protected] wrote:
From: "Paul E. McKenney" <[email protected]>
The RCU tasks list of callbacks,
rcu_tasks_cbs_head, is sampled locklessly byrcu_tasks_kthread()when waiting for work to do. This commit therefore appliesREAD_ONCE()to that lockless sampling andWRITE_ONCE()to the single potential store outside ofrcu_tasks_kthread.Quoted 6 lines
Quoted 2 lines
This data race was reported by KCSAN. Not appropriate for backporting due to failure being unlikely.
What failure is possible here? AFAICT this is (again) one of them load-complare-against-constant-discard patterns that are impossible to mess up.
You mean that because we are only testing for NULL, so load/store tearing of
rcu_tasks_cbs_headis not an issue right?I agree. Even with invented stores, worst case we have a false-wakeup and go right back to sleep. Or, we read a partial
rcu_tasks_cbs_head, and then go acquire the lock and read the whole thing correctly under lock.
Quoted 7 lines
Quoted 3 lines
I wonder if we can teach KCSAN to actually ignore this kind of situation so we don't need to employ
READ_ONCE()for no reason. Basically ask it to not bother if the read was only NULL-testing. +Marco since it is KCSAN related.This came up before. It requires somehow making the compiler tell us what type of operation we're doing and in what context:
https://lore.kernel.org/lkml/CANpmjNNZQsatHexXHm4dXvA0na6r9xMgVD5R+-8d7VXEBRi32w@mail.gmail.com/
Oh, wow. Ok.
Quoted 11 lines
In particular:
Quoted 6 lines
Quoted 6 lines
This particular rule relies on semantic analysis that is beyond what the TSAN instrumentation currently supports. Right now we support GCC and Clang; changing the compiler probably means we'd end up with only one (probably Clang), and many more years before the change has propagated to the majority of used compiler versions. It'd be good if we can do this purely as a change in the kernel's codebase.
Load/store tearing might not be an issue, but we also have to be aware of things like load fusing, e.g. in a loop.
Ok. Makes sense.
Quoted 2 lines
That being said, there may be ways to get similar results without yet changing the compiler.
Interesting. thanks!
- Joel
Quoted 38 lines
Thanks,
-- MarcoQuoted 35 lines
thanks,
- Joel
Quoted 30 lines
Quoted 30 lines
Signed-off-by Paul E. McKenney <[email protected]>--- kernel/rcu/update.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)kernel/rcu/update.c +2
-3@@ -528,7 +528,7 @@ void call_rcu_tasks(struct rcu_head *rhp, rcu_callback_t func) rhp->func = func;raw_spin_lock_irqsave (&rcu_tasks_cbs_lock, flags); needwake = !rcu_tasks_cbs_head; - *rcu_tasks_cbs_tail = rhp; +WRITE_ONCE (*rcu_tasks_cbs_tail, rhp); rcu_tasks_cbs_tail = &rhp->next;raw_spin_unlock_irqrestore (&rcu_tasks_cbs_lock, flags);/* We can't create the thread unless interrupts are enabled. */ @@ -658,7 +658,7 @@ static int __noreturn rcu_tasks_kthread(void *arg)/* If there were none, wait a bit and start over. */ if (!list) {wait_event_interruptible (rcu_tasks_cbs_wq, - rcu_tasks_cbs_head); +READ_ONCE (rcu_tasks_cbs_head));if (!rcu_tasks_cbs_head) {WARN_ON (signal_pending (current));schedule_timeout_interruptible (HZ /10 ); --2.9.5
[email protected]
maintainerPATCH 2/3 rcu: Add missing annotation for exit_tasks_rcu_start()
In reply to Paul E. McKenneyFrom: Jules Irenge <[email protected]>
Sparse reports a warning at exit_tasks_rcu_start(void)
|warning: context imbalance in exit_tasks_rcu_start() - wrong count at exit
To fix this, this commit adds an __acquires(&tasks_rcu_exit_srcu). Given that exit_tasks_rcu_start() does actually call __srcu_read_lock(), this not only fixes the warning but also improves on the readability of the code.
--- kernel/rcu/update.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
kernel/rcu/update.c +1 -1
@@ -801,7 +801,7 @@ static int __init rcu_spawn_tasks_kthread(void)core_initcall (rcu_spawn_tasks_kthread);/* Do the srcu_read_lock() for the above synchronize_srcu(). */ -void exit_tasks_rcu_start (void ) +void exit_tasks_rcu_start(void) __acquires(&tasks_rcu_exit_srcu) {preempt_disable (); current->rcu_tasks_idx =__srcu_read_lock (&tasks_rcu_exit_srcu);
Signature · 1 line
2.9.5
Re: [PATCH tip/core/rcu 2/3] rcu: Add missing annotation for exit_tasks_rcu_start()
Quoted 10 lines · On Fri, Feb 14, 2020 at 04:25:19PM -0800, [email protected] wrote:
From: Jules Irenge <[email protected]>
Sparse reports a warning at
exit_tasks_rcu_start(void)|warning: context imbalance in
exit_tasks_rcu_start()- wrong count at exitTo fix this, this commit adds an
__acquires(&tasks_rcu_exit_srcu). Given thatexit_tasks_rcu_start()does actually call__srcu_read_lock(), this not only fixes the warning but also improves on the readability of the code.
For patch 1/3 and 2/3:
Though IMO it would be good to squash both the patches.
thanks,
- Joel
Quoted 22 lines
Signed-off-by Jules Irenge <[email protected]>Signed-off-by Paul E. McKenney <[email protected]>--- kernel/rcu/update.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)kernel/rcu/update.c +1
-1@@ -801,7 +801,7 @@ static int __init rcu_spawn_tasks_kthread(void)core_initcall (rcu_spawn_tasks_kthread);/* Do the srcu_read_lock() for the above synchronize_srcu(). */ -void exit_tasks_rcu_start (void ) +void exit_tasks_rcu_start(void) __acquires(&tasks_rcu_exit_srcu) {preempt_disable (); current->rcu_tasks_idx =__srcu_read_lock (&tasks_rcu_exit_srcu);Signature · 1 line
2.9.5
Re: [PATCH tip/core/rcu 2/3] rcu: Add missing annotation for exit_tasks_rcu_start()
Quoted 7 lines · Joel Fernandes
Quoted 6 lines · On Fri, Feb 14, 2020 at 04:25:19PM -0800, [email protected] wrote:
From: Jules Irenge <[email protected]>
Sparse reports a warning at
exit_tasks_rcu_start(void)|warning: context imbalance in
exit_tasks_rcu_start()- wrong count at exit
Quoted 8 lines
Quoted 4 lines
To fix this, this commit adds an
__acquires(&tasks_rcu_exit_srcu). Given thatexit_tasks_rcu_start()does actually call__srcu_read_lock(), this not only fixes the warning but also improves on the readability of the code.For patch 1/3 and 2/3:
Reviewed-by Joel Fernandes (Google) <[email protected]>
Applied, thank you!
Quoted 1 line
Though IMO it would be good to squash both the patches.
Fair point, but I will leave them be. ;-)
Thanx, Paul
Quoted 27 lines
thanks,
- Joel
Quoted 22 lines
Signed-off-by Jules Irenge <[email protected]>Signed-off-by Paul E. McKenney <[email protected]>--- kernel/rcu/update.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)kernel/rcu/update.c +1
-1@@ -801,7 +801,7 @@ static int __init rcu_spawn_tasks_kthread(void)core_initcall (rcu_spawn_tasks_kthread);/* Do the srcu_read_lock() for the above synchronize_srcu(). */ -void exit_tasks_rcu_start (void ) +void exit_tasks_rcu_start(void) __acquires(&tasks_rcu_exit_srcu) {preempt_disable (); current->rcu_tasks_idx =__srcu_read_lock (&tasks_rcu_exit_srcu);Signature · 1 line
2.9.5
[email protected]
maintainerPATCH 3/3 rcu: Add missing annotation for exit_tasks_rcu_finish()
In reply to Paul E. McKenneyFrom: Jules Irenge <[email protected]>
Sparse reports a warning at exit_tasks_rcu_finish(void)
|warning: context imbalance in exit_tasks_rcu_finish() |- wrong count at exit
To fix this, this commit adds a __releases(&tasks_rcu_exit_srcu). Given that exit_tasks_rcu_finish() does actually call __srcu_read_lock(), this not only fixes the warning but also improves on the readability of the code.
--- kernel/rcu/update.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
kernel/rcu/update.c +1 -1
@@ -809,7 +809,7 @@ void exit_tasks_rcu_start(void) __acquires(&tasks_rcu_exit_srcu) }/* Do the srcu_read_unlock() for the above synchronize_srcu(). */ -void exit_tasks_rcu_finish (void ) +void exit_tasks_rcu_finish(void) __releases(&tasks_rcu_exit_srcu) {preempt_disable ();__srcu_read_unlock (&tasks_rcu_exit_srcu, current->rcu_tasks_idx);
Signature · 1 line
2.9.5