From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=100.103.45.18 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1796417527; b=XGnER+uoKEgMBBuwWLciUUnhA13NtWwCnoqP5tvOOqKmXEks7e/Vp/l20CP8jAdbmk6o U0B427F6qkLVWP9IbhNF1br1vBY/ukfR1QNZmBV68Gew7Qmr6bIlYtW/TA+oA9yXDU8Br 327dqaFnfAMiHc8BDxTVU7AzKrIzzlEr9pYHP0NS7Wm4uOvdYXRdjp2tahE73G4K4xXpT Gqwn4H2BblD2sZqQylaZLTWxj7N9usTY2Q0ZnoKmQduQCEb8vr7P7E7hi/2qbbtJCL+i+ 2pMSBcx/GVg6RRgx1oPm5XjUoNjrj++rhwk3rzVgGP5sTBa16G24HiFKPFXNg3sqkeQ== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796417527; h=Received:DKIM-Signature:Message-ID:From:Subject:Reply-To:To:Cc: In-Reply-To:References:Content-Type:Content-Transfer-Encoding:Date; bh=ni00pmwZ1pvuIwOgpjMq5n0tt7eewAmwdo4STKlX/U0=; b=PDUwOxjFC4j46QgJ6ht6VPvnAYInrpTgu8WaeUX7JO0y3NdsZBY9qmyQlFQU4M41Rqbt vqCB9Ix51+B6niQu5GPjBf7zvcOYSRgb1hZZwjcM5qtFM7z8sE9/P7ppDaTNsmjY1vfe8 EdCwFP687p5y54KZtNJTEw16DXzaTBXoqoYDiaf3nOQ4Q4216FXJAut3pXB8lBlMVfyZs HWgkftvjQLtjLKx9+DRBeCMud2qJXeKP3IFbvXxspy8x7MFjOW7FVlHhYUX8hOgWoI0Eg 9x9hMAwyi8PNUBucqHRsQtMjWMzVspFen8EcEMKbaGZnd07ytz8sr0qwHqDQiQCqLYQ== ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass header.d=kernel.org header.i=@kernel.org header.a=rsa-sha256 header.s=k20260515 header.b=SdKdG5ql; arc=none smtp.remote-ip=100.103.45.18 Received: from smtp.kernel.org (quasi.space.kernel.org [100.103.45.18]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (prime256v1)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id BBD23606A32F; Fri, 4 Dec 2026 20:52:07 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.a=rsa-sha256 header.s=k20260515 header.b=SdKdG5ql Received: by smtp.kernel.org (Postfix) with ESMTPSA id 77AC81F00A10; Fri, 4 Dec 2026 20:52:07 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel.org; s=k20260515; t=1796417527; bh=ni00pmwZ1pvuIwOgpjMq5n0tt7eewAmwdo4STKlX/U0=; h=From:Subject:Reply-To:To:Cc:In-Reply-To:References:Date; b=SdKdG5qld9hWqFLDK1Yvet1JiJDcUMpFlOjNMehEZEbYTKMpBXG1XiV03OE0E6mAu eqeqzW0dEi8Fp4/eg4o3yBaTjmD4mVXUNviqrD+HYxbXFpBpDOaeKbthNFwbGDLbT1 PbcdU8zla7iasWOU6PyjHHF11ntX6ms+HbfZUnQh2KnMdCFvffInYXKxd1Grcln52D B58jgidwN7/O0i+U1dKyAqyJcNByw1fbWv5+DxEzW+Q+/zZwEm+5rA82MRwlRPAekM Q/M4WIJm/QVmUHUcLekTlEhKqesancQ2+wTwAeJWU/MYRI22m0em7f4VGoGCyOgCX7 k6g4O3ZmKk7SA== Message-ID: From: sashiko-bot@kernel.org Subject: Re: [PATCH v2 2/4] selftests/hid: test a device event on a refused report descriptor Reply-To: sashiko-reviews@lists.linux.dev To: "Yassine Ouamer" Cc: linux-input@vger.kernel.org, bpf@vger.kernel.org, dmitry.torokhov@gmail.com In-Reply-To: <20261204-hid-bpf-event-buffer-v2-2-188e8e960231@proton.me> References: <20261204-hid-bpf-event-buffer-v2-0-188e8e960231@proton.me> <20261204-hid-bpf-event-buffer-v2-2-188e8e960231@proton.me> Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable Date: Fri, 04 Dec 2026 20:52:07 +0000 X-Mailing-List: linux-input@vger.kernel.org List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list Thank you for your contribution! Sashiko AI review found 4 potential issues to consider: - [Low] selftests/hid: double pthread_join() in FIXTURE_TEARDOWN() on test failure - [Low] selftests/hid: race between uhid device_add() and LOAD_PROGRAMS() - [Low] selftests/hid: fixture misuse and early-fail double pthread_join() - [Low] selftests/hid: hid_refused_event() duplicates hid_first_event() -- commit 24965259c6874c1e527e7846a0a8da3ce17f15d1 Author: Yassine Ouamer selftests/hid: test a device event on a refused report descriptor This commit adds a HID-BPF selftest that creates a uhid device with a report descriptor refused by the HID core, attaches a struct_ops program with both a report descriptor fixup and a hid_device_event hook, and verifies that an injected event is seen and modified by the program. > diff --git a/tools/testing/selftests/hid/hid_bpf.c b/tools/testing/selfte= sts/hid/hid_bpf.c > index 8c41ebfb85e42..568d84e0eeaa5 100644 > --- a/tools/testing/selftests/hid/hid_bpf.c > +++ b/tools/testing/selftests/hid/hid_bpf.c > @@ -1010,6 +1010,79 @@ TEST_F(hid_bpf, test_rdesc_fixup_change_uniq_name_= phys) [ ... ] > +TEST_F(hid_bpf, test_rdesc_fixup_refused_device_event) > +{ > + const struct test_program progs[] =3D { > + { .name =3D "hid_rdesc_fixup_refused" }, > + }; > + __u8 buf[MAX_BUF_SIZE] =3D {0}; > + void *uhid_err; > + int err; > + > + if (variant->rdesc !=3D rdesc) > + SKIP(return, "not compatible report descriptor"); > + > + /* > + * The fixture's device replaced with one the kernel refuses. It starts > + * only once the program fixed its descriptor, so the uhid events are > + * listened to after that. > + */ > + uhid_destroy(_metadata, &self->hid); > + pthread_join(self->hid.tid, &uhid_err); > + close(self->hid.uhid_fd); > + self->hid.pid =3D 0x0a37; [Severity: Low] Should this test use its own fixture instead of reusing hid_bpf? Neither hid_bpf variant uses variant->rdesc here: unnumbered emits a spurious skip, and numbered creates a throwaway uhid device only to tear it down and open-code device creation. Hardcoding 0x0a37 also collides with the product ID already used in tools/testing/selftests/hid/hidraw.c. A dedicated fixture or helper for creating a uhid device without starting the listener would avoid the throwaway setup, skip, and ID collision. > + self->hid.uhid_fd =3D open("/dev/uhid", O_RDWR | O_CLOEXEC); > + ASSERT_GE(self->hid.uhid_fd, 0) TH_LOG("open uhid-cdev failed"); [Severity: Low] Can an assertion failure before uhid_start_listener() trigger a double pthread_join() in FIXTURE_TEARDOWN(hid_bpf)? pthread_join(self->hid.tid, &uhid_err) has already joined the fixture's listener thread, but self->hid.tid still holds that thread ID until uhid_start_listener() overwrites it. If any assertion fails in between (such as open() or LOAD_PROGRAMS()), kselftest_harness __bail() invokes FIXTURE_TEARDOWN(hid_bpf), which unconditionally calls uhid_destroy() and pthread_join(self->hid.tid, &uhid_err) a second time, risking a crash or hang in teardown (and writing to fd -1 if open() failed) that masks the original failure. > + err =3D uhid_create(_metadata, self->hid.uhid_fd, self->hid.dev_id, sel= f->hid.bus, > + self->hid.vid, self->hid.pid, refused_rdesc, sizeof(refused_rdesc)); > + ASSERT_OK(err) TH_LOG("create uhid device failed"); > + self->hid.hid_id =3D get_hid_id(&self->hid); > + ASSERT_GT(self->hid.hid_id, 0) TH_LOG("Could not locate uhid device id"= ); > + > + LOAD_PROGRAMS(progs); > + > + err =3D uhid_start_listener(_metadata, &self->hid.tid, self->hid.uhid_f= d); [Severity: Low] Can LOAD_PROGRAMS(progs) race with asynchronous uhid device registration? uhid_create() schedules uhid_device_add_worker() on system_wq and returns immediately. Unlike setup_uhid(), which waits for UHID_START first, this test proceeds straight from get_hid_id() into LOAD_PROGRAMS(progs) as soon as the sysfs uevent file appears, before device_add() finishes: test thread kworker (uhid_device_add_worker) uhid_create() -> UHID_CREATE2 hid_add_device() -> device_add() kobject_add() device_create_file(...uevent) get_hid_id() (reads uevent) LOAD_PROGRAMS(progs) bpf_map__attach_struct_ops() hid_bpf_reg() hid_get_device() bus_find_device() <-- -EINVAL, not on bus yet bus_add_device() dev_set_ready_to_probe() bus_probe_device() If hid_bpf_reg() runs between bus_add_device() and dev_set_ready_to_probe(), hid_bpf_reconnect() hits -EPROBE_DEFER and open_hidraw() can time out before the hidraw node appears. If it sets rdesc_ops before bus_probe_device(), the initial probe plus reprobe can queue UHID_START, UHID_STOP, UHID_START, causing uhid_event() to set uhid_stopped and exit the listener thread prematurely once uhid_start_listener() starts. > diff --git a/tools/testing/selftests/hid/progs/hid.c b/tools/testing/self= tests/hid/progs/hid.c > index 48aa8088cc53e..88aa122f4d94f 100644 > --- a/tools/testing/selftests/hid/progs/hid.c > +++ b/tools/testing/selftests/hid/progs/hid.c > @@ -639,3 +639,56 @@ SEC(".struct_ops.link") [ ... ] > +SEC("?struct_ops/hid_device_event") > +int BPF_PROG(hid_refused_event, struct hid_bpf_ctx *hid_ctx, enum hid_re= port_type type) > +{ > + __u8 *rw_data =3D hid_bpf_get_data(hid_ctx, 0 /* offset */, 3 /* size *= /); > + > + if (!rw_data) > + return 0; /* EPERM check */ > + > + callback_check =3D rw_data[1]; > + > + rw_data[2] =3D rw_data[1] + 5; > + > + return hid_ctx->size; > +} > + > +SEC(".struct_ops.link") > +struct hid_bpf_ops rdesc_fixup_refused =3D { > + .hid_rdesc_fixup =3D (void *)hid_rdesc_fixup_refused, > + .hid_device_event =3D (void *)hid_refused_event, > +}; [Severity: Low] Can rdesc_fixup_refused reuse hid_first_event instead of adding hid_refused_event? hid_refused_event() is identical to the existing hid_first_event() in this file, and libbpf supports referencing the same struct_ops program from multiple .struct_ops.link maps. --=20 Sashiko AI review =C2=B7 https://sashiko.dev/#/patchset/20261204-hid-bpf-ev= ent-buffer-v2-0-188e8e960231@proton.me?part=3D2