BPF List
 help / color / mirror / Atom feed
* [PATCH bpf-next v1] selftests/bpf: fix file_reader test
@ 2025-10-29 19:59 Mykyta Yatsenko
  2025-10-29 21:49 ` Ihor Solodrai
  2025-10-30  1:20 ` patchwork-bot+netdevbpf
  0 siblings, 2 replies; 3+ messages in thread
From: Mykyta Yatsenko @ 2025-10-29 19:59 UTC (permalink / raw)
  To: bpf, ast, andrii, daniel, kafai, kernel-team, eddyz87,
	ihor.solodrai
  Cc: Mykyta Yatsenko

From: Mykyta Yatsenko <yatsenko@meta.com>

file_reader/on_open_expect_fault intermittently fails when test_progs
runs tests in parallel, because it expects a page fault on first read.
Another file_reader test running concurrently may have already pulled
the same pages into the page cache, eliminating the fault and causing a
spurious failure.

Make file_reader/on_open_expect_fault read from a file region that does
not overlap with other file_reader tests, so the initial access still
faults even under parallel execution.

Signed-off-by: Mykyta Yatsenko <yatsenko@meta.com>
---
 tools/testing/selftests/bpf/prog_tests/file_reader.c | 6 +++++-
 tools/testing/selftests/bpf/progs/file_reader.c      | 2 +-
 2 files changed, 6 insertions(+), 2 deletions(-)

diff --git a/tools/testing/selftests/bpf/prog_tests/file_reader.c b/tools/testing/selftests/bpf/prog_tests/file_reader.c
index 2a034d43b73e..5cde32b35da4 100644
--- a/tools/testing/selftests/bpf/prog_tests/file_reader.c
+++ b/tools/testing/selftests/bpf/prog_tests/file_reader.c
@@ -52,7 +52,11 @@ static int initialize_file_contents(void)
 	/* page-align base file address */
 	addr = (void *)((unsigned long)addr & ~(page_sz - 1));
 
