All of lore.kernel.org
 help / color / mirror / Atom feed
From: Chih-En Lin <shiyn.lin@gmail.com>
To: Ingo Molnar <mingo@kernel.org>
Cc: Arnaldo Carvalho de Melo <acme@redhat.com>,
	Adrian Hunter <adrian.hunter@intel.com>,
	Borislav Petkov <bp@suse.de>, Don Zickus <dzickus@redhat.com>,
	Frederic Weisbecker <fweisbec@gmail.com>,
	Jiri Olsa <jolsa@redhat.com>, Namhyung Kim <namhyung@kernel.org>,
	Peter Zijlstra <peterz@infradead.org>,
	Stephane Eranian <eranian@google.com>,
	linux-kernel@vger.kernel.org,
	asas1asas200 <asas1asas200@gmail.com>,
	Huichun Feng <foxhoundsk.tw@gmail.com>,
	Jim Huang <jserv@ccns.ncku.edu.tw>,
	Chih-En Lin <shiyn.lin@gmail.com>
Subject: [PATCH] tools: Upgrade atomic_set() to use WRITE_ONCE()
Date: Tue, 12 Jul 2022 01:08:51 +0800	[thread overview]
Message-ID: <20220711170851.72208-1-shiyn.lin@gmail.com> (raw)

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


                 reply	other threads:[~2022-07-11 17:09 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20220711170851.72208-1-shiyn.lin@gmail.com \
    --to=shiyn.lin@gmail.com \
    --cc=acme@redhat.com \
    --cc=adrian.hunter@intel.com \
    --cc=asas1asas200@gmail.com \
    --cc=bp@suse.de \
    --cc=dzickus@redhat.com \
    --cc=eranian@google.com \
    --cc=foxhoundsk.tw@gmail.com \
    --cc=fweisbec@gmail.com \
    --cc=jolsa@redhat.com \
    --cc=jserv@ccns.ncku.edu.tw \
    --cc=linux-kernel@vger.kernel.org \
    --cc=mingo@kernel.org \
    --cc=namhyung@kernel.org \
    --cc=peterz@infradead.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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.