atomic, arch: Audit atomic_{read,set}()

This patch makes sure that atomic_{read,set}() are at least
{READ,WRITE}_ONCE().

We already had the 'requirement' that atomic_read() should use
ACCESS_ONCE(), and most archs had this, but a few were lacking.
All are now converted to use READ_ONCE().

And, by a symmetry and general paranoia argument, upgrade atomic_set()
to use WRITE_ONCE().

Signed-off-by: Peter Zijlstra (Intel) <peterz@infradead.org>
Cc: Andrew Morton <akpm@linux-foundation.org>
Cc: Dmitry Vyukov <dvyukov@google.com>
Cc: Linus Torvalds <torvalds@linux-foundation.org>
Cc: Paul E. McKenney <paulmck@linux.vnet.ibm.com>
Cc: Peter Zijlstra <peterz@infradead.org>
Cc: Thomas Gleixner <tglx@linutronix.de>
Cc: james.hogan@imgtec.com
Cc: linux-kernel@vger.kernel.org
Cc: oleg@redhat.com
Cc: will.deacon@arm.com
Signed-off-by: Ingo Molnar <mingo@kernel.org>
This commit is contained in:
Peter Zijlstra 2015-09-18 11:13:10 +02:00 committed by Ingo Molnar
parent 90fe65148e
commit 62e8a3258b
24 changed files with 53 additions and 53 deletions

View File

@ -17,11 +17,11 @@
#define ATOMIC_INIT(i) { (i) } #define ATOMIC_INIT(i) { (i) }
#define ATOMIC64_INIT(i) { (i) } #define ATOMIC64_INIT(i) { (i) }
#define atomic_read(v) ACCESS_ONCE((v)->counter) #define atomic_read(v) READ_ONCE((v)->counter)
#define atomic64_read(v) ACCESS_ONCE((v)->counter) #define atomic64_read(v) READ_ONCE((v)->counter)
#define atomic_set(v,i) ((v)->counter = (i)) #define atomic_set(v,i) WRITE_ONCE((v)->counter, (i))
#define atomic64_set(v,i) ((v)->counter = (i)) #define atomic64_set(v,i) WRITE_ONCE((v)->counter, (i))
/* /*
* To get proper branch prediction for the main line, we must branch * To get proper branch prediction for the main line, we must branch

View File

@ -17,11 +17,11 @@
#include <asm/barrier.h> #include <asm/barrier.h>
#include <asm/smp.h> #include <asm/smp.h>
#define atomic_read(v) ((v)->counter) #define atomic_read(v) READ_ONCE((v)->counter)
#ifdef CONFIG_ARC_HAS_LLSC #ifdef CONFIG_ARC_HAS_LLSC
#define atomic_set(v, i) (((v)->counter) = (i)) #define atomic_set(v, i) WRITE_ONCE(((v)->counter), (i))
#ifdef CONFIG_ARC_STAR_9000923308 #ifdef CONFIG_ARC_STAR_9000923308
@ -107,7 +107,7 @@ static inline int atomic_##op##_return(int i, atomic_t *v) \
#ifndef CONFIG_SMP #ifndef CONFIG_SMP
/* violating atomic_xxx API locking protocol in UP for optimization sake */ /* violating atomic_xxx API locking protocol in UP for optimization sake */
#define atomic_set(v, i) (((v)->counter) = (i)) #define atomic_set(v, i) WRITE_ONCE(((v)->counter), (i))
#else #else
@ -125,7 +125,7 @@ static inline void atomic_set(atomic_t *v, int i)
unsigned long flags; unsigned long flags;
atomic_ops_lock(flags); atomic_ops_lock(flags);
v->counter = i; WRITE_ONCE(v->counter, i);
atomic_ops_unlock(flags); atomic_ops_unlock(flags);
} }

View File

@ -27,8 +27,8 @@
* strex/ldrex monitor on some implementations. The reason we can use it for * strex/ldrex monitor on some implementations. The reason we can use it for
* atomic_set() is the clrex or dummy strex done on every exception return. * atomic_set() is the clrex or dummy strex done on every exception return.
*/ */
#define atomic_read(v) ACCESS_ONCE((v)->counter) #define atomic_read(v) READ_ONCE((v)->counter)
#define atomic_set(v,i) (((v)->counter) = (i)) #define atomic_set(v,i) WRITE_ONCE(((v)->counter), (i))
#if __LINUX_ARM_ARCH__ >= 6 #if __LINUX_ARM_ARCH__ >= 6

View File

