[PATCH HID v3 9/9] selftests/hid: add test for assigning a given device to hid-generic

2024-10-01 Thread Benjamin Tissoires
We use a well known VID/PID on a driver that doesn't need to talk to the device, ensures we created the device against the target driver, then load our program and ensure we have unbound to this driver and use hid-generic instead. Reviewed-by: Peter Hutterer Signed-off-by: Benjamin Tiss

[PATCH HID 3/7] selftests/hid: allow to parametrize bus/vid/pid/rdesc on the test device

2024-09-02 Thread Benjamin Tissoires
This will be useful to introduce variants in tests to test the interactions between HID-BPF and some kernel modules. Signed-off-by: Benjamin Tissoires --- tools/testing/selftests/hid/hid_bpf.c| 2 +- tools/testing/selftests/hid/hid_common.h | 46 tools

[PATCH HID 2/7] selftests/hid: cleanup C tests by adding a common struct uhid_device

2024-09-02 Thread Benjamin Tissoires
Allows to have an abstract class uhid_device which handles all of the uhid part without having to mess up with individual fds. struct attach_prog_args is now never used in hid_bpf.c, so drop it as well Signed-off-by: Benjamin Tissoires --- tools/testing/selftests/hid/hid_bpf.c| 77

[PATCH HID 5/7] selftests/hid: add test for assigning a given device to hid-generic

2024-09-02 Thread Benjamin Tissoires
We use a well known VID/PID on a driver that doesn't need to talk to the device, ensures we created the device against the target driver, then load our program and ensure we have unbound to this driver and use hid-generic instead. Signed-off-by: Benjamin Tissoires --- tools/testing/self

[PATCH HID 4/7] HID: bpf: allow BPF programs to force using hid-generic

2024-09-02 Thread Benjamin Tissoires
ply have a couple of writeable fields in the new struct hid_bpf_driver, and then hid-core can make its educated decision. Signed-off-by: Benjamin Tissoires --- Documentation/hid/hid-bpf.rst| 2 +- drivers/hid/bpf/hid_bpf_dispatch.c | 31 drivers/hid/bpf/hid_b

[PATCH HID 7/7] selftests/hid: add test to disable hid-input

2024-09-02 Thread Benjamin Tissoires
Add a test for the newly enabled feature to control the connect_mask of hid-generic. Signed-off-by: Benjamin Tissoires --- tools/testing/selftests/hid/hid_bpf.c | 60 +- tools/testing/selftests/hid/progs/hid.c| 6 ++- .../testing/selftests/hid/progs

[PATCH HID 0/7] HID: bpf: add a new hook to control hid-generic

2024-09-02 Thread Benjamin Tissoires
tps://gitlab.freedesktop.org/libinput/libinput/-/issues/1014 Signed-off-by: Benjamin Tissoires --- Benjamin Tissoires (7): selftests/hid: add dependency on hid_common.h selftests/hid: cleanup C tests by adding a common struct uhid_device selftests/hid: allow to parametrize bus/vid/pid/rdesc on the t

[PATCH HID 1/7] selftests/hid: add dependency on hid_common.h

2024-09-02 Thread Benjamin Tissoires
Allows to recompile the C tests when that file changes Signed-off-by: Benjamin Tissoires --- tools/testing/selftests/hid/Makefile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tools/testing/selftests/hid/Makefile b/tools/testing/selftests/hid/Makefile index 72be55ac4bdf

[PATCH HID 6/7] HID: bpf: Allow to control the connect mask of hid-generic from BPF

2024-09-02 Thread Benjamin Tissoires
oaded and the normal driver takes back the control of the device. Signed-off-by: Benjamin Tissoires --- drivers/hid/bpf/hid_bpf_struct_ops.c | 1 + drivers/hid/hid-core.c | 14 -- drivers/hid/hid-generic.c| 5 +++-- 3 files changed, 12 insertions(+), 8 dele

Re: [PATCH v5 0/4] HID: hidraw: HIDIOCREVOKE introduction

2024-08-29 Thread Benjamin Tissoires
3892a629c [4/4] selftests/hid: Add HIDIOCREVOKE tests https://git.kernel.org/hid/hid/c/321f7798cfb8 Cheers, -- Benjamin Tissoires

[PATCH v5 4/4] selftests/hid: Add HIDIOCREVOKE tests

2024-08-27 Thread Benjamin Tissoires
Add 4 tests for the new revoke ioctl, for read/write/ioctl and poll. Signed-off-by: Benjamin Tissoires Reviewed-by: Peter Hutterer --- new in v4 Changes to v4: - fix a few error messages - also check for ENODEV errno when required - use ENODEV instead of its plain value --- tools/testing

[PATCH v5 3/4] selftests/hid: Add initial hidraw tests skeleton

2024-08-27 Thread Benjamin Tissoires
and BPFs to revoke the hidraw node. Signed-off-by: Benjamin Tissoires Reviewed-by: Peter Hutterer --- new in v4 Changes to v4: - dropped the common code in favor of hid_common.h --- tools/testing/selftests/hid/.gitignore | 1 + tools/testing/selftests/hid/Makefile | 2 +- tools/testing

[PATCH v5 2/4] selftests/hid: extract the utility part of hid_bpf.c into its own header

2024-08-27 Thread Benjamin Tissoires
When adding new tests programs, we need the same mechanics to create new virtual devices, and read from their matching hidraw node. Extract the common part into its own header so we can easily add new tests C-files. Signed-off-by: Benjamin Tissoires --- new in v5 --- tools/testing/selftests

[PATCH v4 3/3] selftests/hid: Add HIDIOCREVOKE tests

