Skip to content

Commit 625da74

Browse files
Yonghong SongKernel Patches Daemon
authored andcommitted
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. Signed-off-by: Yonghong Song <[email protected]>
1 parent 2fccc2d commit 625da74

File tree

1 file changed

+10
-4
lines changed
  • tools/testing/selftests/bpf/prog_tests

1 file changed

+10
-4
lines changed

tools/testing/selftests/bpf/prog_tests/usdt.c

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -270,8 +270,16 @@ static void subtest_multispec_usdt(void)
270270
*/
271271
trigger_300_usdts();
272272

273-
/* we'll reuse usdt_100 BPF program for usdt_300 test */
274273
bpf_link__destroy(skel->links.usdt_100);
274+
275+
bss->usdt_100_called = 0;
276+
bss->usdt_100_sum = 0;
277+
278+
/* If built with arm64/clang, there will be much less number of specs
279+
* for usdt_300 call sites.
280+
*/
281+
#if !defined(__aarch64__) || !defined(__clang__)
282+
/* we'll reuse usdt_100 BPF program for usdt_300 test */
275283
skel->links.usdt_100 = bpf_program__attach_usdt(skel->progs.usdt_100, -1, "/proc/self/exe",
276284
"test", "usdt_300", NULL);
277285
err = -errno;
@@ -282,13 +290,11 @@ static void subtest_multispec_usdt(void)
282290
/* let's check that there are no "dangling" BPF programs attached due
283291
* to partial success of the above test:usdt_300 attachment
284292
*/
285-
bss->usdt_100_called = 0;
286-
bss->usdt_100_sum = 0;
287-
288293
f300(777); /* this is 301st instance of usdt_300 */
289294

290295
ASSERT_EQ(bss->usdt_100_called, 0, "usdt_301_called");
291296
ASSERT_EQ(bss->usdt_100_sum, 0, "usdt_301_sum");
297+
#endif
292298

293299
/* This time we have USDT with 400 inlined invocations, but arg specs
294300
* should be the same across all sites, so libbpf will only need to

0 commit comments

Comments
 (0)