diff mbox series

[bpf-next] selftests/bpf: fix uprobe_multi compilation error

Message ID 20240926144948.172090-1-alan.maguire@oracle.com (mailing list archive)
State Accepted
Commit db38ed2cfa62dec7e49b703dc080acc6711f8026
Delegated to: BPF
Headers show
Series [bpf-next] selftests/bpf: fix uprobe_multi compilation error | expand

Checks

Context Check Description
bpf/vmtest-bpf-next-PR success PR summary
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: 9 this patch: 9
netdev/build_tools success Errors and warnings before: 0 this patch: 0
netdev/cc_maintainers warning 2 maintainers not CCed: shuah@kernel.org linux-kselftest@vger.kernel.org
netdev/build_clang success Errors and warnings before: 7 this patch: 7
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 Fixes tag looks correct
netdev/build_allmodconfig_warn success Errors and warnings before: 7 this patch: 7
netdev/checkpatch success total: 0 errors, 0 warnings, 0 checks, 10 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
bpf/vmtest-bpf-next-VM_Test-0 success Logs for Lint
bpf/vmtest-bpf-next-VM_Test-5 success Logs for aarch64-gcc / build-release
bpf/vmtest-bpf-next-VM_Test-2 success Logs for Unittests
bpf/vmtest-bpf-next-VM_Test-10 success Logs for aarch64-gcc / veristat
bpf/vmtest-bpf-next-VM_Test-12 success Logs for s390x-gcc / build-release
bpf/vmtest-bpf-next-VM_Test-9 success Logs for aarch64-gcc / test (test_verifier, false, 360) / test_verifier on aarch64 with gcc
bpf/vmtest-bpf-next-VM_Test-7 success Logs for aarch64-gcc / test (test_progs, false, 360) / test_progs on aarch64 with gcc
bpf/vmtest-bpf-next-VM_Test-8 success Logs for aarch64-gcc / test (test_progs_no_alu32, false, 360) / test_progs_no_alu32 on aarch64 with gcc
bpf/vmtest-bpf-next-VM_Test-11 success Logs for s390x-gcc / build / build for s390x with gcc
bpf/vmtest-bpf-next-VM_Test-16 success Logs for s390x-gcc / veristat
bpf/vmtest-bpf-next-VM_Test-17 success Logs for set-matrix
bpf/vmtest-bpf-next-VM_Test-19 success Logs for x86_64-gcc / build-release
bpf/vmtest-bpf-next-VM_Test-18 success Logs for x86_64-gcc / build / build for x86_64 with gcc
bpf/vmtest-bpf-next-VM_Test-27 success Logs for x86_64-llvm-17 / build / build for x86_64 with llvm-17
bpf/vmtest-bpf-next-VM_Test-28 success Logs for x86_64-llvm-17 / build-release / build for x86_64 with llvm-17-O2
bpf/vmtest-bpf-next-VM_Test-34 success Logs for x86_64-llvm-18 / build / build for x86_64 with llvm-18
bpf/vmtest-bpf-next-VM_Test-35 success Logs for x86_64-llvm-18 / build-release / build for x86_64 with llvm-18-O2
bpf/vmtest-bpf-next-VM_Test-33 success Logs for x86_64-llvm-17 / veristat
bpf/vmtest-bpf-next-VM_Test-41 success Logs for x86_64-llvm-18 / veristat
bpf/vmtest-bpf-next-VM_Test-15 success Logs for s390x-gcc / test (test_verifier, false, 360) / test_verifier on s390x with gcc
bpf/vmtest-bpf-next-VM_Test-14 success Logs for s390x-gcc / test (test_progs_no_alu32, false, 360) / test_progs_no_alu32 on s390x with gcc
bpf/vmtest-bpf-next-VM_Test-13 success Logs for s390x-gcc / test (test_progs, false, 360) / test_progs on s390x with gcc
bpf/vmtest-bpf-next-VM_Test-40 success Logs for x86_64-llvm-18 / test (test_verifier, false, 360) / test_verifier on x86_64 with llvm-18
bpf/vmtest-bpf-next-VM_Test-36 success Logs for x86_64-llvm-18 / test (test_maps, false, 360) / test_maps on x86_64 with llvm-18
bpf/vmtest-bpf-next-VM_Test-37 success Logs for x86_64-llvm-18 / test (test_progs, false, 360) / test_progs on x86_64 with llvm-18
bpf/vmtest-bpf-next-VM_Test-38 success Logs for x86_64-llvm-18 / test (test_progs_cpuv4, false, 360) / test_progs_cpuv4 on x86_64 with llvm-18
bpf/vmtest-bpf-next-VM_Test-39 success Logs for x86_64-llvm-18 / test (test_progs_no_alu32, false, 360) / test_progs_no_alu32 on x86_64 with llvm-18
bpf/vmtest-bpf-next-VM_Test-20 success Logs for x86_64-gcc / test (test_maps, false, 360) / test_maps on x86_64 with gcc
bpf/vmtest-bpf-next-VM_Test-21 success Logs for x86_64-gcc / test (test_progs, false, 360) / test_progs on x86_64 with gcc
bpf/vmtest-bpf-next-VM_Test-24 success Logs for x86_64-gcc / test (test_progs_parallel, true, 30) / test_progs_parallel on x86_64 with gcc
bpf/vmtest-bpf-next-VM_Test-23 success Logs for x86_64-gcc / test (test_progs_no_alu32_parallel, true, 30) / test_progs_no_alu32_parallel on x86_64 with gcc
bpf/vmtest-bpf-next-VM_Test-25 success Logs for x86_64-gcc / test (test_verifier, false, 360) / test_verifier on x86_64 with gcc
bpf/vmtest-bpf-next-VM_Test-22 success Logs for x86_64-gcc / test (test_progs_no_alu32, false, 360) / test_progs_no_alu32 on x86_64 with gcc
bpf/vmtest-bpf-next-VM_Test-26 success Logs for x86_64-gcc / veristat / veristat on x86_64 with gcc
bpf/vmtest-bpf-next-VM_Test-29 success Logs for x86_64-llvm-17 / test (test_maps, false, 360) / test_maps on x86_64 with llvm-17
bpf/vmtest-bpf-next-VM_Test-32 success Logs for x86_64-llvm-17 / test (test_verifier, false, 360) / test_verifier on x86_64 with llvm-17
bpf/vmtest-bpf-next-VM_Test-30 success Logs for x86_64-llvm-17 / test (test_progs, false, 360) / test_progs on x86_64 with llvm-17
bpf/vmtest-bpf-next-VM_Test-31 success Logs for x86_64-llvm-17 / test (test_progs_no_alu32, false, 360) / test_progs_no_alu32 on x86_64 with llvm-17
bpf/vmtest-bpf-next-VM_Test-1 success Logs for aarch64-gcc / build-release
bpf/vmtest-bpf-next-VM_Test-3 success Logs for s390x-gcc / build-release
bpf/vmtest-bpf-next-VM_Test-6 success Logs for x86_64-gcc / build-release
bpf/vmtest-bpf-next-VM_Test-4 success Logs for set-matrix

