mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: "Paul E. McKenney" <paulmck@kernel.org>
To: Alan Stern <stern@rowland.harvard.edu>
Cc: LKMM Maintainers -- Akira Yokosawa <akiyks@gmail.com>,
	Andrea Parri <parri.andrea@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>,
	Luc Maranget <luc.maranget@inria.fr>,
	Nicholas Piggin <npiggin@gmail.com>,
	"Paul E. McKenney" <paulmck@linux.ibm.com>,
	Peter Zijlstra <peterz@infradead.org>,
	Will Deacon <will@kernel.org>,
	Kernel development list <linux-kernel@vger.kernel.org>
Subject: Re: [PATCH RFC] tools/memory-model: Fix data race detection for unordered store and load
Date: Sat, 7 Sep 2019 08:57:06 -0700	[thread overview]
Message-ID: <20190907155706.GA27893@paulmck-ThinkPad-P72> (raw)
In-Reply-To: <Pine.LNX.4.44L0.1909061649430.1627-100000@iolanthe.rowland.org>

On Fri, Sep 06, 2019 at 04:57:22PM -0400, Alan Stern wrote:
> Currently the Linux Kernel Memory Model gives an incorrect response
> for the following litmus test:
> 
> C plain-WWC
> 
> {}
> 
> P0(int *x)
> {
> 	WRITE_ONCE(*x, 2);
> }
> 
> P1(int *x, int *y)
> {
> 	int r1;
> 	int r2;
> 	int r3;
> 
> 	r1 = READ_ONCE(*x);
> 	if (r1 == 2) {
> 		smp_rmb();
> 		r2 = *x;
> 	}
> 	smp_rmb();
> 	r3 = READ_ONCE(*x);
> 	WRITE_ONCE(*y, r3 - 1);
> }
> 
> P2(int *x, int *y)
> {
> 	int r4;
> 
> 	r4 = READ_ONCE(*y);
> 	if (r4 > 0)
> 		WRITE_ONCE(*x, 1);
> }
> 
> exists (x=2 /\ 1:r2=2 /\ 2:r4=1)
> 
> The memory model says that the plain read of *x in P1 races with the
> WRITE_ONCE(*x) in P2.
> 
> The problem is that we have a write W and a read R related by neither
> fre or rfe, but rather W ->coe W' ->rfe R, where W' is an intermediate
> write (the WRITE_ONCE() in P0).  In this situation there is no
> particular ordering between W and R, so either a wr-vis link from W to
> R or an rw-xbstar link from R to W would prove that the accesses
> aren't concurrent.
> 
> But the LKMM only looks for a wr-vis link, which is equivalent to
> assuming that W must execute before R.  This is not necessarily true
> on non-multicopy-atomic systems, as the WWC pattern demonstrates.
> 
> This patch changes the LKMM to accept either a wr-vis or a reverse
> rw-xbstar link as a proof of non-concurrency.
> 
> Signed-off-by: Alan Stern <stern@rowland.harvard.edu>

Queued and pushed for review and testing, thank you very much!

						Thanx, Paul

> ---
> 
>  tools/memory-model/linux-kernel.cat |    2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
> 
> Index: usb-devel/tools/memory-model/linux-kernel.cat
> ===================================================================
> --- usb-devel.orig/tools/memory-model/linux-kernel.cat
> +++ usb-devel/tools/memory-model/linux-kernel.cat
> @@ -197,7 +197,7 @@ empty (wr-incoh | rw-incoh | ww-incoh) a
>  (* Actual races *)
>  let ww-nonrace = ww-vis & ((Marked * W) | rw-xbstar) & ((W * Marked) | wr-vis)
>  let ww-race = (pre-race & co) \ ww-nonrace
> -let wr-race = (pre-race & (co? ; rf)) \ wr-vis
> +let wr-race = (pre-race & (co? ; rf)) \ wr-vis \ rw-xbstar^-1
>  let rw-race = (pre-race & fr) \ rw-xbstar
>  
>  flag ~empty (ww-race | wr-race | rw-race) as data-race
> 

  reply	other threads:[~2019-09-07 15:57 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-09-06 20:57 Alan Stern
2019-09-07 15:57 ` Paul E. McKenney [this message]
2019-09-17 11:39 ` Andrea Parri
2019-09-18 17:24   ` 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=20190907155706.GA27893@paulmck-ThinkPad-P72 \
    --to=paulmck@kernel.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-kernel@vger.kernel.org \
    --cc=luc.maranget@inria.fr \
    --cc=npiggin@gmail.com \
    --cc=parri.andrea@gmail.com \
    --cc=paulmck@linux.ibm.com \
    --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

all inboxes | Powered by JetHome®