selftests/bpf: Fix intermittent failures in file_reader test

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>
Acked-by: Ihor Solodrai <ihor.solodrai@linux.dev>
Link: https://lore.kernel.org/r/20251029195907.858217-1-mykyta.yatsenko5@gmail.com
Signed-off-by: Alexei Starovoitov <ast@kernel.org>
This commit is contained in:
Mykyta Yatsenko
2025-10-29 19:59:07 +00:00
committed by Alexei Starovoitov
parent e2e668bd81
commit 5913e936f6
2 changed files with 6 additions and 2 deletions

View File

@@ -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;

View File

@@ -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;