lkmm.lists.linux.dev archive mirror
 help / color / mirror / Atom feed
From: Jonas Oberhauser <jonas.oberhauser@huaweicloud.com>
To: paulmck@kernel.org
Cc: stern@rowland.harvard.edu, 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, dlustig@nvidia.com,
	joel@joelfernandes.org, urezki@gmail.com,
	quic_neeraju@quicinc.com, frederic@kernel.org,
	linux-kernel@vger.kernel.org, lkmm@lists.linux.dev,
	hernan.poncedeleon@huaweicloud.com
Subject: Re: [RFC] tools/memory-model: Rule out OOTA
Date: Tue, 7 Jan 2025 16:46:35 +0100	[thread overview]
Message-ID: <9df85484-9a31-4682-a053-f3aaf01c0bbb@huaweicloud.com> (raw)
In-Reply-To: <20250106214003.504664-1-jonas.oberhauser@huaweicloud.com>



Am 1/6/2025 um 10:40 PM schrieb Jonas Oberhauser:>
> Signed-off-by: Jonas Oberhauser <jonas.oberhauser@huaweicloud.com>
> ---
>   tools/memory-model/linux-kernel.cat | 6 +++++-
>   1 file changed, 5 insertions(+), 1 deletion(-)
> 
> diff --git a/tools/memory-model/linux-kernel.cat b/tools/memory-model/linux-kernel.cat
> index d7e7bf13c831..180cab56729e 100644
> --- a/tools/memory-model/linux-kernel.cat
> +++ b/tools/memory-model/linux-kernel.cat
> @@ -71,6 +71,10 @@ let barrier = fencerel(Barrier | Rmb | Wmb | Mb | Sync-rcu | Sync-srcu |
>   		Rcu-lock | Rcu-unlock | Srcu-lock | Srcu-unlock) |
>   	(po ; [Release]) | ([Acquire] ; po)
>   
> +let w_barrier = po? ; [F | Marked] ; po?
> +let rmb-plain = [R4rmb] ; po ; [Rmb] ; (po \ (po ; [W] ; (po-loc \ w_barrier))) ; [R4rmb & Plain]
> +let plain-wmb = [W & Plain] ; (po \ ((po-loc \ w_barrier) ; po ; [W] ; po)) ; [Wmb] ; po ; [W]
> +
>   (**********************************)
>   (* Fundamental coherence ordering *)
>   (**********************************)
> @@ -90,7 +94,7 @@ empty rmw & (fre ; coe) as atomic
>   let dep = addr | data
>   let rwdep = (dep | ctrl) ; [W]
>   let overwrite = co | fr
> -let to-w = rwdep | (overwrite & int) | (addr ; [Plain] ; wmb)
> +let to-w = ((addr | rmb-plain)? ; rwdep ; plain-wmb?) | (overwrite & int) | addr ; [Plain] ; wmb
>   let to-r = (addr ; [R]) | (dep ; [Marked] ; rfi)
>   let ppo = to-r | to-w | (fence & int) | (po-unlock-lock-po & int)
>   

I will also try to give an intuitive :) :( :) reasoning for why this 
patch rules out OOTA.

If we look at an dep ; rfe cycle

   dep ; rfe ; dep ; rfe ; ...


then because of the absence of data races, each rfe is more or less an

   w-post-bounded ; rfe ; r-pre-bounded

edge.

If we rotate the circle around we turn

   dep ; w-post-bounded ; rfe ; r-pre-bounded ; dep ; w-post-bounded ; 
rfe ; r-pre-bounded ; ...

