Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > linux.kernel > #1668202

[PATCH v4 2/7] x86: use s64* for old arg of atomic64_try_cmpxchg()

From Dmitry Vyukov <dvyukov@google.com>
Newsgroups linux.kernel
Subject [PATCH v4 2/7] x86: use s64* for old arg of atomic64_try_cmpxchg()
Date 2017-06-17 11:20 +0200
Message-ID <tTi3E-4Xc-11@gated-at.bofh.it> (permalink)
References <tTi3E-4Xc-3@gated-at.bofh.it>
Organization linux.* mail to news gateway

Show all headers | View raw


atomic64_try_cmpxchg() declares old argument as long*,
this makes it impossible to use it in portable code.
If caller passes long*, it becomes 32-bits on 32-bit arches.
If caller passes s64*, it does not compile on x86_64.

Change type of old arg to s64*.

Signed-off-by: Dmitry Vyukov <dvyukov@google.com>
Cc: Mark Rutland <mark.rutland@arm.com>
Cc: Peter Zijlstra <peterz@infradead.org>
Cc: Will Deacon <will.deacon@arm.com>
Cc: Andrew Morton <akpm@linux-foundation.org>
Cc: Andrey Ryabinin <aryabinin@virtuozzo.com>
Cc: Ingo Molnar <mingo@redhat.com>
Cc: "H. Peter Anvin" <hpa@zytor.com>
Cc: kasan-dev@googlegroups.com
Cc: linux-mm@kvack.org
Cc: linux-kernel@vger.kernel.org
Cc: x86@kernel.org
---
 arch/x86/include/asm/atomic64_64.h | 12 ++++++------
 arch/x86/include/asm/cmpxchg.h     |  2 +-
 2 files changed, 7 insertions(+), 7 deletions(-)

diff --git a/arch/x86/include/asm/atomic64_64.h b/arch/x86/include/asm/atomic64_64.h
index 8db8879a6d8c..5d9de36a2f04 100644
--- a/arch/x86/include/asm/atomic64_64.h
+++ b/arch/x86/include/asm/atomic64_64.h
@@ -177,7 +177,7 @@ static inline long atomic64_cmpxchg(atomic64_t *v, long old, long new)
 }
 
 #define atomic64_try_cmpxchg atomic64_try_cmpxchg
-static __always_inline bool atomic64_try_cmpxchg(atomic64_t *v, long *old, long new)
+static __always_inline bool atomic64_try_cmpxchg(atomic64_t *v, s64 *old, long new)
 {
 	return try_cmpxchg(&v->counter, old, new);
 }
