public inbox for bpf@vger.kernel.org
 help / color / mirror / Atom feed
* [PATCH bpf-next 0/2] selftests/bpf: fix flaky build_id test
@ 2026-02-16 19:17 Gregory Bell
  2026-02-16 19:17 ` [PATCH bpf-next 1/2] " Gregory Bell
  2026-02-16 19:17 ` [PATCH bpf-next 2/2] selftests/bpf: align build_id test mapping to 64K page size Gregory Bell
  0 siblings, 2 replies; 4+ messages in thread
From: Gregory Bell @ 2026-02-16 19:17 UTC (permalink / raw)
  To: bpf
  Cc: andrii, eddyz87, ast, daniel, martin.lau, song, yonghong.song,
	john.fastabend, kpsingh, sdf, haoluo, jolsa, shuah, Gregory Bell

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.

Gregory Bell (2):
  selftests/bpf: fix flaky build_id test
  selftests/bpf: align build_id test mapping to 64K page size

 tools/testing/selftests/bpf/uprobe_multi.c  | 19 ++++++++++++++++---
 tools/testing/selftests/bpf/uprobe_multi.ld |  4 ++--
 2 files changed, 18 insertions(+), 5 deletions(-)

-- 
2.52.0


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

* [PATCH bpf-next 1/2] selftests/bpf: fix flaky build_id test
  2026-02-16 19:17 [PATCH bpf-next 0/2] selftests/bpf: fix flaky build_id test Gregory Bell
@ 2026-02-16 19:17 ` Gregory Bell
  2026-02-16 19:48   ` bot+bpf-ci
  2026-02-16 19:17 ` [PATCH bpf-next 2/2] selftests/bpf: align build_id test mapping to 64K page size Gregory Bell
  1 sibling, 1 reply; 4+ messages in thread
From: Gregory Bell @ 2026-02-16 19:17 UTC (permalink / raw)
  To: bpf
  Cc: andrii, eddyz87, ast, daniel, martin.lau, song, yonghong.song,
	john.fastabend, kpsingh, sdf, haoluo, jolsa, shuah, Gregory Bell

The build_id selftest occasionally fails because MADV_PAGEOUT
does not guarantee the immediate eviction of the page. The test
assumes eviction happens and proceeds without verifying
that the page was actually reclaimed, leading to false test
failures.

Fix the test by retrying the page-out sequence until eviction
is successful, instead of relying on a single MADV_PAGEOUT attempt.

Signed-off-by: Gregory Bell <grbell@redhat.com>
---
 tools/testing/selftests/bpf/uprobe_multi.c | 19 ++++++++++++++++---
 1 file changed, 16 insertions(+), 3 deletions(-)

diff --git a/tools/testing/selftests/bpf/uprobe_multi.c b/tools/testing/selftests/bpf/uprobe_multi.c
index dd38dc68f635..ba0a9dcc7b1a 100644
--- a/tools/testing/selftests/bpf/uprobe_multi.c
+++ b/tools/testing/selftests/bpf/uprobe_multi.c
@@ -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;
-- 
2.52.0


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

* [PATCH bpf-next 2/2] selftests/bpf: align build_id test mapping to 64K page size
  2026-02-16 19:17 [PATCH bpf-next 0/2] selftests/bpf: fix flaky build_id test Gregory Bell
  2026-02-16 19:17 ` [PATCH bpf-next 1/2] " Gregory Bell