Commit Message

Alan Maguire Sept. 26, 2024, 2:49 p.m. UTC
When building selftests, the following was seen:

uprobe_multi.c: In function ‘trigger_uprobe’:
uprobe_multi.c:108:40: error: ‘MADV_PAGEOUT’ undeclared (first use in this function)
  108 |                 madvise(addr, page_sz, MADV_PAGEOUT);
      |                                        ^~~~~~~~~~~~
uprobe_multi.c:108:40: note: each undeclared identifier is reported only once for each function it appears in
make: *** [Makefile:850: bpf-next/tools/testing/selftests/bpf/uprobe_multi] Error 1

...even with updated UAPI headers. It seems the above value is
defined in UAPI <linux/mman.h> but including that file triggers
other redefinition errors.  Simplest solution is to add a
guarded definition, as was done for MADV_POPULATE_READ.

Fixes: 3c217a182018 ("selftests/bpf: add build ID tests")
Signed-off-by: Alan Maguire <alan.maguire@oracle.com>
---
 tools/testing/selftests/bpf/uprobe_multi.c | 4 ++++
 1 file changed, 4 insertions(+)

Comments

Eduard Zingerman Sept. 26, 2024, 11:44 p.m. UTC | #1
On Thu, 2024-09-26 at 15:49 +0100, Alan Maguire wrote:
> When building selftests, the following was seen:
> 
> uprobe_multi.c: In function ‘trigger_uprobe’:
> uprobe_multi.c:108:40: error: ‘MADV_PAGEOUT’ undeclared (first use in this function)
>   108 |                 madvise(addr, page_sz, MADV_PAGEOUT);
>       |                                        ^~~~~~~~~~~~
> uprobe_multi.c:108:40: note: each undeclared identifier is reported only once for each function it appears in
> make: *** [Makefile:850: bpf-next/tools/testing/selftests/bpf/uprobe_multi] Error 1
> 
> ...even with updated UAPI headers. It seems the above value is
> defined in UAPI <linux/mman.h> but including that file triggers
> other redefinition errors.  Simplest solution is to add a
> guarded definition, as was done for MADV_POPULATE_READ.
> 
> Fixes: 3c217a182018 ("selftests/bpf: add build ID tests")
> Signed-off-by: Alan Maguire <alan.maguire@oracle.com>
> ---

I was curious why this error is not triggered on my local machine or CI.
MADV_PAGEOUT is indeed defined in UAPI.
Selftests build picks it from host system header, which is
/usr/include/bits/mman-linux.h for my Fedora 40 setup.
The MADV_PAGEOUT was added by commit [1] back in 2019
(and should be available from Linux 5.4, I guess Alan uses a very old kernel).

