diff mbox series

[bpf-next] bpf: handle MADV_PAGEOUT error in uprobe_multi.c

Message ID 20241020031422.46894-1-kerneljasonxing@gmail.com (mailing list archive)
State Superseded
Delegated to: BPF
Headers show
Series [bpf-next] bpf: handle MADV_PAGEOUT error in uprobe_multi.c | expand

Checks

Context Check Description
bpf/vmtest-bpf-next-PR fail PR summary
bpf/vmtest-bpf-next-VM_Test-1 success Logs for ShellCheck
bpf/vmtest-bpf-next-VM_Test-0 success Logs for Lint
bpf/vmtest-bpf-next-VM_Test-2 success Logs for Unittests
bpf/vmtest-bpf-next-VM_Test-4 fail Logs for aarch64-gcc / build / build for aarch64 with gcc
bpf/vmtest-bpf-next-VM_Test-3 success Logs for Validate matrix.py
bpf/vmtest-bpf-next-VM_Test-5 success Logs for aarch64-gcc / build-release
bpf/vmtest-bpf-next-VM_Test-7 success Logs for aarch64-gcc / veristat
bpf/vmtest-bpf-next-VM_Test-6 success Logs for aarch64-gcc / test
bpf/vmtest-bpf-next-VM_Test-8 fail Logs for s390x-gcc / build / build for s390x with gcc
bpf/vmtest-bpf-next-VM_Test-10 success Logs for s390x-gcc / test
bpf/vmtest-bpf-next-VM_Test-9 success Logs for s390x-gcc / build-release
bpf/vmtest-bpf-next-VM_Test-11 success Logs for s390x-gcc / veristat
bpf/vmtest-bpf-next-VM_Test-16 success Logs for x86_64-gcc / veristat
bpf/vmtest-bpf-next-VM_Test-15 success Logs for x86_64-gcc / test
bpf/vmtest-bpf-next-VM_Test-12 success Logs for set-matrix
bpf/vmtest-bpf-next-VM_Test-13 fail Logs for x86_64-gcc / build / build for x86_64 with gcc
bpf/vmtest-bpf-next-VM_Test-14 success Logs for x86_64-gcc / build-release
bpf/vmtest-bpf-next-VM_Test-17 fail Logs for x86_64-llvm-17 / build / build for x86_64 with llvm-17
bpf/vmtest-bpf-next-VM_Test-22 fail Logs for x86_64-llvm-18 / build-release / build for x86_64 with llvm-18-O2
bpf/vmtest-bpf-next-VM_Test-19 success Logs for x86_64-llvm-17 / test
bpf/vmtest-bpf-next-VM_Test-20 success Logs for x86_64-llvm-17 / veristat
bpf/vmtest-bpf-next-VM_Test-23 success Logs for x86_64-llvm-18 / test
bpf/vmtest-bpf-next-VM_Test-18 fail Logs for x86_64-llvm-17 / build-release / build for x86_64 with llvm-17-O2
bpf/vmtest-bpf-next-VM_Test-21 fail Logs for x86_64-llvm-18 / build / build for x86_64 with llvm-18
bpf/vmtest-bpf-next-VM_Test-24 success Logs for x86_64-llvm-18 / veristat
netdev/series_format success Single patches do not need cover letters
netdev/tree_selection success Clearly marked for bpf-next
netdev/ynl success Generated files up to date; no warnings/errors; no diff in generated;
netdev/fixes_present success Fixes tag not required for -next series
netdev/header_inline success No static functions without inline keyword in header files
netdev/build_32bit success Errors and warnings before: 5 this patch: 5
netdev/build_tools success Errors and warnings before: 0 (+1) this patch: 0 (+1)
netdev/cc_maintainers success CCed 16 of 16 maintainers
netdev/build_clang success Errors and warnings before: 5 this patch: 5
netdev/verify_signedoff success Signed-off-by tag matches author and committer
netdev/deprecated_api success None detected
netdev/check_selftest success No net selftest shell script
netdev/verify_fixes success No Fixes tag
netdev/build_allmodconfig_warn success Errors and warnings before: 3 this patch: 3
netdev/checkpatch success total: 0 errors, 0 warnings, 0 checks, 7 lines checked
netdev/build_clang_rust success No Rust files in patch. Skipping build
netdev/kdoc success Errors and warnings before: 0 this patch: 0
netdev/source_inline success Was 0 now: 0