2024-08-26 Thread Benjamin Tissoires
Add 4 tests for the new revoke ioctl, for read/write/ioctl and poll. Signed-off-by: Benjamin Tissoires --- new in v4 --- tools/testing/selftests/hid/hidraw.c | 143 +++ 1 file changed, 143 insertions(+) diff --git a/tools/testing/selftests/hid/hidraw.c b

[PATCH v4 2/3] selftests/hid: Add initial hidraw tests skeleton

2024-08-26 Thread Benjamin Tissoires
start adding the ioctl and BPFs to revoke the hidraw node. Signed-off-by: Benjamin Tissoires --- new in v4 --- tools/testing/selftests/hid/.gitignore | 1 + tools/testing/selftests/hid/Makefile | 2 +- tools/testing/selftests/hid/hidraw.c | 522 + 3 files

Re: [PATCH HID 0/4] HID: selftest fixes after merge into 6.11-rc0 tree

2024-07-24 Thread Benjamin Tissoires
On Tue, 23 Jul 2024 18:21:50 +0200, Benjamin Tissoires wrote: > After HID-BPF struct_ops was merged into 6.11-rc0, there are a few > mishaps: > - the bpf_wq API changed and needs to be updated here > - libbpf now auto-attach all the struct_ops it sees in the bpf object, > leadin

[PATCH HID 4/4] selftests/hid: add test for attaching multiple time the same struct_ops

2024-07-23 Thread Benjamin Tissoires
Turns out that we would en up in a bad state if we attempt to attach twice the same HID-BPF struct_ops, so have a test for it. Signed-off-by: Benjamin Tissoires --- tools/testing/selftests/hid/hid_bpf.c | 18 ++ 1 file changed, 18 insertions(+) diff --git a/tools/testing

[PATCH HID 3/4] HID: bpf: prevent the same struct_ops to be attached more than once

2024-07-23 Thread Benjamin Tissoires
If the struct_ops is already attached, we should bail out or we will end up in various locks and pointer issues while unregistering. Signed-off-by: Benjamin Tissoires --- drivers/hid/bpf/hid_bpf_struct_ops.c | 5 + 1 file changed, 5 insertions(+) diff --git a/drivers/hid/bpf

[PATCH HID 2/4] selftests/hid: disable struct_ops auto-attach

2024-07-23 Thread Benjamin Tissoires
at a time, or we end up locking the syscall. Signed-off-by: Benjamin Tissoires --- tools/testing/selftests/hid/hid_bpf.c | 8 1 file changed, 8 insertions(+) diff --git a/tools/testing/selftests/hid/hid_bpf.c b/tools/testing/selftests/hid/hid_bpf.c index dc0408a831d0..9c935fd0dffc 10

[PATCH HID 1/4] selftests/hid: fix bpf_wq new API

2024-07-23 Thread Benjamin Tissoires
Since commit f56f4d541eab ("bpf: helpers: fix bpf_wq_set_callback_impl signature"), the API for bpf_wq changed a bit. We need to update the selftests/hid code to reflect that or the bpf program will not load. Signed-off-by: Benjamin Tissoires --- tools/testing/selftests/hid/p

[PATCH HID 0/4] HID: selftest fixes after merge into 6.11-rc0 tree

2024-07-23 Thread Benjamin Tissoires
same struct_ops to be attached more than once as this enters various locks, confusions, and kernel oopses. Signed-off-by: Benjamin Tissoires --- Benjamin Tissoires (4): selftests/hid: fix bpf_wq new API selftests/hid: disable struct_ops auto-attach HID: bpf: prevent the same

[PATCH bpf-next v2 1/2] bpf: helpers: fix bpf_wq_set_callback_impl signature

2024-07-08 Thread Benjamin Tissoires
e" as this is not a struct bpf_wq *. This is a change of API, but there doesn't seem to be much users of bpf_wq right now, so we should be able to go with this right now. Fixes: 81f1d7a583fa ("bpf: wq: add bpf_wq_set_callback_impl") Signed-off-by: Benjamin Tissoires --- kerne

[PATCH bpf-next v2 2/2] selftests/bpf: amend for wrong bpf_wq_set_callback_impl signature

2024-07-08 Thread Benjamin Tissoires
See the previous patch: the API was wrong, we were provided the pointer to the value, not the actual struct bpf_wq *. Signed-off-by: Benjamin Tissoires --- changes in v2: - amended to retrieve something from the third argument of the callback --- tools/testing/selftests/bpf/bpf_experimental.h

[PATCH bpf-next v2 0/2] Small API fix for bpf_wq

2024-07-08 Thread Benjamin Tissoires
e" as this is not a struct bpf_wq *. This is a change of API, but there doesn't seem to be much users of bpf_wq right now, so we should be able to go with this right now. Signed-off-by: Benjamin Tissoires --- Changes in v2: - amended the selftests to retrieve something from the third ar

Re: [PATCH bpf-next 2/2] selftests/bpf: amend for wrong bpf_wq_set_callback_impl signature

2024-07-08 Thread Benjamin Tissoires
On Jul 06 2024, Alexei Starovoitov wrote: > On Fri, Jul 5, 2024 at 1:54 PM Eduard Zingerman wrote: > > > > On Fri, 2024-07-05 at 15:44 +0200, Benjamin Tissoires wrote: > > > See the previous patch: the API was wrong, we were provided the pointer > > > to the va

[PATCH bpf-next 2/2] selftests/bpf: amend for wrong bpf_wq_set_callback_impl signature

