<feed xmlns='http://www.w3.org/2005/Atom'>
<title>linux/tools/memory-model, branch v6.3</title>
<subtitle>Mirror of https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/
</subtitle>
<id>https://git.shady.money/linux/atom?h=v6.3</id>
<link rel='self' href='https://git.shady.money/linux/atom?h=v6.3'/>
<link rel='alternate' type='text/html' href='https://git.shady.money/linux/'/>
<updated>2023-01-04T04:47:04Z</updated>
<entry>
<title>tools: memory-model: Make plain accesses carry dependencies</title>
<updated>2023-01-04T04:47:04Z</updated>
<author>
<name>Jonas Oberhauser</name>
<email>jonas.oberhauser@huawei.com</email>
</author>
<published>2022-12-02T12:51:00Z</published>
<link rel='alternate' type='text/html' href='https://git.shady.money/linux/commit/?id=9ba7d3b3b826ef47c1b7b8dbc2d57da868168128'/>
<id>urn:sha1:9ba7d3b3b826ef47c1b7b8dbc2d57da868168128</id>
<content type='text'>
As reported by Viktor, plain accesses in LKMM are weaker than
accesses to registers: the latter carry dependencies but the former
do not. This is exemplified in the following snippet:

  int r = READ_ONCE(*x);
  WRITE_ONCE(*y, r);

Here a data dependency links the READ_ONCE() to the WRITE_ONCE(),
preserving their order, because the model treats r as a register.
If r is turned into a memory location accessed by plain accesses,
however, the link is broken and the order between READ_ONCE() and
WRITE_ONCE() is no longer preserved.

This is too conservative, since any optimizations on plain
accesses that might break dependencies are also possible on
registers; it also contradicts the intuitive notion of "dependency"
as the data stored by the WRITE_ONCE() does depend on the data read
by the READ_ONCE(), independently of whether r is a register or a
memory location.

This is resolved by redefining all dependencies to include
dependencies carried by memory accesses; a dependency is said to be
carried by memory accesses (in the model: carry-dep) from one load
to another load if the initial load is followed by an arbitrarily
long sequence alternating between stores and loads of the same
thread, where the data of each store depends on the previous load,
and is read by the next load.

Any dependency linking the final load in the sequence to another
access also links the initial load in the sequence to that access.

More deep details can be found in this LKML discussion:

https://lore.kernel.org/lkml/d86295788ad14a02874ab030ddb8a6f8@huawei.com/

Reported-by: Viktor Vafeiadis &lt;viktor@mpi-sws.org&gt;
Signed-off-by: Jonas Oberhauser &lt;jonas.oberhauser@huawei.com&gt;
Reviewed-by: Alan Stern &lt;stern@rowland.harvard.edu&gt;
Signed-off-by: Paul E. McKenney &lt;paulmck@kernel.org&gt;
</content>
</entry>
<entry>
<title>tools: memory-model: Add rmw-sequences to the LKMM</title>
<updated>2023-01-04T04:47:04Z</updated>
<author>
<name>Alan Stern</name>
<email>stern@rowland.harvard.edu</email>
</author>
<published>2022-11-16T20:48:01Z</published>
<link rel='alternate' type='text/html' href='https://git.shady.money/linux/commit/?id=ebd50e2947de9d2675b800a6a29748d0ed7d7fd4'/>
<id>urn:sha1:ebd50e2947de9d2675b800a6a29748d0ed7d7fd4</id>
<content type='text'>
Viktor (as relayed by Jonas) has pointed out a weakness in the Linux
Kernel Memory Model.  Namely, the memory ordering properties of atomic
operations are not monotonic: An atomic op with full-barrier semantics
does not always provide ordering as strong as one with release-barrier
semantics.

The following litmus test illustrates the problem:

--------------------------------------------------
C atomics-not-monotonic

{}

P0(int *x, atomic_t *y)
{
	WRITE_ONCE(*x, 1);
	smp_wmb();
	atomic_set(y, 1);
}

P1(atomic_t *y)
{
	int r1;

	r1 = atomic_inc_return(y);
}

P2(int *x, atomic_t *y)
{
	int r2;
	int r3;

	r2 = atomic_read(y);
	smp_rmb();
	r3 = READ_ONCE(*x);
}

exists (2:r2=2 /\ 2:r3=0)
--------------------------------------------------

