Skip to content

Commit

Permalink
locking/atomic: Fix atomic_set_release() for 'funny' architectures
Browse files Browse the repository at this point in the history
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) <[email protected]>
Acked-by: Chris Metcalf <[email protected]> [for tile]
Cc: Boqun Feng <[email protected]>
Cc: Linus Torvalds <[email protected]>
Cc: Paul McKenney <[email protected]>
Cc: Peter Zijlstra <[email protected]>
Cc: Thomas Gleixner <[email protected]>
Cc: Will Deacon <[email protected]>
Cc: [email protected]
Cc: [email protected]
Cc: [email protected]
Cc: [email protected]
Cc: [email protected]
Link: http://lkml.kernel.org/r/[email protected]
Signed-off-by: Ingo Molnar <[email protected]>
  • Loading branch information
Peter Zijlstra authored and Ingo Molnar committed Aug 10, 2017
1 parent 35a2897 commit 9d664c0
Show file tree
Hide file tree
Showing 7 changed files with 14 additions and 0 deletions.
2 changes: 2 additions & 0 deletions arch/arc/include/asm/atomic.h
Original file line number Diff line number Diff line change
Expand Up @@ -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

/*
Expand Down
2 changes: 2 additions & 0 deletions arch/hexagon/include/asm/atomic.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 2 additions & 0 deletions arch/metag/include/asm/atomic_lock1.h
Original file line number Diff line number Diff line change
Expand Up @@ -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) \
{ \
Expand Down
2 changes: 2 additions & 0 deletions arch/parisc/include/asm/atomic.h
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
2 changes: 2 additions & 0 deletions arch/sparc/include/asm/atomic_32.h
Original file line number Diff line number Diff line change
Expand Up @@ -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)))
Expand Down
2 changes: 2 additions & 0 deletions arch/tile/include/asm/atomic_32.h
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
2 changes: 2 additions & 0 deletions include/asm-generic/atomic64.h
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand Down

0 comments on commit 9d664c0

Please sign in to comment.