mirror of
git://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
synced 2026-03-21 23:16:50 +08:00
This can happen in situations when CONFIG_HID_SUPPORT is set to no, or
some complex situations where struct bpf_wq is not exported.
So do the usual dance of hiding them before including vmlinux.h, and
then redefining them and make use of CO-RE to have the correct offsets.
Reported-by: kernel test robot <lkp@intel.com>
Closes: https://lore.kernel.org/oe-kbuild-all/202603111558.KLCIxsZB-lkp@intel.com/
Fixes: fe8d561db3 ("selftests/hid: add wq test for hid_bpf_input_report()")
Cc: stable@vger.kernel.org
Acked-by: Jiri Kosina <jkosina@suse.com>
Reviewed-by: Thomas Weißschuh <thomas.weissschuh@linutronix.de>
Signed-off-by: Benjamin Tissoires <bentiss@kernel.org>
136 lines
4.2 KiB
C
136 lines
4.2 KiB
C
/* SPDX-License-Identifier: GPL-2.0-only */
|
|
/* Copyright (c) 2022 Benjamin Tissoires
|
|
*/
|
|
|
|
#ifndef __HID_BPF_HELPERS_H
|
|
#define __HID_BPF_HELPERS_H
|
|
|
|
/* "undefine" structs and enums in vmlinux.h, because we "override" them below */
|
|
#define bpf_wq bpf_wq___not_used
|
|
#define hid_bpf_ctx hid_bpf_ctx___not_used
|
|
#define hid_bpf_ops hid_bpf_ops___not_used
|
|
#define hid_device hid_device___not_used
|
|
#define hid_report_type hid_report_type___not_used
|
|
#define hid_class_request hid_class_request___not_used
|
|
#define hid_bpf_attach_flags hid_bpf_attach_flags___not_used
|
|
#define HID_INPUT_REPORT HID_INPUT_REPORT___not_used
|
|
#define HID_OUTPUT_REPORT HID_OUTPUT_REPORT___not_used
|
|
#define HID_FEATURE_REPORT HID_FEATURE_REPORT___not_used
|
|
#define HID_REPORT_TYPES HID_REPORT_TYPES___not_used
|
|
#define HID_REQ_GET_REPORT HID_REQ_GET_REPORT___not_used
|
|
#define HID_REQ_GET_IDLE HID_REQ_GET_IDLE___not_used
|
|
#define HID_REQ_GET_PROTOCOL HID_REQ_GET_PROTOCOL___not_used
|
|
#define HID_REQ_SET_REPORT HID_REQ_SET_REPORT___not_used
|
|
#define HID_REQ_SET_IDLE HID_REQ_SET_IDLE___not_used
|
|
#define HID_REQ_SET_PROTOCOL HID_REQ_SET_PROTOCOL___not_used
|
|
|
|
/* do not define kfunc through vmlinux.h as this messes up our custom hack */
|
|
#define BPF_NO_KFUNC_PROTOTYPES
|
|
|
|
#include "vmlinux.h"
|
|
|
|
#undef bpf_wq
|
|
#undef hid_bpf_ctx
|
|
#undef hid_bpf_ops
|
|
#undef hid_device
|
|
#undef hid_report_type
|
|
#undef hid_class_request
|
|
#undef hid_bpf_attach_flags
|
|
#undef HID_INPUT_REPORT
|
|
#undef HID_OUTPUT_REPORT
|
|
#undef HID_FEATURE_REPORT
|
|
#undef HID_REPORT_TYPES
|
|
#undef HID_REQ_GET_REPORT
|
|
#undef HID_REQ_GET_IDLE
|
|
#undef HID_REQ_GET_PROTOCOL
|
|
#undef HID_REQ_SET_REPORT
|
|
#undef HID_REQ_SET_IDLE
|
|
#undef HID_REQ_SET_PROTOCOL
|
|
|
|
#include <bpf/bpf_helpers.h>
|
|
#include <bpf/bpf_tracing.h>
|
|
#include <linux/const.h>
|
|
|
|
enum hid_report_type {
|
|
HID_INPUT_REPORT = 0,
|
|
HID_OUTPUT_REPORT = 1,
|
|
HID_FEATURE_REPORT = 2,
|
|
|
|
HID_REPORT_TYPES,
|
|
};
|
|
|
|
struct hid_device {
|
|
unsigned int id;
|
|
} __attribute__((preserve_access_index));
|
|
|
|
struct bpf_wq {
|
|
__u64 __opaque[2];
|
|
};
|
|
|
|
struct hid_bpf_ctx {
|
|
struct hid_device *hid;
|
|
__u32 allocated_size;
|
|
union {
|
|
__s32 retval;
|
|
__s32 size;
|
|
};
|
|
} __attribute__((preserve_access_index));
|
|
|
|
enum hid_class_request {
|
|
HID_REQ_GET_REPORT = 0x01,
|
|
HID_REQ_GET_IDLE = 0x02,
|
|
HID_REQ_GET_PROTOCOL = 0x03,
|
|
HID_REQ_SET_REPORT = 0x09,
|
|
HID_REQ_SET_IDLE = 0x0A,
|
|
HID_REQ_SET_PROTOCOL = 0x0B,
|
|
};
|
|
|
|
struct hid_bpf_ops {
|
|
int hid_id;
|
|
u32 flags;
|
|
struct list_head list;
|
|
int (*hid_device_event)(struct hid_bpf_ctx *ctx, enum hid_report_type report_type,
|
|
u64 source);
|
|
int (*hid_rdesc_fixup)(struct hid_bpf_ctx *ctx);
|
|
int (*hid_hw_request)(struct hid_bpf_ctx *ctx, unsigned char reportnum,
|
|
enum hid_report_type rtype, enum hid_class_request reqtype,
|
|
u64 source);
|
|
int (*hid_hw_output_report)(struct hid_bpf_ctx *ctx, u64 source);
|
|
struct hid_device *hdev;
|
|
};
|
|
|
|
#ifndef BPF_F_BEFORE
|
|
#define BPF_F_BEFORE (1U << 3)
|
|
#endif
|
|
|
|
/* following are kfuncs exported by HID for HID-BPF */
|
|
extern __u8 *hid_bpf_get_data(struct hid_bpf_ctx *ctx,
|
|
unsigned int offset,
|
|
const size_t __sz) __weak __ksym;
|
|
extern struct hid_bpf_ctx *hid_bpf_allocate_context(unsigned int hid_id) __weak __ksym;
|
|
extern void hid_bpf_release_context(struct hid_bpf_ctx *ctx) __weak __ksym;
|
|
extern int hid_bpf_hw_request(struct hid_bpf_ctx *ctx,
|
|
__u8 *data,
|
|
size_t buf__sz,
|
|
enum hid_report_type type,
|
|
enum hid_class_request reqtype) __weak __ksym;
|
|
extern int hid_bpf_hw_output_report(struct hid_bpf_ctx *ctx,
|
|
__u8 *buf, size_t buf__sz) __weak __ksym;
|
|
extern int hid_bpf_input_report(struct hid_bpf_ctx *ctx,
|
|
enum hid_report_type type,
|
|
__u8 *data,
|
|
size_t buf__sz) __weak __ksym;
|
|
extern int hid_bpf_try_input_report(struct hid_bpf_ctx *ctx,
|
|
enum hid_report_type type,
|
|
__u8 *data,
|
|
size_t buf__sz) __weak __ksym;
|
|
|
|
/* bpf_wq implementation */
|
|
extern int bpf_wq_init(struct bpf_wq *wq, void *p__map, unsigned int flags) __weak __ksym;
|
|
extern int bpf_wq_start(struct bpf_wq *wq, unsigned int flags) __weak __ksym;
|
|
extern int bpf_wq_set_callback(struct bpf_wq *wq,
|
|
int (*callback_fn)(void *, int *, void *),
|
|
unsigned int flags) __weak __ksym;
|
|
|
|
#endif /* __HID_BPF_HELPERS_H */
|