linux-arch.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Alan Stern <stern@rowland.harvard.edu>
To: "Paul E. McKenney" <paulmck@kernel.org>
Cc: linux-kernel@vger.kernel.org, linux-arch@vger.kernel.org,
	kernel-team@fb.com, mingo@kernel.org, parri.andrea@gmail.com,
	will@kernel.org, peterz@infradead.org, boqun.feng@gmail.com,
	npiggin@gmail.com, dhowells@redhat.com, j.alglave@ucl.ac.uk,
	luc.maranget@inria.fr, akiyks@gmail.com
Subject: Re: [PATCH kcsan 9/9] tools/memory-model:  Document locking corner cases
Date: Mon, 31 Aug 2020 21:45:04 -0400	[thread overview]
Message-ID: <20200901014504.GB571008@rowland.harvard.edu> (raw)
In-Reply-To: <20200831214738.GE2855@paulmck-ThinkPad-P72>

On Mon, Aug 31, 2020 at 02:47:38PM -0700, Paul E. McKenney wrote:
> On Mon, Aug 31, 2020 at 04:17:01PM -0400, Alan Stern wrote:

> > Is this discussion perhaps overkill?
> > 
> > Let's put it this way: Suppose we have the following code:
> > 
> > 	P0(int *x, int *lck)
> > 	{
> > 		spin_lock(lck);
> > 		WRITE_ONCE(*x, 1);
> > 		do_something();
> > 		spin_unlock(lck);
> > 	}
> > 
> > 	P1(int *x, int *lck)
> > 	{
> > 		while (READ_ONCE(*x) == 0)
> > 			;
> > 		spin_lock(lck);
> > 		do_something_else();
> > 		spin_unlock(lck);
> > 	}
> > 
> > It's obvious that this test won't deadlock.  But if P1 is changed to:
> > 
> > 	P1(int *x, int *lck)
> > 	{
> > 		spin_lock(lck);
> > 		while (READ_ONCE(*x) == 0)
> > 			;
> > 		do_something_else();
> > 		spin_unlock(lck);
> > 	}
> > 
> > then it's equally obvious that the test can deadlock.  No need for
> > fancy memory models or litmus tests or anything else.
> 
> For people like you and me, who have been thinking about memory ordering
> for longer than either of us care to admit, this level of exposition is
> most definitely -way- overkill!!!
> 
> But I have had people be very happy and grateful that I explained this to
> them at this level of detail.  Yes, I started parallel programming before
> some of them were born, but they are definitely within our target audience
> for this particular document.  And it is not just Linux kernel hackers
> who need this level of detail.  A roughly similar transactional-memory
> scenario proved to be so non-obvious to any number of noted researchers
> that Blundell, Lewis, and Martin needed to feature it in this paper:
> https://ieeexplore.ieee.org/abstract/document/4069174
> (Alternative source: https://repository.upenn.edu/cgi/viewcontent.cgi?article=1344&context=cis_papers)
> 
> Please note that I am -not- advocating making (say) explanation.txt or
> recipes.txt more newbie-accessible than they already are.  After all,
> the point of the README file in that same directory is to direct people
> to the documentation files that are the best fit for them, and both
> explanation.txt and recipes.txt contain advanced material, and thus
> require similarly advanced prerequisites.
> 
> Seem reasonable, or am I missing your point?

The question is, what are you trying to accomplish in this section?  Are 
you trying to demonstrate that it isn't safe to allow arbitrary code to 
leak into a critical section?  If so then you don't need to present an 
LKMM litmus test to make the point; the example I gave here will do 
quite as well.  Perhaps even better, since it doesn't drag in all sorts 
of extraneous concepts like limitations of litmus tests or how to 
emulate a spin loop.

On the other hand, if your goal is to show how to construct a litmus 
test that will model a particular C language test case (such as the one 
I gave), then the text does a reasonable job -- although I do think it 
could be clarified somewhat.  For instance, it wouldn't hurt to include 
the real C code before giving the corresponding litmus test, so that the 
reader will have a clear idea of what you're trying to model.

Just what you want to achieve here is not clear from the context.

Besides, the example is in any case a straw man.  The text starts out 
saying "It is tempting to allow memory-reference instructions to be 
pulled into a critical section", but then the example pulls an entire 
spin loop inside -- not just the memory references but also the 
conditional branch instruction at the bottom of the loop!  I can't 
imagine anyone would think it was safe to allow branches to leak into a 
critical section, particularly when doing so would break a control 
dependency (as it does here).

Alan

  reply	other threads:[~2020-09-01  1:45 UTC|newest]

Thread overview: 30+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-08-31 18:20 [PATCH memory-model 0/9] LKMM updates for v5.10 Paul E. McKenney
2020-08-31 18:20 ` [PATCH kcsan 1/9] docs: fix references for DMA*.txt files paulmck
2020-08-31 18:20 ` [PATCH kcsan 2/9] Replace HTTP links with HTTPS ones: LKMM paulmck
2020-08-31 18:20 ` [PATCH kcsan 3/9] tools/memory-model: Update recipes.txt prime_numbers.c path paulmck
2020-08-31 18:20 ` [PATCH kcsan 4/9] tools/memory-model: Improve litmus-test documentation paulmck
2020-08-31 18:20 ` [PATCH kcsan 5/9] tools/memory-model: Add a simple entry point document paulmck
2020-08-31 18:20 ` [PATCH kcsan 6/9] tools/memory-model: Expand the cheatsheet.txt notion of relaxed paulmck
2020-09-02  3:54   ` Boqun Feng
2020-09-02 10:14     ` peterz
2020-09-02 12:37       ` Boqun Feng
2020-09-02 12:47         ` peterz
2020-09-03 23:30         ` Paul E. McKenney
2020-09-04  0:59           ` Boqun Feng
2020-09-04  2:39             ` Paul E. McKenney
2020-09-04  2:47               ` Boqun Feng
2020-09-04 19:56                 ` Paul E. McKenney
2020-08-31 18:20 ` [PATCH kcsan 7/9] tools/memory-model: Move Documentation description to Documentation/README paulmck
2020-08-31 18:20 ` [PATCH kcsan 8/9] tools/memory-model: Document categories of ordering primitives paulmck
2020-08-31 22:34   ` Akira Yokosawa
2020-08-31 23:12     ` Paul E. McKenney
2020-09-01  1:23   ` Alan Stern
2020-09-01  2:58     ` Paul E. McKenney
2020-08-31 18:20 ` [PATCH kcsan 9/9] tools/memory-model: Document locking corner cases paulmck
2020-08-31 20:17   ` Alan Stern
2020-08-31 21:47     ` Paul E. McKenney
2020-09-01  1:45       ` Alan Stern [this message]
2020-09-01 17:04         ` Paul E. McKenney
2020-09-01 20:11           ` Alan Stern
2020-09-03 23:45             ` Paul E. McKenney
2020-09-04 19:52               ` Alan Stern

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=20200901014504.GB571008@rowland.harvard.edu \
    --to=stern@rowland.harvard.edu \
    --cc=akiyks@gmail.com \
    --cc=boqun.feng@gmail.com \
    --cc=dhowells@redhat.com \
    --cc=j.alglave@ucl.ac.uk \
    --cc=kernel-team@fb.com \
    --cc=linux-arch@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=luc.maranget@inria.fr \
    --cc=mingo@kernel.org \
    --cc=npiggin@gmail.com \
    --cc=parri.andrea@gmail.com \
    --cc=paulmck@kernel.org \
    --cc=peterz@infradead.org \
    --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).