@ -54,7 +54,7 @@
#define ATOMIC_INIT(i) { (i) } #define ATOMIC_INIT(i) { (i) }
#define atomic_read(v) READ_ONCE((v)->counter) #define atomic_read(v) READ_ONCE((v)->counter)
#define atomic_set(v, i) (((v)->counter) = (i)) #define atomic_set(v, i) WRITE_ONCE(((v)->counter), (i))
#define atomic_xchg(v, new) xchg(&((v)->counter), (new)) #define atomic_xchg(v, new) xchg(&((v)->counter), (new))
#define atomic_cmpxchg(v, old, new) cmpxchg(&((v)->counter), (old), (new)) #define atomic_cmpxchg(v, old, new) cmpxchg(&((v)->counter), (old), (new))

View File

@ -19,8 +19,8 @@
#define ATOMIC_INIT(i) { (i) } #define ATOMIC_INIT(i) { (i) }
#define atomic_read(v) ACCESS_ONCE((v)->counter) #define atomic_read(v) READ_ONCE((v)->counter)
#define atomic_set(v, i) (((v)->counter) = i) #define atomic_set(v, i) WRITE_ONCE(((v)->counter), (i))
#define ATOMIC_OP_RETURN(op, asm_op, asm_con) \ #define ATOMIC_OP_RETURN(op, asm_op, asm_con) \
static inline int __atomic_##op##_return(int i, atomic_t *v) \ static inline int __atomic_##op##_return(int i, atomic_t *v) \

View File

