selftests/hid: ensure we can compile the tests on kernels pre-6.3
authorBenjamin Tissoires <bentiss@kernel.org>
Thu, 5 Oct 2023 15:55:32 +0000 (17:55 +0200)
committerBenjamin Tissoires <bentiss@kernel.org>
Wed, 11 Oct 2023 12:02:54 +0000 (14:02 +0200)
commitae7487d112cf9f310d32f27d5956f53d9f143fea
tree9ffe6aba1af30560034221f66d48a780535bd0a6
parent19fbf677b2530740d71d4fb64ab2de0dbdc31111
selftests/hid: ensure we can compile the tests on kernels pre-6.3

For the hid-bpf tests to compile, we need to have the definition of
struct hid_bpf_ctx. This definition is an internal one from the kernel
and it is supposed to be defined in the generated vmlinux.h.

This vmlinux.h header is generated based on the currently running kernel
or if the kernel was already compiled in the tree. If you just compile
the selftests without compiling the kernel beforehand and you are running
on a 6.2 kernel, you'll end up with a vmlinux.h without the hid_bpf_ctx
definition.

Use the clever trick from tools/testing/selftests/bpf/progs/bpf_iter.h
to force the definition of that symbol in case we don't find it in the
BTF and also add __attribute__((preserve_access_index)) to further
support CO-RE functionality for these tests.

Signed-off-by: Justin Stitt <justinstitt@google.com>
Tested-by: Nick Desaulniers <ndesaulniers@google.com> # Build
Tested-by: Justin Stitt <justinstitt@google.com>
Link: https://lore.kernel.org/r/20230825-wip-selftests-v3-1-639963c54109@kernel.org
Signed-off-by: Benjamin Tissoires <bentiss@kernel.org>
tools/testing/selftests/hid/progs/hid.c
tools/testing/selftests/hid/progs/hid_bpf_helpers.h