Skip to contentSkip to conversation

xen/arm: cmpxchg: Add missing memory barriers in __cmpxchg_mb_timeout()

PATCH In review Julien Grall 3 participants 3 messages Jul 30, 2020 – Jul 31, 2020

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 xen/arm: cmpxchg: Add missing memory barriers in __cmpxchg_mb_timeout()

From: Julien Grall <[email protected]>

The function __cmpxchg_mb_timeout() was intended to have the same semantics as __cmpxchg_mb(). Unfortunately, the memory barriers were not added when first implemented.

There is no known issue with the existing callers, but the barriers are added given this is the expected semantics in Xen.

The issue was introduced by XSA-295.

Backport: 4.8+

Fixes 86b0bc958373 ("xen/arm: cmpxchg: Provide a new helper that can timeout")
---
 xen/include/asm-arm/arm32/cmpxchg.h | 8 +++++++-
 xen/include/asm-arm/arm64/cmpxchg.h | 8 +++++++-
 2 files changed, 14 insertions(+), 2 deletions(-)
xen/include/asm-arm/arm32/cmpxchg.h +7 -1
index 49ca2a0d7ab1..0770f272ee99 100644
@@ -147,7 +147,13 @@ static always_inline bool __cmpxchg_mb_timeout(volatile void *ptr,
 					       int size,
 					       unsigned int max_try)
 {
-	return __int_cmpxchg(ptr, old, new, size, true, max_try);
+	bool ret;
+
+	smp_mb();
+	ret = __int_cmpxchg(ptr, old, new, size, true, max_try);
+	smp_mb();
+
+	return ret;
 }
 
 #define cmpxchg(ptr,o,n)						\
xen/include/asm-arm/arm64/cmpxchg.h +7 -1
index 5bc2e1f78674..fc5c60f0bd74 100644
@@ -160,7 +160,13 @@ static always_inline bool __cmpxchg_mb_timeout(volatile void *ptr,
 					       int size,
 					       unsigned int max_try)
 {
-	return __int_cmpxchg(ptr, old, new, size, true, max_try);
+	bool ret;
+
+	smp_mb();
+	ret = __int_cmpxchg(ptr, old, new, size, true, max_try);
+	smp_mb();
+
+	return ret;
 }
 
 #define cmpxchg(ptr, o, n) \
Signature · 1 line
2.17.1
Reviewed-by on v1 1/1
#1 lore raw
Quoted 6 lines · Julien Grall

From: Julien Grall <[email protected]>

The function __cmpxchg_mb_timeout() was intended to have the same semantics as __cmpxchg_mb(). Unfortunately, the memory barriers were not added when first implemented.

Quoted 8 lines

There is no known issue with the existing callers, but the barriers are added given this is the expected semantics in Xen.

The issue was introduced by XSA-295.

Backport: 4.8+

Fixes 86b0bc958373 ("xen/arm: cmpxchg: Provide a new helper that can timeout")
Quoted 46 lines
---
 xen/include/asm-arm/arm32/cmpxchg.h | 8 +++++++-
 xen/include/asm-arm/arm64/cmpxchg.h | 8 +++++++-
 2 files changed, 14 insertions(+), 2 deletions(-)
xen/include/asm-arm/arm32/cmpxchg.h +7 -1
index 49ca2a0d7ab1..0770f272ee99 100644
@@ -147,7 +147,13 @@ static always_inline bool __cmpxchg_mb_timeout(volatile void *ptr,
 					       int size,
 					       unsigned int max_try)
 {
-	return __int_cmpxchg(ptr, old, new, size, true, max_try);
+	bool ret;
+
+	smp_mb();
+	ret = __int_cmpxchg(ptr, old, new, size, true, max_try);
+	smp_mb();
+
+	return ret;
 }
 
 #define cmpxchg(ptr,o,n)						\
xen/include/asm-arm/arm64/cmpxchg.h +7 -1
index 5bc2e1f78674..fc5c60f0bd74 100644
@@ -160,7 +160,13 @@ static always_inline bool __cmpxchg_mb_timeout(volatile void *ptr,
 					       int size,
 					       unsigned int max_try)
 {
-	return __int_cmpxchg(ptr, old, new, size, true, max_try);
+	bool ret;
+
+	smp_mb();
+	ret = __int_cmpxchg(ptr, old, new, size, true, max_try);
+	smp_mb();
+
+	return ret;
 }
 
 #define cmpxchg(ptr, o, n) \
Signature · 1 line
2.17.1
Reviewed-by on v1 1/1
#2 lore raw
In reply to Julien Grall
Quoted 10 lines · Julien Grall

From: Julien Grall <[email protected]>

The function __cmpxchg_mb_timeout() was intended to have the same semantics as __cmpxchg_mb(). Unfortunately, the memory barriers were not added when first implemented.

Quoted 8 lines

There is no known issue with the existing callers, but the barriers are added given this is the expected semantics in Xen.

The issue was introduced by XSA-295.

Backport: 4.8+

Fixes 86b0bc958373 ("xen/arm: cmpxchg: Provide a new helper that can timeout")
Quoted 47 lines

---
xen/include/asm-arm/arm32/cmpxchg.h | 8 +++++++-
xen/include/asm-arm/arm64/cmpxchg.h | 8 +++++++-

2 files changed, 14 insertions(+), 2 deletions(-)
xen/include/asm-arm/arm32/cmpxchg.h +7 -1
index 49ca2a0d7ab1..0770f272ee99 100644
@@ -147,7 +147,13 @@ static always_inline bool __cmpxchg_mb_timeout(volatile void *ptr,
 					       int size,
 					       unsigned int max_try)
 {
-	return __int_cmpxchg(ptr, old, new, size, true, max_try);
+	bool ret;
+
+	smp_mb();
+	ret = __int_cmpxchg(ptr, old, new, size, true, max_try);
+	smp_mb();
+
+	return ret;
 }
 
 #define cmpxchg(ptr,o,n)						\
xen/include/asm-arm/arm64/cmpxchg.h +7 -1
index 5bc2e1f78674..fc5c60f0bd74 100644
@@ -160,7 +160,13 @@ static always_inline bool __cmpxchg_mb_timeout(volatile void *ptr,
 					       int size,
 					       unsigned int max_try)
 {
-	return __int_cmpxchg(ptr, old, new, size, true, max_try);
+	bool ret;
+
+	smp_mb();
+	ret = __int_cmpxchg(ptr, old, new, size, true, max_try);
+	smp_mb();
+
+	return ret;
 }
 
 #define cmpxchg(ptr, o, n) \
Signature · 1 line
2.17.1