* [PATCH] rculist: Add brackets around cond argument in __list_check_rcu macro
@ 2020-01-18 16:54 Amol Grover
2020-01-19 2:14 ` Joel Fernandes
0 siblings, 1 reply; 3+ messages in thread
From: Amol Grover @ 2020-01-18 16:54 UTC (permalink / raw)
To: Paul E. McKenney, Josh Triplett, Steven Rostedt,
Mathieu Desnoyers, Lai Jiangshan, Joel Fernandes
Cc: rcu, linux-kernel, linux-kernel-mentees, Madhuparna Bhowmik, Amol Grover
Passing a complex lockdep condition to __list_check_rcu results
in false positive lockdep splat due to incorrect expression
evaluation.
For example, a lockdep check condition `cond1 || cond2` is
evaluated as `!cond1 || cond2 && !rcu_read_lock_any_held()`
which, according to operator precedence, evaluates to
`!cond1 || (cond2 && !rcu_read_lock_any_held())`.
This would result in a lockdep splat when cond1 is false
and cond2 is true which is logically incorrect.
Signed-off-by: Amol Grover <frextrite@gmail.com>
---
include/linux/rculist.h | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
diff --git a/include/linux/rculist.h b/include/linux/rculist.h
index 4158b7212936..dce491f0b354 100644
--- a/include/linux/rculist.h
+++ b/include/linux/rculist.h
@@ -50,9 +50,9 @@ static inline void INIT_LIST_HEAD_RCU(struct list_head *list)
#define __list_check_rcu(dummy, cond, extra...) \
({ \
check_arg_count_one(extra); \
- RCU_LOCKDEP_WARN(!cond && !rcu_read_lock_any_held(), \
+ RCU_LOCKDEP_WARN(!(cond) && !rcu_read_lock_any_held(), \
"RCU-list traversed in non-reader section!"); \
- })
+ })
#else
#define __list_check_rcu(dummy, cond, extra...) \
({ check_arg_count_one(extra); })
--
2.24.1
^ permalink raw reply related [flat|nested] 3+ messages in thread
* Re: [PATCH] rculist: Add brackets around cond argument in __list_check_rcu macro
2020-01-18 16:54 [PATCH] rculist: Add brackets around cond argument in __list_check_rcu macro Amol Grover
@ 2020-01-19 2:14 ` Joel Fernandes
2020-01-21 0:00 ` Paul E. McKenney
0 siblings, 1 reply; 3+ messages in thread
From: Joel Fernandes @ 2020-01-19 2:14 UTC (permalink / raw)
To: Amol Grover
Cc: Paul E. McKenney, Josh Triplett, Steven Rostedt,
Mathieu Desnoyers, Lai Jiangshan, rcu, linux-kernel,
linux-kernel-mentees, Madhuparna Bhowmik
On Sat, Jan 18, 2020 at 10:24:18PM +0530, Amol Grover wrote:
> Passing a complex lockdep condition to __list_check_rcu results
> in false positive lockdep splat due to incorrect expression
> evaluation.
>
> For example, a lockdep check condition `cond1 || cond2` is
> evaluated as `!cond1 || cond2 && !rcu_read_lock_any_held()`
> which, according to operator precedence, evaluates to
> `!cond1 || (cond2 && !rcu_read_lock_any_held())`.
> This would result in a lockdep splat when cond1 is false
> and cond2 is true which is logically incorrect.
>
> Signed-off-by: Amol Grover <frextrite@gmail.com>
Good catch!
Acked-by: Joel Fernandes (Google) <joel@joelfernandes.org>
thanks,
- Joel
> ---
> include/linux/rculist.h | 4 ++--
> 1 file changed, 2 insertions(+), 2 deletions(-)
>
> diff --git a/include/linux/rculist.h b/include/linux/rculist.h
> index 4158b7212936..dce491f0b354 100644
> --- a/include/linux/rculist.h
> +++ b/include/linux/rculist.h
> @@ -50,9 +50,9 @@ static inline void INIT_LIST_HEAD_RCU(struct list_head *list)
> #define __list_check_rcu(dummy, cond, extra...) \
> ({ \
> check_arg_count_one(extra); \
> - RCU_LOCKDEP_WARN(!cond && !rcu_read_lock_any_held(), \
> + RCU_LOCKDEP_WARN(!(cond) && !rcu_read_lock_any_held(), \
> "RCU-list traversed in non-reader section!"); \
> - })
> + })
> #else
> #define __list_check_rcu(dummy, cond, extra...) \
> ({ check_arg_count_one(extra); })
> --
> 2.24.1
>
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: [PATCH] rculist: Add brackets around cond argument in __list_check_rcu macro
2020-01-19 2:14 ` Joel Fernandes
@ 2020-01-21 0:00 ` Paul E. McKenney
0 siblings, 0 replies; 3+ messages in thread
From: Paul E. McKenney @ 2020-01-21 0:00 UTC (permalink / raw)
To: Joel Fernandes
Cc: Amol Grover, Josh Triplett, Steven Rostedt, Mathieu Desnoyers,
Lai Jiangshan, rcu, linux-kernel, linux-kernel-mentees,
Madhuparna Bhowmik
On Sat, Jan 18, 2020 at 09:14:25PM -0500, Joel Fernandes wrote:
> On Sat, Jan 18, 2020 at 10:24:18PM +0530, Amol Grover wrote:
> > Passing a complex lockdep condition to __list_check_rcu results
> > in false positive lockdep splat due to incorrect expression
> > evaluation.
> >
> > For example, a lockdep check condition `cond1 || cond2` is
> > evaluated as `!cond1 || cond2 && !rcu_read_lock_any_held()`
> > which, according to operator precedence, evaluates to
> > `!cond1 || (cond2 && !rcu_read_lock_any_held())`.
> > This would result in a lockdep splat when cond1 is false
> > and cond2 is true which is logically incorrect.
> >
> > Signed-off-by: Amol Grover <frextrite@gmail.com>
>
> Good catch!
>
> Acked-by: Joel Fernandes (Google) <joel@joelfernandes.org>
Queued for v5.7, thank you both!
Thanx, Paul
> thanks,
>
> - Joel
>
>
> > ---
> > include/linux/rculist.h | 4 ++--
> > 1 file changed, 2 insertions(+), 2 deletions(-)
> >
> > diff --git a/include/linux/rculist.h b/include/linux/rculist.h
> > index 4158b7212936..dce491f0b354 100644
> > --- a/include/linux/rculist.h
> > +++ b/include/linux/rculist.h
> > @@ -50,9 +50,9 @@ static inline void INIT_LIST_HEAD_RCU(struct list_head *list)
> > #define __list_check_rcu(dummy, cond, extra...) \
> > ({ \
> > check_arg_count_one(extra); \
> > - RCU_LOCKDEP_WARN(!cond && !rcu_read_lock_any_held(), \
> > + RCU_LOCKDEP_WARN(!(cond) && !rcu_read_lock_any_held(), \
> > "RCU-list traversed in non-reader section!"); \
> > - })
> > + })
> > #else
> > #define __list_check_rcu(dummy, cond, extra...) \
> > ({ check_arg_count_one(extra); })
> > --
> > 2.24.1
> >
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2020-01-21 0:01 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-01-18 16:54 [PATCH] rculist: Add brackets around cond argument in __list_check_rcu macro Amol Grover
2020-01-19 2:14 ` Joel Fernandes
2020-01-21 0:00 ` Paul E. McKenney
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).