Skip to content

Commit 764ad6b

Browse files
author
Benjamin Tissoires
committed
HID: bpf: use __bpf_kfunc instead of noinline
Follow the docs at Documentation/bpf/kfuncs.rst: - declare the function with `__bpf_kfunc` - disables missing prototype warnings, which allows to remove them from include/linux/hid-bpf.h Removing the prototypes is not an issue because we currently have to redeclare them when writing the BPF program. They will eventually be generated by bpftool directly AFAIU. Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Benjamin Tissoires <[email protected]>
1 parent 89be8aa commit 764ad6b

File tree

2 files changed

+13
-16
lines changed

2 files changed

+13
-16
lines changed

drivers/hid/bpf/hid_bpf_dispatch.c

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -143,6 +143,9 @@ u8 *call_hid_bpf_rdesc_fixup(struct hid_device *hdev, u8 *rdesc, unsigned int *s
143143
}
144144
EXPORT_SYMBOL_GPL(call_hid_bpf_rdesc_fixup);
145145

146+
/* Disables missing prototype warnings */
147+
__bpf_kfunc_start_defs();
148+
146149
/**
147150
* hid_bpf_get_data - Get the kernel memory pointer associated with the context @ctx
148151
*
@@ -152,7 +155,7 @@ EXPORT_SYMBOL_GPL(call_hid_bpf_rdesc_fixup);
152155
*
153156
* @returns %NULL on error, an %__u8 memory pointer on success
154157
*/
155-
noinline __u8 *
158+
__bpf_kfunc __u8 *
156159
hid_bpf_get_data(struct hid_bpf_ctx *ctx, unsigned int offset, const size_t rdwr_buf_size)
157160
{
158161
struct hid_bpf_ctx_kern *ctx_kern;
@@ -167,6 +170,7 @@ hid_bpf_get_data(struct hid_bpf_ctx *ctx, unsigned int offset, const size_t rdwr
167170

168171
return ctx_kern->data + offset;
169172
}
173+
__bpf_kfunc_end_defs();
170174

171175
/*
172176
* The following set contains all functions we agree BPF programs
@@ -274,6 +278,9 @@ static int do_hid_bpf_attach_prog(struct hid_device *hdev, int prog_fd, struct b
274278
return fd;
275279
}
276280

281+
/* Disables missing prototype warnings */
282+
__bpf_kfunc_start_defs();
283+
277284
/**
278285
* hid_bpf_attach_prog - Attach the given @prog_fd to the given HID device
279286
*
@@ -286,7 +293,7 @@ static int do_hid_bpf_attach_prog(struct hid_device *hdev, int prog_fd, struct b
286293
* is pinned to the BPF file system).
287294
*/
288295
/* called from syscall */
289-
noinline int
296+
__bpf_kfunc int
290297
hid_bpf_attach_prog(unsigned int hid_id, int prog_fd, __u32 flags)
291298
{
292299
struct hid_device *hdev;
@@ -338,7 +345,7 @@ hid_bpf_attach_prog(unsigned int hid_id, int prog_fd, __u32 flags)
338345
*
339346
* @returns A pointer to &struct hid_bpf_ctx on success, %NULL on error.
340347
*/
341-
noinline struct hid_bpf_ctx *
348+
__bpf_kfunc struct hid_bpf_ctx *
342349
hid_bpf_allocate_context(unsigned int hid_id)
343350
{
344351
struct hid_device *hdev;
@@ -371,7 +378,7 @@ hid_bpf_allocate_context(unsigned int hid_id)
371378
* @ctx: the HID-BPF context to release
372379
*
373380
*/
374-
noinline void
381+
__bpf_kfunc void
375382
hid_bpf_release_context(struct hid_bpf_ctx *ctx)
376383
{
377384
struct hid_bpf_ctx_kern *ctx_kern;
@@ -397,7 +404,7 @@ hid_bpf_release_context(struct hid_bpf_ctx *ctx)
397404
*
398405
* @returns %0 on success, a negative error code otherwise.
399406
*/
400-
noinline int
407+
__bpf_kfunc int
401408
hid_bpf_hw_request(struct hid_bpf_ctx *ctx, __u8 *buf, size_t buf__sz,
402409
enum hid_report_type rtype, enum hid_class_request reqtype)
403410
{
@@ -465,6 +472,7 @@ hid_bpf_hw_request(struct hid_bpf_ctx *ctx, __u8 *buf, size_t buf__sz,
465472
kfree(dma_data);
466473
return ret;
467474
}
475+
__bpf_kfunc_end_defs();
468476

469477
/* our HID-BPF entrypoints */
470478
BTF_SET8_START(hid_bpf_fmodret_ids)

include/linux/hid_bpf.h

Lines changed: 0 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -77,17 +77,6 @@ enum hid_bpf_attach_flags {
7777
int hid_bpf_device_event(struct hid_bpf_ctx *ctx);
7878
int hid_bpf_rdesc_fixup(struct hid_bpf_ctx *ctx);
7979

80-
/* Following functions are kfunc that we export to BPF programs */
81-
/* available everywhere in HID-BPF */
82-
__u8 *hid_bpf_get_data(struct hid_bpf_ctx *ctx, unsigned int offset, const size_t __sz);
83-
84-
/* only available in syscall */
85-
int hid_bpf_attach_prog(unsigned int hid_id, int prog_fd, __u32 flags);
86-
int hid_bpf_hw_request(struct hid_bpf_ctx *ctx, __u8 *buf, size_t buf__sz,
87-
enum hid_report_type rtype, enum hid_class_request reqtype);
88-
struct hid_bpf_ctx *hid_bpf_allocate_context(unsigned int hid_id);
89-
void hid_bpf_release_context(struct hid_bpf_ctx *ctx);
90-
9180
/*
9281
* Below is HID internal
9382
*/

0 commit comments

Comments
 (0)