public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
* [PATCH 0/2] selftests/bpf: fix bpf_cookie failures
@ 2026-02-27 16:40 Sun Jian
  2026-02-27 16:40 ` [PATCH 1/2] selftests/bpf: bpf_cookie: skip kprobe_multi tests without bpf_testmod Sun Jian
  2026-02-27 16:40 ` [PATCH 2/2] selftests/bpf: bpf_cookie: make perf_event subtest trigger reliably Sun Jian
  0 siblings, 2 replies; 8+ messages in thread
From: Sun Jian @ 2026-02-27 16:40 UTC (permalink / raw)
  To: Andrii Nakryiko, Shuah Khan
  Cc: Eduard Zingerman, Alexei Starovoitov, Daniel Borkmann, bpf,
	linux-kselftest, linux-kernel, Sun Jian

Patch 1/2 skips kprobe_multi subtests when bpf_testmod isn't available.
Patch 2 makes perf_event triggering reliable on slower systems.

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

Sun Jian (2):
  selftests/bpf: bpf_cookie: skip kprobe_multi tests without bpf_testmod
  selftests/bpf: bpf_cookie: make perf_event subtest trigger reliably

 .../selftests/bpf/prog_tests/bpf_cookie.c     | 29 ++++++++++++++-----
 1 file changed, 21 insertions(+), 8 deletions(-)


base-commit: f4d0ec0aa20d49f09dc01d82894ce80d72de0560
-- 
2.43.0


^ permalink raw reply	[flat|nested] 8+ messages in thread

* [PATCH 1/2] selftests/bpf: bpf_cookie: skip kprobe_multi tests without bpf_testmod
  2026-02-27 16:40 [PATCH 0/2] selftests/bpf: fix bpf_cookie failures Sun Jian
@ 2026-02-27 16:40 ` Sun Jian
  2026-02-27 18:18   ` Alexei Starovoitov
  2026-02-27 16:40 ` [PATCH 2/2] selftests/bpf: bpf_cookie: make perf_event subtest trigger reliably Sun Jian
  1 sibling, 1 reply; 8+ messages in thread
From: Sun Jian @ 2026-02-27 16:40 UTC (permalink / raw)
  To: Andrii Nakryiko, Shuah Khan
  Cc: Eduard Zingerman, Alexei Starovoitov, Daniel Borkmann, bpf,
	linux-kselftest, linux-kernel, Sun Jian

The kprobe_multi subtests rely on bpf_testmod fentry ksyms.

When bpf_testmod isn't available, libbpf fails to resolve
bpf_testmod_fentry_test* and skeleton load fails with -ESRCH, causing
false failures.

Skip these subtests when env.has_testmod is false.

Signed-off-by: Sun Jian <sun.jian.kdev@gmail.com>
---
 tools/testing/selftests/bpf/prog_tests/bpf_cookie.c | 12 +++++++++++-
 1 file changed, 11 insertions(+), 1 deletion(-)

diff --git a/tools/testing/selftests/bpf/prog_tests/bpf_cookie.c b/tools/testing/selftests/bpf/prog_tests/bpf_cookie.c
index 75f4dff7d042..50f5e11e6e65 100644
--- a/tools/testing/selftests/bpf/prog_tests/bpf_cookie.c
+++ b/tools/testing/selftests/bpf/prog_tests/bpf_cookie.c
@@ -105,6 +105,11 @@ static void kprobe_multi_link_api_subtest(void)
 	unsigned long long addrs[8];
 	__u64 cookies[8];
 
+	if (!env.has_testmod) {
+		test__skip();
+		return;
+	}
+
 	if (!ASSERT_OK(load_kallsyms(), "load_kallsyms"))
 		goto cleanup;
 
@@ -192,6 +197,11 @@ static void kprobe_multi_attach_api_subtest(void)
 	};
 	__u64 cookies[8];
 
+	if (!env.has_testmod) {
+		test__skip();
+		return;
+	}
+
 	skel = kprobe_multi__open_and_load();
 	if (!ASSERT_OK_PTR(skel, "fentry_raw_skel_load"))
 		goto cleanup;
@@ -451,7 +461,7 @@ static void pe_subtest(struct test_bpf_cookie *skel)
 	attr.type = PERF_TYPE_SOFTWARE;
 	attr.config = PERF_COUNT_SW_CPU_CLOCK;
 	attr.sample_period = 100000;
-	pfd = syscall(__NR_perf_event_open, &attr, -1, 0, -1, PERF_FLAG_FD_CLOEXEC);
+	pfd = syscall(__NR_perf_event_open, &attr, 0, -1, -1, PERF_FLAG_FD_CLOEXEC);
 	if (!ASSERT_GE(pfd, 0, "perf_fd"))
 		goto cleanup;
 
-- 
2.43.0


^ permalink raw reply related	[flat|nested] 8+ messages in thread

* [PATCH 2/2] selftests/bpf: bpf_cookie: make perf_event subtest trigger reliably
  2026-02-27 16:40 [PATCH 0/2] selftests/bpf: fix bpf_cookie failures Sun Jian
  2026-02-27 16:40 ` [PATCH 1/2] selftests/bpf: bpf_cookie: skip kprobe_multi tests without bpf_testmod Sun Jian
