From: Jonas Oberhauser <jonas.oberhauser@huawei.com>
To: Alan Stern <stern@rowland.harvard.edu>
Cc: Jonas Oberhauser <jonas.oberhauser@huaweicloud.com>,
"paulmck@kernel.org" <paulmck@kernel.org>,
"parri.andrea@gmail.com" <parri.andrea@gmail.com>,
"will@kernel.org" <will@kernel.org>,
"peterz@infradead.org" <peterz@infradead.org>,
"boqun.feng@gmail.com" <boqun.feng@gmail.com>,
"npiggin@gmail.com" <npiggin@gmail.com>,
"dhowells@redhat.com" <dhowells@redhat.com>,
"j.alglave@ucl.ac.uk" <j.alglave@ucl.ac.uk>,
"luc.maranget@inria.fr" <luc.maranget@inria.fr>,
"akiyks@gmail.com" <akiyks@gmail.com>,
"dlustig@nvidia.com" <dlustig@nvidia.com>,
"joel@joelfernandes.org" <joel@joelfernandes.org>,
"urezki@gmail.com" <urezki@gmail.com>,
"quic_neeraju@quicinc.com" <quic_neeraju@quicinc.com>,
"frederic@kernel.org" <frederic@kernel.org>,
"linux-kernel@vger.kernel.org" <linux-kernel@vger.kernel.org>
Subject: RE: [PATCH] tools: memory-model: Make plain accesses carry dependencies
Date: Sat, 3 Dec 2022 11:47:06 +0000 [thread overview]
Message-ID: <bcacee1a2ce84123a664d783d108050e@huawei.com> (raw)
In-Reply-To: <Y4pec7lfQHwmH4V/@rowland.harvard.edu>
-----Original Message-----
From: Alan Stern [mailto:stern@rowland.harvard.edu]
Sent: Friday, December 2, 2022 9:22 PM
> > void *y[2];
> > void *x[2] = { (void*)&y[1], (void*)&y[0] };
> >
> > P0() {
> > void **t = (void**)(x[0]);
> Now t holds a pointer to y[1].
Unfortunately, this kind of inductive reasoning (arguing about what happens based on what happened "before") is not possible with memory models that allow OOTA; as you put it, one must allow for loads reading from stores that haven't happened yet.
One such store (I promise!(*)) is a store to x[0] which writes &x[1]. Let's consider the alternative universe where we read from this future store, so now t holds a pointer to x[1].
> > *t = (void*)(t-1);
> And now y[1] holds a pointer to y[0].
In our alternative universe, x[1] now holds a pointer to x[0].
> > }
> > P1() {
> > void **u = (void**)(x[1]);
> Now u holds a pointer to y[0].
In our alternative universe, u holds the pointer to x[0] stored by P0().
> > *u = (void*)(u+1);
> And now y[0] holds a pointer to y[1].
In our alternative universe, now x[0] holds a pointer to x[1]. Behold, the store I promised would happen!
> > }
> The contents of x[] never get changed, so there's no question about the values of t and u.
They might get changed, by the stores *t=... and *u=...
Have fun,
Jonas
(*= because this example is provided free of charge, there is no actual promise, to the extent permitted by applicable law)
next prev parent reply other threads:[~2022-12-03 11:47 UTC|newest]
Thread overview: 9+ messages / expand[flat|nested] mbox.gz Atom feed top
2022-12-01 12:18 [PATCH] tools: memory-model: Make plain accesses carry dependencies Jonas Oberhauser
2022-12-01 16:02 ` Alan Stern
2022-12-01 17:21 ` Jonas Oberhauser
2022-12-01 20:21 ` Alan Stern
2022-12-02 17:22 ` Jonas Oberhauser
2022-12-02 20:22 ` Alan Stern
2022-12-03 11:47 ` Jonas Oberhauser [this message]
2022-12-03 15:20 ` Alan Stern
2022-12-03 19:04 ` 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=bcacee1a2ce84123a664d783d108050e@huawei.com \
--to=jonas.oberhauser@huawei.com \
--cc=akiyks@gmail.com \
--cc=boqun.feng@gmail.com \
--cc=dhowells@redhat.com \
--cc=dlustig@nvidia.com \
--cc=frederic@kernel.org \
--cc=j.alglave@ucl.ac.uk \
--cc=joel@joelfernandes.org \
--cc=jonas.oberhauser@huaweicloud.com \
--cc=linux-kernel@vger.kernel.org \
--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