Re: [PATCH] tools/memory-model: Provide extra ordering for unlock+lock pair on the same CPU

From: Alan Stern
Date: Thu Sep 30 2021 - 21:30:58 EST


On Fri, Oct 01, 2021 at 08:12:56AM +0800, Boqun Feng wrote:
> On Thu, Sep 30, 2021 at 04:46:34PM -0400, Alan Stern wrote:
> > On Thu, Sep 30, 2021 at 11:17:53AM -0700, Paul E. McKenney wrote:
> > > On Thu, Sep 30, 2021 at 11:20:33AM -0400, Alan Stern wrote:
> > > > On Thu, Sep 30, 2021 at 09:08:23PM +0800, Boqun Feng wrote:
> > > > > A recent discussion[1] shows that we are in favor of strengthening the
> > > > > ordering of unlock + lock on the same CPU: a unlock and a po-after lock
> > > > > should provide the so-called RCtso ordering, that is a memory access S
> > > > > po-before the unlock should be ordered against a memory access R
> > > > > po-after the lock, unless S is a store and R is a load.
> > > > >
> > > > > The strengthening meets programmers' expection that "sequence of two
> > > > > locked regions to be ordered wrt each other" (from Linus), and can
> > > > > reduce the mental burden when using locks. Therefore add it in LKMM.
> > > > >
> > > > > [1]: https://lore.kernel.org/lkml/20210909185937.GA12379@xxxxxxxxxxxxxxxxxxx/
> > > > >
> > > > > Co-developed-by: Alan Stern <stern@xxxxxxxxxxxxxxxxxxx>
> > > > > Signed-off-by: Alan Stern <stern@xxxxxxxxxxxxxxxxxxx>
> > > > > Signed-off-by: Boqun Feng <boqun.feng@xxxxxxxxx>
> > > > > ---
> > > > > Alan,
> > > > >
> > > > > I added the "Co-developed-by" and "Signed-off-by" tags since most of the
> > > > > work is done by you. Feel free to let me know if you want to change
> > > > > anything.
> > > >
> > > > It looks good to me. However, do we really want to add these litmus
> > > > tests to the kernel source, or would it be better to keep them with
> > > > the thousands of other tests in Paul's archives?
> > >
> > > Either way works for me. But if they are referred to from within the
> > > kernel, it is best to have them in the kernel source. Which might be seen
> > > as a reason to minimize referring to litmus tests from the kernel. ;-)
> >
> > In this case the litmus tests are not referred to within the kernel
> > source.
> >
>
> I'm OK to drop the litmus tests, but the reason I add the two litmus
> tests is that they directly describe one of our memory model rules. The
> two litmus tests tells developers "you can use unlock+lock on the same
> CPU to order READ->WRITE or WRITE->WRITE", so they are kind of part of
> the manual of our memory model. Thoughts?

The explanation.txt file already contains example litmus tests (not
in a form acceptable to herd7, though) for these things.

Alan