Skip to contentSkip to conversation

documentation: memory-barriers: fix smp_mb__before_spinlock() semantics

PATCH RESEND In review Will Deacon 3 participants 7 messages Mar 31, 2015 – Apr 1, 2015

Subsystems (4)
lore
Share & tools
lore
#0 lore raw

PATCH RESEND 1/1 documentation: memory-barriers: fix smp_mb__before_spinlock() semantics

Our current documentation claims that, when followed by an ACQUIRE, smp_mb__before_spinlock() orders prior loads against subsequent loads and stores, which isn't actually true.

Fix the documentation to state that this sequence orders only prior stores against subsequent loads and stores.

Cc Oleg Nesterov <[email protected]>
Cc "Paul E. McKenney" <[email protected]>
Cc Peter Zijlstra <[email protected]>

---

Could somebody pick this up please? I guess I could route it via the arm64 tree with an Ack, but I'd rather it went through Paul or -tip.

 Documentation/memory-barriers.txt | 7 +++----
 1 file changed, 3 insertions(+), 4 deletions(-)
Documentation/memory-barriers.txt +3 -4
index ca2387ef27ab..fa28a0c1e2b1 100644
@@ -1768,10 +1768,9 @@ for each construct.  These operations all imply certain barriers:
 
      Memory operations issued before the ACQUIRE may be completed after
      the ACQUIRE operation has completed.  An smp_mb__before_spinlock(),
-     combined with a following ACQUIRE, orders prior loads against
-     subsequent loads and stores and also orders prior stores against
-     subsequent stores.  Note that this is weaker than smp_mb()!  The
-     smp_mb__before_spinlock() primitive is free on many architectures.
+     combined with a following ACQUIRE, orders prior stores against
+     subsequent loads and stores. Note that this is weaker than smp_mb()!
+     The smp_mb__before_spinlock() primitive is free on many architectures.
 
  (2) RELEASE operation implication:
 
Signature · 1 line
2.1.4
#1 lore raw
Quoted 3 lines · Will Deacon

Could somebody pick this up please? I guess I could route it via the arm64 tree with an Ack, but I'd rather it went through Paul or -tip.

I think this would be the best route ;)

Documentation/memory-barriers.txt for each construct. These operations all imply certain barriers: · line 1773

Quoted 13 lines
Documentation/memory-barriers.txt +3 -4
@@ -1768,10 +1768,9 @@ for each construct.  These operations all imply certain barriers:
 
      Memory operations issued before the ACQUIRE may be completed after
      the ACQUIRE operation has completed.  An smp_mb__before_spinlock(),
-     combined with a following ACQUIRE, orders prior loads against
-     subsequent loads and stores and also orders prior stores against
-     subsequent stores.  Note that this is weaker than smp_mb()!  The
-     smp_mb__before_spinlock() primitive is free on many architectures.
+     combined with a following ACQUIRE, orders prior stores against
+     subsequent loads and stores. Note that this is weaker than smp_mb()!
+     The smp_mb__before_spinlock() primitive is free on many architectures.

I agree, this description was always wrong.

But perhaps you can also update the comment above smp_mb__before_spinlock? It only documents the STORE - LOAD serialization, and this was on purpose.

But people started to use this helper assuming that it can also serialize the STOREs. Perhaps the changelog could also mention this fact, this is why we need to update this comment and fix memory-barriers.txt.

Oleg.

#6 lore raw
In reply to Will Deacon
Quoted 7 lines · Will Deacon

Our current documentation claims that, when followed by an ACQUIRE, smp_mb__before_spinlock() orders prior loads against subsequent loads and stores, which isn't actually true.

Fix the documentation to state that this sequence orders only prior stores against subsequent loads and stores.

Quoted 8 lines
Cc Oleg Nesterov <[email protected]>
Cc "Paul E. McKenney" <[email protected]>
Cc Peter Zijlstra <[email protected]>

---

Could somebody pick this up please? I guess I could route it via the arm64 tree with an Ack, but I'd rather it went through Paul or -tip.

Queued for 4.2, along with a separate patch for PowerPC that make it so that PowerPC actually behaves as described below. ;-)

Thanx, Paul

Quoted 10 lines
 Documentation/memory-barriers.txt | 7 +++----
 1 file changed, 3 insertions(+), 4 deletions(-)