2024-07-05 Thread Benjamin Tissoires
See the previous patch: the API was wrong, we were provided the pointer to the value, not the actual struct bpf_wq *. Signed-off-by: Benjamin Tissoires --- tools/testing/selftests/bpf/bpf_experimental.h | 2 +- tools/testing/selftests/bpf/progs/wq.c | 8 tools/testing

[PATCH bpf-next 1/2] bpf: helpers: fix bpf_wq_set_callback_impl signature

2024-07-05 Thread Benjamin Tissoires
e" as this is not a struct bpf_wq *. This is a change of API, but there doesn't seem to be much users of bpf_wq right now, so we should be able to go with this right now. Fixes: 81f1d7a583fa ("bpf: wq: add bpf_wq_set_callback_impl") Signed-off-by: Benjamin Tissoires --- kerne

[PATCH bpf-next 0/2] Small API fix for bpf_wq

2024-07-05 Thread Benjamin Tissoires
e" as this is not a struct bpf_wq *. This is a change of API, but there doesn't seem to be much users of bpf_wq right now, so we should be able to go with this right now. Signed-off-by: Benjamin Tissoires --- Benjamin Tissoires (2): bpf: helpers: fix bpf_wq_set_callback

Re: [PATCH v2 0/4] Fix warnings in for-6.11/bpf

2024-07-01 Thread Benjamin Tissoires
On Mon, 01 Jul 2024 14:39:48 +0200, Benjamin Tissoires wrote: > We had several complains in linux-next that there were warnings: > > CKI was not happy: it was the same situation than in an early report > when HID-BPF was initially included: the automatically generated > vmlinux.h

[PATCH v2 4/4] HID: bpf: doc fixes for hid_hw_request() hooks

2024-07-01 Thread Benjamin Tissoires
hooks for hid_hw_output_report") Signed-off-by: Benjamin Tissoires --- drivers/hid/bpf/hid_bpf_dispatch.c | 2 +- include/linux/hid_bpf.h| 14 -- 2 files changed, 9 insertions(+), 7 deletions(-) diff --git a/drivers/hid/bpf/hid_bpf_dispatch.c b/drive

[PATCH v2 3/4] HID: bpf: doc fixes for hid_hw_request() hooks

2024-07-01 Thread Benjamin Tissoires
. Documentation/hid/hid-bpf:185: include/linux/hid_bpf.h:147: ERROR: Unexpected indentation. Reported-by: Stephen Rothwell Fixes: 8bd0488b5ea5 ("HID: bpf: add HID-BPF hooks for hid_hw_raw_requests") Signed-off-by: Benjamin Tissoires --- include/linux/hid_bpf.h | 11 +++--

[PATCH v2 2/4] HID: bpf: fix gcc warning and unify __u64 into u64

2024-07-01 Thread Benjamin Tissoires
d source argument to HID low level functions") Signed-off-by: Benjamin Tissoires --- drivers/hid/bpf/hid_bpf_dispatch.c | 6 +++--- drivers/hid/bpf/hid_bpf_struct_ops.c | 2 +- drivers/hid/hid-core.c | 4 ++-- drivers/hid/hidraw.c | 6 +++--- include/linux/h

[PATCH v2 1/4] selftests/hid: ensure CKI can compile our new tests on old kernels

2024-07-01 Thread Benjamin Tissoires
bpf_ops. Fixes: d7696738d66b ("selftests/hid: convert the hid_bpf selftests with struct_ops") Reported-by: kernel test robot Closes: https://lore.kernel.org/r/202406270328.bscln1if-...@intel.com/ Signed-off-by: Benjamin Tissoires --- tools/testing/selftests/hid/progs/hid_bpf_helpers.h | 16

[PATCH v2 0/4] Fix warnings in for-6.11/bpf

2024-07-01 Thread Benjamin Tissoires
fails. We have multiple pointer to int cast complains and some docs that were not rendered properly. Include everything here. Signed-off-by: Benjamin Tissoires --- Changes in v2: - Also fix the pointer to int casts - Also fix the docs complains - Link to v1: https://lore.kernel.org/r/2024062

[PATCH] selftests/hid: ensure CKI can compile our new tests on old kernels

2024-06-27 Thread Benjamin Tissoires
bpf_ops. Fixes: d7696738d66b ("selftests/hid: convert the hid_bpf selftests with struct_ops") Reported-by: kernel test robot Closes: https://lore.kernel.org/r/202406270328.bscln1if-...@intel.com/ Signed-off-by: Benjamin Tissoires --- Same situation than in an early report when HID-BPF wa

Re: [PATCH HID v2 04/13] HID: bpf: add HID-BPF hooks for hid_hw_raw_requests

2024-06-27 Thread Benjamin Tissoires
On Jun 26 2024, Alexei Starovoitov wrote: > On Wed, Jun 26, 2024 at 6:46 AM Benjamin Tissoires wrote: > > > > This allows to intercept and prevent or change the behavior of > > hid_hw_raw_request() from a bpf program. > > > > The intent is to solve a couple of

Re: [PATCH HID v2 00/13] HID: bpf_struct_ops, part 2

2024-06-27 Thread Benjamin Tissoires
On Wed, 26 Jun 2024 15:46:21 +0200, Benjamin Tissoires wrote: > This series is a followup of the struct_ops conversion. > > Therefore, it is based on top of the for-6.11/bpf branch of the hid.git > tree: > https://git.kernel.org/pub/scm/linux/kernel/git/hid/hid.git/log/?h=for-6.

[PATCH HID v2 13/13] selftests/hid: add an infinite loop test for hid_bpf_try_input_report

