summaryrefslogtreecommitdiffstats
path: root/Documentation/hid
diff options
context:
space:
mode:
authorBenjamin Tissoires <benjamin.tissoires@redhat.com>2023-01-13 10:09:32 +0100
committerJiri Kosina <jkosina@suse.cz>2023-01-18 22:08:38 +0100
commit4b9a3f49f02bf682eedfde23ef56a8df82c1e5d2 (patch)
tree64a4570e557871a6abd43d5d799aba90baab032e /Documentation/hid
parent2574917a2b48f87bd45f1c3e6d80c976f4fe3c3d (diff)
downloadlinux-stable-4b9a3f49f02bf682eedfde23ef56a8df82c1e5d2.tar.gz
linux-stable-4b9a3f49f02bf682eedfde23ef56a8df82c1e5d2.tar.bz2
linux-stable-4b9a3f49f02bf682eedfde23ef56a8df82c1e5d2.zip
HID: bpf: rework how programs are attached and stored in the kernel
Previously, HID-BPF was relying on a bpf tracing program to be notified when a program was released from userspace. This is error prone, as LLVM sometimes inline the function and sometimes not. So instead of messing up with the bpf prog ref count, we can use the bpf_link concept which actually matches exactly what we want: - a bpf_link represents the fact that a given program is attached to a given HID device - as long as the bpf_link has fd opened (either by the userspace program still being around or by pinning the bpf object in the bpffs), the program stays attached to the HID device - once every user has closed the fd, we get called by hid_bpf_link_release() that we no longer have any users, and we can disconnect the program to the device in 2 passes: first atomically clear the bit saying that the link is active, and then calling release_work in a scheduled work item. This solves entirely the problems of BPF tracing not showing up and is definitely cleaner. Signed-off-by: Benjamin Tissoires <benjamin.tissoires@redhat.com> Acked-by: Alexei Starovoitov <ast@kernel.org> Signed-off-by: Jiri Kosina <jkosina@suse.cz>
Diffstat (limited to 'Documentation/hid')
-rw-r--r--Documentation/hid/hid-bpf.rst12
1 files changed, 11 insertions, 1 deletions
diff --git a/Documentation/hid/hid-bpf.rst b/Documentation/hid/hid-bpf.rst
index a55f191d49a3..c205f92b7bcc 100644
--- a/Documentation/hid/hid-bpf.rst
+++ b/Documentation/hid/hid-bpf.rst
@@ -427,12 +427,22 @@ program first::
prog_fd = bpf_program__fd(hid_skel->progs.attach_prog);
err = bpf_prog_test_run_opts(prog_fd, &tattrs);
- return err;
+ if (err)
+ return err;
+
+ return args.retval; /* the fd of the created bpf_link */
}
Our userspace program can now listen to notifications on the ring buffer, and
is awaken only when the value changes.
+When the userspace program doesn't need to listen to events anymore, it can just
+close the returned fd from :c:func:`attach_filter`, which will tell the kernel to
+detach the program from the HID device.
+
+Of course, in other use cases, the userspace program can also pin the fd to the
+BPF filesystem through a call to :c:func:`bpf_obj_pin`, as with any bpf_link.
+
Controlling the device
----------------------