Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

selftests/hid: fix kfunc inclusions with newer bpftool

bpftool now embeds the kfuncs definitions directly in the generated
vmlinux.h

This is great, but because the selftests dir might be compiled with
HID_BPF disabled, we have no guarantees to be able to compile the
sources with the generated kfuncs.

If we have the kfuncs, because we have the `__not_used` hack, the newly
defined kfuncs do not match the ones from vmlinux.h and things go wrong.

Prevent vmlinux.h to define its kfuncs and also add the missing `__weak`
symbols for our custom kfuncs definitions

Link: https://patch.msgid.link/20241128-fix-new-bpftool-v1-1-c9abdf94a719@kernel.org
Signed-off-by: Benjamin Tissoires <bentiss@kernel.org>

+11 -8
+11 -8
tools/testing/selftests/hid/progs/hid_bpf_helpers.h
··· 22 22 #define HID_REQ_SET_IDLE HID_REQ_SET_IDLE___not_used 23 23 #define HID_REQ_SET_PROTOCOL HID_REQ_SET_PROTOCOL___not_used 24 24 25 + /* do not define kfunc through vmlinux.h as this messes up our custom hack */ 26 + #define BPF_NO_KFUNC_PROTOTYPES 27 + 25 28 #include "vmlinux.h" 26 29 27 30 #undef hid_bpf_ctx ··· 94 91 /* following are kfuncs exported by HID for HID-BPF */ 95 92 extern __u8 *hid_bpf_get_data(struct hid_bpf_ctx *ctx, 96 93 unsigned int offset, 97 - const size_t __sz) __ksym; 98 - extern struct hid_bpf_ctx *hid_bpf_allocate_context(unsigned int hid_id) __ksym; 99 - extern void hid_bpf_release_context(struct hid_bpf_ctx *ctx) __ksym; 94 + const size_t __sz) __weak __ksym; 95 + extern struct hid_bpf_ctx *hid_bpf_allocate_context(unsigned int hid_id) __weak __ksym; 96 + extern void hid_bpf_release_context(struct hid_bpf_ctx *ctx) __weak __ksym; 100 97 extern int hid_bpf_hw_request(struct hid_bpf_ctx *ctx, 101 98 __u8 *data, 102 99 size_t buf__sz, 103 100 enum hid_report_type type, 104 - enum hid_class_request reqtype) __ksym; 101 + enum hid_class_request reqtype) __weak __ksym; 105 102 extern int hid_bpf_hw_output_report(struct hid_bpf_ctx *ctx, 106 - __u8 *buf, size_t buf__sz) __ksym; 103 + __u8 *buf, size_t buf__sz) __weak __ksym; 107 104 extern int hid_bpf_input_report(struct hid_bpf_ctx *ctx, 108 105 enum hid_report_type type, 109 106 __u8 *data, 110 - size_t buf__sz) __ksym; 107 + size_t buf__sz) __weak __ksym; 111 108 extern int hid_bpf_try_input_report(struct hid_bpf_ctx *ctx, 112 109 enum hid_report_type type, 113 110 __u8 *data, 114 - size_t buf__sz) __ksym; 111 + size_t buf__sz) __weak __ksym; 115 112 116 113 /* bpf_wq implementation */ 117 114 extern int bpf_wq_init(struct bpf_wq *wq, void *p__map, unsigned int flags) __weak __ksym; 118 115 extern int bpf_wq_start(struct bpf_wq *wq, unsigned int flags) __weak __ksym; 119 116 extern int bpf_wq_set_callback_impl(struct bpf_wq *wq, 120 117 int (callback_fn)(void *map, int *key, void *wq), 121 - unsigned int flags__k, void *aux__ign) __ksym; 118 + unsigned int flags__k, void *aux__ign) __weak __ksym; 122 119 #define bpf_wq_set_callback(timer, cb, flags) \ 123 120 bpf_wq_set_callback_impl(timer, cb, flags, NULL) 124 121