selftests/bpf: Fix usdt multispec failure with arm64/clang20 selftest build
Subsystems (3)
Yonghong Song
reviewerPATCH v3 1/1 selftests/bpf: Fix usdt multispec failure with arm64/clang20 selftest build
When building the selftest with arm64/clang20, the following test failed:
...
ubtest_multispec_usdt:PASS:usdt_100_called 0 nsec subtest_multispec_usdt:PASS:usdt_100_sum 0 nsec subtest_multispec_usdt:FAIL:usdt_300_bad_attach unexpected pointer: 0xaaaad82a2a80
#471/2 usdt/multispec:FAIL
#471 usdt:FAIL
But arm64/gcc11 built kernel selftests succeeded. Further debug found arm64/clang generated code has much less argument pattern after dedup, but gcc generated code has a lot more.
Check usdt probes with usdt.test.o on arm64 platform:
with gcc11 build binary:
stapsdt 0x0000002e NT_STAPSDT (SystemTap probe descriptors)
Provider: test
Name: usdt_300
Location: 0x00000000000054f8, Base: 0x0000000000000000, Semaphore: 0x0000000000000008
Arguments: -4@[sp]
stapsdt 0x00000031 NT_STAPSDT (SystemTap probe descriptors)
Provider: test
Name: usdt_300
Location: 0x0000000000005510, Base: 0x0000000000000000, Semaphore: 0x0000000000000008
Arguments: -4@[sp, 4]
...
stapsdt 0x00000032 NT_STAPSDT (SystemTap probe descriptors)
Provider: test
Name: usdt_300
Location: 0x0000000000005660, Base: 0x0000000000000000, Semaphore: 0x0000000000000008
Arguments: -4@[sp, 60]
...
stapsdt 0x00000034 NT_STAPSDT (SystemTap probe descriptors)
Provider: test
Name: usdt_300
Location: 0x00000000000070e8, Base: 0x0000000000000000, Semaphore: 0x0000000000000008
Arguments: -4@[sp, 1192]
stapsdt 0x00000034 NT_STAPSDT (SystemTap probe descriptors)
Provider: test
Name: usdt_300
Location: 0x0000000000007100, Base: 0x0000000000000000, Semaphore: 0x0000000000000008
Arguments: -4@[sp, 1196]
...
stapsdt 0x00000032 NT_STAPSDT (SystemTap probe descriptors)
Provider: test
Name: usdt_300
Location: 0x0000000000009ec4, Base: 0x0000000000000000, Semaphore: 0x0000000000000008
Arguments: -4@[sp, 60]with clang20 build binary:
stapsdt 0x0000002e NT_STAPSDT (SystemTap probe descriptors)
Provider: test
Name: usdt_300
Location: 0x00000000000009a0, Base: 0x0000000000000000, Semaphore: 0x0000000000000008
Arguments: -4@[x9]
stapsdt 0x0000002e NT_STAPSDT (SystemTap probe descriptors)
Provider: test
Name: usdt_300
Location: 0x00000000000009b8, Base: 0x0000000000000000, Semaphore: 0x0000000000000008
Arguments: -4@[x9]
...
stapsdt 0x0000002e NT_STAPSDT (SystemTap probe descriptors)
Provider: test
Name: usdt_300
Location: 0x0000000000002590, Base: 0x0000000000000000, Semaphore: 0x0000000000000008
Arguments: -4@[x9]
stapsdt 0x0000002e NT_STAPSDT (SystemTap probe descriptors)
Provider: test
Name: usdt_300
Location: 0x00000000000025a8, Base: 0x0000000000000000, Semaphore: 0x0000000000000008
Arguments: -4@[x8]
...
stapsdt 0x0000002f NT_STAPSDT (SystemTap probe descriptors)
Provider: test
Name: usdt_300
Location: 0x0000000000007fdc, Base: 0x0000000000000000, Semaphore: 0x0000000000000008
Arguments: -4@[x10]There are total 300 locations for usdt_300. For gcc11 built binary, there are 300 spec's. But for clang20 built binary, there are 3 spec's. The default BPF_USDT_MAX_SPEC_CNT is 256, so bpf_program__attach_usdt() will fail for gcc but it will succeed with clang.
To fix the problem, do not do bpf_program__attach_usdt() for usdt_300 with arm64/clang setup.
--- tools/testing/selftests/bpf/prog_tests/usdt.c | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-)
Changelogs:
v2 -> v3:
- v2: https://lore.kernel.org/bpf/[email protected]/
- Skip some tests where not arm64/clang setup will succeed and arm64/clang setup will fail.
v1 -> v2:
- v1: https://lore.kernel.org/bpf/[email protected]/
- The commit description in v1 is not right, it checks sdt's for usdt_100 while actually it usdt_300 should be checked. Patch 1 has proper descriptions.
- Refactor the code to add a new test ust/multispec_fail where a new prog is added and in that new prog BPF_USDT_MAX_SPEC_CNT can overwrite the default value in order to pass the test.
tools/testing/selftests/bpf/prog_tests/usdt.c +10 -4
@@ -270,8 +270,16 @@ static void subtest_multispec_usdt(void)*/ trigger_300_usdts (); -/* we'll reuse usdt_100 BPF program for usdt_300 test */ bpf_link__destroy (skel->links.usdt_100); + + bss->usdt_100_called =0 ; + bss->usdt_100_sum =0 ; + +/* If built with arm64/clang, there will be much less number of specs +* for usdt_300 call sites. +*/ +#if !defined(__aarch64__) || !defined(__clang__) +/* we'll reuse usdt_100 BPF program for usdt_300 test */ skel->links.usdt_100 =bpf_program__attach_usdt (skel->progs.usdt_100,-1 ,"/proc/self/exe" ,"test" ,"usdt_300" ,NULL ); err = -errno;
@@ -282,13 +290,11 @@ static void subtest_multispec_usdt(void)/* let's check that there are no "dangling" BPF programs attached due * to partial success of the above test:usdt_300 attachment */ - bss->usdt_100_called =0 ; - bss->usdt_100_sum =0 ; -f300 (777 );/* this is 301st instance of usdt_300 */ ASSERT_EQ (bss->usdt_100_called,0 ,"usdt_301_called" );ASSERT_EQ (bss->usdt_100_sum,0 ,"usdt_301_sum" ); +#endif /* This time we have USDT with 400 inlined invocations, but arg specs * should be the same across all sites, so libbpf will only need to
Signature · 1 line
2.47.1
This patch was applied to bpf/bpf-next.git (master) by Andrii Nakryiko <[email protected]>:
Hello:
This patch was applied to bpf/bpf-next.git (master) by Andrii Nakryiko <[email protected]>:
Quoted 9 lines · On Tue, 24 Jun 2025 14:18:02 -0700 you wrote:
When building the selftest with arm64/clang20, the following test failed:
...
ubtest_multispec_usdt:PASS:usdt_100_called 0 nsec subtest_multispec_usdt:PASS:usdt_100_sum 0 nsec subtest_multispec_usdt:FAIL:usdt_300_bad_attach unexpected pointer:0xaaaad82a2a80
#471/2 usdt/multispec:FAIL
#471 usdt:FAIL[...]
Here is the summary with links:
- [bpf-next,v3] selftests/bpf: Fix usdt multispec failure with arm64/clang20 selftest build
https://git.kernel.org/bpf/bpf-next/c/d69bafe6ee2b
You are awesome, thank you!
Signature · 2 lines
Deet-doot-dot, I am a bot. https://korg.docs.kernel.org/patchwork/pwbot.html