]> www.infradead.org Git - users/jedix/linux-maple.git/commit
HID: bpf: new hid_bpf_async.h common header
authorBenjamin Tissoires <bentiss@kernel.org>
Fri, 7 Feb 2025 13:56:02 +0000 (14:56 +0100)
committerBenjamin Tissoires <bentiss@kernel.org>
Mon, 24 Feb 2025 08:25:34 +0000 (09:25 +0100)
commit4a94deb94994a121d7a7ae21d9860445a14018fc
tree14b5ba365f0b44b95593acd53829a8090471da1b
parent91bb3115efdf30a5457f2b68805b2d21630a4f4a
HID: bpf: new hid_bpf_async.h common header

The purpose is to simplify the use of bpf_wq to defer blocking
operations in a sleepable context. Compared to a more "classic"
async approach, there is no sync mechanism to wait for the async
to finish.

The "simple" API is the following:

```

static int HID_BPF_ASYNC(async_fun)(struct hid_bpf_ctx *hctx)
{
        bpf_printk("%s", __fun__);
        return 0;
}

SEC("syscall")
int probe(struct hid_bpf_probe_args *ctx)
{
        ctx->retval = HID_BPF_ASYNC_INIT(async_fun);
        return 0;
}

SEC(HID_BPF_DEVICE_EVENT)
int BPF_PROG(event_handler, struct hid_bpf_ctx *hctx)
{
        /* async_fun() can be called now, it's not a sleepable
         * function in this example
         */
        async_fun(hctx);

        /* but we can also delay the call by 10 ms */
        HID_BPF_ASYNC_DELAYED_CALL(async_fun, hctx, 10);

        return 0;
}

HID_BPF_OPS(xppen_ack05_remote) = {
        .hid_device_event = (void *)event_handler,
};
```

Link: https://gitlab.freedesktop.org/libevdev/udev-hid-bpf/-/merge_requests/133
Acked-by: Jiri Kosina <jkosina@suse.com>
Link: https://patch.msgid.link/20250207-bpf-import-2025-02-07-v1-6-6048fdd5a206@kernel.org
Signed-off-by: Benjamin Tissoires <bentiss@kernel.org>
drivers/hid/bpf/progs/hid_bpf_async.h [new file with mode: 0644]