Commit 5913e936 authored by Mykyta Yatsenko's avatar Mykyta Yatsenko Committed by Alexei Starovoitov
Browse files

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: default avatarMykyta Yatsenko <yatsenko@meta.com>
Acked-by: default avatarIhor Solodrai <ihor.solodrai@linux.dev>
Link: https://lore.kernel.org/r/20251029195907.858217-1-mykyta.yatsenko5@gmail.com


Signed-off-by: default avatarAlexei Starovoitov <ast@kernel.org>
parent e2e668bd
Loading
Loading
Loading
Loading
+5 −1
Original line number Diff line number Diff line
@@ -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;
+1 −1
Original line number Diff line number Diff line
@@ -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;