[<prev] [next>] [day] [month] [year] [list]
Message-Id: <20220711170851.72208-1-shiyn.lin@gmail.com>
Date: Tue, 12 Jul 2022 01:08:51 +0800
From: Chih-En Lin <shiyn.lin@...il.com>
To: Ingo Molnar <mingo@...nel.org>
Cc: Arnaldo Carvalho de Melo <acme@...hat.com>,
Adrian Hunter <adrian.hunter@...el.com>,
Borislav Petkov <bp@...e.de>, Don Zickus <dzickus@...hat.com>,
Frederic Weisbecker <fweisbec@...il.com>,
Jiri Olsa <jolsa@...hat.com>,
Namhyung Kim <namhyung@...nel.org>,
Peter Zijlstra <peterz@...radead.org>,
Stephane Eranian <eranian@...gle.com>,
linux-kernel@...r.kernel.org,
asas1asas200 <asas1asas200@...il.com>,
Huichun Feng <foxhoundsk.tw@...il.com>,
Jim Huang <jserv@...s.ncku.edu.tw>,
Chih-En Lin <shiyn.lin@...il.com>
Subject: [PATCH] tools: Upgrade atomic_set() to use WRITE_ONCE()
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@...il.com>
Signed-off-by: Chih-En Lin <shiyn.lin@...il.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
Powered by blists - more mailing lists