All of lore.kernel.org
 help / color / mirror / Atom feed
From: Joel Fernandes <joel@joelfernandes.org>
To: Amol Grover <frextrite@gmail.com>
Cc: "Paul E. McKenney" <paulmck@kernel.org>,
	Lai Jiangshan <jiangshanlai@gmail.com>,
	Josh Triplett <josh@joshtriplett.org>,
	Steven Rostedt <rostedt@goodmis.org>,
	linux-kernel@vger.kernel.org, rcu@vger.kernel.org,
	Mathieu Desnoyers <mathieu.desnoyers@efficios.com>,
	linux-kernel-mentees@lists.linuxfoundation.org
Subject: Re: [Linux-kernel-mentees] [PATCH] rculist: Add brackets around cond argument in __list_check_rcu macro
Date: Sat, 18 Jan 2020 21:14:25 -0500	[thread overview]
Message-ID: <20200119021425.GH244899@google.com> (raw)
In-Reply-To: <20200118165417.12325-1-frextrite@gmail.com>

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
> 
_______________________________________________
Linux-kernel-mentees mailing list
Linux-kernel-mentees@lists.linuxfoundation.org
https://lists.linuxfoundation.org/mailman/listinfo/linux-kernel-mentees

WARNING: multiple messages have this Message-ID (diff)
From: Joel Fernandes <joel@joelfernandes.org>
To: Amol Grover <frextrite@gmail.com>
Cc: "Paul E. McKenney" <paulmck@kernel.org>,
	Josh Triplett <josh@joshtriplett.org>,
	Steven Rostedt <rostedt@goodmis.org>,
	Mathieu Desnoyers <mathieu.desnoyers@efficios.com>,
	Lai Jiangshan <jiangshanlai@gmail.com>,
	rcu@vger.kernel.org, linux-kernel@vger.kernel.org,
	linux-kernel-mentees@lists.linuxfoundation.org,
	Madhuparna Bhowmik <madhuparnabhowmik04@gmail.com>
Subject: Re: [PATCH] rculist: Add brackets around cond argument in __list_check_rcu macro
Date: Sat, 18 Jan 2020 21:14:25 -0500	[thread overview]
Message-ID: <20200119021425.GH244899@google.com> (raw)
In-Reply-To: <20200118165417.12325-1-frextrite@gmail.com>

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
> 

  reply	other threads:[~2020-01-19  2:14 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-01-18 16:54 [Linux-kernel-mentees] [PATCH] rculist: Add brackets around cond argument in __list_check_rcu macro Amol Grover
2020-01-18 16:54 ` Amol Grover
2020-01-19  2:14 ` Joel Fernandes [this message]
2020-01-19  2:14   ` Joel Fernandes
2020-01-21  0:00   ` [Linux-kernel-mentees] " Paul E. McKenney
2020-01-21  0:00     ` Paul E. McKenney

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20200119021425.GH244899@google.com \
    --to=joel@joelfernandes.org \
    --cc=frextrite@gmail.com \
    --cc=jiangshanlai@gmail.com \
    --cc=josh@joshtriplett.org \
    --cc=linux-kernel-mentees@lists.linuxfoundation.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=mathieu.desnoyers@efficios.com \
    --cc=paulmck@kernel.org \
    --cc=rcu@vger.kernel.org \
    --cc=rostedt@goodmis.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.