-	for (off = 0; off < sizeof(file_contents); off += page_sz) {
+	/*
+	 * Page out range 0..512K, use 0..256K for positive tests and
+	 * 256K..512K for negative tests expecting page faults
+	 */
+	for (off = 0; off < sizeof(file_contents) * 2; off += page_sz) {
 		if (!ASSERT_OK(madvise(addr + off, page_sz, MADV_PAGEOUT),
 			       "madvise pageout"))
 			return errno;
diff --git a/tools/testing/selftests/bpf/progs/file_reader.c b/tools/testing/selftests/bpf/progs/file_reader.c
index 2585f83b0ce5..166c3ac6957d 100644
--- a/tools/testing/selftests/bpf/progs/file_reader.c
+++ b/tools/testing/selftests/bpf/progs/file_reader.c
@@ -49,7 +49,7 @@ int on_open_expect_fault(void *c)
 	if (bpf_dynptr_from_file(file, 0, &dynptr))
 		goto out;
 
-	local_err = bpf_dynptr_read(tmp_buf, user_buf_sz, &dynptr, 0, 0);
+	local_err = bpf_dynptr_read(tmp_buf, user_buf_sz, &dynptr, user_buf_sz, 0);
 	if (local_err == -EFAULT) { /* Expect page fault */
 		local_err = 0;
 		run_success = 1;
-- 
2.51.1


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

* Re: [PATCH bpf-next v1] selftests/bpf: fix file_reader test
  2025-10-29 19:59 [PATCH bpf-next v1] selftests/bpf: fix file_reader test Mykyta Yatsenko
@ 2025-10-29 21:49 ` Ihor Solodrai
  2025-10-30  1:20 ` patchwork-bot+netdevbpf
  1 sibling, 0 replies; 3+ messages in thread
From: Ihor Solodrai @ 2025-10-29 21:49 UTC (permalink / raw)
  To: Mykyta Yatsenko, bpf, ast, andrii, daniel, kafai, kernel-team,
	eddyz87
  Cc: Mykyta Yatsenko

On 10/29/25 12:59 PM, Mykyta Yatsenko wrote:
> From: Mykyta Yatsenko <yatsenko@meta.com>
> 
> file_reader/on_open_expect_fault intermittently fails when test_progs
> runs tests in parallel, because it expects a page fault on first read.
> Another file_reader test running concurrently may have already pulled
> the same pages into the page cache, eliminating the fault and causing a
> spurious failure.
> 
> Make file_reader/on_open_expect_fault read from a file region that does
> not overlap with other file_reader tests, so the initial access still
> faults even under parallel execution.
> 
> Signed-off-by: Mykyta Yatsenko <yatsenko@meta.com>
> ---
>  tools/testing/selftests/bpf/prog_tests/file_reader.c | 6 +++++-
>  tools/testing/selftests/bpf/progs/file_reader.c      | 2 +-
>  2 files changed, 6 insertions(+), 2 deletions(-)

No more failures on CI:
https://github.com/kernel-patches/bpf/actions/runs/18920720310/job/54022355262

Thank you for fixing.

Acked-by: Ihor Solodrai <ihor.solodrai@linux.dev>

> 
> diff --git a/tools/testing/selftests/bpf/prog_tests/file_reader.c b/tools/testing/selftests/bpf/prog_tests/file_reader.c
> index 2a034d43b73e..5cde32b35da4 100644
> --- a/tools/testing/selftests/bpf/prog_tests/file_reader.c
> +++ b/tools/testing/selftests/bpf/prog_tests/file_reader.c
> @@ -52,7 +52,11 @@ static int initialize_file_contents(void)
>  	/* page-align base file address */
>  	addr = (void *)((unsigned long)addr & ~(page_sz - 1));
>  
> -	for (off = 0; off < sizeof(file_contents); off += page_sz) {
> +	/*
> +	 * Page out range 0..512K, use 0..256K for positive tests and
> +	 * 256K..512K for negative tests expecting page faults
> +	 */
> +	for (off = 0; off < sizeof(file_contents) * 2; off += page_sz) {
>  		if (!ASSERT_OK(madvise(addr + off, page_sz, MADV_PAGEOUT),
>  			       "madvise pageout"))
>  			return errno;
> diff --git a/tools/testing/selftests/bpf/progs/file_reader.c b/tools/testing/selftests/bpf/progs/file_reader.c
> index 2585f83b0ce5..166c3ac6957d 100644
> --- a/tools/testing/selftests/bpf/progs/file_reader.c
> +++ b/tools/testing/selftests/bpf/progs/file_reader.c
> @@ -49,7 +49,7 @@ int on_open_expect_fault(void *c)
>  	if (bpf_dynptr_from_file(file, 0, &dynptr))
>  		goto out;
>  
> -	local_err = bpf_dynptr_read(tmp_buf, user_buf_sz, &dynptr, 0, 0);
> +	local_err = bpf_dynptr_read(tmp_buf, user_buf_sz, &dynptr, user_buf_sz, 0);
>  	if (local_err == -EFAULT) { /* Expect page fault */
>  		local_err = 0;
>  		run_success = 1;


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

* Re: [PATCH bpf-next v1] selftests/bpf: fix file_reader test
  2025-10-29 19:59 [PATCH bpf-next v1] selftests/bpf: fix file_reader test Mykyta Yatsenko
  2025-10-29 21:49 ` Ihor Solodrai
@ 2025-10-30  1:20 ` patchwork-bot+netdevbpf
  1 sibling, 0 replies; 3+ messages in thread
From: patchwork-bot+netdevbpf @ 2025-10-30  1:20 UTC (permalink / raw)
  To: Mykyta Yatsenko
  Cc: bpf, ast, andrii, daniel, kafai, kernel-team, eddyz87,
	ihor.solodrai, yatsenko

Hello:

This patch was applied to bpf/bpf-next.git (master)
by Alexei Starovoitov <ast@kernel.org>:

On Wed, 29 Oct 2025 19:59:07 +0000 you wrote:
> From: Mykyta Yatsenko <yatsenko@meta.com>
> 
> file_reader/on_open_expect_fault intermittently fails when test_progs
> runs tests in parallel, because it expects a page fault on first read.
> Another file_reader test running concurrently may have already pulled
> the same pages into the page cache, eliminating the fault and causing a
> spurious failure.
> 
> [...]

Here is the summary with links:
  - [bpf-next,v1] selftests/bpf: fix file_reader test
    https://git.kernel.org/bpf/bpf-next/c/5913e936f6d5

You are awesome, thank you!
-- 
Deet-doot-dot, I am a bot.
https://korg.docs.kernel.org/patchwork/pwbot.html



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

end of thread, other threads:[~2025-10-30  1:20 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-10-29 19:59 [PATCH bpf-next v1] selftests/bpf: fix file_reader test Mykyta Yatsenko
2025-10-29 21:49 ` Ihor Solodrai
2025-10-30  1:20 ` patchwork-bot+netdevbpf

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