The litmus test is allowed as shown with atomic_inc_return(), which
has full-barrier semantics.  But if the operation is changed to
atomic_inc_return_release(), which only has release-barrier semantics,
the litmus test is forbidden.  Clearly this violates monotonicity.

The reason is because the LKMM treats full-barrier atomic ops as if
they were written:

	mb();
	load();
	store();
	mb();

(where the load() and store() are the two parts of an atomic RMW op),
whereas it treats release-barrier atomic ops as if they were written:

	load();
	release_barrier();
	store();

The difference is that here the release barrier orders the load part
of the atomic op before the store part with A-cumulativity, whereas
the mb()'s above do not.  This means that release-barrier atomics can
effectively extend the cumul-fence relation but full-barrier atomics
cannot.

To resolve this problem we introduce the rmw-sequence relation,
representing an arbitrarily long sequence of atomic RMW operations in
which each operation reads from the previous one, and explicitly allow
it to extend cumul-fence.  This modification of the memory model is
sound; it holds for PPC because of B-cumulativity, it holds for TSO
and ARM64 because of other-multicopy atomicity, and we can assume that
atomic ops on all other architectures will be implemented so as to
make it hold for them.

For similar reasons we also allow rmw-sequence to extend the
w-post-bounded relation, which is analogous to cumul-fence in some
ways.

Reported-by: Viktor Vafeiadis &lt;viktor@mpi-sws.org&gt;
Signed-off-by: Alan Stern &lt;stern@rowland.harvard.edu&gt;
Reviewed-by: Jonas Oberhauser &lt;jonas.oberhauser@huawei.com&gt;
Signed-off-by: Paul E. McKenney &lt;paulmck@kernel.org&gt;
</content>
</entry>
<entry>
<title>tools/memory-model: Weaken ctrl dependency definition in explanation.txt</title>
<updated>2022-10-18T22:14:52Z</updated>
<author>
<name>Paul Heidekrüger</name>
<email>paul.heidekrueger@in.tum.de</email>
</author>
<published>2022-09-03T16:57:17Z</published>
<link rel='alternate' type='text/html' href='https://git.shady.money/linux/commit/?id=fc13b47692efdc829842757798011fa2e13eb9ff'/>
<id>urn:sha1:fc13b47692efdc829842757798011fa2e13eb9ff</id>
<content type='text'>
The current informal control dependency definition in explanation.txt is
too broad and, as discussed, needs to be updated.

Consider the following example:

&gt; if(READ_ONCE(x))
&gt;   return 42;
&gt;
&gt; WRITE_ONCE(y, 42);
&gt;
&gt; return 21;

The read event determines whether the write event will be executed "at all"
- as per the current definition - but the formal LKMM does not recognize
this as a control dependency.

Introduce a new definition which includes the requirement for the second
memory access event to syntactically lie within the arm of a non-loop
conditional.

Link: https://lore.kernel.org/all/20220615114330.2573952-1-paul.heidekrueger@in.tum.de/
Cc: Marco Elver &lt;elver@google.com&gt;
Cc: Charalampos Mainas &lt;charalampos.mainas@gmail.com&gt;
Cc: Pramod Bhatotia &lt;pramod.bhatotia@in.tum.de&gt;
Cc: Soham Chakraborty &lt;s.s.chakraborty@tudelft.nl&gt;
Cc: Martin Fink &lt;martin.fink@in.tum.de&gt;
Co-developed-by: Alan Stern &lt;stern@rowland.harvard.edu&gt;
Signed-off-by: Alan Stern &lt;stern@rowland.harvard.edu&gt;
Signed-off-by: Paul Heidekrüger &lt;paul.heidekrueger@in.tum.de&gt;
Signed-off-by: Paul E. McKenney &lt;paulmck@kernel.org&gt;
</content>
</entry>
<entry>
<title>tools/memory-model: Clarify LKMM's limitations in litmus-tests.txt</title>
<updated>2022-08-31T12:15:31Z</updated>
<author>
<name>Paul Heidekrüger</name>
<email>paul.heidekrueger@in.tum.de</email>
</author>
<published>2022-06-14T15:48:11Z</published>
<link rel='alternate' type='text/html' href='https://git.shady.money/linux/commit/?id=be94ecf7608cc11ff46442012e710bb8fb139b99'/>
<id>urn:sha1:be94ecf7608cc11ff46442012e710bb8fb139b99</id>
<content type='text'>
As discussed, clarify LKMM not recognizing certain kinds of orderings.
In particular, highlight the fact that LKMM might deliberately make
weaker guarantees than compilers and architectures.

