All of lore.kernel.org
 help / color / mirror / Atom feed
From: Omar Sandoval <osandov@osandov.com>
To: Pranith Kumar <bobby.prani@gmail.com>
Cc: Chris Mason <clm@fb.com>, Josef Bacik <jbacik@fb.com>,
	Joe Perches <joe@perches.com>,
	"Paul E. McKenney" <paulmck@linux.vnet.ibm.com>,
	Josh Triplett <josh@joshtriplett.org>,
	Steven Rostedt <rostedt@goodmis.org>,
	Mathieu Desnoyers <mathieu.desnoyers@efficios.com>,
	LKML <linux-kernel@vger.kernel.org>,
	linux-btrfs@vger.kernel.org
Subject: Re: [PATCH 3/3] btrfs: refactor btrfs_device->name updates
Date: Sun, 30 Nov 2014 18:52:05 -0800	[thread overview]
Message-ID: <20141201025205.GA14040@mew> (raw)
In-Reply-To: <CAJhHMCDNtQi0y8iYBXVJGwUAyK_sT74KmoZ-RwV_J0JPV3SgAA@mail.gmail.com>

On Sun, Nov 30, 2014 at 10:26:43AM -0500, Pranith Kumar wrote:
> On Sun, Nov 30, 2014 at 3:26 AM, Omar Sandoval <osandov@osandov.com> wrote:
> > The rcu_string API introduced some new sparse errors but also revealed existing
> > ones. First of all, the name in struct btrfs_device should be annotated as
> > __rcu to prevent unsafe reads. Additionally, updates should go through
> > rcu_dereference_protected to make it clear what's going on. This introduces
> > some helper functions that factor out this functionality.
> >
> > Signed-off-by: Omar Sandoval <osandov@osandov.com>
> > diff --git a/fs/btrfs/volumes.h b/fs/btrfs/volumes.h
> > index 6e04f27..2298a70 100644
> > --- a/fs/btrfs/volumes.h
> > +++ b/fs/btrfs/volumes.h
> > @@ -54,7 +54,7 @@ struct btrfs_device {
> >
> >         struct btrfs_root *dev_root;
> >
> > -       struct rcu_string *name;
> > +       struct rcu_string __rcu *name;
> >
> >         u64 generation;
> >
> 
> Since rcu_strings are rcu specific, why not annotate the char pointer
> in 'struct rcu_string' with __rcu annotation? That should catch all
> error-prone users of rcu_string.
> 
Because the whole structure is RCU'd, not just the str part of it. If str is
annotated as __rcu, when we (correctly) rcu_dereference an rcu_string and then
access the str member, we'll still get sparse warnings.

In any case, the above code does what I want it to do. See the following
(non-sense but illustrative) example:

#include <linux/rcustring.h>

static void example_func(void)
{
	struct rcu_string __rcu *example;
	char *str;
	str = example->str;
}

  CHECK   /home/osandov/linux/example/example.c
/home/osandov/linux/example/example.c:7:13: warning: incorrect type in assignment (different address spaces)
/home/osandov/linux/example/example.c:7:13:    expected char *str
/home/osandov/linux/example/example.c:7:13:    got char [noderef] <asn:4>*<noident>

-- 
Omar

      reply	other threads:[~2014-12-01  2:52 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2014-11-30  8:26 [PATCH 0/3] btrfs: fix RCU string sparse noise Omar Sandoval
2014-11-30  8:26 ` [PATCH 1/3] rcustring: clean up botched __rcu annotations Omar Sandoval
2014-11-30  8:26 ` [PATCH 2/3] btrfs: fix suspicious RCU in BTRFS_IOC_DEV_INFO Omar Sandoval
2014-11-30 15:11   ` Pranith Kumar
2014-12-01  3:15     ` Omar Sandoval
2014-11-30  8:26 ` [PATCH 3/3] btrfs: refactor btrfs_device->name updates Omar Sandoval
2014-11-30 15:26   ` Pranith Kumar
2014-12-01  2:52     ` Omar Sandoval [this message]

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=20141201025205.GA14040@mew \
    --to=osandov@osandov.com \
    --cc=bobby.prani@gmail.com \
    --cc=clm@fb.com \
    --cc=jbacik@fb.com \
    --cc=joe@perches.com \
    --cc=josh@joshtriplett.org \
    --cc=linux-btrfs@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=mathieu.desnoyers@efficios.com \
    --cc=paulmck@linux.vnet.ibm.com \
    --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.