Skip to content

Commit bf28ae5

Browse files
AlanSterningomolnar
authored andcommitted
tools/memory-model: Remove rb-dep, smp_read_barrier_depends, and lockless_dereference
Since commit 76ebbe7 ("locking/barriers: Add implicit smp_read_barrier_depends() to READ_ONCE()") was merged for the 4.15 kernel, it has not been necessary to use smp_read_barrier_depends(). Similarly, commit 59ecbbe ("locking/barriers: Kill lockless_dereference()") removed lockless_dereference() from the kernel. Since these primitives are no longer part of the kernel, they do not belong in the Linux Kernel Memory Consistency Model. This patch removes them, along with the internal rb-dep relation, and updates the revelant documentation. Signed-off-by: Alan Stern <stern@rowland.harvard.edu> Signed-off-by: Paul E. McKenney <paulmck@linux.vnet.ibm.com> Acked-by: Peter Zijlstra <peterz@infradead.org> Cc: Linus Torvalds <torvalds@linux-foundation.org> Cc: Thomas Gleixner <tglx@linutronix.de> Cc: akiyks@gmail.com Cc: boqun.feng@gmail.com Cc: dhowells@redhat.com Cc: j.alglave@ucl.ac.uk Cc: linux-arch@vger.kernel.org Cc: luc.maranget@inria.fr Cc: nborisov@suse.com Cc: npiggin@gmail.com Cc: parri.andrea@gmail.com Cc: will.deacon@arm.com Link: http://lkml.kernel.org/r/1519169112-20593-12-git-send-email-paulmck@linux.vnet.ibm.com Signed-off-by: Ingo Molnar <mingo@kernel.org>
1 parent cac79a3 commit bf28ae5

5 files changed

Lines changed: 46 additions & 48 deletions

File tree

‎tools/memory-model/Documentation/cheatsheet.txt‎

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,7 @@
66
Store, e.g., WRITE_ONCE() Y Y
77
Load, e.g., READ_ONCE() Y Y Y
88
Unsuccessful RMW operation Y Y Y
9-
smp_read_barrier_depends() Y Y Y
10-
*_dereference() Y Y Y Y
9+
rcu_dereference() Y Y Y Y
1110
Successful *_acquire() R Y Y Y Y Y Y
1211
Successful *_release() C Y Y Y W Y
1312
smp_rmb() Y R Y Y R

‎tools/memory-model/Documentation/explanation.txt‎

Lines changed: 43 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
Explanation of the Linux-Kernel Memory Model
2-
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
1+
Explanation of the Linux-Kernel Memory Consistency Model
2+
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
33

44
:Author: Alan Stern <stern@rowland.harvard.edu>
55
:Created: October 2017
@@ -35,25 +35,24 @@ Explanation of the Linux-Kernel Memory Model
3535
INTRODUCTION
3636
------------
3737

38-
The Linux-kernel memory model (LKMM) is rather complex and obscure.
39-
This is particularly evident if you read through the linux-kernel.bell
40-
and linux-kernel.cat files that make up the formal version of the
41-
memory model; they are extremely terse and their meanings are far from
42-
clear.
38+
The Linux-kernel memory consistency model (LKMM) is rather complex and
39+
obscure. This is particularly evident if you read through the
40+
linux-kernel.bell and linux-kernel.cat files that make up the formal
41+
version of the model; they are extremely terse and their meanings are
42+
far from clear.
4343

4444
This document describes the ideas underlying the LKMM. It is meant
45-
for people who want to understand how the memory model was designed.
46-
It does not go into the details of the code in the .bell and .cat
47-
files; rather, it explains in English what the code expresses
48-
symbolically.
45+
for people who want to understand how the model was designed. It does
46+
not go into the details of the code in the .bell and .cat files;
47+
rather, it explains in English what the code expresses symbolically.
4948

5049
Sections 2 (BACKGROUND) through 5 (ORDERING AND CYCLES) are aimed
51-
toward beginners; they explain what memory models are and the basic
52-
notions shared by all such models. People already familiar with these
53-
concepts can skim or skip over them. Sections 6 (EVENTS) through 12
54-
(THE FROM_READS RELATION) describe the fundamental relations used in
55-
many memory models. Starting in Section 13 (AN OPERATIONAL MODEL),
56-
the workings of the LKMM itself are covered.
50+
toward beginners; they explain what memory consistency models are and
51+
the basic notions shared by all such models. People already familiar
52+
with these concepts can skim or skip over them. Sections 6 (EVENTS)
53+
through 12 (THE FROM_READS RELATION) describe the fundamental
54+
relations used in many models. Starting in Section 13 (AN OPERATIONAL
55+
MODEL), the workings of the LKMM itself are covered.
5756

