[PATCH 00/18] HID: Include current HID-BPF fixes in tree

From: Benjamin Tissoires
Date: Wed Apr 10 2024 - 13:20:00 EST


When I introduced HID-BPF, I mentioned that we should ship the HID-BPF
programs in the kernel when they are fixes so that everybody can benefit
from them.

I tried multiple times to do so but I was confronted to a tough problem:
how can I make the kernel load them automatically?

I went over a few solutions, but it always came down to something either
ugly, or either not satisfying (like forcing `bpftool` to be compiled
first, or not being able to insert them as a module).

OTOH, I was working with Peter on `udev-hid-bpf`[0] as a proof of
concept on how a minimal loader should look like. This allowed me to
experiment on the BPF files and how they should look like.

And after further thoughts, I realized that `udev-hid-bpf` could very
well be the `kmod load` that we currently have:
- the kernel handles the device normally
- a udev event is emitted
- a udev rule fires `udev-hid-bpf` and load the appropriate HID-BPF
file(s) based on the modalias

Given that most HID devices are supposed to work to a minimal level when
connected without any driver, this makes the whole HID-BPF programs nice
to have but not critical. We can then postpone the HID-BPF loading when
userspace is ready.

Working with HID-BPF is also a much better user experience for end users
(as I predicted). All they have to do is to go to the `udev-hid-bpf`
project, fetch an artifact from the MR that concerns them, run
`install.sh` (no compilation required), and their devices are fixed
(minus some back and forth when the HID-BPF program needs some changes).

So I already have that loader available, and it works well enough for
our users. But the missing point was still how to "upstream" those BPF
fixes?

That's where this patch series comes in: we simply store the fixes in
the kernel under `drivers/hid/bpf/progs`, provide a way to compile them,
but also add tests for them in the selftests dir.

Once a program is accepted here, for convenience, the same program will
move from a "testing" directory to a "stable" directory on
`udev-hid-bpf`. This way, distributions don't need to follow when there
is a new program added here, they can just ship the "stable" ones from
`udev-hid-bpf`.

Signed-off-by: Benjamin Tissoires <bentiss@xxxxxxxxxx>

[0] https://gitlab.freedesktop.org/libevdev/udev-hid-bpf/

---
Benjamin Tissoires (18):
HID: do not assume HAT Switch logical max < 8
HID: bpf: add first in-tree HID-BPF fix for the XPPen Artist 24
HID: bpf: add in-tree HID-BPF fix for the XPPen Artist 16
HID: bpf: add in-tree HID-BPF fix for the HP Elite Presenter Mouse
HID: bpf: add in-tree HID-BPF fix for the IOGear Kaliber Gaming MMOmentum mouse
HID: bpf: add in-tree HID-BPF fix for the Wacom ArtPen
HID: bpf: add in-tree HID-BPF fix for the XBox Elite 2 over Bluetooth
HID: bpf: add in-tree HID-BPF fix for the Huion Kamvas Pro 19
HID: bpf: add in-tree HID-BPF fix for the Raptor Mach 2
selftests/hid: import base_device.py from hid-tools
selftests/hid: add support for HID-BPF pre-loading before starting a test
selftests/hid: tablets: reduce the number of pen state
selftests/hid: tablets: add a couple of XP-PEN tablets
selftests/hid: tablets: also check for XP-Pen offset correction
selftests/hid: add Huion Kamvas Pro 19 tests
selftests/hid: import base_gamepad.py from hid-tools
selftests/hid: move the gamepads definitions in the test file
selftests/hid: add tests for the Raptor Mach 2 joystick

drivers/hid/bpf/progs/FR-TEC__Raptor-Mach-2.bpf.c | 185 ++++++
drivers/hid/bpf/progs/HP__Elite-Presenter.bpf.c | 58 ++
drivers/hid/bpf/progs/Huion__Kamvas-Pro-19.bpf.c | 290 +++++++++
.../hid/bpf/progs/IOGEAR__Kaliber-MMOmentum.bpf.c | 59 ++
drivers/hid/bpf/progs/Makefile | 91 +++
.../hid/bpf/progs/Microsoft__XBox-Elite-2.bpf.c | 133 ++++
drivers/hid/bpf/progs/README | 102 +++
drivers/hid/bpf/progs/Wacom__ArtPen.bpf.c | 173 +++++
drivers/hid/bpf/progs/XPPen__Artist24.bpf.c | 229 +++++++
drivers/hid/bpf/progs/XPPen__ArtistPro16Gen2.bpf.c | 274 ++++++++
drivers/hid/bpf/progs/hid_bpf.h | 15 +
drivers/hid/bpf/progs/hid_bpf_helpers.h | 170 +++++
include/linux/hid.h | 6 +-
tools/testing/selftests/hid/tests/base.py | 87 ++-
tools/testing/selftests/hid/tests/base_device.py | 421 ++++++++++++
tools/testing/selftests/hid/tests/base_gamepad.py | 238 +++++++
tools/testing/selftests/hid/tests/test_gamepad.py | 457 ++++++++++++-
tools/testing/selftests/hid/tests/test_tablet.py | 723 +++++++++++++++------
18 files changed, 3507 insertions(+), 204 deletions(-)
---
base-commit: 3e78a6c0d3e02e4cf881dc84c5127e9990f939d6
change-id: 20240328-bpf_sources-be1f3c617c5e

Best regards,
--
Benjamin Tissoires <bentiss@xxxxxxxxxx>