@@ -198,7 +198,7 @@ static inline long atomic64_xchg(atomic64_t *v, long new)
  */
 static inline bool atomic64_add_unless(atomic64_t *v, long a, long u)
 {
-	long c = atomic64_read(v);
+	s64 c = atomic64_read(v);
 	do {
 		if (unlikely(c == u))
 			return false;
@@ -217,7 +217,7 @@ static inline bool atomic64_add_unless(atomic64_t *v, long a, long u)
  */
 static inline long atomic64_dec_if_positive(atomic64_t *v)
 {
-	long dec, c = atomic64_read(v);
+	s64 dec, c = atomic64_read(v);
 	do {
 		dec = c - 1;
 		if (unlikely(dec < 0))
@@ -236,7 +236,7 @@ static inline void atomic64_and(long i, atomic64_t *v)
 
 static inline long atomic64_fetch_and(long i, atomic64_t *v)
 {
-	long val = atomic64_read(v);
+	s64 val = atomic64_read(v);
 
 	do {
 	} while (!atomic64_try_cmpxchg(v, &val, val & i));
@@ -253,7 +253,7 @@ static inline void atomic64_or(long i, atomic64_t *v)
 
 static inline long atomic64_fetch_or(long i, atomic64_t *v)
 {
-	long val = atomic64_read(v);
+	s64 val = atomic64_read(v);
 
 	do {
 	} while (!atomic64_try_cmpxchg(v, &val, val | i));
@@ -270,7 +270,7 @@ static inline void atomic64_xor(long i, atomic64_t *v)
 
 static inline long atomic64_fetch_xor(long i, atomic64_t *v)
 {
-	long val = atomic64_read(v);
+	s64 val = atomic64_read(v);
 
 	do {
 	} while (!atomic64_try_cmpxchg(v, &val, val ^ i));
diff --git a/arch/x86/include/asm/cmpxchg.h b/arch/x86/include/asm/cmpxchg.h
index d90296d061e8..b5069e802d5c 100644
--- a/arch/x86/include/asm/cmpxchg.h
+++ b/arch/x86/include/asm/cmpxchg.h
@@ -157,7 +157,7 @@ extern void __add_wrong_size(void)
 #define __raw_try_cmpxchg(_ptr, _pold, _new, size, lock)		\
 ({									\
 	bool success;							\
-	__typeof__(_ptr) _old = (_pold);				\
+	__typeof__(_ptr) _old = (__typeof__(_ptr))(_pold);		\
 	__typeof__(*(_ptr)) __old = *_old;				\
 	__typeof__(*(_ptr)) __new = (_new);				\
 	switch (size) {							\
-- 
2.13.1.518.g3df882009-goog

Back to linux.kernel | Previous | NextPrevious in thread | Next in thread | Find similar | Unroll thread


Thread

[PATCH v4 0/7] x86, kasan: add KASAN checks to atomic operations Dmitry Vyukov <dvyukov@google.com> - 2017-06-17 11:20 +0200
  [PATCH v4 6/7] asm-generic: add KASAN instrumentation to atomic operations Dmitry Vyukov <dvyukov@google.com> - 2017-06-17 11:20 +0200
    Re: [PATCH v4 6/7] asm-generic: add KASAN instrumentation to atomic  operations Mark Rutland <mark.rutland@arm.com> - 2017-06-19 13:00 +0200
  [PATCH v4 2/7] x86: use s64* for old arg of atomic64_try_cmpxchg() Dmitry Vyukov <dvyukov@google.com> - 2017-06-17 11:20 +0200
  [PATCH v4 4/7] x86: switch atomic.h to use atomic-instrumented.h Dmitry Vyukov <dvyukov@google.com> - 2017-06-17 11:20 +0200
  [PATCH v4 5/7] kasan: allow kasan_check_read/write() to accept pointers to volatiles Dmitry Vyukov <dvyukov@google.com> - 2017-06-17 11:20 +0200
    Re: [PATCH v4 5/7] kasan: allow kasan_check_read/write() to accept  pointers to volatiles Mark Rutland <mark.rutland@arm.com> - 2017-06-19 13:00 +0200
      Re: [PATCH v4 5/7] kasan: allow kasan_check_read/write() to accept  pointers to volatiles Dmitry Vyukov <dvyukov@google.com> - 2017-06-19 15:20 +0200
  [PATCH v4 7/7] asm-generic, x86: add comments for atomic instrumentation Dmitry Vyukov <dvyukov@google.com> - 2017-06-17 11:20 +0200
    Re: [PATCH v4 7/7] asm-generic, x86: add comments for atomic  instrumentation Mark Rutland <mark.rutland@arm.com> - 2017-06-19 13:00 +0200
  [PATCH v4 3/7] asm-generic: add atomic-instrumented.h Dmitry Vyukov <dvyukov@google.com> - 2017-06-17 11:20 +0200
    Re: [PATCH v4 3/7] asm-generic: add atomic-instrumented.h Mark Rutland <mark.rutland@arm.com> - 2017-06-19 13:00 +0200
  [PATCH v4 1/7] x86: un-macro-ify atomic ops implementation Dmitry Vyukov <dvyukov@google.com> - 2017-06-17 11:20 +0200

csiph-web