Merge branch 'selftests-bpf-fix-flaky-build_id-test'

Gregory Bell says:

====================
selftests/bpf: fix flaky build_id test

The build_id selftest intermittently fails with the following error:

	./test_progs -t build_id/nofault-paged-out
	serial_test_build_id:PASS:parse_build_id 0 nsec
	subtest_nofault:PASS:skel_open 0 nsec
	subtest_nofault:PASS:link 0 nsec
	subtest_nofault:PASS:trigger_uprobe 0 nsec
	subtest_nofault:PASS:res 0 nsec
	subtest_nofault:FAIL:build_id_status unexpected build_id_status: actual 1 != expected 2
	46/1    build_id/nofault-paged-out:FAIL
	46      build_id:FAIL
	397     stacktrace_build_id:OK
	398     stacktrace_build_id_nmi:OK

On RHEL we consistently hit the reported failure on the first run of
the test following installation, after which subsequent runs pass.

This patch implements the approach discussed in the following thread:
https://lore.kernel.org/all/CAEf4BzYWVtfZh07iQm5Fo=kMm+8hgAu+rXRx1uLRHz07wc59+Q@mail.gmail.com/

Following the discussion, the fix makes the test verify eviction rather
than assuming it. In the discussion it was recommended to add a sleep before
and after the madvise operations, this did not resolve the issue in our case,
rather the test timed out every time. I was successful by retrying the
page-out sequence until the page is actually evicted.

Additionally, the mapping alignment is increased to
64K so the test operates on a properly page-aligned buffer across
supported architectures.

changelog:
 - fixed indentations
 - removed trailing whitespace
 - add space between opening and closing brackets

====================

Link: https://patch.msgid.link/cover.1771338492.git.grbell@redhat.com
Signed-off-by: Alexei Starovoitov <ast@kernel.org>
This commit is contained in:
Alexei Starovoitov 2026-02-19 11:29:41 -08:00
commit 9cd168a272
2 changed files with 18 additions and 5 deletions

View File

@ -100,6 +100,9 @@ int __attribute__((weak)) trigger_uprobe(bool build_id_resident)
int page_sz = sysconf(_SC_PAGESIZE);
void *addr;
unsigned char vec[1];
int poll = 0;
/* page-align build ID start */
addr = (void *)((uintptr_t)&build_id_start & ~(page_sz - 1));
@ -108,9 +111,19 @@ int __attribute__((weak)) trigger_uprobe(bool build_id_resident)
* do MADV_POPULATE_READ, and then MADV_PAGEOUT, if necessary
*/
madvise(addr, page_sz, MADV_POPULATE_READ);
if (!build_id_resident)
madvise(addr, page_sz, MADV_PAGEOUT);
if (!build_id_resident) {
do {
madvise(addr, page_sz, MADV_PAGEOUT);
/* check if page has been evicted */
mincore(addr, page_sz, vec);
if (!(vec[0] & 1))
break;
/* if page is still resident re-attempt MADV_POPULATE_READ/MADV_PAGEOUT */
madvise(addr, page_sz, MADV_POPULATE_READ);
poll++;
usleep(100);
} while (poll < 500);
}
(void)uprobe();
return 0;

View File

@ -1,8 +1,8 @@
SECTIONS
{
. = ALIGN(4096);
. = ALIGN(65536);
.note.gnu.build-id : { *(.note.gnu.build-id) }
. = ALIGN(4096);
. = ALIGN(65536);
}
INSERT AFTER .text;