2024-06-26 Thread Benjamin Tissoires
We don't want this call to allow an infinite loop in HID-BPF, so let's have some tests. Signed-off-by: Benjamin Tissoires --- no changes in v2 --- tools/testing/selftests/hid/hid_bpf.c | 41 + tools/testing/selftests/hid/progs/

[PATCH HID v2 12/13] selftests/hid: add another test for injecting an event from an event hook

2024-06-26 Thread Benjamin Tissoires
. Signed-off-by: Benjamin Tissoires --- no changes in v2 --- tools/testing/selftests/hid/hid_bpf.c | 36 tools/testing/selftests/hid/progs/hid.c| 39 ++ .../testing/selftests/hid/progs/hid_bpf_helpers.h | 4 +++ 3 files changed

[PATCH HID v2 11/13] HID: bpf: allow hid_device_event hooks to inject input reports on self

2024-06-26 Thread Benjamin Tissoires
introduce a new kfunc for it: hid_bpf_try_input_report() Signed-off-by: Benjamin Tissoires --- no changes in v2 --- Documentation/hid/hid-bpf.rst | 2 +- drivers/hid/bpf/hid_bpf_dispatch.c | 56 -- drivers/hid/hid-core.c | 5 ++-- include

[PATCH HID v2 10/13] selftests/hid: add wq test for hid_bpf_input_report()

2024-06-26 Thread Benjamin Tissoires
Now that bpf_wq is available, we can write a test with it. Having hid_bpf_input_report() waiting for the device means that we can directly call it, and we get that event when the device is ready. Signed-off-by: Benjamin Tissoires --- no changes in v2 --- tools/testing/selftests/hid/hid_bpf.c

[PATCH HID v2 09/13] HID: bpf: make hid_bpf_input_report() sleep until the device is ready

2024-06-26 Thread Benjamin Tissoires
allows to work with the following pseudo code: in struct_ops/hid_device_event: - schedule a bpf_wq, which calls hid_bpf_input_report() - once this struct_ops function terminates, hid_bpf_input_report() immediately starts before the next event Signed-off-by: Benjamin Tissoires --- no changes

[PATCH HID v2 08/13] selftests/hid: add tests for hid_hw_output_report HID-BPF hooks

2024-06-26 Thread Benjamin Tissoires
ensure that we can not loop between hooks for hid_hw_output_report() and manual calls to hid_bpf_hw_output_report() from that same hook Signed-off-by: Benjamin Tissoires --- no changes in v2 --- drivers/hid/bpf/hid_bpf_dispatch.c | 5 ++ tools/testing/selftests/hid/hid_bpf.c | 102

[PATCH HID v2 07/13] HID: bpf: add HID-BPF hooks for hid_hw_output_report

2024-06-26 Thread Benjamin Tissoires
n call the feature request on a different HID device on the same physical device. Signed-off-by: Benjamin Tissoires --- changes in v2: - make use of SRCU --- drivers/hid/bpf/hid_bpf_dispatch.c | 38 drivers/hid/bpf/hid_bpf_struct_ops.c | 1 + drivers/hid/

[PATCH HID v2 06/13] selftests/hid: add tests for hid_hw_raw_request HID-BPF hooks

2024-06-26 Thread Benjamin Tissoires
we can not loop between hooks for hid_hw_raw_request() and manual calls to hid_bpf_hw_request() from that hook Signed-off-by: Benjamin Tissoires --- no changes in v2 --- tools/testing/selftests/hid/hid_bpf.c | 109 tools/testing/selftests/hid/progs/hid.c

[PATCH HID v2 05/13] HID: bpf: prevent infinite recursions with hid_hw_raw_requests hooks

2024-06-26 Thread Benjamin Tissoires
f" is very interesting because while writing such a bpf program, you need to match at least the report number and/or the source of the call. So a blind "if there is a hid_hw_raw_request() call, I'm emitting another one" makes no real sense. Signed-off-by: Benjamin Tissoires --- no

[PATCH HID v2 03/13] HID: bpf: protect HID-BPF prog_list access by a SRCU

2024-06-26 Thread Benjamin Tissoires
accommodate for this. Signed-off-by: Benjamin Tissoires --- new in v2 --- drivers/hid/bpf/hid_bpf_dispatch.c | 6 +- drivers/hid/bpf/hid_bpf_struct_ops.c | 2 ++ drivers/hid/hid-core.c | 8 +++- include/linux/hid_bpf.h | 6 -- 4 files changed, 18

[PATCH HID v2 04/13] HID: bpf: add HID-BPF hooks for hid_hw_raw_requests

2024-06-26 Thread Benjamin Tissoires
n the same physical device. Signed-off-by: Benjamin Tissoires --- changes in v2: - make use of SRCU --- drivers/hid/bpf/hid_bpf_dispatch.c | 37 drivers/hid/bpf/hid_bpf_struct_ops.c | 1 + drivers/hid/hid-core.c | 6 ++ include/linux

[PATCH HID v2 02/13] HID: add source argument to HID low level functions

2024-06-26 Thread Benjamin Tissoires
This allows to know who actually sent what when we process the request to the device. This will be useful for a BPF firewall program to allow or not requests coming from a dedicated hidraw node client. Signed-off-by: Benjamin Tissoires --- no changes in v2 --- drivers/hid/bpf

[PATCH HID v2 01/13] HID: bpf: fix dispatch_hid_bpf_device_event uninitialized ret value

2024-06-26 Thread Benjamin Tissoires
han only the last program in the chain could change the size of the incoming buffer. Reported-by: Dan Carpenter Link: https://lore.kernel.org/all/00f7b624-219f-4a05-a7ad-5335f15a41c7@moroto.mountain Fixes: 4a86220e046d ("HID: bpf: remove tracing HID-BPF capability") Signed-off-by: Benja

