diff mbox

[Xen-devel,03/17] xen: arm32: ensure cmpxchg has full barrier semantics

Message ID 1395330365-9901-3-git-send-email-ian.campbell@citrix.com
State Superseded
Headers show

Commit Message

Ian Campbell March 20, 2014, 3:45 p.m. UTC
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 <ian.campbell@citrix.com>
---
We got our cmpxchg implementation from Linux which AFAICS has always had these
additional barriers. I don't recall us having decided that Xen barriers should
not have this property as well, and if we did we were remiss in not adding a
comment etc... If my memory is faulty then I am happy to replace thispatch
with one which adds a comment instead.
---
 xen/include/asm-arm/arm32/system.h |   26 +++++++++++++++++++++++---
 1 file changed, 23 insertions(+), 3 deletions(-)

Comments

Julien Grall March 20, 2014, 5:22 p.m. UTC | #1
Hi Ian,

On 03/20/2014 03:45 PM, Ian Campbell wrote:
> 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 <ian.campbell@citrix.com>
> ---
> We got our cmpxchg implementation from Linux which AFAICS has always had these
> additional barriers. I don't recall us having decided that Xen barriers should
> not have this property as well, and if we did we were remiss in not adding a
> comment etc... If my memory is faulty then I am happy to replace thispatch
> with one which adds a comment instead.

I think the barrier is good for Xen. We may have some place where both
of this macro are used as a "barrier".

Acked-by: Julien Grall <julien.grall@linaro.org>

Regards,
diff mbox

Patch

diff --git a/xen/include/asm-arm/arm32/system.h b/xen/include/asm-arm/arm32/system.h
index 9f233fe..dfaa3b6 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" )