]> git.ipfire.org Git - thirdparty/linux.git/commitdiff
selftests/bpf: fix flaky build_id test
authorGregory Bell <grbell@redhat.com>
Tue, 17 Feb 2026 14:32:36 +0000 (09:32 -0500)
committerAlexei Starovoitov <ast@kernel.org>
Thu, 19 Feb 2026 19:29:41 +0000 (11:29 -0800)
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>
Link: https://lore.kernel.org/r/038bd27c69dd3a16958894fcb19e4fb6fbfe317e.1771338492.git.grbell@redhat.com
Signed-off-by: Alexei Starovoitov <ast@kernel.org>
tools/testing/selftests/bpf/uprobe_multi.c

index dd38dc68f635921cb0af60f05a45d8d356d2404a..3e58a86b8e25410d862340fdb1933f45923db5fc 100644 (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;