linux-input.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH 0/2] HID: bpf: allow bpf to rebind a driver to hid-mutltiouch
@ 2025-08-21 14:38 Benjamin Tissoires
  2025-08-21 14:38 ` [PATCH 1/2] HID: core: factor out hid_set_group() Benjamin Tissoires
                   ` (2 more replies)
  0 siblings, 3 replies; 4+ messages in thread
From: Benjamin Tissoires @ 2025-08-21 14:38 UTC (permalink / raw)
  To: Jiri Kosina, Peter Hutterer; +Cc: linux-input, linux-kernel, Benjamin Tissoires

This happened while Peter was trying to fix a Viewsonic device: the HID
device sending multiotuch data through a proprietary collection was
handled by hid-generic, and we don't have any way of attaching it to
hid-multitouch because the pre-scanning wasn't able to see the Contact
ID HID usage.

After a little of back and forth, it turns out that the best solution is
to re-scan the device when a report descriptor is changed from the BPF
point of view.

Signed-off-by: Benjamin Tissoires <bentiss@kernel.org>
---
Benjamin Tissoires (2):
      HID: core: factor out hid_set_group()
      HID: bpf: rescan the device for the group after a load/unload

 drivers/hid/hid-core.c | 44 ++++++++++++++++++++++++++++++++++++--------
 1 file changed, 36 insertions(+), 8 deletions(-)
---
base-commit: f55f91622e6f10884d30049f6748588b3718eecd
change-id: 20250821-bpf-rescan-d4764865c67f

Best regards,
-- 
Benjamin Tissoires <bentiss@kernel.org>


^ permalink raw reply	[flat|nested] 4+ messages in thread

* [PATCH 1/2] HID: core: factor out hid_set_group()
  2025-08-21 14:38 [PATCH 0/2] HID: bpf: allow bpf to rebind a driver to hid-mutltiouch Benjamin Tissoires
@ 2025-08-21 14:38 ` Benjamin Tissoires
  2025-08-21 14:38 ` [PATCH 2/2] HID: bpf: rescan the device for the group after a load/unload Benjamin Tissoires
  2025-08-26  2:54 ` [PATCH 0/2] HID: bpf: allow bpf to rebind a driver to hid-mutltiouch Peter Hutterer
  2 siblings, 0 replies; 4+ messages in thread
From: Benjamin Tissoires @ 2025-08-21 14:38 UTC (permalink / raw)
  To: Jiri Kosina, Peter Hutterer; +Cc: linux-input, linux-kernel, Benjamin Tissoires

When we load a bpf, we can change the report descriptor. However, the
current implementation doesn't change the group meaning that we can not
rebind a device from hid-generic to hid-multitouch.

This is a preparatory patch to force a rescan of the device after the
bpf has been loaded.

Signed-off-by: Benjamin Tissoires <bentiss@kernel.org>
---
 drivers/hid/hid-core.c | 23 +++++++++++++++--------
 1 file changed, 15 insertions(+), 8 deletions(-)

diff --git a/drivers/hid/hid-core.c b/drivers/hid/hid-core.c
index 5419a6c10907e307df08c3b44e2b3a147f1b154a..cf68fdffe0581eefb29a9d691f4acfc8f0d175d5 100644
--- a/drivers/hid/hid-core.c
+++ b/drivers/hid/hid-core.c
@@ -2708,6 +2708,20 @@ static bool hid_check_device_match(struct hid_device *hdev,
 	return !hid_ignore_special_drivers && !(hdev->quirks & HID_QUIRK_IGNORE_SPECIAL_DRIVER);
 }
 
+static void hid_set_group(struct hid_device *hdev)
+{
+	int ret;
+
+	if (hid_ignore_special_drivers) {
+		hdev->group = HID_GROUP_GENERIC;
+	} else if (!hdev->group &&
+		   !(hdev->quirks & HID_QUIRK_HAVE_SPECIAL_DRIVER)) {
+		ret = hid_scan_report(hdev);
+		if (ret)
+			hid_warn(hdev, "bad device descriptor (%d)\n", ret);
+	}
+}
+
 static int __hid_device_probe(struct hid_device *hdev, struct hid_driver *hdrv)
 {
 	const struct hid_device_id *id;
@@ -2903,14 +2917,7 @@ int hid_add_device(struct hid_device *hdev)
 	/*
 	 * Scan generic devices for group information
 	 */
-	if (hid_ignore_special_drivers) {
-		hdev->group = HID_GROUP_GENERIC;
-	} else if (!hdev->group &&
-		   !(hdev->quirks & HID_QUIRK_HAVE_SPECIAL_DRIVER)) {
-		ret = hid_scan_report(hdev);
-		if (ret)
-			hid_warn(hdev, "bad device descriptor (%d)\n", ret);
-	}
+	hid_set_group(hdev);
 
 	hdev->id = atomic_inc_return(&id);
 

-- 
2.50.1


^ permalink raw reply related	[flat|nested] 4+ messages in thread

* [PATCH 2/2] HID: bpf: rescan the device for the group after a load/unload
  2025-08-21 14:38 [PATCH 0/2] HID: bpf: allow bpf to rebind a driver to hid-mutltiouch Benjamin Tissoires
  2025-08-21 14:38 ` [PATCH 1/2] HID: core: factor out hid_set_group() Benjamin Tissoires