into

    rfe ; (r-pre-bounded ; dep ; w-post-bounded) ; rfe ; (r-pre-bounded 
; dep ; w-post-bounded) ; rfe ; (r-pre-bounded ; ...


and ideally, each of these (w-pre-bounded ; dep ; r-post-bounded) would 
imply happens-before, since then the cycle would be.
    rfe ; hb+; rfe; hb+ ; ...
which is acyclic.

However, we do not get hb+ in general, in particular if the bounding is 
due to rmb/wmb. For all other cases, it is relatively easy to see that 
we get hb+, e.g., if the bound is due to an smp_mb().

Luckily, in our specific case, we can get hb+ evenfor cases where 
rmb/wmb bound these accesses, because these accesses related by the dep 
edges are known to be reading/read-from externally.
Such an external interaction would be impossible if there were another 
store to the same location between such an access and the next 
w_barrier: because of the absence of data races and the lack of 
w_barriers that would allow synchronization with the outside world, the 
external event could not "occur between" the access and such a store.

As a result, all pre-bounds caused by a rmb must have the form

[R4rmb] ; po ; [Rmb] ; (po \ (po ; [W] ; (po-loc \ w_barrier))) ; [R4rmb 
& Plain]

and similar for post-bounds caused by wmb, which means the corresponding

    r-pre-bounded ; dep ; w-post-bounded

edges must be

    rmb-plain ; dep ; plain-wmb

which is in ppo and thus also hb.

Hope that helps clarify the idea...

   jonas


  parent reply	other threads:[~2025-01-07 15:46 UTC|newest]

Thread overview: 59+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-01-06 21:40 [RFC] tools/memory-model: Rule out OOTA Jonas Oberhauser
2025-01-07 10:06 ` Peter Zijlstra
2025-01-07 11:02   ` Jonas Oberhauser
2025-01-07 15:46 ` Jonas Oberhauser [this message]
2025-01-07 16:09 ` Alan Stern
2025-01-07 18:47   ` Paul E. McKenney
2025-01-08 17:39     ` Jonas Oberhauser
2025-01-08 18:09       ` Paul E. McKenney
2025-01-08 19:17         ` Jonas Oberhauser
2025-01-09 17:54           ` Paul E. McKenney
2025-01-09 18:35             ` Jonas Oberhauser
2025-01-10 14:54               ` Paul E. McKenney
2025-01-10 16:21                 ` Jonas Oberhauser
2025-01-13 22:04                   ` Paul E. McKenney
2025-01-16 18:40                     ` Paul E. McKenney
2025-01-16 19:13                       ` Jonas Oberhauser
2025-01-16 19:31                         ` Paul E. McKenney
2025-01-16 20:21                           ` Jonas Oberhauser
2025-01-16 19:28                       ` Jonas Oberhauser
2025-01-16 19:39                         ` Paul E. McKenney
2025-01-17 12:08                           ` Jonas Oberhauser
2025-01-16 19:08                     ` Jonas Oberhauser
2025-01-16 23:02                       ` Alan Stern
2025-01-17  8:34                         ` Hernan Ponce de Leon
2025-01-17 11:29                         ` Jonas Oberhauser
2025-01-17 20:01                           ` Alan Stern
2025-01-21 10:36                             ` Jonas Oberhauser
2025-01-21 16:39                               ` Alan Stern
2025-01-22  3:46                                 ` Jonas Oberhauser
2025-01-22 19:11                                   ` Alan Stern
2025-01-17 15:52                         ` Alan Stern
2025-01-17 16:45                           ` Jonas Oberhauser
2025-01-17 19:02                             ` Alan Stern
2025-01-09 20:37             ` Peter Zijlstra
2025-01-09 21:13               ` Paul E. McKenney
2025-01-08 17:33   ` Jonas Oberhauser
2025-01-08 18:47     ` Alan Stern
2025-01-08 19:22       ` Jonas Oberhauser
2025-01-09 16:17         ` Alan Stern
2025-01-09 16:44           ` Jonas Oberhauser
2025-01-09 19:27             ` Alan Stern
2025-01-09 20:09               ` Jonas Oberhauser
2025-01-10  3:12                 ` Alan Stern
2025-01-10 12:21                   ` Jonas Oberhauser
2025-01-10 21:51                     ` Alan Stern
2025-01-11 12:46                       ` Jonas Oberhauser
2025-01-11 21:19                         ` Alan Stern
2025-01-12 15:55                           ` Jonas Oberhauser
2025-01-13 19:43                             ` Alan Stern
2025-07-23  0:43 ` Paul E. McKenney
2025-07-23  7:26   ` Hernan Ponce de Leon
2025-07-23 16:39     ` Paul E. McKenney
2025-07-24 14:14       ` Paul E. McKenney
2025-07-25  5:23         ` Hernan Ponce de Leon
2025-07-29 20:34           ` Paul E. McKenney
2025-07-23 17:13   ` Alan Stern
2025-07-23 17:27     ` Paul E. McKenney
2025-07-23 19:25   ` Alan Stern
2025-07-23 19:57     ` 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=9df85484-9a31-4682-a053-f3aaf01c0bbb@huaweicloud.com \
    --to=jonas.oberhauser@huaweicloud.com \
    --cc=akiyks@gmail.com \
    --cc=boqun.feng@gmail.com \
    --cc=dhowells@redhat.com \
    --cc=dlustig@nvidia.com \
    --cc=frederic@kernel.org \
    --cc=hernan.poncedeleon@huaweicloud.com \
    --cc=j.alglave@ucl.ac.uk \
    --cc=joel@joelfernandes.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=lkmm@lists.linux.dev \
    --cc=luc.maranget@inria.fr \
    --cc=npiggin@gmail.com \
    --cc=parri.andrea@gmail.com \
    --cc=paulmck@kernel.org \
    --cc=peterz@infradead.org \
    --cc=quic_neeraju@quicinc.com \
    --cc=stern@rowland.harvard.edu \
    --cc=urezki@gmail.com \
    --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 read-only IMAP folder(s) and NNTP newsgroup(s).