Re: [PATCHv2 3/4] tools/memory-model: Define effect of Mb tags on RMWs in tools/...

From: Alan Stern
Date: Wed Jun 05 2024 - 09:52:37 EST


On Tue, Jun 04, 2024 at 09:28:42PM -0700, Boqun Feng wrote:
> On Tue, Jun 04, 2024 at 06:04:40PM +0200, Jonas Oberhauser wrote:
> > --- a/tools/memory-model/linux-kernel.cat
> > +++ b/tools/memory-model/linux-kernel.cat
> > @@ -34,6 +34,16 @@ let R4rmb = R \ Noreturn (* Reads for which rmb works *)
> > let rmb = [R4rmb] ; fencerel(Rmb) ; [R4rmb]
> > let wmb = [W] ; fencerel(Wmb) ; [W]
> > let mb = ([M] ; fencerel(Mb) ; [M]) |
> > + (*
> > + * full-barrier RMWs (successful cmpxchg(), xchg(), etc.) act as
> > + * though there were enclosed by smp_mb().
> > + * The effect of these virtual smp_mb() is formalized by adding
> > + * Mb tags to the read and write of the operation, and providing
> > + * the same ordering as though there were additional po edges
> > + * between the Mb tag and the read resp. write.
> > + *)
> > + ([M] ; po ; [Mb & R]) |
> > + ([Mb & W] ; po ; [M]) |
>
> I couldn't help suggestting:
>
> ([M] ; po ; [Mb & domain(rmw)]) |
> ([Mb & range(rmw)] ; po ; [M]) |
>
> , it's a bit more clear to me, but maybe the comment above is good
> enough?

We may want to use the patch's approach for other things besides RMW.
For instance, it would be a good way to implement smp_store_mb() --
compare it to the existing implementation in the .def file.

Alan