@ 2026-02-27 16:40 ` Sun Jian
  2026-02-27 17:16   ` bot+bpf-ci
  2026-03-01 19:59   ` Emil Tsalapatis
  1 sibling, 2 replies; 8+ messages in thread
From: Sun Jian @ 2026-02-27 16:40 UTC (permalink / raw)
  To: Andrii Nakryiko, Shuah Khan
  Cc: Eduard Zingerman, Alexei Starovoitov, Daniel Borkmann, bpf,
	linux-kselftest, linux-kernel, Sun Jian

The perf_event subtest relies on SW_CPU_CLOCK sampling to trigger the BPF
program, but the current CPU burn loop can be too short on slower systems
and may fail to generate any overflow sample. This leaves pe_res unchanged
and makes the test flaky.

Make burn_cpu() take a loop count and use a longer burn only for the
perf_event subtest. Also scope perf_event_open() to the current task to
avoid wasting samples on unrelated activity.

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

Signed-off-by: Sun Jian <sun.jian.kdev@gmail.com>
---
 .../selftests/bpf/prog_tests/bpf_cookie.c       | 17 ++++++++++-------
 1 file changed, 10 insertions(+), 7 deletions(-)

diff --git a/tools/testing/selftests/bpf/prog_tests/bpf_cookie.c b/tools/testing/selftests/bpf/prog_tests/bpf_cookie.c
index 50f5e11e6e65..35adc3f6d443 100644
--- a/tools/testing/selftests/bpf/prog_tests/bpf_cookie.c
+++ b/tools/testing/selftests/bpf/prog_tests/bpf_cookie.c
@@ -6,6 +6,7 @@
 #include <sys/syscall.h>
 #include <sys/mman.h>
 #include <unistd.h>
+#include <linux/compiler.h>
 #include <test_progs.h>
 #include <network_helpers.h>
 #include <bpf/btf.h>
@@ -431,11 +432,12 @@ static void tp_subtest(struct test_bpf_cookie *skel)
 	bpf_link__destroy(link3);
 }
 
-static void burn_cpu(void)
+static void burn_cpu(long loops)
 {
-	volatile int j = 0;
+	long j = 0;
 	cpu_set_t cpu_set;
-	int i, err;
+	long i;
+	int err;
 
 	/* generate some branches on cpu 0 */
 	CPU_ZERO(&cpu_set);
@@ -443,9 +445,10 @@ static void burn_cpu(void)
 	err = pthread_setaffinity_np(pthread_self(), sizeof(cpu_set), &cpu_set);
 	ASSERT_OK(err, "set_thread_affinity");
 
-	/* spin the loop for a while (random high number) */
-	for (i = 0; i < 1000000; ++i)
+	for (i = 0; i < loops; ++i) {
 		++j;
+		barrier();
+	}
 }
 
 static void pe_subtest(struct test_bpf_cookie *skel)
@@ -470,7 +473,7 @@ static void pe_subtest(struct test_bpf_cookie *skel)
 	if (!ASSERT_OK_PTR(link, "link1"))
 		goto cleanup;
 
-	burn_cpu(); /* trigger BPF prog */
+	burn_cpu(100000000L); /* trigger BPF prog */
 
 	ASSERT_EQ(skel->bss->pe_res, 0x100000, "pe_res1");
 
@@ -489,7 +492,7 @@ static void pe_subtest(struct test_bpf_cookie *skel)
 	if (!ASSERT_OK_PTR(link, "link2"))
 		goto cleanup;
 
-	burn_cpu(); /* trigger BPF prog */
+	burn_cpu(100000000L); /* trigger BPF prog */
 
 	ASSERT_EQ(skel->bss->pe_res, 0x200000, "pe_res2");
 
-- 
2.43.0


^ permalink raw reply related	[flat|nested] 8+ messages in thread

* Re: [PATCH 2/2] selftests/bpf: bpf_cookie: make perf_event subtest trigger reliably
  2026-02-27 16:40 ` [PATCH 2/2] selftests/bpf: bpf_cookie: make perf_event subtest trigger reliably Sun Jian
