From: Jiawei Zhao <phoenix500526@163.com>
To: ast@kernel.org
Cc: daniel@iogearbox.net, andrii@kernel.org, yonghong.song@linux.dev,
bpf@vger.kernel.org, linux-kselftest@vger.kernel.org,
linux-kernel@vger.kernel.org
Subject: [PATCH bpf-next v10 3/3] selftests/bpf: make usdt_o2 reliably generate SIB USDT arg spec
Date: Thu, 14 Aug 2025 16:07:39 +0000 [thread overview]
Message-ID: <20250814160740.96150-4-phoenix500526@163.com> (raw)
In-Reply-To: <20250814160740.96150-1-phoenix500526@163.com>
usdt_o2 is intended to exercise the SIB (Scale-Index-Base) argument
handling in libbpf's USDT path. With GCC 13 this reliably produced a
SIB-form argument (e.g. 8@(%rdx,%rax,8)), but with newer GCC (e.g. 15)
the compiler frequently optimizes the probe argument into a plain
register (e.g. 8@%rax) or a stack slot, so the test stops covering the
SIB code path and becomes flaky across toolchains.
Force a SIB memory operand in the probe by:
* placing the base pointer into %rdx and the index into %rax using an
empty inline asm with output constraints ("=d", "=a") and matching
inputs
* immediately passing base[idx] to STAP_PROBE1.
* only enable on x86 platform.
This makes the compiler encode the operand as SIB (base + index8),
which in .note.stapsdt shows up as 8@(%rdx,%rax,8) regardless of GCC
version. A memory clobber and noinline prevent reordering/re-allocation
around the probe site.
This change is x86_64-specific and does not alter program semantics; it
only stabilizes the USDT argument shape so the test consistently
validates SIB handling. Clang historically prefers stack temporaries for
such operands, but the selftests build with GCC, and this keeps behavior
stable across GCC versions without introducing a separate .S file.
Signed-off-by: Jiawei Zhao <phoenix500526@163.com>
---
.../selftests/bpf/prog_tests/usdt_o2.c | 20 ++++++++++++++-----
1 file changed, 15 insertions(+), 5 deletions(-)
diff --git a/tools/testing/selftests/bpf/prog_tests/usdt_o2.c b/tools/testing/selftests/bpf/prog_tests/usdt_o2.c
index f02dcf5188ab..e46d5743ad24 100644
--- a/tools/testing/selftests/bpf/prog_tests/usdt_o2.c
+++ b/tools/testing/selftests/bpf/prog_tests/usdt_o2.c
@@ -15,11 +15,19 @@ __attribute__((optimize("O2")))
int lets_test_this(int);
static volatile __u64 array[1] = {test_value};
-static __always_inline void trigger_func(void)
+static noinline void trigger_func(void)
{
+#if defined(__x86_64__) || defined(__i386__)
/* Base address + offset + (index * scale) */
- for (volatile int i = 0; i <= 0; i++)
- STAP_PROBE1(test, usdt1, array[i]);
+ /* Force SIB addressing with inline assembly */
+ const __u64 *base;
+ __u32 idx;
+ /* binding base to %rdx and idx to %rax */
+ asm volatile("" : "=d"(base), "=a"(idx) : "0"(array), "1"((__u32)0) : "memory");
+ STAP_PROBE1(test, usdt1, base[idx]);
+#else
+ STAP_PROBE1(test, usdt1, array[0]);
+#endif
}
static void basic_sib_usdt(void)
@@ -61,9 +69,11 @@ static void basic_sib_usdt(void)
test_usdt_o2__destroy(skel);
}
-
-
void test_usdt_o2(void)
{
+#if !defined(__x86_64__) && !defined(__i386__)
+ test__skip();
+ return;
+#endif
basic_sib_usdt();
}
--
2.43.0
next prev parent reply other threads:[~2025-08-14 16:08 UTC|newest]
Thread overview: 7+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-08-14 16:07 [PATCH bpf-next v10 0/3] libbpf: fix USDT SIB argument handling causing unrecognized register error Jiawei Zhao
2025-08-14 16:07 ` [PATCH bpf-next v10 1/3] " Jiawei Zhao
2025-08-14 16:07 ` [PATCH bpf-next v10 2/3] selftests/bpf: Add an usdt_o2 test case in selftests to cover SIB handling logic Jiawei Zhao
2025-08-14 16:07 ` Jiawei Zhao [this message]
2025-08-15 12:44 ` [PATCH bpf-next v10 3/3] selftests/bpf: make usdt_o2 reliably generate SIB USDT arg spec Jiri Olsa
2025-08-16 7:04 ` 赵佳炜
2025-08-18 6:56 ` Jiri Olsa
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=20250814160740.96150-4-phoenix500526@163.com \
--to=phoenix500526@163.com \
--cc=andrii@kernel.org \
--cc=ast@kernel.org \
--cc=bpf@vger.kernel.org \
--cc=daniel@iogearbox.net \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-kselftest@vger.kernel.org \
--cc=yonghong.song@linux.dev \
/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
all inboxes | Powered by JetHome®