Re: [PATCH] rcu: small rcu_dereference doc update

From: Paul E. McKenney
Date: Fri Apr 17 2015 - 12:15:41 EST


On Fri, Apr 17, 2015 at 11:55:20AM -0400, Pranith Kumar wrote:
> On Fri, Apr 17, 2015 at 6:33 AM, Milos Vyletel <milos@xxxxxxxxxx> wrote:
> > Make a note stating that repeated calls of rcu_dereference() may not
> > return the same pointer if update happens while in critical section.
>
> Might as well make it more explicit with an example then. See below:
>
> >
> > Reported-by: Jeff Haran <jeff.haran@xxxxxxxxxx>
> > Signed-off-by: Milos Vyletel <milos@xxxxxxxxxx>
> > ---
> > Documentation/RCU/whatisRCU.txt | 4 +++-
> > 1 file changed, 3 insertions(+), 1 deletion(-)
> >
> > diff --git a/Documentation/RCU/whatisRCU.txt b/Documentation/RCU/whatisRCU.txt
> > index 88dfce1..82b1b2c 100644
> > --- a/Documentation/RCU/whatisRCU.txt
> > +++ b/Documentation/RCU/whatisRCU.txt
> > @@ -256,7 +256,9 @@ rcu_dereference()
> > If you are going to be fetching multiple fields from the
> > RCU-protected structure, using the local variable is of
> > course preferred. Repeated rcu_dereference() calls look
> > - ugly and incur unnecessary overhead on Alpha CPUs.
> > + ugly, do not guarantee that same pointer will be returned
> > + if update happened while in critical section and incur
> > + unnecessary overhead on Alpha CPUs.
> >
>
> An example like follows:
>
> struct some_ds {
> int data;
> bool ready;
> };
>
> struct some_ds *p = ...;
>
> rcu_read_lock();
> if (rcu_dereference(p->ready))
> data = rcu_dereference(p->data); // bug
> rcu_read_unlock();
>
> or some such.

Hello, Pranith!

Sounds like a good thought for a separate patch. Please take a look
through the rest of the documentation -- this might well be the right
place for such an example, but there might well be a better place.
Is this issue mentioned in the checklist? If not, another item might
be good.

Thanx, Paul

--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/