On Thu, Jan 18, 2024 at 05:58:20PM +0200, Eduard Zingerman wrote:
> On Thu, 2024-01-18 at 19:58 +0800, Shung-Hsi Yu wrote:
> > Compilation of lsm_cgroup.c will fail if the vmlinux.h comes from a
> > kernel that does _not_ have CONFIG_PACKET=y. The reason is that the
> > definition of struct sockaddr_ll is not present in vmlinux.h and the
> > compiler will complain that is has an incomplete type.
> >
> > CLNG-BPF [test_maps] lsm_cgroup.bpf.o
> > progs/lsm_cgroup.c:105:21: error: variable has incomplete type 'struct
> > sockaddr_ll'
> > 105 | struct sockaddr_ll sa = {};
> > | ^
> > progs/lsm_cgroup.c:105:9: note: forward declaration of 'struct
> > sockaddr_ll'
> > 105 | struct sockaddr_ll sa = {};
> > | ^
> > 1 error generated.
> >
> > [...]
>
> Hi Shung-Hsi,
>
> One option is to use CO-RE, e.g. as at the bottom of this email
> (not sure if people would agree with me).
> But that would not produce usable test anyways,
> as load would fail with unresolved CO-RE relocation.
>
> But what is your final goal?
Final goal would be have BPF selftests compiled and test against our own
kernel, without having to come up with a specific kernel flavor that is
used to build and run the selftest. For v5.14 and v5.19-based kernel it
works: compilation is successful and I was able to run the verifier
tests. (Did not try running the other tests though)
> As far as I understand, selftests are supposed to be built and run
> using specific configuration, here is how config for x86 CI is prepared:
>
> ./scripts/kconfig/merge_config.sh \
> ./tools/testing/selftests/bpf/config \
> ./tools/testing/selftests/bpf/config.vm \
> ./tools/testing/selftests/bpf/config.x86_64
>
> (root is kernel source).
> I'm not sure if other configurations are supposed to be supported.
Would it make sense to have makefile target that builds/runs a smaller
subset of general, config-agnostic selftests that tests the core feature
(e.g. verifier + instruction set)?
> [...]