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.orgSigned-off-by: Benjamin Tissoires <bentiss@kernel.org>
Showing
Please register or sign in to comment