Commit Message

Jason Xing Oct. 20, 2024, 3:14 a.m. UTC
From: Jason Xing <kernelxing@tencent.com>

When I compiled the tools/testing/selftests/bpf, the following error
pops out:
uprobe_multi.c: In function ‘trigger_uprobe’:
uprobe_multi.c:109:26: error: ‘MADV_PAGEOUT’ undeclared (first use in this function); did you mean ‘MADV_RANDOM’?
   madvise(addr, page_sz, MADV_PAGEOUT);
                          ^~~~~~~~~~~~
                          MADV_RANDOM

We can see MADV_PAGEOUT existing in mman-common.h on x86 arch, so
including this header file solves this compilation error.

Signed-off-by: Jason Xing <kernelxing@tencent.com>
---
 tools/testing/selftests/bpf/uprobe_multi.c | 1 +
 1 file changed, 1 insertion(+)

Comments

Jason Xing Oct. 20, 2024, 4:10 a.m. UTC | #1
On Sun, Oct 20, 2024 at 11:14 AM Jason Xing <kerneljasonxing@gmail.com> wrote:
>
> From: Jason Xing <kernelxing@tencent.com>
>
> When I compiled the tools/testing/selftests/bpf, the following error
> pops out:
> uprobe_multi.c: In function ‘trigger_uprobe’:
> uprobe_multi.c:109:26: error: ‘MADV_PAGEOUT’ undeclared (first use in this function); did you mean ‘MADV_RANDOM’?
>    madvise(addr, page_sz, MADV_PAGEOUT);
>                           ^~~~~~~~~~~~
>                           MADV_RANDOM
>
> We can see MADV_PAGEOUT existing in mman-common.h on x86 arch, so
> including this header file solves this compilation error.
>
> Signed-off-by: Jason Xing <kernelxing@tencent.com>
> ---
>  tools/testing/selftests/bpf/uprobe_multi.c | 1 +
>  1 file changed, 1 insertion(+)
>
> diff --git a/tools/testing/selftests/bpf/uprobe_multi.c b/tools/testing/selftests/bpf/uprobe_multi.c
> index c7828b13e5ff..b0e11ffe0e1c 100644
> --- a/tools/testing/selftests/bpf/uprobe_multi.c
> +++ b/tools/testing/selftests/bpf/uprobe_multi.c
> @@ -5,6 +5,7 @@
>  #include <stdbool.h>
>  #include <stdint.h>
>  #include <sys/mman.h>
> +#include <mman-common.h>

uprobe_multi.c:8:10: fatal error: mman-common.h: No such file or directory
61 8 | #include <mman-common.h>
62 | ^~~~~~~~~~~~~~~

After seeing the error that CI reported to me, I realized that I did
cp /usr/include/asm-generic/mman-common.h to
/usr/include/mman-common.h.

If I try "#include <asm-generic/mman-common.h>", then I will see
redefinition error:
tools/include/uapi/asm-generic/mman-common.h:26: error: "MAP_POPULATE"
redefined [-Werror]
 #define MAP_POPULATE  0x008000 /* populate (prefault) pagetables */

In file included from /usr/include/sys/mman.h:41,
                 from uprobe_multi.c:7:
/usr/include/bits/mman.h:38: note: this is the location of the
previous definition
 # define MAP_POPULATE 0x08000  /* Populate (prefault) pagetables.  */

It looks odd to me. Let me dig into it more.

