Skip to content

Commit 9ba19cc

Browse files
committed
Merge tag 'locking-core-2020-08-03' of git://git.kernel.org/pub/scm/linux/kernel/git/tip/tip
Pull locking updates from Ingo Molnar: - LKMM updates: mostly documentation changes, but also some new litmus tests for atomic ops. - KCSAN updates: the most important change is that GCC 11 now has all fixes in place to support KCSAN, so GCC support can be enabled again. Also more annotations. - futex updates: minor cleanups and simplifications - seqlock updates: merge preparatory changes/cleanups for the 'associated locks' facilities. - lockdep updates: - simplify IRQ trace event handling - add various new debug checks - simplify header dependencies, split out <linux/lockdep_types.h>, decouple lockdep from other low level headers some more - fix NMI handling - misc cleanups and smaller fixes * tag 'locking-core-2020-08-03' of git://git.kernel.org/pub/scm/linux/kernel/git/tip/tip: (60 commits) kcsan: Improve IRQ state trace reporting lockdep: Refactor IRQ trace events fields into struct seqlock: lockdep assert non-preemptibility on seqcount_t write lockdep: Add preemption enabled/disabled assertion APIs seqlock: Implement raw_seqcount_begin() in terms of raw_read_seqcount() seqlock: Add kernel-doc for seqcount_t and seqlock_t APIs seqlock: Reorder seqcount_t and seqlock_t API definitions seqlock: seqcount_t latch: End read sections with read_seqcount_retry() seqlock: Properly format kernel-doc code samples Documentation: locking: Describe seqlock design and usage locking/qspinlock: Do not include atomic.h from qspinlock_types.h locking/atomic: Move ATOMIC_INIT into linux/types.h lockdep: Move list.h inclusion into lockdep.h locking/lockdep: Fix TRACE_IRQFLAGS vs. NMIs futex: Remove unused or redundant includes futex: Consistently use fshared as boolean futex: Remove needless goto's futex: Remove put_futex_key() rwsem: fix commas in initialisation docs: locking: Replace HTTP links with HTTPS ones ...
2 parents 8f0cb66 + 992414a commit 9ba19cc

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

86 files changed

+2797
-854
lines changed

Documentation/atomic_t.txt

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -85,21 +85,21 @@ smp_store_release() respectively. Therefore, if you find yourself only using
8585
the Non-RMW operations of atomic_t, you do not in fact need atomic_t at all
8686
and are doing it wrong.
8787

88-
A subtle detail of atomic_set{}() is that it should be observable to the RMW
89-
ops. That is:
88+
A note for the implementation of atomic_set{}() is that it must not break the
89+
atomicity of the RMW ops. That is:
9090

91-
C atomic-set
91+
C Atomic-RMW-ops-are-atomic-WRT-atomic_set
9292

9393
{
94-
atomic_set(v, 1);
94+
atomic_t v = ATOMIC_INIT(1);
9595
}
9696

97-
P1(atomic_t *v)
97+
P0(atomic_t *v)
9898
{
99-
atomic_add_unless(v, 1, 0);
99+
(void)atomic_add_unless(v, 1, 0);
100100
}
101101

102-
P2(atomic_t *v)
102+
P1(atomic_t *v)
103103
{
104104
atomic_set(v, 0);
105105
}
@@ -233,34 +233,34 @@ as well. Similarly, something like:
233233
is an ACQUIRE pattern (though very much not typical), but again the barrier is
234234
strictly stronger than ACQUIRE. As illustrated:
235235

236-
C strong-acquire
236+
C Atomic-RMW+mb__after_atomic-is-stronger-than-acquire
237237

238238
{
239239
}
240240

241-
P1(int *x, atomic_t *y)
241+
P0(int *x, atomic_t *y)
242242
{
243243
r0 = READ_ONCE(*x);
244244
smp_rmb();
245245
r1 = atomic_read(y);
246246
}
247247

248-
P2(int *x, atomic_t *y)
248+
P1(int *x, atomic_t *y)
249249
{
250250
atomic_inc(y);
251251
smp_mb__after_atomic();
252252
WRITE_ONCE(*x, 1);
253253
}
254254

255255
exists
256-
(r0=1 /\ r1=0)
256+
(0:r0=1 /\ 0:r1=0)
257257

258258
This should not happen; but a hypothetical atomic_inc_acquire() --
259259
(void)atomic_fetch_inc_acquire() for instance -- would allow the outcome,
260260
because it would not order the W part of the RMW against the following
261261
WRITE_ONCE. Thus:
262262

263-
P1 P2
263+
P0 P1
264264

265265
t = LL.acq *y (0)
266266
t++;

Documentation/dev-tools/kcsan.rst

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,8 @@ approach to detect races. KCSAN's primary purpose is to detect `data races`_.
88
Usage
99
-----
1010

11-
KCSAN requires Clang version 11 or later.
11+
KCSAN is supported by both GCC and Clang. With GCC we require version 11 or
12+
later, and with Clang also require version 11 or later.
1213

1314
To enable KCSAN configure the kernel with::
1415