@ 2026-02-27 17:16   ` bot+bpf-ci
  2026-03-01 19:59   ` Emil Tsalapatis
  1 sibling, 0 replies; 8+ messages in thread
From: bot+bpf-ci @ 2026-02-27 17:16 UTC (permalink / raw)
  To: sun.jian.kdev, andrii, shuah
  Cc: eddyz87, ast, daniel, bpf, linux-kselftest, linux-kernel,
	sun.jian.kdev, ast, andrii, daniel, martin.lau, eddyz87,
	yonghong.song, clm, ihor.solodrai

[-- Attachment #1: Type: text/plain, Size: 1211 bytes --]

> Make burn_cpu() take a loop count and use a longer burn only for the
> perf_event subtest. Also scope perf_event_open() to the current task to
> avoid wasting samples on unrelated activity.

The second sentence here doesn't appear to match this commit's diff.
The perf_event_open() argument change from (attr, -1, 0, -1, flags)
to (attr, 0, -1, -1, flags) was made in the previous commit
e93098f90837 ("selftests/bpf: bpf_cookie: skip kprobe_multi tests
without bpf_testmod"), not in this one.

Should this sentence be dropped from the commit message, or moved
to the commit that actually makes the change?


---
AI reviewed your patch. Please fix the bug or email reply why it's not a bug.
See: https://github.com/kernel-patches/vmtest/blob/master/ci/claude/README.md

CI run summary: https://github.com/kernel-patches/bpf/actions/runs/22495307331

AI-authorship-score: low
AI-authorship-explanation: Focused, minimal fix with idiomatic kernel patterns and natural commit message style consistent with human authorship.
issues-found: 1
issue-severity-score: low
issue-severity-explanation: Commit message claims a perf_event_open() scoping change that was actually made in the previous commit, not this one.

^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: [PATCH 1/2] selftests/bpf: bpf_cookie: skip kprobe_multi tests without bpf_testmod
  2026-02-27 16:40 ` [PATCH 1/2] selftests/bpf: bpf_cookie: skip kprobe_multi tests without bpf_testmod Sun Jian
@ 2026-02-27 18:18   ` Alexei Starovoitov
  2026-02-28  2:58     ` sun jian
  0 siblings, 1 reply; 8+ messages in thread
From: Alexei Starovoitov @ 2026-02-27 18:18 UTC (permalink / raw)
  To: Sun Jian
  Cc: Andrii Nakryiko, Shuah Khan, Eduard Zingerman, Alexei Starovoitov,
	Daniel Borkmann, bpf, open list:KERNEL SELFTEST FRAMEWORK, LKML

On Fri, Feb 27, 2026 at 8:40 AM Sun Jian <sun.jian.kdev@gmail.com> wrote:
>
> The kprobe_multi subtests rely on bpf_testmod fentry ksyms.
>
> When bpf_testmod isn't available, libbpf fails to resolve
> bpf_testmod_fentry_test* and skeleton load fails with -ESRCH, causing
> false failures.
>
> Skip these subtests when env.has_testmod is false.
>
> Signed-off-by: Sun Jian <sun.jian.kdev@gmail.com>
> ---
>  tools/testing/selftests/bpf/prog_tests/bpf_cookie.c | 12 +++++++++++-
>  1 file changed, 11 insertions(+), 1 deletion(-)
>
> diff --git a/tools/testing/selftests/bpf/prog_tests/bpf_cookie.c b/tools/testing/selftests/bpf/prog_tests/bpf_cookie.c
> index 75f4dff7d042..50f5e11e6e65 100644
> --- a/tools/testing/selftests/bpf/prog_tests/bpf_cookie.c
> +++ b/tools/testing/selftests/bpf/prog_tests/bpf_cookie.c
> @@ -105,6 +105,11 @@ static void kprobe_multi_link_api_subtest(void)
>         unsigned long long addrs[8];
>         __u64 cookies[8];
>
> +       if (!env.has_testmod) {
> +               test__skip();
> +               return;
> +       }
> +
>         if (!ASSERT_OK(load_kallsyms(), "load_kallsyms"))
>                 goto cleanup;
>
> @@ -192,6 +197,11 @@ static void kprobe_multi_attach_api_subtest(void)
>         };
>         __u64 cookies[8];
>
> +       if (!env.has_testmod) {
> +               test__skip();
> +               return;
> +       }
> +
>         skel = kprobe_multi__open_and_load();
>         if (!ASSERT_OK_PTR(skel, "fentry_raw_skel_load"))
>                 goto cleanup;
> @@ -451,7 +461,7 @@ static void pe_subtest(struct test_bpf_cookie *skel)
>         attr.type = PERF_TYPE_SOFTWARE;
>         attr.config = PERF_COUNT_SW_CPU_CLOCK;
>         attr.sample_period = 100000;
> -       pfd = syscall(__NR_perf_event_open, &attr, -1, 0, -1, PERF_FLAG_FD_CLOEXEC);
> +       pfd = syscall(__NR_perf_event_open, &attr, 0, -1, -1, PERF_FLAG_FD_CLOEXEC);

This part is not explained in the commit log.

pw-bot: cr

^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: [PATCH 1/2] selftests/bpf: bpf_cookie: skip kprobe_multi tests without bpf_testmod
  2026-02-27 18:18   ` Alexei Starovoitov
@ 2026-02-28  2:58     ` sun jian
  0 siblings, 0 replies; 8+ messages in thread
From: sun jian @ 2026-02-28  2:58 UTC (permalink / raw)
  To: Alexei Starovoitov
  Cc: Andrii Nakryiko, Shuah Khan, Eduard Zingerman, Alexei Starovoitov,
	Daniel Borkmann, bpf, open list:KERNEL SELFTEST FRAMEWORK, LKML

On Sat, Feb 28, 2026 at 2:18 AM Alexei Starovoitov
<alexei.starovoitov@gmail.com> wrote:
>
> On Fri, Feb 27, 2026 at 8:40 AM Sun Jian <sun.jian.kdev@gmail.com> wrote:
> >
> > The kprobe_multi subtests rely on bpf_testmod fentry ksyms.
> >         attr.type = PERF_TYPE_SOFTWARE;
> >         attr.config = PERF_COUNT_SW_CPU_CLOCK;
> >         attr.sample_period = 100000;
> > -       pfd = syscall(__NR_perf_event_open, &attr, -1, 0, -1, PERF_FLAG_FD_CLOEXEC);
> > +       pfd = syscall(__NR_perf_event_open, &attr, 0, -1, -1, PERF_FLAG_FD_CLOEXEC);
>
> This part is not explained in the commit log.
>
> pw-bot: cr
You are right: the perf_event_open() argument change is unrelated to
the testmod skip patch
and shouldn't have been in this patch. I'll respin as v2 and move it
to the appropriate patch.

Thanks,
Sun Jian

^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: [PATCH 2/2] selftests/bpf: bpf_cookie: make perf_event subtest trigger reliably
  2026-02-27 16:40 ` [PATCH 2/2] selftests/bpf: bpf_cookie: make perf_event subtest trigger reliably Sun Jian
  2026-02-27 17:16   ` bot+bpf-ci
@ 2026-03-01 19:59   ` Emil Tsalapatis
  2026-03-02  2:24     ` sun jian
  1 sibling, 1 reply; 8+ messages in thread
From: Emil Tsalapatis @ 2026-03-01 19:59 UTC (permalink / raw)
  To: Sun Jian, Andrii Nakryiko, Shuah Khan
  Cc: Eduard Zingerman, Alexei Starovoitov, Daniel Borkmann, bpf,
	linux-kselftest, linux-kernel

On Fri Feb 27, 2026 at 11:40 AM EST, Sun Jian wrote:
> The perf_event subtest relies on SW_CPU_CLOCK sampling to trigger the BPF
> program, but the current CPU burn loop can be too short on slower systems
> and may fail to generate any overflow sample. This leaves pe_res unchanged
> and makes the test flaky.
>
> Make burn_cpu() take a loop count and use a longer burn only for the
> perf_event subtest. Also scope perf_event_open() to the current task to
> avoid wasting samples on unrelated activity.
>
> Tested:
>   ./test_progs -t bpf_cookie/perf_event -vv (30 runs): 0 failures
>
> Signed-off-by: Sun Jian <sun.jian.kdev@gmail.com>

Reviewed-by: Emil Tsalapatis <emil@etsalapatis.com>

Nit below, but change makes sense.

> ---
>  .../selftests/bpf/prog_tests/bpf_cookie.c       | 17 ++++++++++-------
>  1 file changed, 10 insertions(+), 7 deletions(-)
>
> diff --git a/tools/testing/selftests/bpf/prog_tests/bpf_cookie.c b/tools/testing/selftests/bpf/prog_tests/bpf_cookie.c
> index 50f5e11e6e65..35adc3f6d443 100644
> --- a/tools/testing/selftests/bpf/prog_tests/bpf_cookie.c
> +++ b/tools/testing/selftests/bpf/prog_tests/bpf_cookie.c
> @@ -6,6 +6,7 @@
>  #include <sys/syscall.h>
>  #include <sys/mman.h>
>  #include <unistd.h>
> +#include <linux/compiler.h>
>  #include <test_progs.h>
>  #include <network_helpers.h>
>  #include <bpf/btf.h>
> @@ -431,11 +432,12 @@ static void tp_subtest(struct test_bpf_cookie *skel)
>  	bpf_link__destroy(link3);
>  }
>  
> -static void burn_cpu(void)
> +static void burn_cpu(long loops)
>  {
> -	volatile int j = 0;
> +	long j = 0;

Nit: AFAICT most of these changes are unnecessary, you could just bump
the cycle count to 100M and add the barrier. Moving everything to longs
and factoring out the loop count is unnecessary.

>  	cpu_set_t cpu_set;
> -	int i, err;
> +	long i;

> +	int err;
>  
>  	/* generate some branches on cpu 0 */
>  	CPU_ZERO(&cpu_set);
> @@ -443,9 +445,10 @@ static void burn_cpu(void)
>  	err = pthread_setaffinity_np(pthread_self(), sizeof(cpu_set), &cpu_set);
>  	ASSERT_OK(err, "set_thread_affinity");
>  
> -	/* spin the loop for a while (random high number) */
> -	for (i = 0; i < 1000000; ++i)
> +	for (i = 0; i < loops; ++i) {
>  		++j;
> +		barrier();
> +	}
>  }
>  
>  static void pe_subtest(struct test_bpf_cookie *skel)
> @@ -470,7 +473,7 @@ static void pe_subtest(struct test_bpf_cookie *skel)
>  	if (!ASSERT_OK_PTR(link, "link1"))
>  		goto cleanup;
>  
> -	burn_cpu(); /* trigger BPF prog */
> +	burn_cpu(100000000L); /* trigger BPF prog */
>  
>  	ASSERT_EQ(skel->bss->pe_res, 0x100000, "pe_res1");
>  
> @@ -489,7 +492,7 @@ static void pe_subtest(struct test_bpf_cookie *skel)
>  	if (!ASSERT_OK_PTR(link, "link2"))
>  		goto cleanup;
>  
> -	burn_cpu(); /* trigger BPF prog */
> +	burn_cpu(100000000L); /* trigger BPF prog */
>  
>  	ASSERT_EQ(skel->bss->pe_res, 0x200000, "pe_res2");
>  


^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: [PATCH 2/2] selftests/bpf: bpf_cookie: make perf_event subtest trigger reliably
  2026-03-01 19:59   ` Emil Tsalapatis
@ 2026-03-02  2:24     ` sun jian
  0 siblings, 0 replies; 8+ messages in thread
From: sun jian @ 2026-03-02  2:24 UTC (permalink / raw)
  To: Emil Tsalapatis
  Cc: Andrii Nakryiko, Shuah Khan, Eduard Zingerman, Alexei Starovoitov,
	Daniel Borkmann, bpf, linux-kselftest, linux-kernel

On Mon, Mar 2, 2026 at 3:59 AM Emil Tsalapatis <emil@etsalapatis.com> wrote:
>
> On Fri Feb 27, 2026 at 11:40 AM EST, Sun Jian wrote:
> > The perf_event subtest relies on SW_CPU_CLOCK sampling to trigger the BPF
> > Signed-off-by: Sun Jian <sun.jian.kdev@gmail.com>
>
> Reviewed-by: Emil Tsalapatis <emil@etsalapatis.com>
>
> Nit below, but change makes sense.
>
Hi Emil,
Thanks a lot for the review and the Reviewed-by!
> > ---
> > -static void burn_cpu(void)
> > +static void burn_cpu(long loops)
> >  {
> > -     volatile int j = 0;
> > +     long j = 0;
>
> Nit: AFAICT most of these changes are unnecessary, you could just bump
> the cycle count to 100M and add the barrier. Moving everything to longs
> and factoring out the loop count is unnecessary.
>
Good point about keeping the diff small. In v2 I dropped the volatile
and added a barrier().

v2: https://lore.kernel.org/lkml/20260228074555.122950-3-sun.jian.kdev@gmail.com/

I kept the loop-count parameter mainly to keep the "long burn to
trigger perf_event"
intent explicit at the call site, and to avoid  hard-coding a large
constant in the helper
if it gets reused later.

Thanks again,
Sun Jian

^ permalink raw reply	[flat|nested] 8+ messages in thread

end of thread, other threads:[~2026-03-02  2:24 UTC | newest]

Thread overview: 8+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-02-27 16:40 [PATCH 0/2] selftests/bpf: fix bpf_cookie failures Sun Jian
2026-02-27 16:40 ` [PATCH 1/2] selftests/bpf: bpf_cookie: skip kprobe_multi tests without bpf_testmod Sun Jian
2026-02-27 18:18   ` Alexei Starovoitov
2026-02-28  2:58     ` sun jian
2026-02-27 16:40 ` [PATCH 2/2] selftests/bpf: bpf_cookie: make perf_event subtest trigger reliably Sun Jian
2026-02-27 17:16   ` bot+bpf-ci
2026-03-01 19:59   ` Emil Tsalapatis
2026-03-02  2:24     ` sun jian

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox