linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Joel Fernandes <joel@joelfernandes.org>
To: Alan Stern <stern@rowland.harvard.edu>
Cc: Andrea Parri <parri.andrea@gmail.com>,
	linux-kernel@vger.kernel.org, Akira Yokosawa <akiyks@gmail.com>,
	Boqun Feng <boqun.feng@gmail.com>,
	Daniel Lustig <dlustig@nvidia.com>,
	David Howells <dhowells@redhat.com>,
	Jade Alglave <j.alglave@ucl.ac.uk>,
	linux-arch@vger.kernel.org, Luc Maranget <luc.maranget@inria.fr>,
	Nicholas Piggin <npiggin@gmail.com>,
	"Paul E. McKenney" <paulmck@kernel.org>,
	Peter Zijlstra <peterz@infradead.org>,
	Will Deacon <will@kernel.org>
Subject: Re: [PATCH 1/3] LKMM: Add litmus test for RCU GP guarantee where updater frees object
Date: Fri, 20 Mar 2020 12:54:54 -0400	[thread overview]
Message-ID: <20200320165454.GA155212@google.com> (raw)
In-Reply-To: <Pine.LNX.4.44L0.2003201104220.27303-100000@netrider.rowland.org>

On Fri, Mar 20, 2020 at 11:07:10AM -0400, Alan Stern wrote:
> On Fri, 20 Mar 2020, Andrea Parri wrote:
> 
> > On Fri, Mar 20, 2020 at 02:55:50AM -0400, Joel Fernandes (Google) wrote:
> > > This adds an example for the important RCU grace period guarantee, which
> > > shows an RCU reader can never span a grace period.
> > > 
> > > Signed-off-by: Joel Fernandes (Google) <joel@joelfernandes.org>
> > > ---
> > >  .../litmus-tests/RCU+sync+free.litmus         | 40 +++++++++++++++++++
> > >  1 file changed, 40 insertions(+)
> > >  create mode 100644 tools/memory-model/litmus-tests/RCU+sync+free.litmus
> > > 
> > > diff --git a/tools/memory-model/litmus-tests/RCU+sync+free.litmus b/tools/memory-model/litmus-tests/RCU+sync+free.litmus
> > > new file mode 100644
> > > index 0000000000000..c4682502dd296
> > > --- /dev/null
> > > +++ b/tools/memory-model/litmus-tests/RCU+sync+free.litmus
> > > @@ -0,0 +1,40 @@
> > > +C RCU+sync+free
> > > +
> > > +(*
> > > + * Result: Never
> > > + *
> > > + * This litmus test demonstrates that an RCU reader can never see a write after
> > > + * the grace period, if it saw writes that happen before the grace period. This
> > > + * is a typical pattern of RCU usage, where the write before the grace period
> > > + * assigns a pointer, and the writes after destroy the object that the pointer
> > > + * points to.
> > > + *
> > > + * This guarantee also implies, an RCU reader can never span a grace period and
> > > + * is an important RCU grace period memory ordering guarantee.
> > > + *)
> > > +
> > > +{
> > > +x = 1;
> > > +y = x;
> > > +z = 1;
> > 
> > FYI, this could become a little more readable if we wrote it as follows:
> > 
> > int x = 1;
> > int *y = &x;
> > int z = 1;
> 
> Also, the test won't work with klitmus7 unless you do this.

Will do.

> > The LKMM tools are happy either way, just a matter of style/preference;
> > and yes, MP+onceassign+derefonce isn't currently following mine...  ;-/
> > 
> > 
> > > +}
> > > +
> > > +P0(int *x, int *z, int **y)
> > > +{
> > > +	int r0;
> > 
> > This would need to be "int *r0;" in order to make klitmus7(+gcc) happy.

Sorry fixed it now, my version of herd did not complain on this so I missed it.

> > > +	int r1;
> > > +
> > > +	rcu_read_lock();
> > > +	r0 = rcu_dereference(*y);
> > > +	r1 = READ_ONCE(*r0);
> > > +	rcu_read_unlock();
> > > +}
> > > +
> > > +P1(int *x, int *z, int **y)
> > > +{
> > > +	rcu_assign_pointer(*y, z);
> > 
> > AFAICT, you don't need this "RELEASE"; e.g., compare this test with the
> > example in:
> > 
> >   https://www.kernel.org/doc/Documentation/RCU/Design/Requirements/Requirements.html#Grace-Period%20Guarantee
> > 
> > What am I missing?
> 
> If z were not a simple variable but a more complicated structure, the
> RELEASE would be necessary to ensure that all P1's prior changes to z
> became visible before the write to y.
> 
> Besides, it's good form always to match rcu_dereference() with 
> rcu_assign_pointer(), for code documentation if nothing else.

Yes, adding to what Alan said, you can see the effect of not using
rcu_assign_pointer() in: MP+onceassign+derefonce.litmus

Alan and Andrea, may I add your Reviewed-by or Acked-by tags on the v2?

thanks,

 - Joel


  reply	other threads:[~2020-03-20 16:54 UTC|newest]

Thread overview: 15+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-03-20  6:55 [PATCH 1/3] LKMM: Add litmus test for RCU GP guarantee where updater frees object Joel Fernandes (Google)
2020-03-20  6:55 ` [PATCH 2/3] LKMM: Add litmus test for RCU GP guarantee where reader stores Joel Fernandes (Google)
2020-03-20 15:03   ` Alan Stern
2020-03-20 16:59     ` Joel Fernandes
2020-03-20 20:56       ` Alan Stern
2020-03-20 21:44         ` Joel Fernandes
2020-03-21  2:05           ` Boqun Feng
2020-03-23  1:31             ` Joel Fernandes
2020-03-20  6:55 ` [PATCH 3/3] LKMM: Rename MP+onceassign+derefonce for better clarity Joel Fernandes (Google)
2020-03-20 10:26 ` [PATCH 1/3] LKMM: Add litmus test for RCU GP guarantee where updater frees object Andrea Parri
2020-03-20 15:07   ` Alan Stern
2020-03-20 16:54     ` Joel Fernandes [this message]
2020-03-20 10:44 ` Andrea Parri
2020-03-20 14:59 ` Alan Stern
2020-03-20 20:15   ` Joel Fernandes

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=20200320165454.GA155212@google.com \
    --to=joel@joelfernandes.org \
    --cc=akiyks@gmail.com \
    --cc=boqun.feng@gmail.com \
    --cc=dhowells@redhat.com \
    --cc=dlustig@nvidia.com \
    --cc=j.alglave@ucl.ac.uk \
    --cc=linux-arch@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=luc.maranget@inria.fr \
    --cc=npiggin@gmail.com \
    --cc=parri.andrea@gmail.com \
    --cc=paulmck@kernel.org \
    --cc=peterz@infradead.org \
    --cc=stern@rowland.harvard.edu \
    --cc=will@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).