All of lore.kernel.org
 help / color / mirror / Atom feed
From: Julien Grall <julien@xen.org>
To: xen-devel@lists.xenproject.org
Cc: oleksandr_tyshchenko@epam.com, Julien Grall <jgrall@amazon.com>,
	Stefano Stabellini <sstabellini@kernel.org>,
	Julien Grall <julien@xen.org>,
	Volodymyr Babchuk <Volodymyr_Babchuk@epam.com>
Subject: [PATCH v2 1/2] xen/arm: Remove cmpxchg_local() and drop _mb from the other helpers
Date: Fri, 11 Sep 2020 17:06:21 +0100	[thread overview]
Message-ID: <20200911160622.19721-2-julien@xen.org> (raw)
In-Reply-To: <20200911160622.19721-1-julien@xen.org>

From: Julien Grall <jgrall@amazon.com>

The current set of helpers are quite confusing to follow as the naming
is not very consistent.

Given that cmpxchg_local() is not used in Xen, drop it completely.
Furthermore, adopt a naming with _mb so all names are now consistent.

Signed-off-by: Julien Grall <jgrall@amazon.com>

---
    Changes in v2:
        - Patch added
---
 xen/include/asm-arm/arm32/cmpxchg.h | 31 ++++++-----------------
 xen/include/asm-arm/arm64/cmpxchg.h | 38 +++++++----------------------
 xen/include/asm-arm/guest_atomics.h |  6 ++---
 3 files changed, 19 insertions(+), 56 deletions(-)

diff --git a/xen/include/asm-arm/arm32/cmpxchg.h b/xen/include/asm-arm/arm32/cmpxchg.h
index 0770f272ee99..3ef1e5c63276 100644
--- a/xen/include/asm-arm/arm32/cmpxchg.h
+++ b/xen/include/asm-arm/arm32/cmpxchg.h
@@ -112,23 +112,12 @@ static always_inline unsigned long __cmpxchg(volatile void *ptr,
 					     unsigned long new,
 					     int size)
 {
+	smp_mb();
 	if (!__int_cmpxchg(ptr, &old, new, size, false, 0))
 		ASSERT_UNREACHABLE();
-
-	return old;
-}
-
-static always_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;
+	return old;
 }
 
 /*
@@ -141,11 +130,11 @@ static always_inline unsigned long __cmpxchg_mb(volatile void *ptr,
  * The helper will return true when the update has succeeded (i.e no
  * timeout) and false if the update has failed.
  */
-static always_inline bool __cmpxchg_mb_timeout(volatile void *ptr,
-					       unsigned long *old,
-					       unsigned long new,
-					       int size,
-					       unsigned int max_try)
+static always_inline bool __cmpxchg_timeout(volatile void *ptr,
+					    unsigned long *old,
+					    unsigned long new,
+					    int size,
+					    unsigned int max_try)
 {
 	bool ret;
 
@@ -157,12 +146,6 @@ static always_inline bool __cmpxchg_mb_timeout(volatile void *ptr,
 }
 
 #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),		\
diff --git a/xen/include/asm-arm/arm64/cmpxchg.h b/xen/include/asm-arm/arm64/cmpxchg.h
index fc5c60f0bd74..f4a8c1ccba80 100644
--- a/xen/include/asm-arm/arm64/cmpxchg.h
+++ b/xen/include/asm-arm/arm64/cmpxchg.h
@@ -125,23 +125,12 @@ static always_inline unsigned long __cmpxchg(volatile void *ptr,
 					     unsigned long new,
 					     int size)
 {
+	smp_mb();
 	if (!__int_cmpxchg(ptr, &old, new, size, false, 0))
 		ASSERT_UNREACHABLE();
-
-	return old;
-}
-
-static always_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;
+	return old;
 }
 
 /*
@@ -154,11 +143,11 @@ static always_inline unsigned long __cmpxchg_mb(volatile void *ptr,
  * The helper will return true when the update has succeeded (i.e no
  * timeout) and false if the update has failed.
  */
-static always_inline bool __cmpxchg_mb_timeout(volatile void *ptr,
-					       unsigned long *old,
-					       unsigned long new,
-					       int size,
-					       unsigned int max_try)
+static always_inline bool __cmpxchg_timeout(volatile void *ptr,
+					    unsigned long *old,
+					    unsigned long new,
+					    int size,
+					    unsigned int max_try)
 {
 	bool ret;
 
@@ -173,17 +162,8 @@ static always_inline bool __cmpxchg_mb_timeout(volatile void *ptr,
 ({ \
 	__typeof__(*(ptr)) __ret; \
 	__ret = (__typeof__(*(ptr))) \
-		__cmpxchg_mb((ptr), (unsigned long)(o), (unsigned long)(n), \
-			     sizeof(*(ptr))); \
-	__ret; \
-})
-
-#define cmpxchg_local(ptr, o, n) \
-({ \
-	__typeof__(*(ptr)) __ret; \
-	__ret = (__typeof__(*(ptr))) \
-		__cmpxchg((ptr), (unsigned long)(o), \
-			  (unsigned long)(n), sizeof(*(ptr))); \
+		__cmpxchg((ptr), (unsigned long)(o), (unsigned long)(n), \
+			  sizeof(*(ptr))); \
 	__ret; \
 })
 
diff --git a/xen/include/asm-arm/guest_atomics.h b/xen/include/asm-arm/guest_atomics.h
index af27cc627bf3..20347849e56c 100644
--- a/xen/include/asm-arm/guest_atomics.h
+++ b/xen/include/asm-arm/guest_atomics.h
@@ -96,14 +96,14 @@ static inline unsigned long __guest_cmpxchg(struct domain *d,
 
     perfc_incr(atomics_guest);
 
-    if ( __cmpxchg_mb_timeout(ptr, &oldval, new, size,
-                              this_cpu(guest_safe_atomic_max)) )
+    if ( __cmpxchg_timeout(ptr, &oldval, new, size,
+                           this_cpu(guest_safe_atomic_max)) )
         return oldval;
 
     perfc_incr(atomics_guest_paused);
 
     domain_pause_nosync(d);
-    oldval = __cmpxchg_mb(ptr, old, new, size);
+    oldval = __cmpxchg(ptr, old, new, size);
     domain_unpause(d);
 
     return oldval;
-- 
2.17.1



  reply	other threads:[~2020-09-11 16:07 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-09-11 16:06 [PATCH v2 0/2] Introduce cmpxchg64() and guest_cmpxchg64() Julien Grall
2020-09-11 16:06 ` Julien Grall [this message]
2020-09-14 23:59   ` [PATCH v2 1/2] xen/arm: Remove cmpxchg_local() and drop _mb from the other helpers Stefano Stabellini
2020-09-11 16:06 ` [PATCH v2 2/2] xen: Introduce cmpxchg64() and guest_cmpxchg64() Julien Grall
2020-09-14  8:48   ` Jan Beulich
2020-09-14  9:04     ` Julien Grall
2020-09-15  0:00   ` Stefano Stabellini

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20200911160622.19721-2-julien@xen.org \
    --to=julien@xen.org \
    --cc=Volodymyr_Babchuk@epam.com \
    --cc=jgrall@amazon.com \
    --cc=oleksandr_tyshchenko@epam.com \
    --cc=sstabellini@kernel.org \
    --cc=xen-devel@lists.xenproject.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.