summaryrefslogtreecommitdiff
path: root/drivers/hid/bpf/entrypoints/entrypoints.bpf.c
diff options
context:
space:
mode:
authorBenjamin Tissoires <benjamin.tissoires@redhat.com>2022-11-03 18:57:46 +0300
committerJiri Kosina <jkosina@suse.cz>2022-11-15 18:28:29 +0300
commit0baef37335dd4d5cffd00c9b8bbf2e0b71e4239f (patch)
tree725677ea14136fc403a1aeba36a5b0caa0dad86b /drivers/hid/bpf/entrypoints/entrypoints.bpf.c
parentdbb60c8a26daf388f183f599e1e96de5bb9f96e1 (diff)
downloadlinux-0baef37335dd4d5cffd00c9b8bbf2e0b71e4239f.tar.xz
HID: bpf jmp table: simplify the logic of cleaning up programs
Kind of a hack, but works for now: Instead of listening for any close of eBPF program, we now decrement the refcount when we insert it in our internal map of fd progs. This is safe to do because: - we listen to any call of destructor of programs - when a program is being destroyed, we disable it by removing it from any RCU list used by any HID device (so it will never be called) - we then trigger a job to cleanup the prog fd map, but we overwrite the removal of the elements to not do anything on the programs, just remove the allocated space This is better than previously because we can remove the map of known programs and their usage count. We now rely on the refcount of bpf, which has greater chances of being accurate. Signed-off-by: Benjamin Tissoires <benjamin.tissoires@redhat.com> Signed-off-by: Jiri Kosina <jkosina@suse.cz>
Diffstat (limited to 'drivers/hid/bpf/entrypoints/entrypoints.bpf.c')
-rw-r--r--drivers/hid/bpf/entrypoints/entrypoints.bpf.c40
1 files changed, 4 insertions, 36 deletions
diff --git a/drivers/hid/bpf/entrypoints/entrypoints.bpf.c b/drivers/hid/bpf/entrypoints/entrypoints.bpf.c
index 41dd66d5fc7a..7c1895d9e5c0 100644
--- a/drivers/hid/bpf/entrypoints/entrypoints.bpf.c
+++ b/drivers/hid/bpf/entrypoints/entrypoints.bpf.c
@@ -7,7 +7,7 @@
#define HID_BPF_MAX_PROGS 1024
-extern bool call_hid_bpf_prog_release(u64 prog, int table_cnt) __ksym;
+extern void call_hid_bpf_prog_put_deferred(struct work_struct *work) __ksym;
struct {
__uint(type, BPF_MAP_TYPE_PROG_ARRAY);
@@ -16,13 +16,6 @@ struct {
__uint(value_size, sizeof(__u32));
} hid_jmp_table SEC(".maps");
-struct {
- __uint(type, BPF_MAP_TYPE_HASH);
- __uint(max_entries, HID_BPF_MAX_PROGS * HID_BPF_PROG_TYPE_MAX);
- __type(key, void *);
- __type(value, __u8);
-} progs_map SEC(".maps");
-
SEC("fmod_ret/__hid_bpf_tail_call")
int BPF_PROG(hid_tail_call, struct hid_bpf_ctx *hctx)
{
@@ -31,35 +24,10 @@ int BPF_PROG(hid_tail_call, struct hid_bpf_ctx *hctx)
return 0;
}
-static void release_prog(u64 prog)
-{
- u8 *value;
-
- value = bpf_map_lookup_elem(&progs_map, &prog);
- if (!value)
- return;
-
- if (call_hid_bpf_prog_release(prog, *value))
- bpf_map_delete_elem(&progs_map, &prog);
-}
-
-SEC("fexit/bpf_prog_release")
-int BPF_PROG(hid_prog_release, struct inode *inode, struct file *filp)
+SEC("fentry/bpf_prog_put_deferred")
+int BPF_PROG(hid_bpf_prog_put_deferred, struct work_struct *work)
{
- u64 prog = (u64)filp->private_data;
-
- release_prog(prog);
-
- return 0;
-}
-
-SEC("fexit/bpf_free_inode")
-int BPF_PROG(hid_free_inode, struct inode *inode)
-{
- u64 prog = (u64)inode->i_private;
-
- release_prog(prog);
-
+ call_hid_bpf_prog_put_deferred(work);
return 0;
}