@ -32,8 +32,8 @@
*/ */
#define ATOMIC_INIT(i) { (i) } #define ATOMIC_INIT(i) { (i) }
#define atomic_read(v) ACCESS_ONCE((v)->counter) #define atomic_read(v) READ_ONCE((v)->counter)
#define atomic_set(v, i) (((v)->counter) = (i)) #define atomic_set(v, i) WRITE_ONCE(((v)->counter), (i))
static inline int atomic_inc_return(atomic_t *v) static inline int atomic_inc_return(atomic_t *v)
{ {

View File

@ -11,8 +11,8 @@
#define ATOMIC_INIT(i) { (i) } #define ATOMIC_INIT(i) { (i) }
#define atomic_read(v) ACCESS_ONCE((v)->counter) #define atomic_read(v) READ_ONCE((v)->counter)
#define atomic_set(v, i) (((v)->counter) = i) #define atomic_set(v, i) WRITE_ONCE(((v)->counter), (i))
#include <linux/kernel.h> #include <linux/kernel.h>

View File

@ -48,7 +48,7 @@ static inline void atomic_set(atomic_t *v, int new)
* *
* Assumes all word reads on our architecture are atomic. * Assumes all word reads on our architecture are atomic.
*/ */
#define atomic_read(v) ((v)->counter) #define atomic_read(v) READ_ONCE((v)->counter)
/** /**
* atomic_xchg - atomic * atomic_xchg - atomic

View File

@ -21,11 +21,11 @@
#define ATOMIC_INIT(i) { (i) } #define ATOMIC_INIT(i) { (i) }
#define ATOMIC64_INIT(i) { (i) } #define ATOMIC64_INIT(i) { (i) }
#define atomic_read(v) ACCESS_ONCE((v)->counter) #define atomic_read(v) READ_ONCE((v)->counter)
#define atomic64_read(v) ACCESS_ONCE((v)->counter) #define atomic64_read(v) READ_ONCE((v)->counter)
#define atomic_set(v,i) (((v)->counter) = (i)) #define atomic_set(v,i) WRITE_ONCE(((v)->counter), (i))
#define atomic64_set(v,i) (((v)->counter) = (i)) #define atomic64_set(v,i) WRITE_ONCE(((v)->counter), (i))
#define ATOMIC_OP(op, c_op) \ #define ATOMIC_OP(op, c_op) \
static __inline__ int \ static __inline__ int \

View File

@ -28,7 +28,7 @@
* *
* Atomically reads the value of @v. * Atomically reads the value of @v.
*/ */
#define atomic_read(v) ACCESS_ONCE((v)->counter) #define atomic_read(v) READ_ONCE((v)->counter)
/** /**
* atomic_set - set atomic variable * atomic_set - set atomic variable
@ -37,7 +37,7 @@
* *
* Atomically sets the value of @v to @i. * Atomically sets the value of @v to @i.
*/ */
#define atomic_set(v,i) (((v)->counter) = (i)) #define atomic_set(v,i) WRITE_ONCE(((v)->counter), (i))
#ifdef CONFIG_CHIP_M32700_TS1 #ifdef CONFIG_CHIP_M32700_TS1
#define __ATOMIC_CLOBBER , "r4" #define __ATOMIC_CLOBBER , "r4"

View File

@ -17,8 +17,8 @@
#define ATOMIC_INIT(i) { (i) } #define ATOMIC_INIT(i) { (i) }
#define atomic_read(v) ACCESS_ONCE((v)->counter) #define atomic_read(v) READ_ONCE((v)->counter)
#define atomic_set(v, i) (((v)->counter) = i) #define atomic_set(v, i) WRITE_ONCE(((v)->counter), (i))
/* /*
* The ColdFire parts cannot do some immediate to memory operations, * The ColdFire parts cannot do some immediate to memory operations,

View File

@ -3,7 +3,7 @@
#define ATOMIC_INIT(i) { (i) } #define ATOMIC_INIT(i) { (i) }
#define atomic_set(v, i) ((v)->counter = (i)) #define atomic_set(v, i) WRITE_ONCE((v)->counter, (i))
#include <linux/compiler.h> #include <linux/compiler.h>

View File

@ -10,7 +10,7 @@
static inline int atomic_read(const atomic_t *v) static inline int atomic_read(const atomic_t *v)
{ {
return (v)->counter; return READ_ONCE((v)->counter);
} }
/* /*

View File

@ -30,7 +30,7 @@
* *
* Atomically reads the value of @v. * Atomically reads the value of @v.
*/ */
#define atomic_read(v) ACCESS_ONCE((v)->counter) #define atomic_read(v) READ_ONCE((v)->counter)
/* /*
* atomic_set - set atomic variable * atomic_set - set atomic variable
@ -39,7 +39,7 @@
* *
* Atomically sets the value of @v to @i. * Atomically sets the value of @v to @i.
*/ */
#define atomic_set(v, i) ((v)->counter = (i)) #define atomic_set(v, i) WRITE_ONCE((v)->counter, (i))
#define ATOMIC_OP(op, c_op, asm_op) \ #define ATOMIC_OP(op, c_op, asm_op) \
static __inline__ void atomic_##op(int i, atomic_t * v) \ static __inline__ void atomic_##op(int i, atomic_t * v) \
@ -315,14 +315,14 @@ static __inline__ int __atomic_add_unless(atomic_t *v, int a, int u)
* @v: pointer of type atomic64_t * @v: pointer of type atomic64_t
* *
*/ */
#define atomic64_read(v) ACCESS_ONCE((v)->counter) #define atomic64_read(v) READ_ONCE((v)->counter)
/* /*
* atomic64_set - set atomic variable * atomic64_set - set atomic variable
* @v: pointer of type atomic64_t * @v: pointer of type atomic64_t
* @i: required value * @i: required value
*/ */
#define atomic64_set(v, i) ((v)->counter = (i)) #define atomic64_set(v, i) WRITE_ONCE((v)->counter, (i))
#define ATOMIC64_OP(op, c_op, asm_op) \ #define ATOMIC64_OP(op, c_op, asm_op) \
static __inline__ void atomic64_##op(long i, atomic64_t * v) \ static __inline__ void atomic64_##op(long i, atomic64_t * v) \

View File

@ -34,7 +34,7 @@
* *
* Atomically reads the value of @v. Note that the guaranteed * Atomically reads the value of @v. Note that the guaranteed
*/ */
#define atomic_read(v) (ACCESS_ONCE((v)->counter)) #define atomic_read(v) READ_ONCE((v)->counter)
/** /**
* atomic_set - set atomic variable * atomic_set - set atomic variable
@ -43,7 +43,7 @@
* *
* Atomically sets the value of @v to @i. Note that the guaranteed * Atomically sets the value of @v to @i. Note that the guaranteed
*/ */
#define atomic_set(v, i) (((v)->counter) = (i)) #define atomic_set(v, i) WRITE_ONCE(((v)->counter), (i))
#define ATOMIC_OP(op) \ #define ATOMIC_OP(op) \
static inline void atomic_##op(int i, atomic_t *v) \ static inline void atomic_##op(int i, atomic_t *v) \

View File

@ -67,7 +67,7 @@ static __inline__ void atomic_set(atomic_t *v, int i)
static __inline__ int atomic_read(const atomic_t *v) static __inline__ int atomic_read(const atomic_t *v)
{ {
return ACCESS_ONCE((v)->counter); return READ_ONCE((v)->counter);
} }
/* exported interface */ /* exported interface */

View File

@ -14,8 +14,8 @@
#define ATOMIC_INIT(i) { (i) } #define ATOMIC_INIT(i) { (i) }
#define atomic_read(v) ACCESS_ONCE((v)->counter) #define atomic_read(v) READ_ONCE((v)->counter)
#define atomic_set(v,i) ((v)->counter = (i)) #define atomic_set(v,i) WRITE_ONCE((v)->counter, (i))
#if defined(CONFIG_GUSA_RB) #if defined(CONFIG_GUSA_RB)
#include <asm/atomic-grb.h> #include <asm/atomic-grb.h>

View File

@ -14,11 +14,11 @@
#define ATOMIC_INIT(i) { (i) } #define ATOMIC_INIT(i) { (i) }
#define ATOMIC64_INIT(i) { (i) } #define ATOMIC64_INIT(i) { (i) }
#define atomic_read(v) ACCESS_ONCE((v)->counter) #define atomic_read(v) READ_ONCE((v)->counter)
#define atomic64_read(v) ACCESS_ONCE((v)->counter) #define atomic64_read(v) READ_ONCE((v)->counter)
#define atomic_set(v, i) (((v)->counter) = i) #define atomic_set(v, i) WRITE_ONCE(((v)->counter), (i))
#define atomic64_set(v, i) (((v)->counter) = i) #define atomic64_set(v, i) WRITE_ONCE(((v)->counter), (i))
#define ATOMIC_OP(op) \ #define ATOMIC_OP(op) \
void atomic_##op(int, atomic_t *); \ void atomic_##op(int, atomic_t *); \

View File

@ -34,7 +34,7 @@
*/ */
static inline int atomic_read(const atomic_t *v) static inline int atomic_read(const atomic_t *v)
{ {
return ACCESS_ONCE(v->counter); return READ_ONCE(v->counter);
} }
/** /**

View File

@ -24,7 +24,7 @@
/* First, the 32-bit atomic ops that are "real" on our 64-bit platform. */ /* First, the 32-bit atomic ops that are "real" on our 64-bit platform. */
#define atomic_set(v, i) ((v)->counter = (i)) #define atomic_set(v, i) WRITE_ONCE((v)->counter, (i))
/* /*
* The smp_mb() operations throughout are to support the fact that * The smp_mb() operations throughout are to support the fact that
@ -82,8 +82,8 @@ static inline void atomic_xor(int i, atomic_t *v)
#define ATOMIC64_INIT(i) { (i) } #define ATOMIC64_INIT(i) { (i) }
#define atomic64_read(v) ((v)->counter) #define atomic64_read(v) READ_ONCE((v)->counter)
#define atomic64_set(v, i) ((v)->counter = (i)) #define atomic64_set(v, i) WRITE_ONCE((v)->counter, (i))
static inline void atomic64_add(long i, atomic64_t *v) static inline void atomic64_add(long i, atomic64_t *v)
{ {

View File

@ -24,7 +24,7 @@
*/ */
static __always_inline int atomic_read(const atomic_t *v) static __always_inline int atomic_read(const atomic_t *v)
{ {
return ACCESS_ONCE((v)->counter); return READ_ONCE((v)->counter);
} }
/** /**
@ -36,7 +36,7 @@ static __always_inline int atomic_read(const atomic_t *v)
*/ */
static __always_inline void atomic_set(atomic_t *v, int i) static __always_inline void atomic_set(atomic_t *v, int i)
{ {
v->counter = i; WRITE_ONCE(v->counter, i);
} }
/** /**

View File

@ -18,7 +18,7 @@
*/ */
static inline long atomic64_read(const atomic64_t *v) static inline long atomic64_read(const atomic64_t *v)
{ {
return ACCESS_ONCE((v)->counter); return READ_ONCE((v)->counter);
} }
/** /**
@ -30,7 +30,7 @@ static inline long atomic64_read(const atomic64_t *v)
*/ */
static inline void atomic64_set(atomic64_t *v, long i) static inline void atomic64_set(atomic64_t *v, long i)
{ {
v->counter = i; WRITE_ONCE(v->counter, i);
} }
/** /**

View File

@ -47,7 +47,7 @@
* *
* Atomically reads the value of @v. * Atomically reads the value of @v.
*/ */
#define atomic_read(v) ACCESS_ONCE((v)->counter) #define atomic_read(v) READ_ONCE((v)->counter)
/** /**
* atomic_set - set atomic variable * atomic_set - set atomic variable
@ -56,7 +56,7 @@
* *
* Atomically sets the value of @v to @i. * Atomically sets the value of @v to @i.
*/ */
#define atomic_set(v,i) ((v)->counter = (i)) #define atomic_set(v,i) WRITE_ONCE((v)->counter, (i))
#if XCHAL_HAVE_S32C1I #if XCHAL_HAVE_S32C1I
#define ATOMIC_OP(op) \ #define ATOMIC_OP(op) \

View File

@ -127,7 +127,7 @@ ATOMIC_OP(xor, ^)
* Atomically reads the value of @v. * Atomically reads the value of @v.
*/ */
#ifndef atomic_read #ifndef atomic_read
#define atomic_read(v) ACCESS_ONCE((v)->counter) #define atomic_read(v) READ_ONCE((v)->counter)
#endif #endif
/** /**
@ -137,7 +137,7 @@ ATOMIC_OP(xor, ^)
* *
* Atomically sets the value of @v to @i. * Atomically sets the value of @v to @i.
*/ */
#define atomic_set(v, i) (((v)->counter) = (i)) #define atomic_set(v, i) WRITE_ONCE(((v)->counter), (i))
#include <linux/irqflags.h> #include <linux/irqflags.h>