5857
Warning: The code examples in this document are not written in the
5958
proper format for litmus tests. They don't include a header line, the
@@ -827,8 +826,8 @@ A-cumulative; they only affect the propagation of stores that are
827826
executed on C before the fence (i.e., those which precede the fence in
828827
program order).
829828

830-
smp_read_barrier_depends(), rcu_read_lock(), rcu_read_unlock(), and
831-
synchronize_rcu() fences have other properties which we discuss later.
829+
read_lock(), rcu_read_unlock(), and synchronize_rcu() fences have
830+
other properties which we discuss later.
832831

833832

834833
PROPAGATION ORDER RELATION: cumul-fence
@@ -988,8 +987,8 @@ Another possibility, not mentioned earlier but discussed in the next
988987
section, is:
989988

990989
X and Y are both loads, X ->addr Y (i.e., there is an address
991-
dependency from X to Y), and an smp_read_barrier_depends()
992-
fence occurs between them.
990+
dependency from X to Y), and X is a READ_ONCE() or an atomic
991+
access.
993992

994993
Dependencies can also cause instructions to be executed in program
995994
order. This is uncontroversial when the second instruction is a
@@ -1015,9 +1014,9 @@ After all, a CPU cannot ask the memory subsystem to load a value from
10151014
a particular location before it knows what that location is. However,
10161015
the split-cache design used by Alpha can cause it to behave in a way
10171016
that looks as if the loads were executed out of order (see the next
1018-
section for more details). For this reason, the LKMM does not include
1019-
address dependencies between read events in the ppo relation unless an
1020-
smp_read_barrier_depends() fence is present.
1017+
section for more details). The kernel includes a workaround for this
1018+
problem when the loads come from READ_ONCE(), and therefore the LKMM
1019+
includes address dependencies to loads in the ppo relation.
10211020

10221021
On the other hand, dependencies can indirectly affect the ordering of
10231022
two loads. This happens when there is a dependency from a load to a
@@ -1114,11 +1113,12 @@ code such as the following:
11141113
int *r1;
11151114
int r2;
11161115

1117-
r1 = READ_ONCE(ptr);
1116+
r1 = ptr;
11181117
r2 = READ_ONCE(*r1);
11191118
}
11201119

1121-
can malfunction on Alpha systems. It is quite possible that r1 = &x
1120+
can malfunction on Alpha systems (notice that P1 uses an ordinary load
1121+
to read ptr instead of READ_ONCE()). It is quite possible that r1 = &x
11221122
and r2 = 0 at the end, in spite of the address dependency.
11231123

11241124
At first glance this doesn't seem to make sense. We know that the
@@ -1141,25 +1141,31 @@ This could not have happened if the local cache had processed the
11411141
incoming stores in FIFO order. In constrast, other architectures
11421142
maintain at least the appearance of FIFO order.
11431143

1144-
In practice, this difficulty is solved by inserting an
1145-
smp_read_barrier_depends() fence between P1's two loads. The effect
1146-
of this fence is to cause the CPU not to execute any po-later
1147-
instructions until after the local cache has finished processing all
1148-
the stores it has already received. Thus, if the code was changed to:
1144+
In practice, this difficulty is solved by inserting a special fence
1145+
between P1's two loads when the kernel is compiled for the Alpha
1146+
architecture. In fact, as of version 4.15, the kernel automatically
1147+
adds this fence (called smp_read_barrier_depends() and defined as
1148+
nothing at all on non-Alpha builds) after every READ_ONCE() and atomic
1149+
load. The effect of the fence is to cause the CPU not to execute any
1150+
po-later instructions until after the local cache has finished
1151+
processing all the stores it has already received. Thus, if the code
1152+
was changed to:
11491153

11501154
P1()
11511155
{
11521156
int *r1;
11531157
int r2;
11541158

11551159
r1 = READ_ONCE(ptr);
1156-
smp_read_barrier_depends();
11571160
r2 = READ_ONCE(*r1);
11581161
}
11591162

