public inbox for bpf@vger.kernel.org
 help / color / mirror / Atom feed
From: Amery Hung <ameryhung@gmail.com>
To: bpf@vger.kernel.org
Cc: alexei.starovoitov@gmail.com, andrii@kernel.org,
	daniel@iogearbox.net, eddyz87@gmail.com, memxor@gmail.com,
	yatsenko@meta.com, ameryhung@gmail.com, kernel-team@meta.com
Subject: [PATCH bpf-next v2 4/5] selftests/bpf: Remove TLD_READ_ONCE() in the user space header
Date: Tue, 31 Mar 2026 14:35:54 -0700	[thread overview]
Message-ID: <20260331213555.1993883-5-ameryhung@gmail.com> (raw)
In-Reply-To: <20260331213555.1993883-1-ameryhung@gmail.com>

TLD_READ_ONCE() is redundant as the only reference passed to it is
defined as _Atomic. The load is guaranteed to be atomic in C11 standard
(6.2.6.1). Drop the macro.

Signed-off-by: Amery Hung <ameryhung@gmail.com>
---
 tools/testing/selftests/bpf/prog_tests/task_local_data.h  | 8 +++-----
 .../selftests/bpf/prog_tests/test_task_local_data.c       | 2 +-
 2 files changed, 4 insertions(+), 6 deletions(-)

diff --git a/tools/testing/selftests/bpf/prog_tests/task_local_data.h b/tools/testing/selftests/bpf/prog_tests/task_local_data.h
index e242c455ddae..91f3486439bf 100644
--- a/tools/testing/selftests/bpf/prog_tests/task_local_data.h
+++ b/tools/testing/selftests/bpf/prog_tests/task_local_data.h
@@ -67,8 +67,6 @@
 
 #define TLD_ROUND_UP_POWER_OF_TWO(x) (1UL << (sizeof(x) * 8 - __builtin_clzl(x - 1)))
 
-#define TLD_READ_ONCE(x) (*(volatile typeof(x) *)&(x))
-
 #ifndef TLD_DYN_DATA_SIZE
 #define TLD_DYN_DATA_SIZE 64
 #endif
@@ -184,7 +182,7 @@ static int __tld_init_data_p(int map_fd)
 	 */
 	map_val.data = (void *)(TLD_PAGE_MASK & (intptr_t)data);
 	data->start = (~TLD_PAGE_MASK & (intptr_t)data) + sizeof(struct tld_data_u);
-	map_val.meta = TLD_READ_ONCE(tld_meta_p);
+	map_val.meta = tld_meta_p;
 
 	err = bpf_map_update_elem(map_fd, &tid_fd, &map_val, 0);
 	if (err) {
@@ -207,7 +205,7 @@ static tld_key_t __tld_create_key(const char *name, size_t size, bool dyn_data)
 	int err, i, sz, off = 0;
 	__u16 cnt;
 
-	if (!TLD_READ_ONCE(tld_meta_p)) {
+	if (!tld_meta_p) {
 		err = __tld_init_meta_p();
 		if (err)
 			return (tld_key_t){(__s16)err};
@@ -338,7 +336,7 @@ static inline int tld_key_err_or_zero(tld_key_t key)
 __attribute__((unused))
 static void *tld_get_data(int map_fd, tld_key_t key)
 {
-	if (!TLD_READ_ONCE(tld_meta_p))
+	if (!tld_meta_p)
 		return NULL;
 
 	/* tld_data_p is allocated on the first invocation of tld_get_data() */
diff --git a/tools/testing/selftests/bpf/prog_tests/test_task_local_data.c b/tools/testing/selftests/bpf/prog_tests/test_task_local_data.c
index 9556ad3d986f..e219ff506b56 100644
--- a/tools/testing/selftests/bpf/prog_tests/test_task_local_data.c
+++ b/tools/testing/selftests/bpf/prog_tests/test_task_local_data.c
@@ -26,7 +26,7 @@ TLD_DEFINE_KEY(value0_key, "value0", sizeof(int));
  */
 static void reset_tld(void)
 {
-	if (TLD_READ_ONCE(tld_meta_p)) {
+	if (tld_meta_p) {
 		/* Remove TLDs created by tld_create_key() */
 		tld_meta_p->cnt = 1;
 		tld_meta_p->size = TLD_DYN_DATA_SIZE;
-- 
2.52.0


  parent reply	other threads:[~2026-03-31 21:36 UTC|newest]

Thread overview: 12+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-03-31 21:35 [PATCH bpf-next v2 0/5] Task local data bug fixes and improvement Amery Hung
2026-03-31 21:35 ` [PATCH bpf-next v2 1/5] selftests/bpf: Fix task_local_data data allocation size Amery Hung
2026-04-01  1:48   ` sun jian
2026-03-31 21:35 ` [PATCH bpf-next v2 2/5] selftests/bpf: Simplify task_local_data memory allocation Amery Hung
2026-04-01  1:46   ` sun jian
2026-03-31 21:35 ` [PATCH bpf-next v2 3/5] selftests/bpf: Make sure TLD_DEFINE_KEY runs first Amery Hung
2026-04-01  2:16   ` sun jian
2026-03-31 21:35 ` Amery Hung [this message]
2026-04-01  4:22   ` [PATCH bpf-next v2 4/5] selftests/bpf: Remove TLD_READ_ONCE() in the user space header sun jian
2026-03-31 21:35 ` [PATCH bpf-next v2 5/5] selftests/bpf: Improve task local data documentation and fix potential memory leak Amery Hung
2026-04-01  4:11   ` sun jian
2026-04-02 22:20 ` [PATCH bpf-next v2 0/5] Task local data bug fixes and improvement patchwork-bot+netdevbpf

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=20260331213555.1993883-5-ameryhung@gmail.com \
    --to=ameryhung@gmail.com \
    --cc=alexei.starovoitov@gmail.com \
    --cc=andrii@kernel.org \
    --cc=bpf@vger.kernel.org \
    --cc=daniel@iogearbox.net \
    --cc=eddyz87@gmail.com \
    --cc=kernel-team@meta.com \
    --cc=memxor@gmail.com \
    --cc=yatsenko@meta.com \
    /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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox