Skip to content

Commit 5913e93

Browse files
mykyta5Alexei Starovoitov
authored andcommitted
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 <[email protected]> Acked-by: Ihor Solodrai <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Alexei Starovoitov <[email protected]>
1 parent e2e668b commit 5913e93

File tree

2 files changed

+6
-2
lines changed

2 files changed

+6
-2
lines changed

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

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,11 @@ static int initialize_file_contents(void)
5252
/* page-align base file address */
5353
addr = (void *)((unsigned long)addr & ~(page_sz - 1));
5454

55-
for (off = 0; off < sizeof(file_contents); off += page_sz) {
55+
/*
56+
* Page out range 0..512K, use 0..256K for positive tests and
57+
* 256K..512K for negative tests expecting page faults
58+
*/
59+
for (off = 0; off < sizeof(file_contents) * 2; off += page_sz) {
5660
if (!ASSERT_OK(madvise(addr + off, page_sz, MADV_PAGEOUT),
5761
"madvise pageout"))
5862
return errno;

tools/testing/selftests/bpf/progs/file_reader.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ int on_open_expect_fault(void *c)
4949
if (bpf_dynptr_from_file(file, 0, &dynptr))
5050
goto out;
5151

52-
local_err = bpf_dynptr_read(tmp_buf, user_buf_sz, &dynptr, 0, 0);
52+
local_err = bpf_dynptr_read(tmp_buf, user_buf_sz, &dynptr, user_buf_sz, 0);
5353
if (local_err == -EFAULT) { /* Expect page fault */
5454
local_err = 0;
5555
run_success = 1;

0 commit comments

Comments
 (0)