I think that at some point in time we should adjust selftests to use
UAPI headers that come from the kernel being tested, not from the host.
Until that happens, I think this fix is fine.

[1] 1a4e58cce84e ("mm: introduce MADV_PAGEOUT")

Acked-by: Eduard Zingerman <eddyz87@gmail.com>

(I want back to 2019...)

[...]
Alan Maguire Sept. 27, 2024, 10:26 a.m. UTC | #2
On 27/09/2024 00:44, Eduard Zingerman wrote:
> On Thu, 2024-09-26 at 15:49 +0100, Alan Maguire wrote:
>> When building selftests, the following was seen:
>>
>> uprobe_multi.c: In function ‘trigger_uprobe’:
>> uprobe_multi.c:108:40: error: ‘MADV_PAGEOUT’ undeclared (first use in this function)
>>   108 |                 madvise(addr, page_sz, MADV_PAGEOUT);
>>       |                                        ^~~~~~~~~~~~
>> uprobe_multi.c:108:40: note: each undeclared identifier is reported only once for each function it appears in
>> make: *** [Makefile:850: bpf-next/tools/testing/selftests/bpf/uprobe_multi] Error 1
>>
>> ...even with updated UAPI headers. It seems the above value is
>> defined in UAPI <linux/mman.h> but including that file triggers
>> other redefinition errors.  Simplest solution is to add a
>> guarded definition, as was done for MADV_POPULATE_READ.
>>
>> Fixes: 3c217a182018 ("selftests/bpf: add build ID tests")
>> Signed-off-by: Alan Maguire <alan.maguire@oracle.com>
>> ---
> 
> I was curious why this error is not triggered on my local machine or CI.
> MADV_PAGEOUT is indeed defined in UAPI.
> Selftests build picks it from host system header, which is
> /usr/include/bits/mman-linux.h for my Fedora 40 setup.
> The MADV_PAGEOUT was added by commit [1] back in 2019
> (and should be available from Linux 5.4, I guess Alan uses a very old kernel).
> 
> I think that at some point in time we should adjust selftests to use
> UAPI headers that come from the kernel being tested, not from the host.
> Until that happens, I think this fix is fine.
> 

From what I can see at my end, /usr/include/bits/mman.h is provided by
glibc-headers. On distros the glibc-headers can get quite out of date. I
do a "make headers_install" prior to running bpf selftests to get latest
UAPI headers from the kernel in /usr/include/linux, but that wasn't
enough in this case since /usr/include/sys/mman.h and
/usr/include/bits/mman.h were provided via glibc-headers.

When I tried using <linux/mman.h> in the program, I ended up getting
complaints about madvise() being undefined, and when I used both
<sys/mman.h> and <linux/mman.h> there were complaints about mutiple
definitions so the approach taken in the patch seemed like the most
straightforward.

Thanks for taking a look!

Alan

> [1] 1a4e58cce84e ("mm: introduce MADV_PAGEOUT")
> 
> Acked-by: Eduard Zingerman <eddyz87@gmail.com>
> 
> (I want back to 2019...)
> 
> [...]
>
patchwork-bot+netdevbpf@kernel.org Sept. 27, 2024, 8:50 p.m. UTC | #3
Hello:

This patch was applied to bpf/bpf-next.git (master)
by Andrii Nakryiko <andrii@kernel.org>:

On Thu, 26 Sep 2024 15:49:48 +0100 you wrote:
> When building selftests, the following was seen:
> 
> uprobe_multi.c: In function ‘trigger_uprobe’:
> uprobe_multi.c:108:40: error: ‘MADV_PAGEOUT’ undeclared (first use in this function)
>   108 |                 madvise(addr, page_sz, MADV_PAGEOUT);
>       |                                        ^~~~~~~~~~~~
> uprobe_multi.c:108:40: note: each undeclared identifier is reported only once for each function it appears in
> make: *** [Makefile:850: bpf-next/tools/testing/selftests/bpf/uprobe_multi] Error 1
> 
> [...]

Here is the summary with links:
  - [bpf-next] selftests/bpf: fix uprobe_multi compilation error
    https://git.kernel.org/bpf/bpf-next/c/db38ed2cfa62

You are awesome, thank you!
diff mbox series

Patch

diff --git a/tools/testing/selftests/bpf/uprobe_multi.c b/tools/testing/selftests/bpf/uprobe_multi.c
index c7828b13e5ff..dd38dc68f635 100644
--- a/tools/testing/selftests/bpf/uprobe_multi.c
+++ b/tools/testing/selftests/bpf/uprobe_multi.c
@@ -12,6 +12,10 @@ 
 #define MADV_POPULATE_READ 22
 #endif
 
+#ifndef MADV_PAGEOUT
+#define MADV_PAGEOUT 21
+#endif
+
 int __attribute__((weak)) uprobe(void)
 {
 	return 0;