From nobody Sat Oct 4 00:27:00 2025 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id EF3BD215175; Thu, 21 Aug 2025 14:38:25 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1755787106; cv=none; b=rM/jB5Vi61fp3PVD+2dTsS4fKxxxiVhC4rsn1FyM02xVgrHk7Zzgr/a9ypq8TxOhl1VspWb5v65iUa5hBnWEI/ljkuPr7sOsjjttHgWGT3THrU/Wr900rghJLrcUMdp6bZS7+HTLVqQDKg9IgFHxR3cH9/SCfynk7qSKHGJXVjI= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1755787106; c=relaxed/simple; bh=CRSHc6Vc84YrC2WmGMlDYgT0QJ3LVjv7SG6Lj8AFa+o=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=U54hk7dxdQiKMEvWzBUx2mFN1hUiRdsj+OBREwdC5qgr+jbGBbVDoNilD87xhOKWggKZ9kHEkh8owj9KkGk+AyIU4qBVQatMIoe15lUd6+ri0A1MKlFpX+fvwEQChsuf+IfmN+VxR5SKuYBXiHZ/hHtbbGPw2iEESIokoM8OyA4= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=sTGELLAd; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="sTGELLAd" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 85E3AC4CEED; Thu, 21 Aug 2025 14:38:24 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1755787105; bh=CRSHc6Vc84YrC2WmGMlDYgT0QJ3LVjv7SG6Lj8AFa+o=; h=From:Date:Subject:References:In-Reply-To:To:Cc:From; b=sTGELLAdrcH+pFaMQSLrf3q0XUb09cS4j/4vFlrEZu7Fv705jiky9bidCBywpAUmj mySftYX/Id3FmfXaAzwjw5B7SuNxKffDXE/Rs0oLei66adamffIgnKvH1WGUw6dRmf 4NAonPHiW+k7r5j+crcwDrGKh+o0y4ybt8m+HjTc2uoi+z2F9XN1idPjYdQ4WPn5Xr OKv79j2l33YExI0211kp8dnkb4p3gQ6QcU/s/Y/37lA3l/Fz13xZNGfA8y8MVXU8dJ /Nu5jLNzIMrgNftFMe565lj6aG/4o5uJHbWLkrLa2YvePPm9UtJqAyylKRgqpD58W+ Elex2KaIqAYAw== From: Benjamin Tissoires Date: Thu, 21 Aug 2025 16:38:13 +0200 Subject: [PATCH 1/2] HID: core: factor out hid_set_group() Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Message-Id: <20250821-bpf-rescan-v1-1-08f9e2bc01bb@kernel.org> References: <20250821-bpf-rescan-v1-0-08f9e2bc01bb@kernel.org> In-Reply-To: <20250821-bpf-rescan-v1-0-08f9e2bc01bb@kernel.org> To: Jiri Kosina , Peter Hutterer Cc: linux-input@vger.kernel.org, linux-kernel@vger.kernel.org, Benjamin Tissoires X-Mailer: b4 0.14.2 X-Developer-Signature: v=1; a=ed25519-sha256; t=1755787102; l=1819; i=bentiss@kernel.org; s=20230215; h=from:subject:message-id; bh=CRSHc6Vc84YrC2WmGMlDYgT0QJ3LVjv7SG6Lj8AFa+o=; b=1tlhsteG2K4EjhNgRBUdtFgE0fy2wD4vOoyRs2vglnBxUeaV0cjqEvujkrMFaYHZw0qYvTUhn L2w1pBq04VWDNIDD9nff0LyGQ3WuN8yFDJErzW7fpZPLpAzc88md0bM X-Developer-Key: i=bentiss@kernel.org; a=ed25519; pk=7D1DyAVh6ajCkuUTudt/chMuXWIJHlv2qCsRkIizvFw= 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 Reviewed-by: Peter Hutterer --- 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..cf68fdffe0581eefb29a9d691f4= acfc8f0d175d5 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_S= PECIAL_DRIVER); } =20 +static void hid_set_group(struct hid_device *hdev) +{ + int ret; + + if (hid_ignore_special_drivers) { + hdev->group =3D HID_GROUP_GENERIC; + } else if (!hdev->group && + !(hdev->quirks & HID_QUIRK_HAVE_SPECIAL_DRIVER)) { + ret =3D 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 =3D HID_GROUP_GENERIC; - } else if (!hdev->group && - !(hdev->quirks & HID_QUIRK_HAVE_SPECIAL_DRIVER)) { - ret =3D hid_scan_report(hdev); - if (ret) - hid_warn(hdev, "bad device descriptor (%d)\n", ret); - } + hid_set_group(hdev); =20 hdev->id =3D atomic_inc_return(&id); =20 --=20 2.50.1 From nobody Sat Oct 4 00:27:00 2025 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 5987C23A99D; Thu, 21 Aug 2025 14:38:26 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1755787107; cv=none; b=VjPk7+Dl1q/dl1cJRawhUEHOSk22FW+ttrJVDxpVklUx1IIBH4qiO6tS0Pu/2AFABOR2YyQ++tRKjKUkjCTUPPLpSEo9Vn5C6YBY0LeUOHZ6ATO+wfj4MgkYChLQJkPcz/FbG4fHL1ITN2jkCcbDnwV19R5vaGQtlPaw0NSXH6E= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1755787107; c=relaxed/simple; bh=5rKXOaf+FjApOo2PM3ey29CU7EQXzCLVpo1BMPIg/HE=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=SGm91BPf1joZDKFrzMk4/Cg8iqsdQJ+02vpu3q1cCcGHQmThob4YpCq/b56c/LiKMqufyxo+y1ZUnkMwrHl/hsQYWnAm3p97lqt3MHbgirSCR8l+UgJL5AsLXBQs8s9w/TK5YYMg5H+fR1uxRdP+lomrzjnR8euPAPWPET5K7mU= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=F4bT6Fcx; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="F4bT6Fcx" Received: by smtp.kernel.org (Postfix) with ESMTPSA id D8291C116D0; Thu, 21 Aug 2025 14:38:25 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1755787106; bh=5rKXOaf+FjApOo2PM3ey29CU7EQXzCLVpo1BMPIg/HE=; h=From:Date:Subject:References:In-Reply-To:To:Cc:From; b=F4bT6FcxVFawBtmUVwyyMKGnU/dQZkzLv9I1vI2k7tpR6PRRml2DVv/7YEwFyOa5L q63RLl4gChoNQbARH3lwhzzf/pkPHkzSDvPgAMl5tZlRyjkFeirkxCbcnE3FG4QDj6 WYfrNICb3HxvLsvY16qVlPWs91SgWlKM1OTErvCKJh90ZWYTtLAMhcftozwIJjE/qg eWfKmlZ4HqdBRR/DmjDcdMHLIRKBnLOBEphcOXSsFfpw3WfvZ08WB6AoAWftmpKsUC y2Z15B3CVwoNgMCaNGdcWP1fUNbTd6QjxeieM5s2B9o2TBmlF19TrV3djZLKNjv5y5 P7hplZaEpkqZQ== From: Benjamin Tissoires Date: Thu, 21 Aug 2025 16:38:14 +0200 Subject: [PATCH 2/2] HID: bpf: rescan the device for the group after a load/unload Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Message-Id: <20250821-bpf-rescan-v1-2-08f9e2bc01bb@kernel.org> References: <20250821-bpf-rescan-v1-0-08f9e2bc01bb@kernel.org> In-Reply-To: <20250821-bpf-rescan-v1-0-08f9e2bc01bb@kernel.org> To: Jiri Kosina , Peter Hutterer Cc: linux-input@vger.kernel.org, linux-kernel@vger.kernel.org, Benjamin Tissoires X-Mailer: b4 0.14.2 X-Developer-Signature: v=1; a=ed25519-sha256; t=1755787102; l=2497; i=bentiss@kernel.org; s=20230215; h=from:subject:message-id; bh=5rKXOaf+FjApOo2PM3ey29CU7EQXzCLVpo1BMPIg/HE=; b=yzAF+cNccVC7WjbpG3YRz2KbpOHBRZh09QRqE1nl7hzgIx3xEiG5GS6nc3C5DR8TVUY92lLoo Z5k3GROwUdFCQwPsKT5T2VClPo6uY4823tDWrm+t2eItdhcyhILS9m8 X-Developer-Key: i=bentiss@kernel.org; a=ed25519; pk=7D1DyAVh6ajCkuUTudt/chMuXWIJHlv2qCsRkIizvFw= 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 Signed-off-by: Benjamin Tissoires Reviewed-by: Peter Hutterer --- 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..a5b3a8ca2fcbc868470dd50ec14= e4c7829dd863b 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 =3D hid; hid->group =3D HID_GROUP_GENERIC; =20 + /* + * 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 =3D hid->bpf_rdesc; + end =3D 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 *hde= v, struct hid_driver *hdrv) int ret; =20 if (!hdev->bpf_rsize) { + /* we keep a reference to the currently scanned report descriptor */ + const __u8 *original_rdesc =3D hdev->bpf_rdesc; + + if (!original_rdesc) + original_rdesc =3D hdev->dev_rdesc; + /* in case a bpf program gets detached, we need to free the old one */ hid_free_bpf_rdesc(hdev); =20 @@ -2737,6 +2752,12 @@ static int __hid_device_probe(struct hid_device *hde= v, struct hid_driver *hdrv) /* call_hid_bpf_rdesc_fixup will always return a valid pointer */ hdev->bpf_rdesc =3D 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 !=3D hdev->bpf_rdesc) { + hdev->group =3D 0; + hid_set_group(hdev); + } } =20 if (!hid_check_device_match(hdev, hdrv, &id)) --=20 2.50.1