[PATCH HID v2 00/13] HID: bpf_struct_ops, part 2

2024-06-26 Thread Benjamin Tissoires
the function was already declared as sleepable. Cheers, Benjamin Signed-off-by: Benjamin Tissoires --- Changes in v2: - made use of srcu, for sleepable users - Link to v1: https://lore.kernel.org/r/20240621-hid_hw_req_bpf-v1-0-d7ab8b885...@kernel.org --- Benjamin Tissoires

Re: [PATCH HID 06/12] HID: bpf: add HID-BPF hooks for hid_hw_output_report

2024-06-24 Thread Benjamin Tissoires
On Jun 21 2024, Alexei Starovoitov wrote: > On Fri, Jun 21, 2024 at 9:08 AM Benjamin Tissoires wrote: > > > > On Jun 21 2024, Alexei Starovoitov wrote: > > > On Fri, Jun 21, 2024 at 1:56 AM Benjamin Tissoires > > > wrote: > > > > > > > >

Re: [PATCH HID 06/12] HID: bpf: add HID-BPF hooks for hid_hw_output_report

2024-06-21 Thread Benjamin Tissoires
On Jun 21 2024, Alexei Starovoitov wrote: > On Fri, Jun 21, 2024 at 1:56 AM Benjamin Tissoires wrote: > > > > Same story than hid_hw_raw_requests: > > > > This allows to intercept and prevent or change the behavior of > > hid_hw_output_report() from a bpf program.

[PATCH HID 12/12] selftests/hid: add an infinite loop test for hid_bpf_try_input_report

2024-06-21 Thread Benjamin Tissoires
We don't want this call to allow an infinite loop in HID-BPF, so let's have some tests. Signed-off-by: Benjamin Tissoires --- tools/testing/selftests/hid/hid_bpf.c | 41 + tools/testing/selftests/hid/progs/hid.c | 37

[PATCH HID 11/12] selftests/hid: add another test for injecting an event from an event hook

2024-06-21 Thread Benjamin Tissoires
. Signed-off-by: Benjamin Tissoires --- tools/testing/selftests/hid/hid_bpf.c | 36 tools/testing/selftests/hid/progs/hid.c| 39 ++ .../testing/selftests/hid/progs/hid_bpf_helpers.h | 4 +++ 3 files changed, 79 insertions(+) diff

[PATCH HID 10/12] HID: bpf: allow hid_device_event hooks to inject input reports on self

2024-06-21 Thread Benjamin Tissoires
introduce a new kfunc for it: hid_bpf_try_input_report() Signed-off-by: Benjamin Tissoires --- Documentation/hid/hid-bpf.rst | 2 +- drivers/hid/bpf/hid_bpf_dispatch.c | 56 -- drivers/hid/hid-core.c | 5 ++-- include/linux/hid_bpf.h

[PATCH HID 09/12] selftests/hid: add wq test for hid_bpf_input_report()

2024-06-21 Thread Benjamin Tissoires
Now that bpf_wq is available, we can write a test with it. Having hid_bpf_input_report() waiting for the device means that we can directly call it, and we get that event when the device is ready. Signed-off-by: Benjamin Tissoires --- tools/testing/selftests/hid/hid_bpf.c | 38

[PATCH HID 08/12] HID: bpf: make hid_bpf_input_report() sleep until the device is ready

2024-06-21 Thread Benjamin Tissoires
allows to work with the following pseudo code: in struct_ops/hid_device_event: - schedule a bpf_wq, which calls hid_bpf_input_report() - once this struct_ops function terminates, hid_bpf_input_report() immediately starts before the next event Signed-off-by: Benjamin Tissoires --- drivers/hid

[PATCH HID 07/12] selftests/hid: add tests for hid_hw_output_report HID-BPF hooks

2024-06-21 Thread Benjamin Tissoires
ensure that we can not loop between hooks for hid_hw_output_report() and manual calls to hid_bpf_hw_output_report() from that same hook Signed-off-by: Benjamin Tissoires --- drivers/hid/bpf/hid_bpf_dispatch.c | 5 ++ tools/testing/selftests/hid/hid_bpf.c | 102

[PATCH HID 06/12] HID: bpf: add HID-BPF hooks for hid_hw_output_report

2024-06-21 Thread Benjamin Tissoires
n call the feature request on a different HID device on the same physical device. Signed-off-by: Benjamin Tissoires --- Here checkpatch complains about: WARNING: use of RCU tasks trace is incorrect outside BPF or core RCU code However, we are jumping in BPF code, so I think this is correct, but I'

[PATCH HID 05/12] selftests/hid: add tests for hid_hw_raw_request HID-BPF hooks

2024-06-21 Thread Benjamin Tissoires
we can not loop between hooks for hid_hw_raw_request() and manual calls to hid_bpf_hw_request() from that hook Signed-off-by: Benjamin Tissoires --- tools/testing/selftests/hid/hid_bpf.c | 109 tools/testing/selftests/hid/progs/hid.c | 79

[PATCH HID 04/12] HID: bpf: prevent infinite recursions with hid_hw_raw_requests hooks

2024-06-21 Thread Benjamin Tissoires
f" is very interesting because while writing such a bpf program, you need to match at least the report number and/or the source of the call. So a blind "if there is a hid_hw_raw_request() call, I'm emitting another one" makes no real sense. Signed-off-by: Benjamin Tissoires --- driv

[PATCH HID 03/12] HID: bpf: add HID-BPF hooks for hid_hw_raw_requests