Thanks,
Jason
Jason Xing Oct. 20, 2024, 5:02 a.m. UTC | #2
On Sun, Oct 20, 2024 at 12:10 PM Jason Xing <kerneljasonxing@gmail.com> wrote:
>
> On Sun, Oct 20, 2024 at 11:14 AM Jason Xing <kerneljasonxing@gmail.com> wrote:
> >
> > From: Jason Xing <kernelxing@tencent.com>
> >
> > When I compiled the tools/testing/selftests/bpf, the following error
> > pops out:
> > uprobe_multi.c: In function ‘trigger_uprobe’:
> > uprobe_multi.c:109:26: error: ‘MADV_PAGEOUT’ undeclared (first use in this function); did you mean ‘MADV_RANDOM’?
> >    madvise(addr, page_sz, MADV_PAGEOUT);
> >                           ^~~~~~~~~~~~
> >                           MADV_RANDOM
> >
> > We can see MADV_PAGEOUT existing in mman-common.h on x86 arch, so
> > including this header file solves this compilation error.
> >
> > Signed-off-by: Jason Xing <kernelxing@tencent.com>
> > ---
> >  tools/testing/selftests/bpf/uprobe_multi.c | 1 +
> >  1 file changed, 1 insertion(+)
> >
> > diff --git a/tools/testing/selftests/bpf/uprobe_multi.c b/tools/testing/selftests/bpf/uprobe_multi.c
> > index c7828b13e5ff..b0e11ffe0e1c 100644
> > --- a/tools/testing/selftests/bpf/uprobe_multi.c
> > +++ b/tools/testing/selftests/bpf/uprobe_multi.c
> > @@ -5,6 +5,7 @@
> >  #include <stdbool.h>
> >  #include <stdint.h>
> >  #include <sys/mman.h>
> > +#include <mman-common.h>
>
> uprobe_multi.c:8:10: fatal error: mman-common.h: No such file or directory
> 61 8 | #include <mman-common.h>
> 62 | ^~~~~~~~~~~~~~~
>
> After seeing the error that CI reported to me, I realized that I did
> cp /usr/include/asm-generic/mman-common.h to
> /usr/include/mman-common.h.
>
> If I try "#include <asm-generic/mman-common.h>", then I will see
> redefinition error:
> tools/include/uapi/asm-generic/mman-common.h:26: error: "MAP_POPULATE"
> redefined [-Werror]
>  #define MAP_POPULATE  0x008000 /* populate (prefault) pagetables */
>
> In file included from /usr/include/sys/mman.h:41,
>                  from uprobe_multi.c:7:
> /usr/include/bits/mman.h:38: note: this is the location of the
> previous definition
>  # define MAP_POPULATE 0x08000  /* Populate (prefault) pagetables.  */
>
> It looks odd to me. Let me dig into it more.

Ah, I know how to fix it:
diff --git a/tools/testing/selftests/bpf/uprobe_multi.c
b/tools/testing/selftests/bpf/uprobe_multi.c
index c7828b13e5ff..40231f02b95d 100644
--- a/tools/testing/selftests/bpf/uprobe_multi.c
+++ b/tools/testing/selftests/bpf/uprobe_multi.c
@@ -4,6 +4,7 @@
 #include <string.h>
 #include <stdbool.h>
 #include <stdint.h>
+#include <linux/mman.h>
 #include <sys/mman.h>
 #include <unistd.h>
 #include <sdt.h>

It works. I'll post it in 24 hours.
diff mbox series

Patch

diff --git a/tools/testing/selftests/bpf/uprobe_multi.c b/tools/testing/selftests/bpf/uprobe_multi.c
index c7828b13e5ff..b0e11ffe0e1c 100644
--- a/tools/testing/selftests/bpf/uprobe_multi.c
+++ b/tools/testing/selftests/bpf/uprobe_multi.c
@@ -5,6 +5,7 @@ 
 #include <stdbool.h>
 #include <stdint.h>
 #include <sys/mman.h>
+#include <mman-common.h>
 #include <unistd.h>
 #include <sdt.h>