@ 2025-08-21 14:38 ` Benjamin Tissoires
  2025-08-26  2:54 ` [PATCH 0/2] HID: bpf: allow bpf to rebind a driver to hid-mutltiouch Peter Hutterer
  2 siblings, 0 replies; 4+ messages in thread
From: Benjamin Tissoires @ 2025-08-21 14:38 UTC (permalink / raw)
  To: Jiri Kosina, Peter Hutterer; +Cc: linux-input, linux-kernel, Benjamin Tissoires

When a BPF gets loaded, it was previously not possible to bind a
hid-generic device to hid-multitouch because the group was never
updated.

This change forces a rescan of the report descriptor after a bpf is
loaded/unloaded so we set up the proper group.

This was detected while Peter was trying to fix a Viewsonic device: the
HID device sending multiotuch data through a proprietary collection was
handled by hid-generic, and we don't have any way of attaching it to
hid-multitouch because the pre-scanning wasn't able to see the Contact
ID HID usage.

Suggested-by: Peter Hutterer <peter.hutterer@who-t.net>
Signed-off-by: Benjamin Tissoires <bentiss@kernel.org>
---
 drivers/hid/hid-core.c | 21 +++++++++++++++++++++
 1 file changed, 21 insertions(+)

diff --git a/drivers/hid/hid-core.c b/drivers/hid/hid-core.c
index cf68fdffe0581eefb29a9d691f4acfc8f0d175d5..a5b3a8ca2fcbc868470dd50ec14e4c7829dd863b 100644
--- a/drivers/hid/hid-core.c
+++ b/drivers/hid/hid-core.c
@@ -943,6 +943,15 @@ static int hid_scan_report(struct hid_device *hid)
 	parser->device = hid;
 	hid->group = HID_GROUP_GENERIC;
 
+	/*
+	 * In case we are re-scanning after a BPF has been loaded,
+	 * we need to use the bpf report descriptor, not the original one.
+	 */
+	if (hid->bpf_rdesc && hid->bpf_rsize) {
+		start = hid->bpf_rdesc;
+		end = start + hid->bpf_rsize;
+	}
+
 	/*
 	 * The parsing is simpler than the one in hid_open_report() as we should
 	 * be robust against hid errors. Those errors will be raised by
@@ -2728,6 +2737,12 @@ static int __hid_device_probe(struct hid_device *hdev, struct hid_driver *hdrv)
 	int ret;
 
 	if (!hdev->bpf_rsize) {
+		/* we keep a reference to the currently scanned report descriptor */
+		const __u8  *original_rdesc = hdev->bpf_rdesc;
+
+		if (!original_rdesc)
+			original_rdesc = hdev->dev_rdesc;
+
 		/* in case a bpf program gets detached, we need to free the old one */
 		hid_free_bpf_rdesc(hdev);
 