2024-06-21 Thread Benjamin Tissoires
n the same physical device. Signed-off-by: Benjamin Tissoires --- Here checkpatch complains about: WARNING: use of RCU tasks trace is incorrect outside BPF or core RCU code However, we are jumping in BPF code, so I think this is correct, but I'd like to have the opinion on the BPF folks. -

[PATCH HID 02/12] HID: add source argument to HID low level functions

2024-06-21 Thread Benjamin Tissoires
This allows to know who actually sent what when we process the request to the device. This will be useful for a BPF firewall program to allow or not requests coming from a dedicated hidraw node client. Signed-off-by: Benjamin Tissoires --- drivers/hid/bpf/hid_bpf_dispatch.c | 12

[PATCH HID 01/12] HID: bpf: fix dispatch_hid_bpf_device_event uninitialized ret value

2024-06-21 Thread Benjamin Tissoires
han only the last program in the chain could change the size of the incoming buffer. Reported-by: Dan Carpenter Link: https://lore.kernel.org/all/00f7b624-219f-4a05-a7ad-5335f15a41c7@moroto.mountain Fixes: 4a86220e046d ("HID: bpf: remove tracing HID-BPF capability") Signed-off-by: Benja

[PATCH HID 00/12] HID: bpf_struct_ops, part 2

2024-06-21 Thread Benjamin Tissoires
the function was already declared as sleepable. Cheers, Benjamin Signed-off-by: Benjamin Tissoires --- Benjamin Tissoires (12): HID: bpf: fix dispatch_hid_bpf_device_event uninitialized ret value HID: add source argument to HID low level functions HID: bpf: add HID-BPF hooks for hid_

Re: [PATCH HID v3 00/16] HID: convert HID-BPF into using bpf_struct_ops

2024-06-14 Thread Benjamin Tissoires
On Sat, 08 Jun 2024 11:01:12 +0200, Benjamin Tissoires wrote: > The purpose of this series is to rethink how HID-BPF is invoked. > Currently it implies a jmp table, a prog fd bpf_map, a preloaded tracing > bpf program and a lot of manual work for handling the bpf program > lifetime

Re: [PATCH HID v3 03/16] HID: bpf: implement HID-BPF through bpf_struct_ops

