From ade960be492d0c12648fe86a121808d27adab8f9 Mon Sep 17 00:00:00 2001 From: Ian Campbell Date: Wed, 26 Mar 2014 13:38:38 +0000 Subject: [PATCH] xen: arm32: ensure cmpxchg has full barrier semantics Unrelated reads/writes should not pass the xchg. Provide cmpxchg_local for parity with arm64, although it appears to be unused. It also helps make the reason for the separation of __cmpxchg_mb more apparent. With this our cmpxchg is in sync with Linux v3.14-rc7. Signed-off-by: Ian Campbell Acked-by: Julien Grall Acked-by: Tim Deegan --- xen/include/asm-arm/arm32/system.h | 26 +++++++++++++++++++++++--- 1 file changed, 23 insertions(+), 3 deletions(-) diff --git a/xen/include/asm-arm/arm32/system.h b/xen/include/asm-arm/arm32/system.h index 9f233fe05b..dfaa3b614b 100644 --- a/xen/include/asm-arm/arm32/system.h +++ b/xen/include/asm-arm/arm32/system.h @@ -113,9 +113,29 @@ static always_inline unsigned long __cmpxchg( return oldval; } -#define cmpxchg(ptr,o,n) \ - ((__typeof__(*(ptr)))__cmpxchg((ptr),(unsigned long)(o), \ - (unsigned long)(n),sizeof(*(ptr)))) +static inline unsigned long __cmpxchg_mb(volatile void *ptr, unsigned long old, + unsigned long new, int size) +{ + unsigned long ret; + + smp_mb(); + ret = __cmpxchg(ptr, old, new, size); + smp_mb(); + + return ret; +} + +#define cmpxchg(ptr,o,n) \ + ((__typeof__(*(ptr)))__cmpxchg_mb((ptr), \ + (unsigned long)(o), \ + (unsigned long)(n), \ + sizeof(*(ptr)))) + +#define cmpxchg_local(ptr,o,n) \ + ((__typeof__(*(ptr)))__cmpxchg((ptr), \ + (unsigned long)(o), \ + (unsigned long)(n), \ + sizeof(*(ptr)))) #define local_irq_disable() asm volatile ( "cpsid i @ local_irq_disable\n" : : : "cc" ) #define local_irq_enable() asm volatile ( "cpsie i @ local_irq_enable\n" : : : "cc" ) -- 2.39.5