rcu.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: "Paul E. McKenney" <paulmck@linux.ibm.com>
To: Joel Fernandes <joel@joelfernandes.org>
Cc: rcu@vger.kernel.org
Subject: Re: Should list_entry_rcu use rcu_dereference ?
Date: Mon, 6 May 2019 16:54:30 -0700	[thread overview]
Message-ID: <20190506235430.GA3923@linux.ibm.com> (raw)
In-Reply-To: <20190504185944.GA79652@google.com>

On Sat, May 04, 2019 at 02:59:44PM -0400, Joel Fernandes wrote:
> Hi,
> Sorry if this is a silly question.

Not at all silly!

> Looking at the list_entry_rcu primitive, I see it does direct READ_ONCE
> on ptr. That's Ok, but rcu_dereference also does additional lockdep and
> sparse checking.  Why not call rcu_dereference instead of READ_ONCE? The
> pointer may be dereference by the caller so IMO makes sense to check.
> 
> Here is the definition of list_entry_rcu:
> /**
>  * list_entry_rcu - get the struct for this entry
>  [snip]
> * This primitive may safely run concurrently with the _rcu list-mutation
>  * primitives such as list_add_rcu() as long as it's guarded by rcu_read_lock().
>  */
> #define list_entry_rcu(ptr, type, member) \
> 	container_of(READ_ONCE(ptr), type, member)
> 
> Also, I was curious why hlist_for_each_entry_rcu() uses rcu_dereference_raw()
> while __hlist_for_each_rcu)_ uses rcu_dereference(). I feel both should use
> rcu_dereference to have the lockdep checking. Is this not done due to
> performance reasons?
> 
> thanks!
> 
>   - Joel
> 
> https://cdn-images-1.medium.com/max/1600/0*XTYvSNj_rT2UZwfm.png

The issue is that most of the RCU list macros are generic over the RCU
read-side flavors.  We could have created _bh and _sched variants of all
of these, but that seemed like way too much RCU API expansion at the time,
and still does.  This shows up in the sparse checking as well, so that
there is just __rcu instead of also being __rcu_bh and __rcu_sched.

Or are do you have a trick in mind that would allow lockdep checking
without RCU API expansion?

							Thanx, Paul


  reply	other threads:[~2019-05-06 23:54 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-05-04 18:59 Should list_entry_rcu use rcu_dereference ? Joel Fernandes
2019-05-06 23:54 ` Paul E. McKenney [this message]
2019-05-13  3:30   ` Joel Fernandes
2019-05-14 22:20     ` Paul E. McKenney
2019-05-24  8:07       ` Joel Fernandes
2019-05-24 16:50         ` Joel Fernandes
2019-05-24 17:33           ` 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=20190506235430.GA3923@linux.ibm.com \
    --to=paulmck@linux.ibm.com \
    --cc=joel@joelfernandes.org \
    --cc=rcu@vger.kernel.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 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).