powerpc: Make value-returning atomics fully ordered
Subsystems (2)
PATCH 1/2 powerpc: Make value-returning atomics fully ordered
According to memory-barriers.txt:
Quoted 4 lines
Any atomic operation that modifies some state in memory and returns information about the state (old or new) implies an SMP-conditional general memory barrier (
smp_mb()) on each side of the actual operation ...
Which mean these operations should be fully ordered. However on PPC, PPC_ATOMIC_ENTRY_BARRIER is the barrier before the actual operation, which is currently "lwsync" if SMP=y. The leading "lwsync" can not guarantee fully ordered atomics, according to Paul Mckenney:
https://lkml.org/lkml/2015/10/14/970
To fix this, we define PPC_ATOMIC_ENTRY_BARRIER as "sync" to guarantee the fully-ordered semantics.
This also makes futex atomics fully ordered, which can avoid possible memory ordering problems if userspace code relies on futex system call for fully ordered semantics.
---
These two are separated and splited from the patchset of powerpc atomic variants implementation, whose link is:
https://lkml.org/lkml/2015/10/26/141
Based on next branch of powerpc tree, tested by 0day.
arch/powerpc/include/asm/synch.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
arch/powerpc/include/asm/synch.h +1 -1
@@ -44,7 +44,7 @@ static inline void isync(void)MAKE_LWSYNC_SECTION_ENTRY (97 , __lwsync_fixup);#define PPC_ACQUIRE_BARRIER "\n" stringify_in_c(__PPC_ACQUIRE_BARRIER)#define PPC_RELEASE_BARRIER stringify_in_c(LWSYNC) "\n" -#define PPC_ATOMIC_ENTRY_BARRIER "\n" stringify_in_c(LWSYNC) "\n" +#define PPC_ATOMIC_ENTRY_BARRIER "\n" stringify_in_c(sync) "\n"#define PPC_ATOMIC_EXIT_BARRIER "\n" stringify_in_c(sync) "\n"#else #define PPC_ACQUIRE_BARRIER
Signature · 1 line
2.6.2
PATCH 2/2 powerpc: Make {cmp}xchg* and their atomic_ versions fully ordered
According to memory-barriers.txt, xchg*, cmpxchg* and their atomic_ versions all need to be fully ordered, however they are now just RELEASE+ACQUIRE, which are not fully ordered.
So also replace PPC_RELEASE_BARRIER and PPC_ACQUIRE_BARRIER with PPC_ATOMIC_ENTRY_BARRIER and PPC_ATOMIC_EXIT_BARRIER in __{cmp,}xchg_{u32,u64} respectively to guarantee fully ordered semantics of atomic{,64}_{cmp,}xchg() and {cmp,}xchg(), as a complement of commit b97021f85517 ("powerpc: Fix atomic_xxx_return barrier semantics")
This patch depends on patch "powerpc: Make value-returning atomics fully ordered" for PPC_ATOMIC_ENTRY_BARRIER definition.
--- arch/powerpc/include/asm/cmpxchg.h | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-)
arch/powerpc/include/asm/cmpxchg.h +8 -8
@@ -18,12 +18,12 @@ __xchg_u32(volatile void *p, unsigned long val)unsigned long prev; __asm__ __volatile__( -PPC_RELEASE_BARRIER +PPC_ATOMIC_ENTRY_BARRIER "1: lwarx %0,0,%2 \n" PPC405_ERR77(0,%2)" stwcx. %3,0,%2 \n\ bne- 1b" -PPC_ACQUIRE_BARRIER +PPC_ATOMIC_EXIT_BARRIER : "=&r" (prev), "+m" (*(volatile unsigned int *)p) : "r" (p), "r" (val) : "cc", "memory");
@@ -61,12 +61,12 @@ __xchg_u64(volatile void *p, unsigned long val)unsigned long prev; __asm__ __volatile__( -PPC_RELEASE_BARRIER +PPC_ATOMIC_ENTRY_BARRIER "1: ldarx %0,0,%2 \n" PPC405_ERR77(0,%2)" stdcx. %3,0,%2 \n\ bne- 1b" -PPC_ACQUIRE_BARRIER +PPC_ATOMIC_EXIT_BARRIER : "=&r" (prev), "+m" (*(volatile unsigned long *)p) : "r" (p), "r" (val) : "cc", "memory");
@@ -151,14 +151,14 @@ __cmpxchg_u32(volatile unsigned int *p, unsigned long old, unsigned long new)unsigned int prev; __asm__ __volatile__ ( -PPC_RELEASE_BARRIER +PPC_ATOMIC_ENTRY_BARRIER "1: lwarx %0,0,%2 # __cmpxchg_u32\n\ cmpw 0,%0,%3\n\ bne- 2f\n" PPC405_ERR77(0,%2)" stwcx. %4,0,%2\n\ bne- 1b" -PPC_ACQUIRE_BARRIER +PPC_ATOMIC_EXIT_BARRIER "\n\ 2:" : "=&r" (prev), "+m" (*p)
@@ -197,13 +197,13 @@ __cmpxchg_u64(volatile unsigned long *p, unsigned long old, unsigned long new)unsigned long prev; __asm__ __volatile__ ( -PPC_RELEASE_BARRIER +PPC_ATOMIC_ENTRY_BARRIER "1: ldarx %0,0,%2 # __cmpxchg_u64\n\ cmpd 0,%0,%3\n\ bne- 2f\n\ stdcx. %4,0,%2\n\ bne- 1b" -PPC_ACQUIRE_BARRIER +PPC_ATOMIC_EXIT_BARRIER "\n\ 2:" : "=&r" (prev), "+m" (*p)
Signature · 1 line
2.6.2
Re: [PATCH powerpc/next 2/2] powerpc: Make {cmp}xchg* and their atomic_ versions fully ordered
Quoted 10 lines · Boqun Feng
According to memory-barriers.txt, xchg*, cmpxchg* and their
atomic_versions all need to be fully ordered, however they are now just RELEASE+ACQUIRE, which are not fully ordered.So also replace
PPC_RELEASE_BARRIERandPPC_ACQUIRE_BARRIERwithPPC_ATOMIC_ENTRY_BARRIERandPPC_ATOMIC_EXIT_BARRIERin __{cmp,}xchg_{u32,u64} respectively to guarantee fully ordered semantics of atomic{,64}_{cmp,}xchg() and {cmp,}xchg(), as a complement of commitb97021f85517("powerpc: Fixatomic_xxx_returnbarrier semantics")
Quoted 5 lines
This patch depends on patch "powerpc: Make value-returning atomics fully ordered" for
PPC_ATOMIC_ENTRY_BARRIERdefinition.Cc <[email protected]> # 3.4+Signed-off-by Boqun Feng <[email protected]>
Quoted 74 lines
--- arch/powerpc/include/asm/cmpxchg.h | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-)arch/powerpc/include/asm/cmpxchg.h +8
-8@@ -18,12 +18,12 @@ __xchg_u32(volatile void *p, unsigned long val)unsigned long prev; __asm__ __volatile__( -PPC_RELEASE_BARRIER +PPC_ATOMIC_ENTRY_BARRIER "1: lwarx %0,0,%2 \n" PPC405_ERR77(0,%2)" stwcx. %3,0,%2 \n\ bne- 1b" -PPC_ACQUIRE_BARRIER +PPC_ATOMIC_EXIT_BARRIER : "=&r" (prev), "+m" (*(volatile unsigned int *)p) : "r" (p), "r" (val) : "cc", "memory");@@ -61,12 +61,12 @@ __xchg_u64(volatile void *p, unsigned long val)unsigned long prev; __asm__ __volatile__( -PPC_RELEASE_BARRIER +PPC_ATOMIC_ENTRY_BARRIER "1: ldarx %0,0,%2 \n" PPC405_ERR77(0,%2)" stdcx. %3,0,%2 \n\ bne- 1b" -PPC_ACQUIRE_BARRIER +PPC_ATOMIC_EXIT_BARRIER : "=&r" (prev), "+m" (*(volatile unsigned long *)p) : "r" (p), "r" (val) : "cc", "memory");@@ -151,14 +151,14 @@ __cmpxchg_u32(volatile unsigned int *p, unsigned long old, unsigned long new)unsigned int prev; __asm__ __volatile__ ( -PPC_RELEASE_BARRIER +PPC_ATOMIC_ENTRY_BARRIER "1: lwarx %0,0,%2 # __cmpxchg_u32\n\ cmpw 0,%0,%3\n\ bne- 2f\n" PPC405_ERR77(0,%2)" stwcx. %4,0,%2\n\ bne- 1b" -PPC_ACQUIRE_BARRIER +PPC_ATOMIC_EXIT_BARRIER "\n\ 2:" : "=&r" (prev), "+m" (*p)@@ -197,13 +197,13 @@ __cmpxchg_u64(volatile unsigned long *p, unsigned long old, unsigned long new)unsigned long prev; __asm__ __volatile__ ( -PPC_RELEASE_BARRIER +PPC_ATOMIC_ENTRY_BARRIER "1: ldarx %0,0,%2 # __cmpxchg_u64\n\ cmpd 0,%0,%3\n\ bne- 2f\n\ stdcx. %4,0,%2\n\ bne- 1b" -PPC_ACQUIRE_BARRIER +PPC_ATOMIC_EXIT_BARRIER "\n\ 2:" : "=&r" (prev), "+m" (*p)Signature · 1 line
2.6.2
Re: [PATCH powerpc/next 2/2] powerpc: Make {cmp}xchg* and their atomic_ versions fully ordered
In reply to Boqun FengQuoted 10 lines · Boqun Feng
According to memory-barriers.txt, xchg*, cmpxchg* and their
atomic_versions all need to be fully ordered, however they are now just RELEASE+ACQUIRE, which are not fully ordered.So also replace
PPC_RELEASE_BARRIERandPPC_ACQUIRE_BARRIERwithPPC_ATOMIC_ENTRY_BARRIERandPPC_ATOMIC_EXIT_BARRIERin __{cmp,}xchg_{u32,u64} respectively to guarantee fully ordered semantics of atomic{,64}_{cmp,}xchg() and {cmp,}xchg(), as a complement of commitb97021f85517("powerpc: Fixatomic_xxx_returnbarrier semantics")
Quoted 5 lines
This patch depends on patch "powerpc: Make value-returning atomics fully ordered" for
PPC_ATOMIC_ENTRY_BARRIERdefinition.Cc <[email protected]> # 3.4+Signed-off-by Boqun Feng <[email protected]>
Re: [powerpc/next, 2/2] powerpc: Make {cmp}xchg* and their atomic_ versions fully ordered
In reply to Boqun FengQuoted 10 lines · Boqun Feng
According to memory-barriers.txt, xchg*, cmpxchg* and their
atomic_versions all need to be fully ordered, however they are now just RELEASE+ACQUIRE, which are not fully ordered.So also replace
PPC_RELEASE_BARRIERandPPC_ACQUIRE_BARRIERwithPPC_ATOMIC_ENTRY_BARRIERandPPC_ATOMIC_EXIT_BARRIERin __{cmp,}xchg_{u32,u64} respectively to guarantee fully ordered semantics of atomic{,64}_{cmp,}xchg() and {cmp,}xchg(), as a complement of commitb97021f85517("powerpc: Fixatomic_xxx_returnbarrier semantics")
Quoted 7 lines
This patch depends on patch "powerpc: Make value-returning atomics fully ordered" for
PPC_ATOMIC_ENTRY_BARRIERdefinition.Cc <[email protected]> # 3.4+Signed-off-by Boqun Feng <[email protected]>Reviewed-by Paul E. McKenney <[email protected]>
Applied to powerpc next, thanks.
https://git.kernel.org/powerpc/c/81d7a3294de7e9828310bbf9
cheers
Quoted 17 lines · Boqun Feng
According to memory-barriers.txt:
Quoted 4 lines
Any atomic operation that modifies some state in memory and returns information about the state (old or new) implies an SMP-conditional general memory barrier (
smp_mb()) on each side of the actual operation ...Which mean these operations should be fully ordered. However on PPC,
PPC_ATOMIC_ENTRY_BARRIERis the barrier before the actual operation, which is currently "lwsync" if SMP=y. The leading "lwsync" can not guarantee fully ordered atomics, according to Paul Mckenney:https://lkml.org/lkml/2015/10/14/970
To fix this, we define
PPC_ATOMIC_ENTRY_BARRIERas "sync" to guarantee the fully-ordered semantics.
Quoted 6 lines
This also makes futex atomics fully ordered, which can avoid possible memory ordering problems if userspace code relies on futex system call for fully ordered semantics.
Cc <[email protected]> # 3.4+Signed-off-by Boqun Feng <[email protected]>
Quoted 27 lines
---
These two are separated and splited from the patchset of powerpc atomic variants implementation, whose link is:https://lkml.org/lkml/2015/10/26/141
Based on next branch of powerpc tree, tested by 0day.
arch/powerpc/include/asm/synch.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)arch/powerpc/include/asm/synch.h +1
-1@@ -44,7 +44,7 @@ static inline void isync(void)MAKE_LWSYNC_SECTION_ENTRY (97 , __lwsync_fixup);#define PPC_ACQUIRE_BARRIER "\n" stringify_in_c(__PPC_ACQUIRE_BARRIER)#define PPC_RELEASE_BARRIER stringify_in_c(LWSYNC) "\n" -#define PPC_ATOMIC_ENTRY_BARRIER "\n" stringify_in_c(LWSYNC) "\n" +#define PPC_ATOMIC_ENTRY_BARRIER "\n" stringify_in_c(sync) "\n"#define PPC_ATOMIC_EXIT_BARRIER "\n" stringify_in_c(sync) "\n"#else #define PPC_ACQUIRE_BARRIER Signature · 1 line
2.6.2
Quoted 17 lines · Boqun Feng
According to memory-barriers.txt:
Quoted 4 lines
Any atomic operation that modifies some state in memory and returns information about the state (old or new) implies an SMP-conditional general memory barrier (
smp_mb()) on each side of the actual operation ...Which mean these operations should be fully ordered. However on PPC,
PPC_ATOMIC_ENTRY_BARRIERis the barrier before the actual operation, which is currently "lwsync" if SMP=y. The leading "lwsync" can not guarantee fully ordered atomics, according to Paul Mckenney:https://lkml.org/lkml/2015/10/14/970
To fix this, we define
PPC_ATOMIC_ENTRY_BARRIERas "sync" to guarantee the fully-ordered semantics.
Quoted 6 lines
This also makes futex atomics fully ordered, which can avoid possible memory ordering problems if userspace code relies on futex system call for fully ordered semantics.
Cc <[email protected]> # 3.4+Signed-off-by Boqun Feng <[email protected]>
Quoted 17 lines · Boqun Feng
According to memory-barriers.txt:
Quoted 4 lines
Any atomic operation that modifies some state in memory and returns information about the state (old or new) implies an SMP-conditional general memory barrier (
smp_mb()) on each side of the actual operation ...Which mean these operations should be fully ordered. However on PPC,
PPC_ATOMIC_ENTRY_BARRIERis the barrier before the actual operation, which is currently "lwsync" if SMP=y. The leading "lwsync" can not guarantee fully ordered atomics, according to Paul Mckenney:https://lkml.org/lkml/2015/10/14/970
To fix this, we define
PPC_ATOMIC_ENTRY_BARRIERas "sync" to guarantee the fully-ordered semantics.
Quoted 8 lines
This also makes futex atomics fully ordered, which can avoid possible memory ordering problems if userspace code relies on futex system call for fully ordered semantics.
Cc <[email protected]> # 3.4+Signed-off-by Boqun Feng <[email protected]>Reviewed-by Paul E. McKenney <[email protected]>
Applied to powerpc next, thanks.
https://git.kernel.org/powerpc/c/49e9cf3f0c04bf76ffa59242
cheers