Commit a68415c2 authored by Ingo Molnar's avatar Ingo Molnar
Browse files

Merge branch 'lkmm' of...

Merge branch 'lkmm' of git://git.kernel.org/pub/scm/linux/kernel/git/paulmck/linux-rcu

 into locking/core

Pull v5.9 LKMM changes from Paul E. McKenney.

Mostly documentation changes, but also some new litmus tests for atomic ops.

Signed-off-by: default avatarIngo Molnar <mingo@kernel.org>
parents 63722bbc 5ef0a07a
Loading
Loading
Loading
Loading
+12 −12
Original line number Diff line number Diff line
@@ -85,21 +85,21 @@ smp_store_release() respectively. Therefore, if you find yourself only using
the Non-RMW operations of atomic_t, you do not in fact need atomic_t at all
and are doing it wrong.

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

  C atomic-set
  C Atomic-RMW-ops-are-atomic-WRT-atomic_set

  {
    atomic_set(v, 1);
    atomic_t v = ATOMIC_INIT(1);
  }

  P1(atomic_t *v)
  P0(atomic_t *v)
  {
    atomic_add_unless(v, 1, 0);
    (void)atomic_add_unless(v, 1, 0);
  }

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

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

  {
  }

  P1(int *x, atomic_t *y)
  P0(int *x, atomic_t *y)
  {
    r0 = READ_ONCE(*x);
    smp_rmb();
    r1 = atomic_read(y);
  }

  P2(int *x, atomic_t *y)
  P1(int *x, atomic_t *y)
  {
    atomic_inc(y);
    smp_mb__after_atomic();
@@ -253,14 +253,14 @@ strictly stronger than ACQUIRE. As illustrated:
  }

  exists
  (r0=1 /\ r1=0)
  (0:r0=1 /\ 0:r1=0)

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

  P1			P2
  P0			P1

			t = LL.acq *y (0)
			t++;
+35 −0
Original line number Diff line number Diff line
============
LITMUS TESTS
============

Each subdirectory contains litmus tests that are typical to describe the
semantics of respective kernel APIs.
For more information about how to "run" a litmus test or how to generate
a kernel test module based on a litmus test, please see
tools/memory-model/README.


atomic (/atomic derectory)
--------------------------

Atomic-RMW+mb__after_atomic-is-stronger-than-acquire.litmus
    Test that an atomic RMW followed by a smp_mb__after_atomic() is
    stronger than a normal acquire: both the read and write parts of
    the RMW are ordered before the subsequential memory accesses.

Atomic-RMW-ops-are-atomic-WRT-atomic_set.litmus
    Test that atomic_set() cannot break the atomicity of atomic RMWs.
    NOTE: Require herd7 7.56 or later which supports "(void)expr".


RCU (/rcu directory)
--------------------

MP+onceassign+derefonce.litmus (under tools/memory-model/litmus-tests/)
    Demonstrates the use of rcu_assign_pointer() and rcu_dereference() to
    ensure that an RCU reader will not see pre-initialization garbage.

RCU+sync+read.litmus
RCU+sync+free.litmus
    Both the above litmus tests demonstrate the RCU grace period guarantee
    that an RCU read-side critical section can never span a grace period.
+32 −0
Original line number Diff line number Diff line
C Atomic-RMW+mb__after_atomic-is-stronger-than-acquire

(*
 * Result: Never
 *
 * Test that an atomic RMW followed by a smp_mb__after_atomic() is
 * stronger than a normal acquire: both the read and write parts of
 * the RMW are ordered before the subsequential memory accesses.
 *)

{
}

P0(int *x, atomic_t *y)
{
	int r0;
	int r1;

	r0 = READ_ONCE(*x);
	smp_rmb();
	r1 = atomic_read(y);
}

P1(int *x, atomic_t *y)
{
	atomic_inc(y);
	smp_mb__after_atomic();
	WRITE_ONCE(*x, 1);
}

exists
(0:r0=1 /\ 0:r1=0)
+25 −0
Original line number Diff line number Diff line
C Atomic-RMW-ops-are-atomic-WRT-atomic_set

(*
 * Result: Never
 *
 * Test that atomic_set() cannot break the atomicity of atomic RMWs.
 * NOTE: This requires herd7 7.56 or later which supports "(void)expr".
 *)

{
	atomic_t v = ATOMIC_INIT(1);
}

P0(atomic_t *v)
{
	(void)atomic_add_unless(v, 1, 0);
}

P1(atomic_t *v)
{
	atomic_set(v, 0);
}

exists
(v=2)
+42 −0
Original line number Diff line number Diff line
C RCU+sync+free

(*
 * Result: Never
 *
 * This litmus test demonstrates that an RCU reader can never see a write that
 * follows a grace period, if it did not see writes that precede that grace
 * period.
 *
 * This is a typical pattern of RCU usage, where the write before the grace
 * period assigns a pointer, and the writes following the grace period destroy
 * the object that the pointer used to point to.
 *
 * This is one implication of the RCU grace-period guarantee, which says (among
 * other things) that an RCU read-side critical section cannot span a grace period.
 *)

{
int x = 1;
int *y = &x;
int z = 1;
}

P0(int *x, int *z, int **y)
{
	int *r0;
	int r1;

	rcu_read_lock();
	r0 = rcu_dereference(*y);
	r1 = READ_ONCE(*r0);
	rcu_read_unlock();
}

P1(int *x, int *z, int **y)
{
	rcu_assign_pointer(*y, z);
	synchronize_rcu();
	WRITE_ONCE(*x, 0);
}

exists (0:r0=x /\ 0:r1=0)
Loading