@@ -2737,6 +2752,12 @@ static int __hid_device_probe(struct hid_device *hdev, struct hid_driver *hdrv)
 		/* call_hid_bpf_rdesc_fixup will always return a valid pointer */
 		hdev->bpf_rdesc = call_hid_bpf_rdesc_fixup(hdev, hdev->dev_rdesc,
 							   &hdev->bpf_rsize);
+
+		/* the report descriptor changed, we need to re-scan it */
+		if (original_rdesc != hdev->bpf_rdesc) {
+			hdev->group = 0;
+			hid_set_group(hdev);
+		}
 	}
 
 	if (!hid_check_device_match(hdev, hdrv, &id))

-- 
2.50.1


^ permalink raw reply related	[flat|nested] 4+ messages in thread

* Re: [PATCH 0/2] HID: bpf: allow bpf to rebind a driver to hid-mutltiouch
  2025-08-21 14:38 [PATCH 0/2] HID: bpf: allow bpf to rebind a driver to hid-mutltiouch Benjamin Tissoires
  2025-08-21 14:38 ` [PATCH 1/2] HID: core: factor out hid_set_group() Benjamin Tissoires
  2025-08-21 14:38 ` [PATCH 2/2] HID: bpf: rescan the device for the group after a load/unload Benjamin Tissoires
@ 2025-08-26  2:54 ` Peter Hutterer
  2 siblings, 0 replies; 4+ messages in thread
From: Peter Hutterer @ 2025-08-26  2:54 UTC (permalink / raw)
  To: Benjamin Tissoires; +Cc: Jiri Kosina, linux-input, linux-kernel

On Thu, Aug 21, 2025 at 04:38:12PM +0200, Benjamin Tissoires wrote:
> This happened while Peter was trying to fix a Viewsonic device: the HID
> device sending multiotuch data through a proprietary collection was
> handled by hid-generic, and we don't have any way of attaching it to
> hid-multitouch because the pre-scanning wasn't able to see the Contact
> ID HID usage.
> 
> After a little of back and forth, it turns out that the best solution is
> to re-scan the device when a report descriptor is changed from the BPF
> point of view.
> 
> Signed-off-by: Benjamin Tissoires <bentiss@kernel.org>

Thanks, this series looks good to me.

Reviewed-by: Peter Hutterer <peter.hutterer@who-t.net>

Cheers,
  Peter

> ---
> Benjamin Tissoires (2):
>       HID: core: factor out hid_set_group()
>       HID: bpf: rescan the device for the group after a load/unload
> 
>  drivers/hid/hid-core.c | 44 ++++++++++++++++++++++++++++++++++++--------
>  1 file changed, 36 insertions(+), 8 deletions(-)
> ---
> base-commit: f55f91622e6f10884d30049f6748588b3718eecd
> change-id: 20250821-bpf-rescan-d4764865c67f
> 
> Best regards,
> -- 
> Benjamin Tissoires <bentiss@kernel.org>
> 

^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2025-08-26  2:57 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-08-21 14:38 [PATCH 0/2] HID: bpf: allow bpf to rebind a driver to hid-mutltiouch Benjamin Tissoires
2025-08-21 14:38 ` [PATCH 1/2] HID: core: factor out hid_set_group() Benjamin Tissoires
2025-08-21 14:38 ` [PATCH 2/2] HID: bpf: rescan the device for the group after a load/unload Benjamin Tissoires
2025-08-26  2:54 ` [PATCH 0/2] HID: bpf: allow bpf to rebind a driver to hid-mutltiouch Peter Hutterer

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).