locking/atomic: Fix atomic_set_release() for 'funny' architectures
authorPeter Zijlstra <peterz@infradead.org>
Fri, 9 Jun 2017 11:05:06 +0000 (13:05 +0200)
committerIngo Molnar <mingo@kernel.org>
Thu, 10 Aug 2017 10:28:54 +0000 (12:28 +0200)
Those architectures that have a special atomic_set implementation also
need a special atomic_set_release(), because for the very same reason
WRITE_ONCE() is broken for them, smp_store_release() is too.

The vast majority is architectures that have spinlock hash based atomic
implementation except hexagon which seems to have a hardware 'feature'.

The spinlock based atomics should be SC, that is, none of them appear to
place extra barriers in atomic_cmpxchg() or any of the other SC atomic
primitives and therefore seem to rely on their spinlock implementation
being SC (I did not fully validate all that).

Therefore, the normal atomic_set() is SC and can be used at
atomic_set_release().

Signed-off-by: Peter Zijlstra (Intel) <peterz@infradead.org>
Acked-by: Chris Metcalf <cmetcalf@mellanox.com> [for tile]
Cc: Boqun Feng <boqun.feng@gmail.com>
Cc: Linus Torvalds <torvalds@linux-foundation.org>
Cc: Paul McKenney <paulmck@linux.vnet.ibm.com>
Cc: Peter Zijlstra <peterz@infradead.org>
Cc: Thomas Gleixner <tglx@linutronix.de>
Cc: Will Deacon <will.deacon@arm.com>
Cc: davem@davemloft.net
Cc: james.hogan@imgtec.com
Cc: jejb@parisc-linux.org
Cc: rkuo@codeaurora.org
Cc: vgupta@synopsys.com
Link: http://lkml.kernel.org/r/20170609110506.yod47flaav3wgoj5@hirez.programming.kicks-ass.net
Signed-off-by: Ingo Molnar <mingo@kernel.org>
arch/arc/include/asm/atomic.h
arch/hexagon/include/asm/atomic.h
arch/metag/include/asm/atomic_lock1.h
arch/parisc/include/asm/atomic.h
arch/sparc/include/asm/atomic_32.h
arch/tile/include/asm/atomic_32.h
include/asm-generic/atomic64.h

index 54b54da6384c197a93848e05ef292c224f5c0f91..11859287c52af55df317e7a6d3ab9403706bd172 100644 (file)
@@ -123,6 +123,8 @@ static inline void atomic_set(atomic_t *v, int i)
        atomic_ops_unlock(flags);
 }
 
+#define atomic_set_release(v, i)       atomic_set((v), (i))
+
 #endif
 
 /*
index a62ba368b27d1ddf6f750efd1dcaa2b51419d1d8..fb3dfb2a667ee11626cf9c999e5b303fcc9b9c83 100644 (file)
@@ -42,6 +42,8 @@ static inline void atomic_set(atomic_t *v, int new)
        );
 }
 
+#define atomic_set_release(v, i)       atomic_set((v), (i))
+
 /**
  * atomic_read - reads a word, atomically
  * @v: pointer to atomic value
index 6c1380a8a0d4a437dfb2a4146deada934bcdb354..eee779f26cc4c633b9e5c47e2b156e6f4f2481ce 100644 (file)
@@ -37,6 +37,8 @@ static inline int atomic_set(atomic_t *v, int i)
        return i;
 }
 
+#define atomic_set_release(v, i) atomic_set((v), (i))
+
 #define ATOMIC_OP(op, c_op)                                            \
 static inline void atomic_##op(int i, atomic_t *v)                     \
 {                                                                      \
index 5394b9c5f914fdc4339224a3950e9d1c4ccd6bbb..17b98a87e5e26774298f955a3da234dd2742e2a4 100644 (file)
@@ -65,6 +65,8 @@ static __inline__ void atomic_set(atomic_t *v, int i)
        _atomic_spin_unlock_irqrestore(v, flags);
 }
 
+#define atomic_set_release(v, i)       atomic_set((v), (i))
+
 static __inline__ int atomic_read(const atomic_t *v)
 {
        return READ_ONCE((v)->counter);
index ee3f11c43cdaa2ef6ab6fe444130e8dd2a8a5541..7643e979e3338c8f23affa81269379f3d77fba52 100644 (file)
@@ -29,6 +29,8 @@ int atomic_xchg(atomic_t *, int);
 int __atomic_add_unless(atomic_t *, int, int);
 void atomic_set(atomic_t *, int);
 
+#define atomic_set_release(v, i)       atomic_set((v), (i))
+
 #define atomic_read(v)          ACCESS_ONCE((v)->counter)
 
 #define atomic_add(i, v)       ((void)atomic_add_return( (int)(i), (v)))
index a93774255136d4c250065407d2c295ac7f2088e7..53a423e7cb92e445d54b5f10f546b410683cf367 100644 (file)
@@ -101,6 +101,8 @@ static inline void atomic_set(atomic_t *v, int n)
        _atomic_xchg(&v->counter, n);
 }
 
+#define atomic_set_release(v, i)       atomic_set((v), (i))
+
 /* A 64bit atomic type */
 
 typedef struct {
index dad68bf46c77012e144857898093b99dabea1cd7..8d28eb010d0d11a2f35f769f7ef51cd753a42a94 100644 (file)
@@ -21,6 +21,8 @@ typedef struct {
 extern long long atomic64_read(const atomic64_t *v);
 extern void     atomic64_set(atomic64_t *v, long long i);
 
+#define atomic64_set_release(v, i)     atomic64_set((v), (i))
+
 #define ATOMIC64_OP(op)                                                        \
 extern void     atomic64_##op(long long a, atomic64_t *v);