Documentation/litmus-tests/README

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
============
2+
LITMUS TESTS
3+
============
4+
5+
Each subdirectory contains litmus tests that are typical to describe the
6+
semantics of respective kernel APIs.
7+
For more information about how to "run" a litmus test or how to generate
8+
a kernel test module based on a litmus test, please see
9+
tools/memory-model/README.
10+
11+
12+
atomic (/atomic derectory)
13+
--------------------------
14+
15+
Atomic-RMW+mb__after_atomic-is-stronger-than-acquire.litmus
16+
Test that an atomic RMW followed by a smp_mb__after_atomic() is
17+
stronger than a normal acquire: both the read and write parts of
18+
the RMW are ordered before the subsequential memory accesses.
19+
20+
Atomic-RMW-ops-are-atomic-WRT-atomic_set.litmus
21+
Test that atomic_set() cannot break the atomicity of atomic RMWs.
22+
NOTE: Require herd7 7.56 or later which supports "(void)expr".
23+
24+
25+
RCU (/rcu directory)
26+
--------------------
27+
28+
MP+onceassign+derefonce.litmus (under tools/memory-model/litmus-tests/)
29+
Demonstrates the use of rcu_assign_pointer() and rcu_dereference() to
30+
ensure that an RCU reader will not see pre-initialization garbage.
31+
32+
RCU+sync+read.litmus
33+
RCU+sync+free.litmus
34+
Both the above litmus tests demonstrate the RCU grace period guarantee
35+
that an RCU read-side critical section can never span a grace period.
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
C Atomic-RMW+mb__after_atomic-is-stronger-than-acquire
2+
3+
(*
4+
* Result: Never
5+
*
6+
* Test that an atomic RMW followed by a smp_mb__after_atomic() is
7+
* stronger than a normal acquire: both the read and write parts of
8+
* the RMW are ordered before the subsequential memory accesses.
9+
*)
10+
11+
{
12+
}
13+
14+
P0(int *x, atomic_t *y)
15+
{
16+
int r0;
17+
int r1;
18+
19+
r0 = READ_ONCE(*x);
20+
smp_rmb();
21+
r1 = atomic_read(y);
22+
}
23+
24+
P1(int *x, atomic_t *y)
25+
{
26+
atomic_inc(y);
27+
smp_mb__after_atomic();
28+
WRITE_ONCE(*x, 1);
29+
}
30+
31+
exists
32+
(0:r0=1 /\ 0:r1=0)
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
C Atomic-RMW-ops-are-atomic-WRT-atomic_set
2+
3+
(*
4+
* Result: Never
5+
*
6+
* Test that atomic_set() cannot break the atomicity of atomic RMWs.
7+
* NOTE: This requires herd7 7.56 or later which supports "(void)expr".
8+
*)
9+
10+
{
11+
atomic_t v = ATOMIC_INIT(1);
12+
}
13+
14+
P0(atomic_t *v)
15+
{
16+
(void)atomic_add_unless(v, 1, 0);
17+
}
18+
19+
P1(atomic_t *v)
20+
{
21+
atomic_set(v, 0);
22+
}
23+
24+
exists
25+
(v=2)
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
C RCU+sync+free
2+
3+
(*
4+
* Result: Never
5+
*
6+
* This litmus test demonstrates that an RCU reader can never see a write that
7+
* follows a grace period, if it did not see writes that precede that grace
8+
* period.
9+
*
10+
* This is a typical pattern of RCU usage, where the write before the grace
11+
* period assigns a pointer, and the writes following the grace period destroy
12+
* the object that the pointer used to point to.
13+
*
14+
* This is one implication of the RCU grace-period guarantee, which says (among
15+
* other things) that an RCU read-side critical section cannot span a grace period.
16+
*)
17+
18+
{
19+
int x = 1;
20+
int *y = &x;
21+
int z = 1;
22+
}
23+
24+
P0(int *x, int *z, int **y)
25+
{
26+
int *r0;
27+
int r1;
28+
29+
rcu_read_lock();
30+
r0 = rcu_dereference(*y);
31+
r1 = READ_ONCE(*r0);
32+
rcu_read_unlock();
33+
}
34+
35+
P1(int *x, int *z, int **y)
36+
{
37+
rcu_assign_pointer(*y, z);
38+
synchronize_rcu();
39+
WRITE_ONCE(*x, 0);
40+
}
41+
42+
exists (0:r0=x /\ 0:r1=0)
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
C RCU+sync+read
2+
3+
(*
4+
* Result: Never
5+
*
6+
* This litmus test demonstrates that after a grace period, an RCU updater always
7+
* sees all stores done in prior RCU read-side critical sections. Such
8+
* read-side critical sections would have ended before the grace period ended.
9+
*
10+
* This is one implication of the RCU grace-period guarantee, which says (among
11+
* other things) that an RCU read-side critical section cannot span a grace period.
12+
*)
13+
14+
{
15+
int x = 0;
16+
int y = 0;
17+
}
18+
19+
P0(int *x, int *y)
20+
{
21+
rcu_read_lock();
22+
WRITE_ONCE(*x, 1);
23+
WRITE_ONCE(*y, 1);
24+
rcu_read_unlock();
25+
}
26+
27+
P1(int *x, int *y)
28+
{
29+
int r0;
30+
int r1;
31+
32+
r0 = READ_ONCE(*x);
33+
synchronize_rcu();
34+
r1 = READ_ONCE(*y);
35+
}
36+
37+
exists (1:r0=1 /\ 1:r1=0)

Documentation/locking/index.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ locking
1414
mutex-design
1515
rt-mutex-design
1616
rt-mutex
17+
seqlock
1718
spinlocks
1819
ww-mutex-design
1920
preempt-locking

Documentation/locking/mutex-design.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ as an alternative to these. This new data structure provided a number
1818
of advantages, including simpler interfaces, and at that time smaller
1919
code (see Disadvantages).
2020

21-
[1] http://lwn.net/Articles/164802/
21+
[1] https://lwn.net/Articles/164802/
2222

2323
Implementation
2424
--------------

0 commit comments

Comments
 (0)