* Is tools/testing/selftests/bpf/ maintained?
@ 2023-10-12 13:39 Tetsuo Handa
2023-10-12 16:34 ` Eduard Zingerman
2023-10-12 16:35 ` Andrii Nakryiko
0 siblings, 2 replies; 7+ messages in thread
From: Tetsuo Handa @ 2023-10-12 13:39 UTC (permalink / raw)
To: bpf, KP Singh
Hello.
I'm having problem with finding BPF LSM examples that work.
I tried building tools/testing/selftests/bpf/progs/lsm.c and
tools/testing/selftests/bpf/prog_tests/test_lsm.c explained at
https://docs.kernel.org/bpf/prog_lsm.html , but got a lot of errors.
----------------------------------------
root@ubuntu:/usr/src# git clone https://kernel.googlesource.com/pub/scm/linux/kernel/git/torvalds/linux.git
Cloning into 'linux'...
remote: Total 9723739 (delta 8227084), reused 9723739 (delta 8227084)
Receiving objects: 100% (9723739/9723739), 1.81 GiB | 4.04 MiB/s, done.
Resolving deltas: 100% (8227084/8227084), done.
Checking objects: 100% (33554432/33554432), done.
Updating files: 100% (81759/81759), done.
root@ubuntu:/usr/src# cd linux
root@ubuntu:/usr/src/linux# git describe
v6.6-rc5-72-g401644852d0b
root@ubuntu:/usr/src/linux# make -s headers
root@ubuntu:/usr/src/linux# make -sC tools/testing/selftests/bpf/
MKDIR libbpf
Warning: Kernel ABI header at 'tools/include/uapi/linux/if_xdp.h' differs from latest version at 'include/uapi/linux/if_xdp.h'
TEST-HDR [test_progs] tests.h
EXT-OBJ [test_progs] testing_helpers.o
EXT-OBJ [test_progs] cap_helpers.o
EXT-OBJ [test_progs] unpriv_helpers.o
BINARY test_verifier
BINARY test_tag
MKDIR bpftool
GEN vmlinux.h
CLNG-BPF [test_maps] async_stack_depth.bpf.o
progs/async_stack_depth.c:8:19: error: field has incomplete type 'struct bpf_timer'
struct bpf_timer timer;
^
/usr/src/linux/tools/testing/selftests/bpf/tools/include/bpf/bpf_helper_defs.h:41:8: note: forward declaration of 'struct bpf_timer'
struct bpf_timer;
^
1 error generated.
make: *** [Makefile:598: /usr/src/linux/tools/testing/selftests/bpf/async_stack_depth.bpf.o] Error 1
----------------------------------------
To fix these errors, something like the following
(this seems to be a fraction) is needed. What am I missing?
----------------------------------------
diff --git a/tools/testing/selftests/bpf/progs/async_stack_depth.c b/tools/testing/selftests/bpf/progs/async_stack_depth.c
index 3517c0e01206..0318229d8fb2 100644
--- a/tools/testing/selftests/bpf/progs/async_stack_depth.c
+++ b/tools/testing/selftests/bpf/progs/async_stack_depth.c
@@ -4,6 +4,11 @@
#include "bpf_misc.h"
+struct bpf_timer {
+ __u64 :64;
+ __u64 :64;
+} __attribute__((aligned(8)));
+
struct hmap_elem {
struct bpf_timer timer;
};
diff --git a/tools/testing/selftests/bpf/progs/cb_refs.c b/tools/testing/selftests/bpf/progs/cb_refs.c
index 76d661b20e87..d1fb43346dc1 100644
--- a/tools/testing/selftests/bpf/progs/cb_refs.c
+++ b/tools/testing/selftests/bpf/progs/cb_refs.c
@@ -2,6 +2,9 @@
#include <vmlinux.h>
#include <bpf/bpf_tracing.h>
#include <bpf/bpf_helpers.h>
+struct prog_test_member1 {
+ int a;
+};
#include "../bpf_testmod/bpf_testmod_kfunc.h"
struct map_value {
diff --git a/tools/testing/selftests/bpf/progs/cgrp_ls_attach_cgroup.c b/tools/testing/selftests/bpf/progs/cgrp_ls_attach_cgroup.c
index 8aeba1b75c83..5de35c0e08cc 100644
--- a/tools/testing/selftests/bpf/progs/cgrp_ls_attach_cgroup.c
+++ b/tools/testing/selftests/bpf/progs/cgrp_ls_attach_cgroup.c
@@ -14,7 +14,7 @@ struct socket_cookie {
};
struct {
- __uint(type, BPF_MAP_TYPE_CGRP_STORAGE);
+ __uint(type, BPF_MAP_TYPE_CGROUP_STORAGE);
__uint(map_flags, BPF_F_NO_PREALLOC);
__type(key, int);
__type(value, struct socket_cookie);
diff --git a/tools/testing/selftests/bpf/progs/cgrp_ls_negative.c b/tools/testing/selftests/bpf/progs/cgrp_ls_negative.c
index d41f90e2ab64..21043a18b67d 100644
--- a/tools/testing/selftests/bpf/progs/cgrp_ls_negative.c
+++ b/tools/testing/selftests/bpf/progs/cgrp_ls_negative.c
@@ -8,7 +8,7 @@
char _license[] SEC("license") = "GPL";
struct {
- __uint(type, BPF_MAP_TYPE_CGRP_STORAGE);
+ __uint(type, BPF_MAP_TYPE_CGROUP_STORAGE);
__uint(map_flags, BPF_F_NO_PREALLOC);
__type(key, int);
__type(value, long);
diff --git a/tools/testing/selftests/bpf/progs/cgrp_ls_recursion.c b/tools/testing/selftests/bpf/progs/cgrp_ls_recursion.c
index a043d8fefdac..cc175f004266 100644
--- a/tools/testing/selftests/bpf/progs/cgrp_ls_recursion.c
+++ b/tools/testing/selftests/bpf/progs/cgrp_ls_recursion.c
@@ -8,14 +8,14 @@
char _license[] SEC("license") = "GPL";
struct {
- __uint(type, BPF_MAP_TYPE_CGRP_STORAGE);
+ __uint(type, BPF_MAP_TYPE_CGROUP_STORAGE);
__uint(map_flags, BPF_F_NO_PREALLOC);
__type(key, int);
__type(value, long);
} map_a SEC(".maps");
struct {
- __uint(type, BPF_MAP_TYPE_CGRP_STORAGE);
+ __uint(type, BPF_MAP_TYPE_CGROUP_STORAGE);
__uint(map_flags, BPF_F_NO_PREALLOC);
__type(key, int);
__type(value, long);
diff --git a/tools/testing/selftests/bpf/progs/cgrp_ls_sleepable.c b/tools/testing/selftests/bpf/progs/cgrp_ls_sleepable.c
index 4c7844e1dbfa..0130e2e6b3d7 100644
--- a/tools/testing/selftests/bpf/progs/cgrp_ls_sleepable.c
+++ b/tools/testing/selftests/bpf/progs/cgrp_ls_sleepable.c
@@ -9,7 +9,7 @@
char _license[] SEC("license") = "GPL";
struct {
- __uint(type, BPF_MAP_TYPE_CGRP_STORAGE);
+ __uint(type, BPF_MAP_TYPE_CGROUP_STORAGE);
__uint(map_flags, BPF_F_NO_PREALLOC);
__type(key, int);
__type(value, long);
diff --git a/tools/testing/selftests/bpf/progs/cgrp_ls_tp_btf.c b/tools/testing/selftests/bpf/progs/cgrp_ls_tp_btf.c
index 9ebb8e2fe541..e47c88c8790c 100644
--- a/tools/testing/selftests/bpf/progs/cgrp_ls_tp_btf.c
+++ b/tools/testing/selftests/bpf/progs/cgrp_ls_tp_btf.c
@@ -8,14 +8,14 @@
char _license[] SEC("license") = "GPL";
struct {
- __uint(type, BPF_MAP_TYPE_CGRP_STORAGE);
+ __uint(type, BPF_MAP_TYPE_CGROUP_STORAGE);
__uint(map_flags, BPF_F_NO_PREALLOC);
__type(key, int);
__type(value, long);
} map_a SEC(".maps");
struct {
- __uint(type, BPF_MAP_TYPE_CGRP_STORAGE);
+ __uint(type, BPF_MAP_TYPE_CGROUP_STORAGE);
__uint(map_flags, BPF_F_NO_PREALLOC);
__type(key, int);
__type(value, long);
diff --git a/tools/testing/selftests/bpf/progs/dummy_st_ops_fail.c b/tools/testing/selftests/bpf/progs/dummy_st_ops_fail.c
index 0bf969a0b5ed..f681d6f15c43 100644
--- a/tools/testing/selftests/bpf/progs/dummy_st_ops_fail.c
+++ b/tools/testing/selftests/bpf/progs/dummy_st_ops_fail.c
@@ -3,6 +3,18 @@
#include "vmlinux.h"
#include <bpf/bpf_helpers.h>
+
+struct bpf_dummy_ops_state {
+ int val;
+};
+
+struct bpf_dummy_ops {
+ int (*test_1)(struct bpf_dummy_ops_state *cb);
+ int (*test_2)(struct bpf_dummy_ops_state *cb, int a1, unsigned short a2,
+ char a3, unsigned long a4);
+ int (*test_sleepable)(struct bpf_dummy_ops_state *cb);
+};
+
#include <bpf/bpf_tracing.h>
#include "bpf_misc.h"
diff --git a/tools/testing/selftests/bpf/progs/map_kptr.c b/tools/testing/selftests/bpf/progs/map_kptr.c
index da30f0d59364..b0db7b893461 100644
--- a/tools/testing/selftests/bpf/progs/map_kptr.c
+++ b/tools/testing/selftests/bpf/progs/map_kptr.c
@@ -68,7 +68,7 @@ struct lru_pcpu_hash_map {
} lru_pcpu_hash_map SEC(".maps");
struct cgrp_ls_map {
- __uint(type, BPF_MAP_TYPE_CGRP_STORAGE);
+ __uint(type, BPF_MAP_TYPE_CGROUP_STORAGE);
__uint(map_flags, BPF_F_NO_PREALLOC);
__type(key, int);
__type(value, struct map_value);
----------------------------------------
^ permalink raw reply related [flat|nested] 7+ messages in thread* Re: Is tools/testing/selftests/bpf/ maintained?
2023-10-12 13:39 Is tools/testing/selftests/bpf/ maintained? Tetsuo Handa
@ 2023-10-12 16:34 ` Eduard Zingerman
2023-10-13 13:15 ` Tetsuo Handa
2023-10-12 16:35 ` Andrii Nakryiko
1 sibling, 1 reply; 7+ messages in thread
From: Eduard Zingerman @ 2023-10-12 16:34 UTC (permalink / raw)
To: Tetsuo Handa, bpf, KP Singh
On Thu, 2023-10-12 at 22:39 +0900, Tetsuo Handa wrote:
> Hello.
>
> I'm having problem with finding BPF LSM examples that work.
> I tried building tools/testing/selftests/bpf/progs/lsm.c and
> tools/testing/selftests/bpf/prog_tests/test_lsm.c explained at
> https://docs.kernel.org/bpf/prog_lsm.html , but got a lot of errors.
Hello,
> Is tools/testing/selftests/bpf/ maintained?
It pretty much is, build it every day :)
And we have a CI too: https://github.com/kernel-patches/bpf .
I tried setting up a minimal Debian chroot to showcase the build
and came up with the following list of commands:
# Use trixie to get llvm-16
sudo /usr/sbin/debootstrap --variant=buildd --arch=amd64 trixie trixie-chroot/ http://deb.debian.org/debian
# don't forget to umount with 'umount -R ...'
sudo mount --rbind /dev/pts trixie-chroot/dev/pts
sudo mount -t proc proc trixie-chroot/proc
sudo chroot trixie-chroot
# The reset of commands are from chroot itself, first as root
apt install build-essential llvm clang lld bc flex bison pahole git \
libelf-dev libssl-dev docutils-common rsync
# Note: you might want to build pahole from source
useradd -d /home/eddy -s /bin/bash eddy
mkdir /home/eddy
chown eddy /home/eddy
su eddy
# Now as a user 'eddy':
cd /home/eddy
git clone https://kernel.googlesource.com/pub/scm/linux/kernel/git/torvalds/linux.git
cd linux/
./scripts/kconfig/merge_config.sh tools/testing/selftests/bpf/config tools/testing/selftests/bpf/config.x86_64
# Note: kernel build is mandatory, as vmlinux.h is constructed from DWARF in ./vmlinux
make -j14
make -j14 headers
make -j14 -C tools/testing/selftests/bpf/
Hope this helps,
Eduard
^ permalink raw reply [flat|nested] 7+ messages in thread* Re: Is tools/testing/selftests/bpf/ maintained?
2023-10-12 16:34 ` Eduard Zingerman
@ 2023-10-13 13:15 ` Tetsuo Handa
2023-10-13 13:25 ` Eduard Zingerman
0 siblings, 1 reply; 7+ messages in thread
From: Tetsuo Handa @ 2023-10-13 13:15 UTC (permalink / raw)
To: Eduard Zingerman; +Cc: bpf, KP Singh
Thank you for showing complete command line.
On 2023/10/13 1:34, Eduard Zingerman wrote:
> # Note: kernel build is mandatory, as vmlinux.h is constructed from DWARF in ./vmlinux
is what I was missing. Makefile rules should explicitly describe dependency on vmlinux ,
or at least emit message to teach users about the need to build vmlinux ?
But I still get error. I'm using Ubuntu 22.04.3 LTS.
----------------------------------------
root@ubuntu:/usr/src/linux# make -C tools/testing/selftests/bpf/
make: Entering directory '/usr/src/linux/tools/testing/selftests/bpf'
CLNG-BPF [test_maps] verifier_and.bpf.o
progs/verifier_and.c:58:16: error: invalid operand for instruction
asm volatile (" \
^
<inline asm>:1:184: note: instantiated into assembly here
r1 = 0; *(u64*)(r10 - 8) = r1; r2 = r10; r2 += -8; r1 = map_hash_48b ll; call 1; if r0 == 0 goto l0_1; r1 = *(u32*)(r0 + 0); r9 = 1; w1 %= 2; w1 += 1; w9 &= w1; w9 += 1; w9 >>= 1; w3 = 1; w3 -= w9; w3 *= 0x10000000; r0 += r3; *(u32*)(r0 + 0) = r3; l0_1: r0 = r0; exit;
^
1 error generated.
make: *** [Makefile:598: /usr/src/linux/tools/testing/selftests/bpf/verifier_and.bpf.o] Error 1
make: Leaving directory '/usr/src/linux/tools/testing/selftests/bpf'
----------------------------------------
^ permalink raw reply [flat|nested] 7+ messages in thread* Re: Is tools/testing/selftests/bpf/ maintained?
2023-10-13 13:15 ` Tetsuo Handa
@ 2023-10-13 13:25 ` Eduard Zingerman
2023-10-13 14:17 ` Tetsuo Handa
0 siblings, 1 reply; 7+ messages in thread
From: Eduard Zingerman @ 2023-10-13 13:25 UTC (permalink / raw)
To: Tetsuo Handa; +Cc: bpf, KP Singh
On Fri, 2023-10-13 at 22:15 +0900, Tetsuo Handa wrote:
> Thank you for showing complete command line.
>
> On 2023/10/13 1:34, Eduard Zingerman wrote:
> > # Note: kernel build is mandatory, as vmlinux.h is constructed from DWARF in ./vmlinux
>
> is what I was missing. Makefile rules should explicitly describe dependency on vmlinux ,
> or at least emit message to teach users about the need to build vmlinux ?
Yes, that would be nice.
> But I still get error. I'm using Ubuntu 22.04.3 LTS.
I think you are using clang-14, which does not like u32 instructions.
At least I get the same error message as you with clang-14.
If so, please try using clang-16 instead.
>
> ----------------------------------------
> root@ubuntu:/usr/src/linux# make -C tools/testing/selftests/bpf/
> make: Entering directory '/usr/src/linux/tools/testing/selftests/bpf'
> CLNG-BPF [test_maps] verifier_and.bpf.o
> progs/verifier_and.c:58:16: error: invalid operand for instruction
> asm volatile (" \
> ^
> <inline asm>:1:184: note: instantiated into assembly here
> r1 = 0; *(u64*)(r10 - 8) = r1; r2 = r10; r2 += -8; r1 = map_hash_48b ll; call 1; if r0 == 0 goto l0_1; r1 = *(u32*)(r0 + 0); r9 = 1; w1 %= 2; w1 += 1; w9 &= w1; w9 += 1; w9 >>= 1; w3 = 1; w3 -= w9; w3 *= 0x10000000; r0 += r3; *(u32*)(r0 + 0) = r3; l0_1: r0 = r0; exit;
> ^
> 1 error generated.
> make: *** [Makefile:598: /usr/src/linux/tools/testing/selftests/bpf/verifier_and.bpf.o] Error 1
> make: Leaving directory '/usr/src/linux/tools/testing/selftests/bpf'
> ----------------------------------------
>
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: Is tools/testing/selftests/bpf/ maintained?
2023-10-12 13:39 Is tools/testing/selftests/bpf/ maintained? Tetsuo Handa
2023-10-12 16:34 ` Eduard Zingerman
@ 2023-10-12 16:35 ` Andrii Nakryiko
1 sibling, 0 replies; 7+ messages in thread
From: Andrii Nakryiko @ 2023-10-12 16:35 UTC (permalink / raw)
To: Tetsuo Handa; +Cc: bpf, KP Singh
On Thu, Oct 12, 2023 at 6:40 AM Tetsuo Handa
<penguin-kernel@i-love.sakura.ne.jp> wrote:
>
> Hello.
>
> I'm having problem with finding BPF LSM examples that work.
> I tried building tools/testing/selftests/bpf/progs/lsm.c and
> tools/testing/selftests/bpf/prog_tests/test_lsm.c explained at
> https://docs.kernel.org/bpf/prog_lsm.html , but got a lot of errors.
Make sure you a) have necessary kernel configs set up (see [0], there
are also arch-specific configs) and b) build kernel before building
selftests, because selftests generate vmlinux.h header with all kernel
types based on latest built kernel image.
[0] https://git.kernel.org/pub/scm/linux/kernel/git/bpf/bpf-next.git/tree/tools/testing/selftests/bpf/config
>
> ----------------------------------------
> root@ubuntu:/usr/src# git clone https://kernel.googlesource.com/pub/scm/linux/kernel/git/torvalds/linux.git
> Cloning into 'linux'...
> remote: Total 9723739 (delta 8227084), reused 9723739 (delta 8227084)
> Receiving objects: 100% (9723739/9723739), 1.81 GiB | 4.04 MiB/s, done.
> Resolving deltas: 100% (8227084/8227084), done.
> Checking objects: 100% (33554432/33554432), done.
> Updating files: 100% (81759/81759), done.
> root@ubuntu:/usr/src# cd linux
> root@ubuntu:/usr/src/linux# git describe
> v6.6-rc5-72-g401644852d0b
> root@ubuntu:/usr/src/linux# make -s headers
> root@ubuntu:/usr/src/linux# make -sC tools/testing/selftests/bpf/
> MKDIR libbpf
> Warning: Kernel ABI header at 'tools/include/uapi/linux/if_xdp.h' differs from latest version at 'include/uapi/linux/if_xdp.h'
> TEST-HDR [test_progs] tests.h
> EXT-OBJ [test_progs] testing_helpers.o
> EXT-OBJ [test_progs] cap_helpers.o
> EXT-OBJ [test_progs] unpriv_helpers.o
> BINARY test_verifier
> BINARY test_tag
> MKDIR bpftool
>
> GEN vmlinux.h
> CLNG-BPF [test_maps] async_stack_depth.bpf.o
> progs/async_stack_depth.c:8:19: error: field has incomplete type 'struct bpf_timer'
> struct bpf_timer timer;
> ^
> /usr/src/linux/tools/testing/selftests/bpf/tools/include/bpf/bpf_helper_defs.h:41:8: note: forward declaration of 'struct bpf_timer'
> struct bpf_timer;
> ^
> 1 error generated.
> make: *** [Makefile:598: /usr/src/linux/tools/testing/selftests/bpf/async_stack_depth.bpf.o] Error 1
> ----------------------------------------
>
> To fix these errors, something like the following
> (this seems to be a fraction) is needed. What am I missing?
>
kernel image used for vmlinux.h generation is probably too old
[...]
^ permalink raw reply [flat|nested] 7+ messages in thread
end of thread, other threads:[~2023-10-13 14:23 UTC | newest]
Thread overview: 7+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2023-10-12 13:39 Is tools/testing/selftests/bpf/ maintained? Tetsuo Handa
2023-10-12 16:34 ` Eduard Zingerman
2023-10-13 13:15 ` Tetsuo Handa
2023-10-13 13:25 ` Eduard Zingerman
2023-10-13 14:17 ` Tetsuo Handa
2023-10-13 14:23 ` Eduard Zingerman
2023-10-12 16:35 ` Andrii Nakryiko
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox