mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: "Paul E. McKenney" <paulmck@linux.vnet.ibm.com>
To: "Jason A. Donenfeld" <Jason@zx2c4.com>
Cc: josh@joshtriplett.org, corbet@lwn.net,
	linux-kernel@vger.kernel.org, linux-doc@vger.kernel.org
Subject: Re: [PATCH] rcu: Correct doc to use rcu_dereference_protected
Date: Tue, 11 Aug 2015 07:59:43 -0700	[thread overview]
Message-ID: <20150811145943.GB3895@linux.vnet.ibm.com> (raw)
In-Reply-To: <xagsmtp3.20150811122634.8291@emeavsc.vnet.ibm.com>

On Tue, Aug 11, 2015 at 02:26:33PM +0200, Jason A. Donenfeld wrote:
> As there is lots of misinformation and outdated information on the
> Internet about nearly all topics related to the kernel, I thought it
> would be best if I based my RCU code on the guidelines of the examples
> in the Documentation/ tree of the latest kernel. One thing that stuck
> out when reading the whatisRCU.txt document was, "interesting how we
> don't need any function to dereference rcu protected pointers when doing
> updates if a lock is held. I wonder how static analyzers will work with
> that." Then, a few weeks later, upon discovering sparse's __rcu support,
> I ran it over my code, and lo and behold, things weren't done right.
> Examining other RCU usages in the kernel reveal consistent usage of
> rcu_dereference_protected, passing in lockdep_is_held as the
> conditional. So, this patch adds that idiom to the documentation, so
> that others ahead of me won't endure the same exercise.
> 
> Signed-off-by: Jason A. Donenfeld <Jason@zx2c4.com>

Good catch, queued for 4.4, thank you!

							Thanx, Paul

> ---
>  Documentation/RCU/whatisRCU.txt | 6 +++---
>  1 file changed, 3 insertions(+), 3 deletions(-)
> 
> diff --git a/Documentation/RCU/whatisRCU.txt b/Documentation/RCU/whatisRCU.txt
> index 5746b0c..b852c10 100644
> --- a/Documentation/RCU/whatisRCU.txt
> +++ b/Documentation/RCU/whatisRCU.txt
> @@ -364,7 +364,7 @@ uses of RCU may be found in listRCU.txt, arrayRCU.txt, and NMI-RCU.txt.
>  	};
>  	DEFINE_SPINLOCK(foo_mutex);
> 
> -	struct foo *gbl_foo;
> +	struct foo __rcu *gbl_foo;
> 
>  	/*
>  	 * Create a new struct foo that is the same as the one currently
> @@ -386,7 +386,7 @@ uses of RCU may be found in listRCU.txt, arrayRCU.txt, and NMI-RCU.txt.
> 
>  		new_fp = kmalloc(sizeof(*new_fp), GFP_KERNEL);
>  		spin_lock(&foo_mutex);
> -		old_fp = gbl_foo;
> +		old_fp = rcu_dereference_protected(gbl_foo, lockdep_is_held(&foo_mutex));
>  		*new_fp = *old_fp;
>  		new_fp->a = new_a;
>  		rcu_assign_pointer(gbl_foo, new_fp);
> @@ -487,7 +487,7 @@ The foo_update_a() function might then be written as follows:
> 
>  		new_fp = kmalloc(sizeof(*new_fp), GFP_KERNEL);
>  		spin_lock(&foo_mutex);
> -		old_fp = gbl_foo;
> +		old_fp = rcu_dereference_protected(gbl_foo, lockdep_is_held(&foo_mutex));
>  		*new_fp = *old_fp;
>  		new_fp->a = new_a;
>  		rcu_assign_pointer(gbl_foo, new_fp);
> -- 
> 2.5.0
> 


       reply	other threads:[~2015-08-11 14:59 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
     [not found] <xagsmtp3.20150811122634.8291@emeavsc.vnet.ibm.com>
2015-08-11 14:59 ` Paul E. McKenney [this message]
2015-08-11 12:26 Jason A. Donenfeld

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=20150811145943.GB3895@linux.vnet.ibm.com \
    --to=paulmck@linux.vnet.ibm.com \
    --cc=Jason@zx2c4.com \
    --cc=corbet@lwn.net \
    --cc=josh@joshtriplett.org \
    --cc=linux-doc@vger.kernel.org \
    --cc=linux-kernel@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

all inboxes | Powered by JetHome®