All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] tools: Upgrade atomic_set() to use WRITE_ONCE()
@ 2022-07-11 17:08 Chih-En Lin
  0 siblings, 0 replies; only message in thread
From: Chih-En Lin @ 2022-07-11 17:08 UTC (permalink / raw)
  To: Ingo Molnar
  Cc: Arnaldo Carvalho de Melo, Adrian Hunter, Borislav Petkov,
	Don Zickus, Frederic Weisbecker, Jiri Olsa, Namhyung Kim,
	Peter Zijlstra, Stephane Eranian, linux-kernel, asas1asas200,
	Huichun Feng, Jim Huang, Chih-En Lin

Since the atomic operation in the tools directory is from the kernel
source [1]. And from the commit [2], atomic_set() is at least
WRITE_ONCE() in the kernel source. atomic_{read,set}() should be
symmetry with {READ, WRITE}_ONCE() [3]. To be synchronous with the
source, atomic_set() should use WRITE_ONCE() rather than plain access.

[1] commit da6d8567512d ("tools include: Add basic atomic.h implementation from the kernel sources")
[2] commit 62e8a3258bda ("atomic, arch: Audit atomic_{read,set}()")
[3] commit 6aa7de059173 ("locking/atomics: COCCINELLE/treewide: Convert trivial ACCESS_ONCE() patterns to READ_ONCE()/WRITE_ONCE()")

Signed-off-by: asas1asas200 <asas1asas200@gmail.com>
Signed-off-by: Chih-En Lin <shiyn.lin@gmail.com>
---
 tools/arch/x86/include/asm/atomic.h    | 2 +-
 tools/include/asm-generic/atomic-gcc.h | 2 +-
 2 files changed, 2 insertions(+), 2 deletions(-)

diff --git a/tools/arch/x86/include/asm/atomic.h b/tools/arch/x86/include/asm/atomic.h
index 1f5e26aae9fc..4dcf4e9baecc 100644
--- a/tools/arch/x86/include/asm/atomic.h
+++ b/tools/arch/x86/include/asm/atomic.h
@@ -37,7 +37,7 @@ static inline int atomic_read(const atomic_t *v)
  */
 static inline void atomic_set(atomic_t *v, int i)
 {
-	v->counter = i;
+	WRITE_ONCE(v->counter, i);
 }
 
 /**
diff --git a/tools/include/asm-generic/atomic-gcc.h b/tools/include/asm-generic/atomic-gcc.h
index 4c1966f7c77a..df84af8012e6 100644
--- a/tools/include/asm-generic/atomic-gcc.h
+++ b/tools/include/asm-generic/atomic-gcc.h
@@ -34,7 +34,7 @@ static inline int atomic_read(const atomic_t *v)
  */
 static inline void atomic_set(atomic_t *v, int i)
 {
-        v->counter = i;
+	WRITE_ONCE(v->counter, i);
 }
 
 /**
-- 
2.25.1


^ permalink raw reply related	[flat|nested] only message in thread

only message in thread, other threads:[~2022-07-11 17:09 UTC | newest]

Thread overview: (only message) (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2022-07-11 17:08 [PATCH] tools: Upgrade atomic_set() to use WRITE_ONCE() Chih-En Lin

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.