mirror of
https://github.com/lkl/linux.git
synced 2025-12-19 08:03:01 +09:00
HID: initial BPF implementation
Declare an entry point that can use fmod_ret BPF programs, and also an API to access and change the incoming data. A simpler implementation would consist in just calling hid_bpf_device_event() for any incoming event and let users deal with the fact that they will be called for any event of any device. The goal of HID-BPF is to partially replace drivers, so this situation can be problematic because we might have programs which will step on each other toes. For that, we add a new API hid_bpf_attach_prog() that can be called from a syscall and we manually deal with a jump table in hid-bpf. Whenever we add a program to the jump table (in other words, when we attach a program to a HID device), we keep the number of time we added this program in the jump table so we can release it whenever there are no other users. HID devices have an RCU protected list of available programs in the jump table, and those programs are called one after the other thanks to bpf_tail_call(). To achieve the detection of users losing their fds on the programs we attached, we add 2 tracing facilities on bpf_prog_release() (for when a fd is closed) and bpf_free_inode() (for when a pinned program gets unpinned). Reviewed-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org> Signed-off-by: Benjamin Tissoires <benjamin.tissoires@redhat.com> Signed-off-by: Jiri Kosina <jkosina@suse.cz>
This commit is contained in:
committed by
Jiri Kosina
parent
25621bcc89
commit
f5c27da4e3
@@ -26,6 +26,7 @@
|
||||
#include <linux/mutex.h>
|
||||
#include <linux/power_supply.h>
|
||||
#include <uapi/linux/hid.h>
|
||||
#include <linux/hid_bpf.h>
|
||||
|
||||
/*
|
||||
* We parse each description item into this structure. Short items data
|
||||
@@ -651,6 +652,10 @@ struct hid_device { /* device report descriptor */
|
||||
wait_queue_head_t debug_wait;
|
||||
|
||||
unsigned int id; /* system unique id */
|
||||
|
||||
#ifdef CONFIG_BPF
|
||||
struct hid_bpf bpf; /* hid-bpf data */
|
||||
#endif /* CONFIG_BPF */
|
||||
};
|
||||
|
||||
#define to_hid_device(pdev) \
|
||||
|
||||
Reference in New Issue
Block a user