Merge tag 'for-linus-2024071601' of git://git.kernel.org/pub/scm/linux/kernel/git/hid/hid
Pull HID updates from Benjamin Tissoires: - rewrite of the HID-BPF internal implementation to use bpf struct_ops instead of a tracing endpoint (Benjamin Tissoires) - add two new HID-BPF hooks to be able to intercept userspace calls targeting a HID device and filtering them (Benjamin Tissoires) - add support for various new devices through HID-BPF filters (Benjamin Tissoires) - add support for the magic keyboard backlight (Orlando Chamberlain) - add the missing MODULE_DESCRIPTION() macros in HID drivers (Jeff Johnson) - use of kvzalloc in case memory gets too fragmented (Hailong Liu) - retrieve the device firmware node in the child HID device (Danny Kaehn) - some hid-uclogic improvements (José Expósito) - some more typos, trivial fixes, kernel doctext and unused functions cleanups * tag 'for-linus-2024071601' of git://git.kernel.org/pub/scm/linux/kernel/git/hid/hid: (60 commits) HID: hid-steam: Fix typo in goto label HID: mcp2221: Remove unnecessary semicolon HID: Fix spelling mistakes "Kensigton" -> "Kensington" HID: add more missing MODULE_DESCRIPTION() macros HID: samples: fix the 2 struct_ops definitions HID: fix for amples in for-6.11/bpf HID: apple: Add support for magic keyboard backlight on T2 Macs HID: bpf: Thrustmaster TCA Yoke Boeing joystick fix HID: bpf: Add Huion Dial 2 bpf fixup HID: bpf: Add support for the XP-PEN Deco Mini 4 HID: bpf: move the BIT() macro to hid_bpf_helpers.h HID: bpf: add a driver for the Huion Inspiroy 2S (H641P) HID: bpf: Add a HID report composition helper macros HID: bpf: doc fixes for hid_hw_request() hooks HID: bpf: doc fixes for hid_hw_request() hooks HID: bpf: fix gcc warning and unify __u64 into u64 selftests/hid: ensure CKI can compile our new tests on old kernels selftests/hid: add an infinite loop test for hid_bpf_try_input_report selftests/hid: add another test for injecting an event from an event hook HID: bpf: allow hid_device_event hooks to inject input reports on self ...
This commit is contained in:
@@ -16,7 +16,6 @@ LIBBPF_DESTDIR = $(LIBBPF_OUTPUT)
|
||||
LIBBPF_INCLUDE = $(LIBBPF_DESTDIR)/include
|
||||
LIBBPF = $(LIBBPF_OUTPUT)/libbpf.a
|
||||
|
||||
EXTRA_HEADERS := hid_bpf_attach.h
|
||||
EXTRA_BPF_HEADERS := hid_bpf_helpers.h
|
||||
|
||||
hid_mouse-objs := hid_mouse.o
|
||||
@@ -207,8 +206,8 @@ $(obj)/%.bpf.o: $(src)/%.bpf.c $(EXTRA_BPF_HEADERS_SRC) $(obj)/vmlinux.h
|
||||
LINKED_SKELS := hid_mouse.skel.h hid_surface_dial.skel.h
|
||||
clean-files += $(LINKED_SKELS)
|
||||
|
||||
hid_mouse.skel.h-deps := hid_mouse.bpf.o hid_bpf_attach.bpf.o
|
||||
hid_surface_dial.skel.h-deps := hid_surface_dial.bpf.o hid_bpf_attach.bpf.o
|
||||
hid_mouse.skel.h-deps := hid_mouse.bpf.o
|
||||
hid_surface_dial.skel.h-deps := hid_surface_dial.bpf.o
|
||||
|
||||
LINKED_BPF_SRCS := $(patsubst %.bpf.o,%.bpf.c,$(foreach skel,$(LINKED_SKELS),$($(skel)-deps)))
|
||||
|
||||
|
||||
@@ -1,18 +0,0 @@
|
||||
// SPDX-License-Identifier: GPL-2.0-only
|
||||
/* Copyright (c) 2022 Benjamin Tissoires
|
||||
*/
|
||||
|
||||
#include "vmlinux.h"
|
||||
#include <bpf/bpf_helpers.h>
|
||||
#include <bpf/bpf_tracing.h>
|
||||
#include "hid_bpf_attach.h"
|
||||
#include "hid_bpf_helpers.h"
|
||||
|
||||
SEC("syscall")
|
||||
int attach_prog(struct attach_prog_args *ctx)
|
||||
{
|
||||
ctx->retval = hid_bpf_attach_prog(ctx->hid,
|
||||
ctx->prog_fd,
|
||||
0);
|
||||
return 0;
|
||||
}
|
||||
@@ -1,14 +0,0 @@
|
||||
/* SPDX-License-Identifier: GPL-2.0-only */
|
||||
/* Copyright (c) 2022 Benjamin Tissoires
|
||||
*/
|
||||
|
||||
#ifndef __HID_BPF_ATTACH_H
|
||||
#define __HID_BPF_ATTACH_H
|
||||
|
||||
struct attach_prog_args {
|
||||
int prog_fd;
|
||||
unsigned int hid;
|
||||
int retval;
|
||||
};
|
||||
|
||||
#endif /* __HID_BPF_ATTACH_H */
|
||||
@@ -5,8 +5,7 @@
|
||||
#include <bpf/bpf_tracing.h>
|
||||
#include "hid_bpf_helpers.h"
|
||||
|
||||
SEC("fmod_ret/hid_bpf_device_event")
|
||||
int BPF_PROG(hid_y_event, struct hid_bpf_ctx *hctx)
|
||||
static int hid_y_event(struct hid_bpf_ctx *hctx)
|
||||
{
|
||||
s16 y;
|
||||
__u8 *data = hid_bpf_get_data(hctx, 0 /* offset */, 9 /* size */);
|
||||
@@ -51,8 +50,7 @@ int BPF_PROG(hid_y_event, struct hid_bpf_ctx *hctx)
|
||||
return 0;
|
||||
}
|
||||
|
||||
SEC("fmod_ret/hid_bpf_device_event")
|
||||
int BPF_PROG(hid_x_event, struct hid_bpf_ctx *hctx)
|
||||
static int hid_x_event(struct hid_bpf_ctx *hctx)
|
||||
{
|
||||
s16 x;
|
||||
__u8 *data = hid_bpf_get_data(hctx, 0 /* offset */, 9 /* size */);
|
||||
@@ -69,7 +67,19 @@ int BPF_PROG(hid_x_event, struct hid_bpf_ctx *hctx)
|
||||
return 0;
|
||||
}
|
||||
|
||||
SEC("fmod_ret/hid_bpf_rdesc_fixup")
|
||||
SEC("struct_ops/hid_device_event")
|
||||
int BPF_PROG(hid_event, struct hid_bpf_ctx *hctx, enum hid_report_type type)
|
||||
{
|
||||
int ret = hid_y_event(hctx);
|
||||
|
||||
if (ret)
|
||||
return ret;
|
||||
|
||||
return hid_x_event(hctx);
|
||||
}
|
||||
|
||||
|
||||
SEC("struct_ops/hid_rdesc_fixup")
|
||||
int BPF_PROG(hid_rdesc_fixup, struct hid_bpf_ctx *hctx)
|
||||
{
|
||||
__u8 *data = hid_bpf_get_data(hctx, 0 /* offset */, 4096 /* size */);
|
||||
@@ -109,4 +119,10 @@ int BPF_PROG(hid_rdesc_fixup, struct hid_bpf_ctx *hctx)
|
||||
return 0;
|
||||
}
|
||||
|
||||
SEC(".struct_ops.link")
|
||||
struct hid_bpf_ops mouse_invert = {
|
||||
.hid_rdesc_fixup = (void *)hid_rdesc_fixup,
|
||||
.hid_device_event = (void *)hid_event,
|
||||
};
|
||||
|
||||
char _license[] SEC("license") = "GPL";
|
||||
|
||||
+11
-28
@@ -29,7 +29,6 @@
|
||||
#include <bpf/libbpf.h>
|
||||
|
||||
#include "hid_mouse.skel.h"
|
||||
#include "hid_bpf_attach.h"
|
||||
|
||||
static bool running = true;
|
||||
|
||||
@@ -76,18 +75,11 @@ static int get_hid_id(const char *path)
|
||||
int main(int argc, char **argv)
|
||||
{
|
||||
struct hid_mouse *skel;
|
||||
struct bpf_program *prog;
|
||||
struct bpf_link *link;
|
||||
int err;
|
||||
const char *optstr = "";
|
||||
const char *sysfs_path;
|
||||
int opt, hid_id, attach_fd;
|
||||
struct attach_prog_args args = {
|
||||
.retval = -1,
|
||||
};
|
||||
DECLARE_LIBBPF_OPTS(bpf_test_run_opts, tattr,
|
||||
.ctx_in = &args,
|
||||
.ctx_size_in = sizeof(args),
|
||||
);
|
||||
int opt, hid_id;
|
||||
|
||||
while ((opt = getopt(argc, argv, optstr)) != -1) {
|
||||
switch (opt) {
|
||||
@@ -108,7 +100,7 @@ int main(int argc, char **argv)
|
||||
return 1;
|
||||
}
|
||||
|
||||
skel = hid_mouse__open_and_load();
|
||||
skel = hid_mouse__open();
|
||||
if (!skel) {
|
||||
fprintf(stderr, "%s %s:%d", __func__, __FILE__, __LINE__);
|
||||
return -1;
|
||||
@@ -120,27 +112,18 @@ int main(int argc, char **argv)
|
||||
fprintf(stderr, "can not open HID device: %m\n");
|
||||
return 1;
|
||||
}
|
||||
args.hid = hid_id;
|
||||
skel->struct_ops.mouse_invert->hid_id = hid_id;
|
||||
|
||||
attach_fd = bpf_program__fd(skel->progs.attach_prog);
|
||||
if (attach_fd < 0) {
|
||||
fprintf(stderr, "can't locate attach prog: %m\n");
|
||||
err = hid_mouse__load(skel);
|
||||
if (err < 0) {
|
||||
fprintf(stderr, "can not load HID-BPF program: %m\n");
|
||||
return 1;
|
||||
}
|
||||
|
||||
bpf_object__for_each_program(prog, *skel->skeleton->obj) {
|
||||
/* ignore syscalls */
|
||||
if (bpf_program__get_type(prog) != BPF_PROG_TYPE_TRACING)
|
||||
continue;
|
||||
|
||||
args.retval = -1;
|
||||
args.prog_fd = bpf_program__fd(prog);
|
||||
err = bpf_prog_test_run_opts(attach_fd, &tattr);
|
||||
if (err) {
|
||||
fprintf(stderr, "can't attach prog to hid device %d: %m (err: %d)\n",
|
||||
hid_id, err);
|
||||
return 1;
|
||||
}
|
||||
link = bpf_map__attach_struct_ops(skel->maps.mouse_invert);
|
||||
if (!link) {
|
||||
fprintf(stderr, "can not attach HID-BPF program: %m\n");
|
||||
return 1;
|
||||
}
|
||||
|
||||
signal(SIGINT, int_exit);
|
||||
|
||||
@@ -10,7 +10,7 @@
|
||||
#define HID_UP_BUTTON 0x0009
|
||||
#define HID_GD_WHEEL 0x0038
|
||||
|
||||
SEC("fmod_ret/hid_bpf_device_event")
|
||||
SEC("struct_ops/hid_device_event")
|
||||
int BPF_PROG(hid_event, struct hid_bpf_ctx *hctx)
|
||||
{
|
||||
__u8 *data = hid_bpf_get_data(hctx, 0 /* offset */, 9 /* size */);
|
||||
@@ -101,7 +101,7 @@ int set_haptic(struct haptic_syscall_args *args)
|
||||
}
|
||||
|
||||
/* Convert REL_DIAL into REL_WHEEL */
|
||||
SEC("fmod_ret/hid_bpf_rdesc_fixup")
|
||||
SEC("struct_ops/hid_rdesc_fixup")
|
||||
int BPF_PROG(hid_rdesc_fixup, struct hid_bpf_ctx *hctx)
|
||||
{
|
||||
__u8 *data = hid_bpf_get_data(hctx, 0 /* offset */, 4096 /* size */);
|
||||
@@ -130,5 +130,11 @@ int BPF_PROG(hid_rdesc_fixup, struct hid_bpf_ctx *hctx)
|
||||
return 0;
|
||||
}
|
||||
|
||||
SEC(".struct_ops.link")
|
||||
struct hid_bpf_ops surface_dial = {
|
||||
.hid_rdesc_fixup = (void *)hid_rdesc_fixup,
|
||||
.hid_device_event = (void *)hid_event,
|
||||
};
|
||||
|
||||
char _license[] SEC("license") = "GPL";
|
||||
u32 _version SEC("version") = 1;
|
||||
|
||||
@@ -31,7 +31,6 @@
|
||||
#include <bpf/libbpf.h>
|
||||
|
||||
#include "hid_surface_dial.skel.h"
|
||||
#include "hid_bpf_attach.h"
|
||||
|
||||
static bool running = true;
|
||||
|
||||
@@ -86,34 +85,6 @@ static int get_hid_id(const char *path)
|
||||
return (int)strtol(str_id, NULL, 16);
|
||||
}
|
||||
|
||||
static int attach_prog(struct hid_surface_dial *skel, struct bpf_program *prog, int hid_id)
|
||||
{
|
||||
struct attach_prog_args args = {
|
||||
.hid = hid_id,
|
||||
.retval = -1,
|
||||
};
|
||||
int attach_fd, err;
|
||||
DECLARE_LIBBPF_OPTS(bpf_test_run_opts, tattr,
|
||||
.ctx_in = &args,
|
||||
.ctx_size_in = sizeof(args),
|
||||
);
|
||||
|
||||
attach_fd = bpf_program__fd(skel->progs.attach_prog);
|
||||
if (attach_fd < 0) {
|
||||
fprintf(stderr, "can't locate attach prog: %m\n");
|
||||
return 1;
|
||||
}
|
||||
|
||||
args.prog_fd = bpf_program__fd(prog);
|
||||
err = bpf_prog_test_run_opts(attach_fd, &tattr);
|
||||
if (err) {
|
||||
fprintf(stderr, "can't attach prog to hid device %d: %m (err: %d)\n",
|
||||
hid_id, err);
|
||||
return 1;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int set_haptic(struct hid_surface_dial *skel, int hid_id)
|
||||
{
|
||||
struct haptic_syscall_args args = {
|
||||
@@ -144,10 +115,10 @@ static int set_haptic(struct hid_surface_dial *skel, int hid_id)
|
||||
int main(int argc, char **argv)
|
||||
{
|
||||
struct hid_surface_dial *skel;
|
||||
struct bpf_program *prog;
|
||||
const char *optstr = "r:";
|
||||
struct bpf_link *link;
|
||||
const char *sysfs_path;
|
||||
int opt, hid_id, resolution = 72;
|
||||
int err, opt, hid_id, resolution = 72;
|
||||
|
||||
while ((opt = getopt(argc, argv, optstr)) != -1) {
|
||||
switch (opt) {
|
||||
@@ -189,7 +160,7 @@ int main(int argc, char **argv)
|
||||
return 1;
|
||||
}
|
||||
|
||||
skel = hid_surface_dial__open_and_load();
|
||||
skel = hid_surface_dial__open();
|
||||
if (!skel) {
|
||||
fprintf(stderr, "%s %s:%d", __func__, __FILE__, __LINE__);
|
||||
return -1;
|
||||
@@ -201,15 +172,21 @@ int main(int argc, char **argv)
|
||||
return 1;
|
||||
}
|
||||
|
||||
skel->struct_ops.surface_dial->hid_id = hid_id;
|
||||
|
||||
err = hid_surface_dial__load(skel);
|
||||
if (err < 0) {
|
||||
fprintf(stderr, "can not load HID-BPF program: %m\n");
|
||||
return 1;
|
||||
}
|
||||
|
||||
skel->data->resolution = resolution;
|
||||
skel->data->physical = (int)(resolution / 72);
|
||||
|
||||
bpf_object__for_each_program(prog, *skel->skeleton->obj) {
|
||||
/* ignore syscalls */
|
||||
if (bpf_program__get_type(prog) != BPF_PROG_TYPE_TRACING)
|
||||
continue;
|
||||
|
||||
attach_prog(skel, prog, hid_id);
|
||||
link = bpf_map__attach_struct_ops(skel->maps.surface_dial);
|
||||
if (!link) {
|
||||
fprintf(stderr, "can not attach HID-BPF program: %m\n");
|
||||
return 1;
|
||||
}
|
||||
|
||||
signal(SIGINT, int_exit);
|
||||
|
||||
Reference in New Issue
Block a user