[ paulmck: Fix whitespace issue noted by checkpatch.pl. ]

Link: https://lore.kernel.org/all/YpoW1deb%2FQeeszO1@ethstick13.dse.in.tum.de/T/#u
Co-developed-by: Alan Stern &lt;stern@rowland.harvard.edu&gt;
Signed-off-by: Alan Stern &lt;stern@rowland.harvard.edu&gt;
Signed-off-by: Paul Heidekrüger &lt;paul.heidekrueger@in.tum.de&gt;
Reviewed-by: Marco Elver &lt;elver@google.com&gt;
Reviewed-by: Joel Fernandes (Google) &lt;joel@joelfernandes.org&gt;
Cc: Charalampos Mainas &lt;charalampos.mainas@gmail.com&gt;
Cc: Pramod Bhatotia &lt;pramod.bhatotia@in.tum.de&gt;
Cc: Soham Chakraborty &lt;s.s.chakraborty@tudelft.nl&gt;
Cc: Martin Fink &lt;martin.fink@in.tum.de&gt;
Signed-off-by: Paul E. McKenney &lt;paulmck@kernel.org&gt;
</content>
</entry>
<entry>
<title>tools/memory-model/README: Update klitmus7 compat table</title>
<updated>2022-05-03T17:12:48Z</updated>
<author>
<name>Akira Yokosawa</name>
<email>akiyks@gmail.com</email>
</author>
<published>2022-05-02T12:05:09Z</published>
<link rel='alternate' type='text/html' href='https://git.shady.money/linux/commit/?id=5b759db44195bb779828a188bad6b745c18dcd55'/>
<id>urn:sha1:5b759db44195bb779828a188bad6b745c18dcd55</id>
<content type='text'>
EXPORT_SYMBOL of do_exec() was removed in v5.17.  Unfortunately,
kernel modules from klitmus7 7.56 have do_exec() at the end of
each kthread.

herdtools7 7.56.1 has addressed the issue.

Update the compatibility table accordingly.

Signed-off-by: Akira Yokosawa &lt;akiyks@gmail.com&gt;
Cc: Luc Maranget &lt;luc.maranget@inria.fr&gt;
Cc: Jade Alglave &lt;j.alglave@ucl.ac.uk&gt;
Cc: stable@vger.kernel.org # v5.17+
Signed-off-by: Paul E. McKenney &lt;paulmck@kernel.org&gt;
</content>
</entry>
<entry>
<title>tools/memory-model: Explain syntactic and semantic dependencies</title>
<updated>2022-02-02T01:32:30Z</updated>
<author>
<name>Alan Stern</name>
<email>stern@rowland.harvard.edu</email>
</author>
<published>2022-02-01T19:00:08Z</published>
<link rel='alternate' type='text/html' href='https://git.shady.money/linux/commit/?id=e2b665f612ca2ddc61c3d54817a3a780aee6b251'/>
<id>urn:sha1:e2b665f612ca2ddc61c3d54817a3a780aee6b251</id>
<content type='text'>
Paul Heidekrüger pointed out that the Linux Kernel Memory Model
documentation doesn't mention the distinction between syntactic and
semantic dependencies.  This is an important difference, because the
compiler can easily break dependencies that are only syntactic, not
semantic.

This patch adds a few paragraphs to the LKMM documentation explaining
these issues and illustrating how they can matter.

Suggested-by: Paul Heidekrüger &lt;paul.heidekrueger@in.tum.de&gt;
Reviewed-by: Akira Yokosawa &lt;akiyks@gmail.com&gt;
Signed-off-by: Alan Stern &lt;stern@rowland.harvard.edu&gt;
Signed-off-by: Paul E. McKenney &lt;paulmck@kernel.org&gt;
</content>
</entry>
<entry>
<title>tools/memory-model: litmus: Add two tests for unlock(A)+lock(B) ordering</title>
<updated>2021-12-01T01:47:08Z</updated>
<author>
<name>Boqun Feng</name>
<email>boqun.feng@gmail.com</email>
</author>
<published>2021-10-25T14:54:16Z</published>
<link rel='alternate' type='text/html' href='https://git.shady.money/linux/commit/?id=c438b7d860b4c1acb4ebff6d8d946d593ca5fe1e'/>
<id>urn:sha1:c438b7d860b4c1acb4ebff6d8d946d593ca5fe1e</id>
<content type='text'>
The memory model has been updated to provide a stronger ordering
guarantee for unlock(A)+lock(B) on the same CPU/thread. Therefore add
two litmus tests describing this new guarantee, these tests are simple
yet can clearly show the usage of the new guarantee, also they can serve
as the self tests for the modification in the model.