Documentation/memory-barriers.txt +0 -0
index ca2387ef27ab..fa28a0c1e2b1 100644
@@ -1768,10 +1768,9 @@ for each construct.  These operations all imply certain barriers:
 
      Memory operations issued before the ACQUIRE may be completed after

Documentation/memory-barriers.txt for each construct. These operations all imply certain barriers: · line 1775

Quoted 10 lines
Documentation/memory-barriers.txt +3 -4
      the ACQUIRE operation has completed.  An smp_mb__before_spinlock(),
-     combined with a following ACQUIRE, orders prior loads against
-     subsequent loads and stores and also orders prior stores against
-     subsequent stores.  Note that this is weaker than smp_mb()!  The
-     smp_mb__before_spinlock() primitive is free on many architectures.
+     combined with a following ACQUIRE, orders prior stores against
+     subsequent loads and stores. Note that this is weaker than smp_mb()!
+     The smp_mb__before_spinlock() primitive is free on many architectures.
 
  (2) RELEASE operation implication:

------------------------------------------------------------------------

powerpc: Fix smp_mb__before_spinlock()

Currently, smp_mb__before_spinlock() is defined to be smp_wmb() in core code, but this is not sufficient on PowerPC. This patch therefore supplies an override for the generic definition to strengthen smp_mb__before_spinlock() to smp_mb(), as is needed on PowerPC.

arch/powerpc/include/asm/barrier.h +1 -0
index a3bf5be111ff..1124f59b8df4 100644
@@ -89,5 +89,6 @@ do {									\
 
 #define smp_mb__before_atomic()     smp_mb()
 #define smp_mb__after_atomic()      smp_mb()
+#define smp_mb__before_spinlock()   smp_mb()
 
 #endif /* _ASM_POWERPC_BARRIER_H */
#2 lore raw
In reply to Oleg Nesterov
Quoted 23 lines · Oleg Nesterov
Quoted 3 lines · Will Deacon

Could somebody pick this up please? I guess I could route it via the arm64 tree with an Ack, but I'd rather it went through Paul or -tip.

I think this would be the best route ;)

Documentation/memory-barriers.txt for each construct. These operations all imply certain barriers: · line 1773

Quoted 13 lines
Documentation/memory-barriers.txt +3 -4
@@ -1768,10 +1768,9 @@ for each construct.  These operations all imply certain barriers:
 
      Memory operations issued before the ACQUIRE may be completed after
      the ACQUIRE operation has completed.  An smp_mb__before_spinlock(),
-     combined with a following ACQUIRE, orders prior loads against
-     subsequent loads and stores and also orders prior stores against
-     subsequent stores.  Note that this is weaker than smp_mb()!  The
-     smp_mb__before_spinlock() primitive is free on many architectures.
+     combined with a following ACQUIRE, orders prior stores against
+     subsequent loads and stores. Note that this is weaker than smp_mb()!
+     The smp_mb__before_spinlock() primitive is free on many architectures.

I agree, this description was always wrong.

Quoted 6 lines

But perhaps you can also update the comment above smp_mb__before_spinlock? It only documents the STORE - LOAD serialization, and this was on purpose.

But people started to use this helper assuming that it can also serialize the STOREs. Perhaps the changelog could also mention this fact, this is why we need to update this comment and fix memory-barriers.txt.

If Will agrees, like the following?

Thanx, Paul

------------------------------------------------------------------------

documentation: memory-barriers: Fix smp_mb__before_spinlock() semantics

Our current documentation claims that, when followed by an ACQUIRE, smp_mb__before_spinlock() orders prior loads against subsequent loads and stores, which isn't the intent. This commit therefore fixes the documentation to state that this sequence orders only prior stores against subsequent loads and stores.

In addition, the original intent of smp_mb__before_spinlock() was to only order prior loads against subsequent stores, however, people have started using it as if it ordered prior loads against subsequent loads and stores. This commit therefore also updates smp_mb__before_spinlock()'s header comment to reflect this new reality.

