On Thu Jul 3, 2025 at 8:31 PM CEST, Ihor Solodrai wrote: > On 7/3/25 2:02 AM, Alexis Lothoré (eBPF Foundation) wrote: >> Add a small kernel module representing specific cases likely absent from >> standard vmlinux files. As a starter, the introduced module exposes a >> few functions consuming structs passed by value, some passed by >> register, some passed on the stack: >> >> int kmod_test_init(void); >> int test_kmod_func_ok(int, void *, char, short int); >> int test_kmod_func_struct_ok(int, void *, char, struct kmod_struct); >> int test_kmod_func_struct_on_stack_ok(int, void *, char, short int, int, \ >> void *, char, short int, struct kmod_struct); >> int test_kmod_func_struct_on_stack_ko(int, void *, char, short int, int, \ >> void *, char, short int, struct kmod_struct_packed); >> >> Then enrich btf_functions.sh to make it perform the following steps: >> - build the module >> - generate BTF info and pfunct listing, both with dwarf and the >> generated BTF >> - check that any function encoded in BTF is found in DWARF >> - check that any function announced as skipped is indeed absent from BTF >> - check that any skipped function has been skipped due to uncertain >> parameter location >> >> Those new tests are executed only if a kernel directory is provided as >> script's second argument, they are otherwise skipped. > > While this shouldn't be a problem for CI, since it checks out a kernel > tree to test vmlinux as input, I wonder if there is a way to do the > same test without this dependency. > > We need to generate a binary with DWARF, containing function > prototypes with packed/aligned attributes. Give it to pahole and see > that those functions were skipped. > > Any reason it must be a kernel module? Am I missing something? I guess I have no valid reason, I just focused too much on a specific use case :) It would indeed be simpler with a bare userspace binary, I'll check further and change it. >> Example of the new test execution: >> Encoding...Matched 4 functions exactly. >> Ok >> Validation of skipped function logic... >> Skipped encoding 1 functions in BTF. >> Ok >> Validating skipped functions have uncertain parameter location... >> Found 1 legitimately skipped function due to uncertain loc >> Ok > This part fails for me: > > isolodrai@isolodrai-fedora-PC2K40WQ:~/pahole/tests$ > KDIR=/home/isolodrai/kernels/bpf-next > vmlinux=/home/isolodrai/kernels/bpf-next/vmlinux ./btf_functions.sh > Validation of BTF encoding of functions; this may take some time: Ok > Validation of BTF encoding corner cases with kmod functions; this may > take some time: make: Entering directory '/home/isolodrai/kernels/bpf-next' > Makefile:199: *** specified external module directory "./kmod" does not > exist. Stop. > make: Leaving directory '/home/isolodrai/kernels/bpf-next' > No skipped functions. Done. > > Maybe: > > diff --git a/tests/btf_functions.sh b/tests/btf_functions.sh > index 64810b7..fcb1591 100755 > --- a/tests/btf_functions.sh > +++ b/tests/btf_functions.sh > @@ -208,7 +208,7 @@ fi > echo -n "Validation of BTF encoding corner cases with kmod functions; > this may take some time: " > > test -n "$VERBOSE" && printf "\nBuilding kmod..." > -tests_dir=$(dirname $0) > +tests_dir=$(realpath $(dirname $0)) > make -C ${KDIR} M=${tests_dir}/kmod > > test -n "$VERBOSE" && printf "\nEncoding..." > > > Also, in case kernel is built with LLVM, one must set LLVM=1. > Not sure if this is detectable by the test. Yeah, the tests_dir computation is a bit fragile. I saw it in tests.sh, and so I assumed use cases were simple enough to keep this simple logic. I'll update it to make it more robust. Alexis -- Alexis Lothoré, Bootlin Embedded Linux and Kernel engineering https://bootlin.com