11601163
then we would never get r1 = &x and r2 = 0. By the time P1 executed
11611164
its second load, the x = 1 store would already be fully processed by
1162-
the local cache and available for satisfying the read request.
1165+
the local cache and available for satisfying the read request. Thus
1166+
we have yet another reason why shared data should always be read with
1167+
READ_ONCE() or another synchronization primitive rather than accessed
1168+
directly.
11631169

11641170
The LKMM requires that smp_rmb(), acquire fences, and strong fences
11651171
share this property with smp_read_barrier_depends(): They do not allow
@@ -1751,11 +1757,10 @@ no further involvement from the CPU. Since the CPU doesn't ever read
17511757
the value of x, there is nothing for the smp_rmb() fence to act on.
17521758

17531759
The LKMM defines a few extra synchronization operations in terms of
1754-
things we have already covered. In particular, rcu_dereference() and
1755-
lockless_dereference() are both treated as a READ_ONCE() followed by
1756-
smp_read_barrier_depends() -- which also happens to be how they are
1757-
defined in include/linux/rcupdate.h and include/linux/compiler.h,
1758-
respectively.
1760+
things we have already covered. In particular, rcu_dereference() is
1761+
treated as READ_ONCE() and rcu_assign_pointer() is treated as
1762+
smp_store_release() -- which is basically how the Linux kernel treats
1763+
them.
17591764

17601765
There are a few oddball fences which need special treatment:
17611766
smp_mb__before_atomic(), smp_mb__after_atomic(), and

‎tools/memory-model/linux-kernel.bell‎

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,6 @@ instructions RMW[{'once,'acquire,'release}]
2424
enum Barriers = 'wmb (*smp_wmb*) ||
2525
'rmb (*smp_rmb*) ||
2626
'mb (*smp_mb*) ||
27-
'rb_dep (*smp_read_barrier_depends*) ||
2827
'rcu-lock (*rcu_read_lock*) ||
2928
'rcu-unlock (*rcu_read_unlock*) ||
3029
'sync-rcu (*synchronize_rcu*) ||

‎tools/memory-model/linux-kernel.cat‎

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,6 @@ include "lock.cat"
2525
(*******************)
2626

2727
(* Fences *)
28-
let rb-dep = [R] ; fencerel(Rb_dep) ; [R]
2928
let rmb = [R \ Noreturn] ; fencerel(Rmb) ; [R \ Noreturn]
3029
let wmb = [W] ; fencerel(Wmb) ; [W]
3130
let mb = ([M] ; fencerel(Mb) ; [M]) |
@@ -61,11 +60,9 @@ let dep = addr | data
6160
let rwdep = (dep | ctrl) ; [W]
6261
let overwrite = co | fr
6362
let to-w = rwdep | (overwrite & int)
64-
let rrdep = addr | (dep ; rfi)
65-
let strong-rrdep = rrdep+ & rb-dep
66-
let to-r = strong-rrdep | rfi-rel-acq
63+
let to-r = addr | (dep ; rfi) | rfi-rel-acq
6764
let fence = strong-fence | wmb | po-rel | rmb | acq-po
68-
let ppo = rrdep* ; (to-r | to-w | fence)
65+
let ppo = to-r | to-w | fence
6966

7067
(* Propagation: Ordering from release operations and strong fences. *)
7168
let A-cumul(r) = rfe? ; r

‎tools/memory-model/linux-kernel.def‎

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,14 +13,12 @@ WRITE_ONCE(X,V) { __store{once}(X,V); }
1313
smp_store_release(X,V) { __store{release}(*X,V); }
1414
smp_load_acquire(X) __load{acquire}(*X)
1515
rcu_assign_pointer(X,V) { __store{release}(X,V); }
16-
lockless_dereference(X) __load{lderef}(X)
1716
rcu_dereference(X) __load{deref}(X)
1817

1918
// Fences
2019
smp_mb() { __fence{mb} ; }
2120
smp_rmb() { __fence{rmb} ; }
2221
smp_wmb() { __fence{wmb} ; }
23-
smp_read_barrier_depends() { __fence{rb_dep}; }
2422
smp_mb__before_atomic() { __fence{before-atomic} ; }
2523
smp_mb__after_atomic() { __fence{after-atomic} ; }
2624
smp_mb__after_spinlock() { __fence{after-spinlock} ; }

0 commit comments

Comments
 (0)