Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

Merge branch 'selftests-bpf-fix-bpf_cookie-failures'

Sun Jian says:

====================
selftests/bpf: fix bpf_cookie failures

Fix bpf_cookie failures due to missing bpf_testmod and flaky perf_event
triggering.

Tested:
./test_progs -t bpf_cookie/perf_event -vv (30 runs): 0 failures
./test_progs -t bpf_cookie -vv
====================

Link: https://patch.msgid.link/20260228074555.122950-1-sun.jian.kdev@gmail.com
Signed-off-by: Andrii Nakryiko <andrii@kernel.org>

+21 -8
+21 -8
tools/testing/selftests/bpf/prog_tests/bpf_cookie.c
··· 6 6 #include <sys/syscall.h> 7 7 #include <sys/mman.h> 8 8 #include <unistd.h> 9 + #include <linux/compiler.h> 9 10 #include <test_progs.h> 10 11 #include <network_helpers.h> 11 12 #include <bpf/btf.h> ··· 106 105 unsigned long long addrs[8]; 107 106 __u64 cookies[8]; 108 107 108 + if (!env.has_testmod) { 109 + test__skip(); 110 + return; 111 + } 112 + 109 113 if (!ASSERT_OK(load_kallsyms(), "load_kallsyms")) 110 114 goto cleanup; 111 115 ··· 197 191 "bpf_fentry_test8", 198 192 }; 199 193 __u64 cookies[8]; 194 + 195 + if (!env.has_testmod) { 196 + test__skip(); 197 + return; 198 + } 200 199 201 200 skel = kprobe_multi__open_and_load(); 202 201 if (!ASSERT_OK_PTR(skel, "fentry_raw_skel_load")) ··· 432 421 bpf_link__destroy(link3); 433 422 } 434 423 435 - static void burn_cpu(void) 424 + static void burn_cpu(long loops) 436 425 { 437 - volatile int j = 0; 426 + long j = 0; 438 427 cpu_set_t cpu_set; 439 - int i, err; 428 + long i; 429 + int err; 440 430 441 431 /* generate some branches on cpu 0 */ 442 432 CPU_ZERO(&cpu_set); ··· 445 433 err = pthread_setaffinity_np(pthread_self(), sizeof(cpu_set), &cpu_set); 446 434 ASSERT_OK(err, "set_thread_affinity"); 447 435 448 - /* spin the loop for a while (random high number) */ 449 - for (i = 0; i < 1000000; ++i) 436 + for (i = 0; i < loops; ++i) { 450 437 ++j; 438 + barrier(); 439 + } 451 440 } 452 441 453 442 static void pe_subtest(struct test_bpf_cookie *skel) ··· 464 451 attr.type = PERF_TYPE_SOFTWARE; 465 452 attr.config = PERF_COUNT_SW_CPU_CLOCK; 466 453 attr.sample_period = 100000; 467 - pfd = syscall(__NR_perf_event_open, &attr, -1, 0, -1, PERF_FLAG_FD_CLOEXEC); 454 + pfd = syscall(__NR_perf_event_open, &attr, 0, -1, -1, PERF_FLAG_FD_CLOEXEC); 468 455 if (!ASSERT_GE(pfd, 0, "perf_fd")) 469 456 goto cleanup; 470 457 ··· 473 460 if (!ASSERT_OK_PTR(link, "link1")) 474 461 goto cleanup; 475 462 476 - burn_cpu(); /* trigger BPF prog */ 463 + burn_cpu(100000000L); /* trigger BPF prog */ 477 464 478 465 ASSERT_EQ(skel->bss->pe_res, 0x100000, "pe_res1"); 479 466 ··· 492 479 if (!ASSERT_OK_PTR(link, "link2")) 493 480 goto cleanup; 494 481 495 - burn_cpu(); /* trigger BPF prog */ 482 + burn_cpu(100000000L); /* trigger BPF prog */ 496 483 497 484 ASSERT_EQ(skel->bss->pe_res, 0x200000, "pe_res2"); 498 485