Message ID | 20230113090935.1763477-1-benjamin.tissoires@redhat.com |
---|---|
Headers | show |
Series | HID-BPF LLVM fixes, no more hacks | expand |
On Fri, Jan 13, 2023 at 10:09:32AM +0100, Benjamin Tissoires wrote: > 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>
On Fri, Jan 13, 2023 at 10:09:34AM +0100, Benjamin Tissoires wrote: > We don't need to watch for calls on bpf_prog_put_deferred(), so remove > that from the entrypoints.bpf.c file. > > Signed-off-by: Benjamin Tissoires <benjamin.tissoires@redhat.com> Acked-by: Alexei Starovoitov <ast@kernel.org>
On Fri, 13 Jan 2023, Benjamin Tissoires wrote: > Hi, > > So this is the fix for the bug that actually prevented me to integrate > HID-BPF in v6.2. > > While testing the code base with LLVM, I realized that clang was smarter > than I expected it to be, and it sometimes inlined a function or not > depending on the branch. This lead to segfaults because my current code > in linux-next is messing up the bpf programs refcounts assuming that I > had enough observability over the kernel. > > So I came back to the drawing board and realized that what I was missing > was exactly a bpf_link, to represent the attachment of a bpf program to > a HID device. This is the bulk of the series, in patch 6/9. > > The other patches are cleanups, tests, and also the addition of the > vmtests.sh script I run locally, largely inspired by the one in the bpf > selftests dir. This allows very fast development of HID-BPF, assuming we > have tests that cover the bugs :) > > > changes in v2: > - took Alexei's remarks into account and renamed the indexes into > prog_table_index and hid_table_index > - fixed unused function as reported by the Intel kbuild bot I've now applied this on top of the previous work in hid.git#for-6.3/hid-bpf