x86: Use volatile semantics for atomic_set()
Subsystems (2)
RFC PATCH 1/1 x86: Use volatile semantics for atomic_set()
All the atomic operations have volatile semantics to prevent compiler reordering. Enforce the same semantics for atomic_set() too.
--- arch/x86/include/asm/atomic.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
arch/x86/include/asm/atomic.h +1 -1
@@ -36,7 +36,7 @@ static inline int atomic_read(const atomic_t *v)*/ static inline void atomic_set (atomic_t *v,int i) { - v->counter = i; +ACCESS_ONCE (v->counter) = i; }/**
Signature · 1 line
2.1.0
Peter Zijlstra
maintainerQuoted 2 lines · Pranith Kumar
All the atomic operations have volatile semantics to prevent compiler reordering. Enforce the same semantics for
atomic_set()too.
To what point? atomic_set() is typically not what you expect it to anyhow.
Quoted 6 lines · Peter Zijlstra
Quoted 2 lines · Pranith Kumar
All the atomic operations have volatile semantics to prevent compiler reordering. Enforce the same semantics for
atomic_set()too.To what point?
atomic_set()is typically not what you expect it to anyhow.
This is the only atomic operation which allows compiler reordering. I am not sure why this exception was made. Any ideas as to why we do this?
As I mentioned, this patch removes this inconsistency by disallowing compiler reordering.
Signature · 1 line
Pranith
Peter Zijlstra
maintainerQuoted 11 lines · Pranith Kumar
Quoted 6 lines · Peter Zijlstra
Quoted 2 lines · Pranith Kumar
All the atomic operations have volatile semantics to prevent compiler reordering. Enforce the same semantics for
atomic_set()too.To what point?
atomic_set()is typically not what you expect it to anyhow.This is the only atomic operation which allows compiler reordering. I am not sure why this exception was made. Any ideas as to why we do this?
Because it typically doesn't matter. And you should never use atomic_set() where it does matter.