2024-06-14 Thread Benjamin Tissoires
On Jun 10 2024, Alexei Starovoitov wrote: > On Sat, Jun 8, 2024 at 2:01 AM Benjamin Tissoires wrote: > > > > + > > +static int hid_bpf_ops_init_member(const struct btf_type *t, > > +const struct btf_member *member, > > +

Re: [PATCH HID v3 15/16] HID: bpf: rework hid_bpf_ops_btf_struct_access

2024-06-11 Thread Benjamin Tissoires
On Jun 10 2024, Alexei Starovoitov wrote: > On Sat, Jun 8, 2024 at 2:01 AM Benjamin Tissoires wrote: > > > > The idea is to provide a list of stucts and their editable fields. > > > > Currently no functional changes are introduced here, we will add some > > more w

[PATCH HID v3 16/16] HID: bpf: make part of struct hid_device writable

2024-06-08 Thread Benjamin Tissoires
device export 3 nodes, all with the same name. Signed-off-by: Benjamin Tissoires --- changes in v3: - amend for new WRITE_RANGE API new in v2 --- drivers/hid/bpf/hid_bpf_struct_ops.c | 3 +++ include/linux/hid_bpf.h | 2 +- 2 files changed, 4 insertions(+), 1 deletion(-) diff

[PATCH HID v3 15/16] HID: bpf: rework hid_bpf_ops_btf_struct_access

2024-06-08 Thread Benjamin Tissoires
The idea is to provide a list of stucts and their editable fields. Currently no functional changes are introduced here, we will add some more writeable fields in the next patch. Signed-off-by: Benjamin Tissoires --- changes in v3: - rewrote WRITE_RANGE macro to not deal with offset from the

[PATCH HID v3 14/16] bpf: allow bpf helpers to be used into HID-BPF struct_ops

2024-06-08 Thread Benjamin Tissoires
Without this helpers like bpf_printk() or bpf_map_update() are not available, making anything but change of bytes impossible to do. Signed-off-by: Benjamin Tissoires --- no changes in v3 new in v2 --- drivers/hid/bpf/hid_bpf_struct_ops.c | 1 + 1 file changed, 1 insertion(+) diff --git a

[PATCH HID v3 13/16] HID: bpf: error on warnings when compiling bpf objects

2024-06-08 Thread Benjamin Tissoires
There is no real reasons to paper over warnings for such small programs. Signed-off-by: Benjamin Tissoires --- no changes in v3 no changes in v2 --- drivers/hid/bpf/progs/Makefile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/drivers/hid/bpf/progs/Makefile b/drivers/hid

[PATCH HID v3 12/16] HID: bpf: Artist24: remove unused variable

2024-06-08 Thread Benjamin Tissoires
warning: unused variable ‘tilt’ [-Wunused-variable] Signed-off-by: Peter Hutterer Signed-off-by: Benjamin Tissoires --- no changes in v3 no changes in v2 --- drivers/hid/bpf/progs/XPPen__Artist24.bpf.c | 1 - 1 file changed, 1 deletion(-) diff --git a/drivers/hid/bpf/progs/XPPen__Artist24

[PATCH HID v3 11/16] Documentation: HID: add a small blurb on udev-hid-bpf

2024-06-08 Thread Benjamin Tissoires
This is the current decision we took: we don't provide automatic loading of HID-BPF by the kernel directly, but rely on an external tool for it. This tool is currently udev-hid-bpf, so let's make people aware of it. Signed-off-by: Benjamin Tissoires --- no changes in v3 no cha

[PATCH HID v3 10/16] Documentation: HID: amend HID-BPF for struct_ops

2024-06-08 Thread Benjamin Tissoires
Now that we are using struct_ops, the docs need to be changed. Signed-off-by: Benjamin Tissoires --- no changes in v3 changes in v2 - use BPF_F_BEFORE --- Documentation/hid/hid-bpf.rst | 156 +++--- include/linux/hid_bpf.h | 8 +-- 2 files changed

[PATCH HID v3 09/16] selftests/hid: add subprog call test

2024-06-08 Thread Benjamin Tissoires
I got a weird verifier error with a subprog once, so let's have a test for it. Signed-off-by: Benjamin Tissoires --- no changes in v3 no changes in v2 --- tools/testing/selftests/hid/hid_bpf.c | 41 + tools/testing/selftests/hid/progs/hid.c

[PATCH HID v3 08/16] HID: bpf: remove tracing HID-BPF capability

2024-06-08 Thread Benjamin Tissoires
We can now rely on struct_ops as we cleared the users in-tree. Signed-off-by: Benjamin Tissoires --- no changes in v3 changes in v2: - remove now unused enum hid_bpf_attach_flags --- drivers/hid/bpf/Makefile| 2 +- drivers/hid/bpf/entrypoints/Makefile

[PATCH HID v3 07/16] HID: bpf: convert in-tree fixes into struct_ops

2024-06-08 Thread Benjamin Tissoires
Very mechanical: - Change HID_BPF_DEVICE_EVENT and HID_BPF_RDESC_FIXUP #defines - add a matching SEC(".struct_ops.link") - in ArtistPro16Gen2 make the 2 functions static and have a new one calling them Signed-off-by: Benjamin Tissoires --- no changes in v3 no changes in v2 --- d

[PATCH HID v3 06/16] HID: bpf: add defines for HID-BPF SEC in in-tree bpf fixes

2024-06-08 Thread Benjamin Tissoires
We are going to switch over struct_ops, so instead of having to manually replace all fields one by one, let's have a common place to change it. Signed-off-by: Benjamin Tissoires --- no changes in v3 no changes in v2 --- drivers/hid/bpf/progs/FR-TEC__Raptor-Mach-2.bpf.c | 4 ++-- dr

[PATCH HID v3 05/16] HID: samples: convert the 2 HID-BPF samples into struct_ops

2024-06-08 Thread Benjamin Tissoires
This is mostly mechanical: attach_prog is dropped, and the SEC are converted into struct_ops. Signed-off-by: Benjamin Tissoires --- no changes in v3 no changes in v2 but the commit message. --- samples/hid/Makefile | 5 ++-- samples/hid/hid_bpf_attach.bpf.c | 18

[PATCH HID v3 04/16] selftests/hid: convert the hid_bpf selftests with struct_ops

2024-06-08 Thread Benjamin Tissoires
We drop the need for the attach() bpf syscall, but we need to set up the hid_id field before calling __load(). The .bpf.c part is mechanical: we create one struct_ops per HID-BPF program, as all the tests are for one program at a time. Signed-off-by: Benjamin Tissoires --- no changes in v3

[PATCH HID v3 03/16] HID: bpf: implement HID-BPF through bpf_struct_ops

2024-06-08 Thread Benjamin Tissoires
ouble - the "attach" is now generic through BPF-core: the caller just needs to set hid_id and flags before calling __load(). - all the BPF tough part is not handled in BPF-core through generic processing - hid_bpf_ctx is now only writable where it needs be Signed-off-by: Ben

[PATCH HID v3 02/16] HID: bpf: add hid_get/put_device() helpers

2024-06-08 Thread Benjamin Tissoires
no code change, but this way we reduce code duplication and we can export it later. Signed-off-by: Benjamin Tissoires --- no changes in v3 no changes in v2 --- drivers/hid/bpf/hid_bpf_dispatch.c | 47 ++ 1 file changed, 27 insertions(+), 20 deletions

[PATCH HID v3 01/16] HID: rename struct hid_bpf_ops into hid_ops

2024-06-08 Thread Benjamin Tissoires
Those operations are the ones from HID, not HID-BPF, and I'd like to reuse hid_bpf_ops as the user facing struct_ops API. Signed-off-by: Benjamin Tissoires --- no changes in v3 no changes in v2 --- drivers/hid/bpf/hid_bpf_dispatch.c | 22 +++--- drivers/hid/hid-c

[PATCH HID v3 00/16] HID: convert HID-BPF into using bpf_struct_ops

2024-06-08 Thread Benjamin Tissoires
). The matching user-space loader (udev-hid-bpf) MR is at https://gitlab.freedesktop.org/libevdev/udev-hid-bpf/-/merge_requests/86 I'll put it out of draft once this is merged. Cheers, Benjamin Signed-off-by: Benjamin Tissoires --- Changes in v3: - took Alexei's review into account -

Re: [PATCH HID v2 03/16] HID: bpf: implement HID-BPF through bpf_struct_ops