Co-developed-by: Alan Stern &lt;stern@rowland.harvard.edu&gt;
Signed-off-by: Alan Stern &lt;stern@rowland.harvard.edu&gt;
Signed-off-by: Boqun Feng &lt;boqun.feng@gmail.com&gt;
Acked-by: Peter Zijlstra (Intel) &lt;peterz@infradead.org&gt;
Signed-off-by: Paul E. McKenney &lt;paulmck@kernel.org&gt;
</content>
</entry>
<entry>
<title>tools/memory-model: doc: Describe the requirement of the litmus-tests directory</title>
<updated>2021-12-01T01:47:08Z</updated>
<author>
<name>Boqun Feng</name>
<email>boqun.feng@gmail.com</email>
</author>
<published>2021-10-25T14:54:15Z</published>
<link rel='alternate' type='text/html' href='https://git.shady.money/linux/commit/?id=b47c05ecf60bd8743ad8c0ee510d3e1c060529d7'/>
<id>urn:sha1:b47c05ecf60bd8743ad8c0ee510d3e1c060529d7</id>
<content type='text'>
It's better that we have some "standard" about which test should be put
in the litmus-tests directory because it helps future contributors
understand whether they should work on litmus-tests in kernel or Paul's
GitHub repo. Therefore explain a little bit on what a "representative"
litmus test is.

Signed-off-by: Boqun Feng &lt;boqun.feng@gmail.com&gt;
Acked-by: Peter Zijlstra (Intel) &lt;peterz@infradead.org&gt;
Signed-off-by: Paul E. McKenney &lt;paulmck@kernel.org&gt;
</content>
</entry>
<entry>
<title>tools/memory-model: Provide extra ordering for unlock+lock pair on the same CPU</title>
<updated>2021-12-01T01:47:08Z</updated>
<author>
<name>Boqun Feng</name>
<email>boqun.feng@gmail.com</email>
</author>
<published>2021-10-25T14:54:14Z</published>
<link rel='alternate' type='text/html' href='https://git.shady.money/linux/commit/?id=ddfe12944e84830fe7dc490992e55b4fa773555e'/>
<id>urn:sha1:ddfe12944e84830fe7dc490992e55b4fa773555e</id>
<content type='text'>
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@rowland.harvard.edu/

Co-developed-by: Alan Stern &lt;stern@rowland.harvard.edu&gt;
Signed-off-by: Alan Stern &lt;stern@rowland.harvard.edu&gt;
Signed-off-by: Boqun Feng &lt;boqun.feng@gmail.com&gt;
Reviewed-by: Michael Ellerman &lt;mpe@ellerman.id.au&gt; (powerpc)
Acked-by: Palmer Dabbelt &lt;palmerdabbelt@google.com&gt; (RISC-V)
Acked-by: Peter Zijlstra (Intel) &lt;peterz@infradead.org&gt;
Signed-off-by: Paul E. McKenney &lt;paulmck@kernel.org&gt;
</content>
</entry>
<entry>
<title>tools/memory-model: Document data_race(READ_ONCE())</title>
<updated>2021-07-27T18:48:55Z</updated>
<author>
<name>Paul E. McKenney</name>
<email>paulmck@kernel.org</email>
</author>
<published>2021-05-18T17:47:43Z</published>
<link rel='alternate' type='text/html' href='https://git.shady.money/linux/commit/?id=87859a8e3f083bd57b34e6a962544d775a76b15f'/>
<id>urn:sha1:87859a8e3f083bd57b34e6a962544d775a76b15f</id>
<content type='text'>
It is possible to cause KCSAN to ignore marked accesses by applying
__no_kcsan to the function or applying data_race() to the marked accesses.
These approaches allow the developer to restrict compiler optimizations
while also causing KCSAN to ignore diagnostic accesses.

This commit therefore updates the documentation accordingly.

Signed-off-by: Paul E. McKenney &lt;paulmck@kernel.org&gt;
</content>
</entry>
</feed>