@ 2026-02-16 19:17 ` Gregory Bell
  1 sibling, 0 replies; 4+ messages in thread
From: Gregory Bell @ 2026-02-16 19:17 UTC (permalink / raw)
  To: bpf
  Cc: andrii, eddyz87, ast, daniel, martin.lau, song, yonghong.song,
	john.fastabend, kpsingh, sdf, haoluo, jolsa, shuah, Gregory Bell

Some architectures require mappings to be aligned to the system page size.
The build_id selftest currently uses a smaller alignment, which can result
in madvise operations executing on a different page than intended.

Increase the mapping alignment to 64K so the buffer is page-aligned on
all supported architectures.

Signed-off-by: Gregory Bell <grbell@redhat.com>
---
 tools/testing/selftests/bpf/uprobe_multi.ld | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/tools/testing/selftests/bpf/uprobe_multi.ld b/tools/testing/selftests/bpf/uprobe_multi.ld
index a2e94828bc8c..2063714b2899 100644
--- a/tools/testing/selftests/bpf/uprobe_multi.ld
+++ b/tools/testing/selftests/bpf/uprobe_multi.ld
@@ -1,8 +1,8 @@
 SECTIONS
 {
-	. = ALIGN(4096);
+	. = ALIGN(65536);
 	.note.gnu.build-id : { *(.note.gnu.build-id) }
-	. = ALIGN(4096);
+	. = ALIGN(65536);
 }
 INSERT AFTER .text;
 
-- 
2.52.0


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

* Re: [PATCH bpf-next 1/2] selftests/bpf: fix flaky build_id test
  2026-02-16 19:17 ` [PATCH bpf-next 1/2] " Gregory Bell
@ 2026-02-16 19:48   ` bot+bpf-ci
  0 siblings, 0 replies; 4+ messages in thread
From: bot+bpf-ci @ 2026-02-16 19:48 UTC (permalink / raw)
  To: grbell, bpf
  Cc: andrii, eddyz87, ast, daniel, martin.lau, song, yonghong.song,
	john.fastabend, kpsingh, sdf, haoluo, jolsa, shuah, grbell, ast,
	andrii, daniel, martin.lau, eddyz87, yonghong.song, clm,
	ihor.solodrai

[-- Attachment #1: Type: text/plain, Size: 2066 bytes --]

> diff --git a/tools/testing/selftests/bpf/uprobe_multi.c b/tools/testing/selftests/bpf/uprobe_multi.c
> index dd38dc68f635..ba0a9dcc7b1a 100644
> --- a/tools/testing/selftests/bpf/uprobe_multi.c
> +++ b/tools/testing/selftests/bpf/uprobe_multi.c
> @@ -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;

This line uses spaces for indentation instead of a tab.

> @@ -108,9 +111,19 @@ int __attribute__((weak)) trigger_uprobe(bool build_id_resident)

[ ... ]

> +	if (!build_id_resident){

Missing a space before the opening brace.

> +        do {

Spaces used for indentation here and on several other lines below
(mincore, the if/break, and usleep).  The rest of the file and the
other lines in this same block use tabs.

> +			madvise(addr, page_sz, MADV_PAGEOUT);
> +			/* check if page has been evicted */
> +            mincore(addr, page_sz, vec);
> +            if (!(vec[0] & 1))
> +                break;

Trailing whitespace at the end of this line.

> +			/* 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);

Should there be a space between the closing brace and "while"?
The usual kernel style is "} while".

> +	}


---
AI reviewed your patch. Please fix the bug or email reply why it's not a bug.
See: https://github.com/kernel-patches/vmtest/blob/master/ci/claude/README.md

CI run summary: https://github.com/kernel-patches/bpf/actions/runs/22075174977

AI-authorship-score: medium
AI-authorship-explanation: Mixed spaces/tabs indentation within the same code block is a common pattern in AI-generated code, though editor misconfiguration could also explain it.
issues-found: 4
issue-severity-score: low
issue-severity-explanation: Coding style violations (mixed tabs/spaces, missing brace spacing, trailing whitespace) in a selftest with no functional or system impact.

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

end of thread, other threads:[~2026-02-16 19:48 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-02-16 19:17 [PATCH bpf-next 0/2] selftests/bpf: fix flaky build_id test Gregory Bell
2026-02-16 19:17 ` [PATCH bpf-next 1/2] " Gregory Bell
2026-02-16 19:48   ` bot+bpf-ci
2026-02-16 19:17 ` [PATCH bpf-next 2/2] selftests/bpf: align build_id test mapping to 64K page size Gregory Bell

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