2024-06-08 Thread Benjamin Tissoires
On Jun 07 2024, Alexei Starovoitov wrote: > On Fri, Jun 7, 2024 at 8:28 AM Benjamin Tissoires wrote: > > +struct hid_bpf_ops { > > + /* hid_id needs to stay first so we can easily change it > > +* from userspace. > > +*/ > > +

[PATCH HID v2 16/16] HID: bpf: make part of struct hid_device writable

2024-06-07 Thread Benjamin Tissoires
device export 3 nodes, all with the same name. Signed-off-by: Benjamin Tissoires --- new in v2 --- drivers/hid/bpf/hid_bpf_struct_ops.c | 3 +++ include/linux/hid_bpf.h | 2 +- 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/drivers/hid/bpf/hid_bpf_struct_ops.c b

[PATCH HID v2 15/16] HID: bpf: rework hid_bpf_ops_btf_struct_access

2024-06-07 Thread Benjamin Tissoires
The idea is to provide a list of stucts and their editable fields. Currently no functional changes are introduced here, we will add some more writeable fields in the next patch. Signed-off-by: Benjamin Tissoires --- new in v2 --- drivers/hid/bpf/hid_bpf_struct_ops.c | 91

[PATCH HID v2 14/16] bpf: allow bpf helpers to be used into HID-BPF struct_ops

2024-06-07 Thread Benjamin Tissoires
Without this helpers like bpf_printk() or bpf_map_update() are not available, making anything but change of bytes impossible to do. Signed-off-by: Benjamin Tissoires --- new in v2 --- drivers/hid/bpf/hid_bpf_struct_ops.c | 1 + 1 file changed, 1 insertion(+) diff --git a/drivers/hid/bpf

[PATCH HID v2 13/16] HID: bpf: error on warnings when compiling bpf objects

2024-06-07 Thread Benjamin Tissoires
There is no real reasons to paper over warnings for such small programs. Signed-off-by: Benjamin Tissoires --- no changes in v2 --- drivers/hid/bpf/progs/Makefile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/drivers/hid/bpf/progs/Makefile b/drivers/hid/bpf/progs

[PATCH HID v2 12/16] HID: bpf: Artist24: remove unused variable

2024-06-07 Thread Benjamin Tissoires
warning: unused variable ‘tilt’ [-Wunused-variable] Signed-off-by: Peter Hutterer Signed-off-by: Benjamin Tissoires --- no changes in v2 --- drivers/hid/bpf/progs/XPPen__Artist24.bpf.c | 1 - 1 file changed, 1 deletion(-) diff --git a/drivers/hid/bpf/progs/XPPen__Artist24.bpf.c b/drivers

[PATCH HID v2 11/16] Documentation: HID: add a small blurb on udev-hid-bpf

2024-06-07 Thread Benjamin Tissoires
This is the current decision we took: we don't provide automatic loading of HID-BPF by the kernel directly, but rely on an external tool for it. This tool is currently udev-hid-bpf, so let's make people aware of it. Signed-off-by: Benjamin Tissoires --- no changes in v2 --- Documen

[PATCH HID v2 10/16] Documentation: HID: amend HID-BPF for struct_ops

2024-06-07 Thread Benjamin Tissoires
Now that we are using struct_ops, the docs need to be changed. Signed-off-by: Benjamin Tissoires --- changes in v2 - use BPF_F_BEFORE --- Documentation/hid/hid-bpf.rst | 156 +++--- include/linux/hid_bpf.h | 8 +-- 2 files changed, 76 insertions

[PATCH HID v2 09/16] selftests/hid: add subprog call test

2024-06-07 Thread Benjamin Tissoires
I got a weird verifier error with a subprog once, so let's have a test for it. Signed-off-by: Benjamin Tissoires --- no changes in v2 --- tools/testing/selftests/hid/hid_bpf.c | 41 + tools/testing/selftests/hid/progs/hid.c | 24 +++ 2

[PATCH HID v2 08/16] HID: bpf: remove tracing HID-BPF capability

2024-06-07 Thread Benjamin Tissoires
We can now rely on struct_ops as we cleared the users in-tree. Signed-off-by: Benjamin Tissoires --- changes in v2: - remove now unused enum hid_bpf_attach_flags --- drivers/hid/bpf/Makefile| 2 +- drivers/hid/bpf/entrypoints/Makefile| 93 drivers

[PATCH HID v2 07/16] HID: bpf: convert in-tree fixes into struct_ops

2024-06-07 Thread Benjamin Tissoires
Very mechanical: - Change HID_BPF_DEVICE_EVENT and HID_BPF_RDESC_FIXUP #defines - add a matching SEC(".struct_ops.link") - in ArtistPro16Gen2 make the 2 functions static and have a new one calling them Signed-off-by: Benjamin Tissoires --- no changes in v2 --- drivers/hid/bp

[PATCH HID v2 06/16] HID: bpf: add defines for HID-BPF SEC in in-tree bpf fixes

2024-06-07 Thread Benjamin Tissoires
We are going to switch over struct_ops, so instead of having to manually replace all fields one by one, let's have a common place to change it. Signed-off-by: Benjamin Tissoires --- no changes in v2 --- drivers/hid/bpf/progs/FR-TEC__Raptor-Mach-2.bpf.c | 4 ++-- drivers/hid/bpf/

[PATCH HID v2 05/16] HID: samples: convert the 2 HID-BPF samples into struct_ops

2024-06-07 Thread Benjamin Tissoires
This is mostly mechanical: attach_prog is dropped, and the SEC are converted into struct_ops. Signed-off-by: Benjamin Tissoires --- no changes in v2 but the commit message. --- samples/hid/Makefile | 5 ++-- samples/hid/hid_bpf_attach.bpf.c | 18 - samples/hid

[PATCH HID v2 04/16] selftests/hid: convert the hid_bpf selftests with struct_ops

2024-06-07 Thread Benjamin Tissoires
We drop the need for the attach() bpf syscall, but we need to set up the hid_id field before calling __load(). The .bpf.c part is mechanical: we create one struct_ops per HID-BPF program, as all the tests are for one program at a time. Signed-off-by: Benjamin Tissoires --- changes in v2

  1   2   3   4   >