Cc Oleg Nesterov <[email protected]>
Cc "Paul E. McKenney" <[email protected]>
Cc Peter Zijlstra <[email protected]>
Documentation/memory-barriers.txt +3 -4
index 6974f1c2b4e1..52c320e3f107 100644
@@ -1784,10 +1784,9 @@ for each construct.  These operations all imply certain barriers:
 
      Memory operations issued before the ACQUIRE may be completed after
      the ACQUIRE operation has completed.  An smp_mb__before_spinlock(),
-     combined with a following ACQUIRE, orders prior loads against
-     subsequent loads and stores and also orders prior stores against
-     subsequent stores.  Note that this is weaker than smp_mb()!  The
-     smp_mb__before_spinlock() primitive is free on many architectures.
+     combined with a following ACQUIRE, orders prior stores against
+     subsequent loads and stores. Note that this is weaker than smp_mb()!
+     The smp_mb__before_spinlock() primitive is free on many architectures.
 
  (2) RELEASE operation implication:
 
include/linux/spinlock.h +1 -1
index 3e18379dfa6f..0063b24b4f36 100644
@@ -120,7 +120,7 @@ do {								\
 /*
  * Despite its name it doesn't necessarily has to be a full barrier.
  * It should only guarantee that a STORE before the critical section
- * can not be reordered with a LOAD inside this section.
+ * can not be reordered with LOADs and STOREs inside this section.
  * spin_lock() is the one-way barrier, this LOAD can not escape out
  * of the region. So the default implementation simply ensures that
  * a STORE can not move into the critical section, smp_wmb() should
#3 lore raw
Quoted 2 lines · Paul E. McKenney

If Will agrees, like the following?

Looks good to me, thanks ;)

Quoted 52 lines

documentation: memory-barriers: Fix smp_mb__before_spinlock() semantics

Our current documentation claims that, when followed by an ACQUIRE, smp_mb__before_spinlock() orders prior loads against subsequent loads and stores, which isn't the intent. This commit therefore fixes the documentation to state that this sequence orders only prior stores against subsequent loads and stores.

In addition, the original intent of smp_mb__before_spinlock() was to only order prior loads against subsequent stores, however, people have started using it as if it ordered prior loads against subsequent loads and stores. This commit therefore also updates smp_mb__before_spinlock()'s header comment to reflect this new reality.

Cc Oleg Nesterov <[email protected]>
Cc "Paul E. McKenney" <[email protected]>
Cc Peter Zijlstra <[email protected]>
Documentation/memory-barriers.txt +3 -4
index 6974f1c2b4e1..52c320e3f107 100644
@@ -1784,10 +1784,9 @@ for each construct.  These operations all imply certain barriers:
 
      Memory operations issued before the ACQUIRE may be completed after
      the ACQUIRE operation has completed.  An smp_mb__before_spinlock(),
-     combined with a following ACQUIRE, orders prior loads against
-     subsequent loads and stores and also orders prior stores against
-     subsequent stores.  Note that this is weaker than smp_mb()!  The
-     smp_mb__before_spinlock() primitive is free on many architectures.
+     combined with a following ACQUIRE, orders prior stores against
+     subsequent loads and stores. Note that this is weaker than smp_mb()!
+     The smp_mb__before_spinlock() primitive is free on many architectures.
 
  (2) RELEASE operation implication:
 
include/linux/spinlock.h +1 -1
index 3e18379dfa6f..0063b24b4f36 100644
@@ -120,7 +120,7 @@ do {								\
 /*
  * Despite its name it doesn't necessarily has to be a full barrier.
  * It should only guarantee that a STORE before the critical section
- * can not be reordered with a LOAD inside this section.
+ * can not be reordered with LOADs and STOREs inside this section.
  * spin_lock() is the one-way barrier, this LOAD can not escape out
  * of the region. So the default implementation simply ensures that
  * a STORE can not move into the critical section, smp_wmb() should
#4 lore raw
Quoted 5 lines · Oleg Nesterov
Quoted 2 lines · Paul E. McKenney

If Will agrees, like the following?

Looks good to me, thanks ;)

Same here, thanks for sorting that out Paul.

Will

#5 lore raw
Quoted 8 lines · Will Deacon
Quoted 5 lines · Oleg Nesterov
Quoted 2 lines · Paul E. McKenney

If Will agrees, like the following?

Looks good to me, thanks ;)

Same here, thanks for sorting that out Paul.

Very good, thank you both!

Thanx, Paul