Skip to content

Commit 9b812f9

Browse files
committed
Merge branch 'lkmm-dev.2022.10.18c' into HEAD
lkmm-dev.2022.10.18c: LKMM development branch
2 parents cf73ae5 + 50c6afa commit 9b812f9

21 files changed

+915
-88
lines changed
Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
C DCL-broken
2+
3+
(*
4+
* Result: Sometimes
5+
*
6+
* This litmus test demonstrates more than just locking is required to
7+
* correctly implement double-checked locking.
8+
*)
9+
10+
{
11+
int flag;
12+
int data;
13+
int lck;
14+
}
15+
16+
P0(int *flag, int *data, int *lck)
17+
{
18+
int r0;
19+
int r1;
20+
int r2;
21+
22+
r0 = READ_ONCE(*flag);
23+
if (r0 == 0) {
24+
spin_lock(lck);
25+
r1 = READ_ONCE(*flag);
26+
if (r1 == 0) {
27+
WRITE_ONCE(*data, 1);
28+
WRITE_ONCE(*flag, 1);
29+
}
30+
spin_unlock(lck);
31+
}
32+
r2 = READ_ONCE(*data);
33+
}
34+
35+
P1(int *flag, int *data, int *lck)
36+
{
37+
int r0;
38+
int r1;
39+
int r2;
40+
41+
r0 = READ_ONCE(*flag);
42+
if (r0 == 0) {
43+
spin_lock(lck);
44+
r1 = READ_ONCE(*flag);
45+
if (r1 == 0) {
46+
WRITE_ONCE(*data, 1);
47+
WRITE_ONCE(*flag, 1);
48+
}
49+
spin_unlock(lck);
50+
}
51+
r2 = READ_ONCE(*data);
52+
}
53+
54+
locations [flag;data;lck;0:r0;0:r1;1:r0;1:r1]
55+
exists (0:r2=0 \/ 1:r2=0)
Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
C DCL-fixed
2+
3+
(*
4+
* Result: Never
5+
*
6+
* This litmus test demonstrates that double-checked locking can be
7+
* reliable given proper use of smp_load_acquire() and smp_store_release()
8+
* in addition to the locking.
9+
*)
10+
11+
{
12+
int flag;
13+
int data;
14+
int lck;
15+
}
16+
17+
P0(int *flag, int *data, int *lck)
18+
{
19+
int r0;
20+
int r1;
21+
int r2;
22+
23+
r0 = smp_load_acquire(flag);
24+
if (r0 == 0) {
25+
spin_lock(lck);
26+
r1 = READ_ONCE(*flag);
27+
if (r1 == 0) {
28+
WRITE_ONCE(*data, 1);
29+
smp_store_release(flag, 1);
30+
}
31+
spin_unlock(lck);
32+
}
33+
r2 = READ_ONCE(*data);
34+
}
35+
36+
P1(int *flag, int *data, int *lck)
37+
{
38+
int r0;
39+
int r1;
40+
int r2;
41+
42+
r0 = smp_load_acquire(flag);
43+
if (r0 == 0) {
44+
spin_lock(lck);
45+
r1 = READ_ONCE(*flag);
46+
if (r1 == 0) {
47+
WRITE_ONCE(*data, 1);
48+
smp_store_release(flag, 1);
49+
}
50+
spin_unlock(lck);
51+
}
52+
r2 = READ_ONCE(*data);
53+
}
54+
55+
locations [flag;data;lck;0:r0;0:r1;1:r0;1:r1]
56+
exists (0:r2=0 \/ 1:r2=0)
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
C RM-broken
2+
3+
(*
4+
* Result: DEADLOCK
5+
*
6+
* This litmus test demonstrates that the old "roach motel" approach
7+
* to locking, where code can be freely moved into critical sections,
8+
* cannot be used in the Linux kernel.
9+
*)
10+
11+
{
12+
int lck;
13+
int x;
14+
int y;
15+
}
16+
17+
P0(int *x, int *y, int *lck)
18+
{
19+
int r2;
20+
21+
spin_lock(lck);
22+
r2 = atomic_inc_return(y);
23+
WRITE_ONCE(*x, 1);
24+
spin_unlock(lck);
25+
}
26+
27+
P1(int *x, int *y, int *lck)
28+
{
29+
int r0;
30+
int r1;
31+
int r2;
32+
33+
spin_lock(lck);
34+
r0 = READ_ONCE(*x);
35+
r1 = READ_ONCE(*x);
36+
r2 = atomic_inc_return(y);
37+
spin_unlock(lck);
38+
}
39+
40+
locations [x;lck;0:r2;1:r0;1:r1;1:r2]
41+
filter (y=2 /\ 1:r0=0 /\ 1:r1=1)
42+
exists (1:r2=1)
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
C RM-fixed
2+
3+
(*
4+
* Result: Never
5+
*
6+
* This litmus test demonstrates that the old "roach motel" approach
7+
* to locking, where code can be freely moved into critical sections,
8+
* cannot be used in the Linux kernel.
9+
*)
10+
11+
{
12+
int lck;
13+
int x;
14+
int y;
15+
}
16+
17+
P0(int *x, int *y, int *lck)
18+
{
19+
int r2;
20+
21+
spin_lock(lck);
22+
r2 = atomic_inc_return(y);
23+
WRITE_ONCE(*x, 1);
24+
spin_unlock(lck);
25+
}
26+
27+
P1(int *x, int *y, int *lck)
28+
{
29+
int r0;
30+
int r1;
31+
int r2;
32+
33+
r0 = READ_ONCE(*x);
34+
r1 = READ_ONCE(*x);
35+
spin_lock(lck);
36+
r2 = atomic_inc_return(y);
37+
spin_unlock(lck);
38+
}
39+
40+
locations [x;lck;0:r2;1:r0;1:r1;1:r2]
41+
filter (y=2 /\ 1:r0=0 /\ 1:r1=1)
42+
exists (1:r2=1)

0 commit comments

Comments
 (0)