]> git.ipfire.org Git - thirdparty/kernel/linux.git/commit
hid: bpf: hid_bpf_helpers: add helper for having read/write udev properties
authorBenjamin Tissoires <bentiss@kernel.org>
Fri, 3 Apr 2026 16:12:23 +0000 (18:12 +0200)
committerJiri Kosina <jkosina@suse.com>
Wed, 8 Apr 2026 19:46:00 +0000 (21:46 +0200)
commitbb8be68d1280eff1abb697136b54576af218b266
tree957ae60adba2d1b470af1d18c7125be87512cf0c
parentfc778f21a18e79cfb1ad17b7af0478e21ab41daf
hid: bpf: hid_bpf_helpers: add helper for having read/write udev properties

We want udev-hid-bpf to be able to set udev properties by printing them
out after the BPF object has been loaded. This allows to make a query to
the device, and set a udev prop based on the answer.

Because the way udev works, the properties are cleared on bind/unbind,
and we need a way to store them. After several attempts to keep the
property alive without re-running the udev-hid-bpf tool to communicate
with the device, it came out that HID-BPF maps are pinned in the bpffs
and we can then query them.

So the following would export a UDEV property in the bpffs:
   EXPORT_UDEV_PROP(HID_FOO, 32);

   SEC("syscall")
   int probe(struct hid_bpf_probe_args *ctx)
   {
     const char *foo = "foo";
     UDEV_PROP_SPRINTF(HID_FOO, "%s", foo);

     return 0;
   }

Then, we can debug it with a simple cat:
   sudo cat /sys/fs/bpf/hid/.../UDEV_PROP_HID_FOO
0: {['f','o','o',],}

This way, the property is always accessible without talking to the
device

Link: https://gitlab.freedesktop.org/libevdev/udev-hid-bpf/-/merge_requests/220
Signed-off-by: Benjamin Tissoires <bentiss@kernel.org>
Signed-off-by: Jiri Kosina <jkosina@suse.com>
drivers/hid/bpf/progs/hid_bpf_helpers.h