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=1796453317; b=v/gexIGqtLZQrromVLC3UajQCEM2iaiRE0RZNVN+aor8wnPdolPit6C8yEnhfrNhaq6Z qNv7cjl+EHH1bOikgZ1wxxy+IvcIctoudMMeuzEwstXH0ZgXzqEb76AEe2/PvCyIzW1bo aBSrQnDDAihtCc9hUNcmNvAcFdPJaxXDHRZF/Pj3H3g+Yd1oDpzjdXgmr+NzJp6cEUHIX uUJ1yhndY9IoMB3biO8njuG4tH6tLCVtk1+5dsfVNYvjV/DaSDBdRJCHnL6pNNZl1JqtX 2d481DdYf5+jz5Y4PgXzh0mBDK6NVW7uhB5xQSodFVnaA2SYT4mG2H09j1urA/kCGIQ== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796453317; h=Received:DKIM-Signature:Message-ID:From:Subject:Reply-To:To:Cc: In-Reply-To:References:Content-Type:Content-Transfer-Encoding:Date; bh=77Np+sRqzN+W1deciuJfoF3SqiK1bqP12LCW5G3pgM4=; b=4uG8lJV6P27i+NPlDWpH7iv7whozgs/NQomvNLRm73syPbPziokl9j0BsgYAFZrseoiD dDCsPIb0Tvq8XkILNktc//vJJnhVDVAgcXbiSe9DcGqY16R3pdIWXx6tS6hD3c1FRJHut 279fe5wYj3o7PTFYcgKQxStNh2hm9kdvUQGRw5wNl0SJcptMLkGbEXDXxeBFK7825TDkG J3kbEN8YWCr0LAKM4MxT9LA3Wn27q2Lkg/hBmSFH+rjuIF+Wa7VJJf7xlpNDlBfRyWYDU 6Fz6TGWem4Ms7BT+N29yS9LoFwejsUqYttp8BvpSinKEYTv5kHuzs39ts5TOX/Lj4bw== 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=cSolNOwF; 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 74235606A322 for ; Sat, 5 Dec 2026 06:48:37 +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=cSolNOwF Received: by smtp.kernel.org (Postfix) with ESMTPSA id DD5781F0092B; Sat, 5 Dec 2026 06:48:36 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel.org; s=k20260515; t=1796453317; bh=77Np+sRqzN+W1deciuJfoF3SqiK1bqP12LCW5G3pgM4=; h=From:Subject:Reply-To:To:Cc:In-Reply-To:References:Date; b=cSolNOwFiW31Xgk2jOwY488Wg9QnOrEpntMgEtTkZNhrAOT2tAZCsN7DXBfBQwbPm 33FVpqaH/Gdsf42UKrvKOUlhgfpsFYHM1QAA3VcVMgflBv/HgtghpFbv2GcHbOpKg7 wdr1/bMXb8zRGLukiq3Mck99DT8IBlIyFn2YtSriBsHFpB0vI1DoUzezsBCE/5U29K 7uKcs9CaXi1BDZcjOahONcJkY8MPPiDcDE0oh3pCwBpHYWuq3geE4p58U2zhQoyadc rpKB6bHoZhAjjqPDUNksnT5nMYCORQNMEToKy0C4KlCJy4osVxxIiYVxlHenx49OKc S69MXO25s5I1Q== Message-ID: From: sashiko-bot@kernel.org Subject: Re: [PATCH v5] HID: hid-msi: Guard against delayed 0x06 MCU ACKs Reply-To: sashiko-reviews@lists.linux.dev To: "Kenhou Iijima" Cc: linux-input@vger.kernel.org, dmitry.torokhov@gmail.com In-Reply-To: <20261205062637.84074-1-kenhou@kenhou.net> References: <20261205062637.84074-1-kenhou@kenhou.net> Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable Date: Sat, 05 Dec 2026 06:48:36 +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: - [Medium] HID: hid-msi: 32-bit jiffies wraparound in claw_ack_window_remaining() - [Medium] HID: hid-msi: claw_suspend() races with sysfs writers on ACK windows - [Low] HID: hid-msi: claw_raw_event() omits rom_sync_until expiry check - [Low] HID: hid-msi: claw_remove() allows draining writes to re-arm ACK windows -- commit d4a415522b3d555f6f69674df166a57041041923 Author: Kenhou Iijima HID: hid-msi: Guard against delayed 0x06 MCU ACKs This commit restricts generic 0x06 ACK completion to WRITE_PROFILE_DATA commands and adds jiffies-based quiet and ROM-sync wait windows so delayed MCU ACKs do not prematurely complete subsequent reads or profile writes. Link: https://lore.kernel.org/r/20261201012506.2313913-1-derekjohn.clark@gm= ail.com > diff --git a/drivers/hid/hid-msi.c b/drivers/hid/hid-msi.c > index 23d731f700c90..611cd224f3143 100644 > --- a/drivers/hid/hid-msi.c > +++ b/drivers/hid/hid-msi.c [ ... ] > @@ -486,10 +495,36 @@ static int claw_profile_event(struct claw_drvdata *= drvdata, struct claw_command_ > return 0; > } > =20 > +static unsigned long claw_ack_window_remaining(struct claw_drvdata *drvd= ata, > + bool *pending, unsigned long until, > + unsigned long now) > +{ > + lockdep_assert_held(&drvdata->cmd_lock); > + > + if (!*pending) > + return 0; > + > + if (time_before(now, until)) > + return until - now; > + > + *pending =3D false; > + return 0; > +} [Severity: Medium] Can ack_quiet_until and rom_sync_until wrap around on 32-bit kernels? CONFIG_HID_MSI has no 64BIT dependency, and both pending flags expire lazily with no timer. Every SYNC_TO_ROM commit ACK leaves ack_quiet_pending set, so after 2^31 jiffies (~24.85 days at HZ=3D1000) without clearing it, time_before(now, until) flips back to true and returns up to 0x80000000. claw_wait_ack_window() passes that value directly to wait_event_interruptible_timeout() while holding rom_mutex, causing a multi-week sleep, an indefinite MAX_SCHEDULE_TIMEOUT sleep, or a negative-timeout dump_stack(). >From claw_rgb_queue_fn() on system_wq this stalls the worker and hangs claw_suspend() in cancel_delayed_work_sync() before claw_clear_ack_windows() can wake it. Later timeout-0 commands also fail to overwrite the wrapped deadline in __claw_hw_output_report() because time_after() returns false. Storing 64-bit timestamps via get_jiffies_64() or ktime_t would avoid this. [ ... ] > @@ -525,14 +560,45 @@ static int claw_raw_event(struct claw_drvdata *drvd= ata, struct hid_report *repor > =20 > break; > case CLAW_COMMAND_TYPE_ACK: > + /* > + * SYNC_TO_ROM can emit an immediate ACK (~4 ms) and a flash > + * commit ACK (~515-566 ms), or only the commit ACK. Once a > + * commit-window 0x06 arrives outside an active TX quiet > + * window, mark the ROM sync settled and open a 35 ms quiet > + * window to absorb any timeout-0 ACKs (e.g. SWITCH_MODE) > + * that the MCU queued behind the flash commit. > + */ > + now =3D jiffies; > + if (!claw_ack_window_remaining(drvdata, > + &drvdata->ack_quiet_pending, > + drvdata->ack_quiet_until, now) && > + drvdata->rom_sync_pending && > + time_after_eq(now, drvdata->rom_sync_min_ack)) { > + drvdata->rom_sync_pending =3D false; > + /* +1 jiffy so the window never expires early */ > + drvdata->ack_quiet_until =3D now + msecs_to_jiffies(35) + 1; > + drvdata->ack_quiet_pending =3D true; > + wake_up_all(&drvdata->ack_waitq); > + } [Severity: Low] Should this check claw_ack_window_remaining() on rom_sync_until instead of testing bare drvdata->rom_sync_pending? If a SYNC_TO_ROM commit ACK is missed or lands during a 35 ms quiet window, rom_sync_pending stays true past 700 ms. Any later 0x06 ACK outside an active quiet window (such as a reply to a userspace hidraw command) is then misclassified as that commit ACK and arms a spurious 35 ms quiet window. Using claw_ack_window_remaining() on rom_sync_pending and rom_sync_until would enforce the upper bound and lazily clear an expired window instead. [ ... ] > @@ -1946,6 +2154,8 @@ static void claw_remove(struct hid_device *hdev) > smp_store_release(&drvdata->rgb_registered, false); > } > =20 > + claw_clear_ack_windows(drvdata); > + > if (gp_registered) > device_remove_group(&hdev->dev, &claw_gamepad_attr_group); > =20 > @@ -1953,7 +2163,11 @@ static void claw_remove(struct hid_device *hdev) > device_remove_group(drvdata->led_mc.led_cdev.dev, &claw_rgb_attr_group= ); > led_classdev_multicolor_unregister(&drvdata->led_mc); > } > + > + /* Wake rgb_queue as well if a draining sysfs store re-armed a window. = */ > + claw_clear_ack_windows(drvdata); > cancel_delayed_work_sync(&drvdata->rgb_queue); > + claw_clear_ack_windows(drvdata); > =20 > hid_hw_close(hdev); > } [Severity: Low] Can draining sysfs stores re-arm rom_sync_pending after the first claw_clear_ack_windows() and stall device_remove_group()? Profile-write stores (such as rumble_intensity_left_store()) check gp_registered before acquiring rom_mutex and do not re-check it afterward. Because claw_clear_ack_windows() clears the flags once without preventing re-arming, a second draining store can sleep for the full 700 ms window while claw_remove() waits on it before reaching the later clears: CPU0 (claw_remove) CPU1 (store 1) CPU2 (store 2) clear gp_registered (passed gp_registered) claw_clear_ack_windows() mutex_lock(rom_mutex) device_remove_group() SYNC_TO_ROM -> (waits for store 2) rom_sync_pending=3Dtrue mutex_unlock(rom_mutex) WRITE_PROFILE_DATA -> claw_wait_ack_window() <-- stalls 700 ms Multiple draining stores can chain this stall sequentially during unbind or disconnect. Latching a teardown flag under cmd_lock in claw_remove() and checking it before arming or waiting on ACK windows would prevent re-arming. [ ... ] > @@ -2016,6 +2230,15 @@ static int claw_suspend(struct hid_device *hdev) > cancel_delayed_work_sync(&drvdata->cfg_setup); > cancel_delayed_work_sync(&drvdata->rgb_queue); > =20 > + /* > + * Delayed ACKs across suspend will not arrive after resume. Clear > + * windows before taking cfg_mutex so any active window waiter wakes > + * first, then clear again under cfg_mutex. > + */ > + claw_clear_ack_windows(drvdata); > + scoped_guard(mutex, &drvdata->cfg_mutex) > + claw_clear_ack_windows(drvdata); > + > return 0; > } [Severity: Medium] Can claw_suspend() wake a concurrent sysfs profile writer early and let it send WRITE_PROFILE_DATA prematurely or re-arm rom_sync_pending across suspend? Under USB runtime autosuspend, hid_suspend() calls claw_suspend() without freezing userspace and before hid_cease_io() or port suspend runs. Because claw_wait_ack_window() returns 0 on wake and claw_suspend() synchronizes only on cfg_mutex (not rom_mutex), a profile store can race as follows: CPU0 (runtime autosuspend) CPU1 (rumble_intensity_left_store) hid_suspend() mutex_lock(rom_mutex) claw_suspend() WRITE_PROFILE_DATA -> claw_clear_ack_windows() claw_wait_ack_window() -> returns 0 mutex_lock(cfg_mutex) [waits] mutex_lock(cfg_mutex) __claw_hw_output_report() <-- sends inside active ACK window mutex_unlock(cfg_mutex) claw_clear_ack_windows() mutex_unlock(cfg_mutex) return 0 SYNC_TO_ROM -> rom_sync_pending =3D true usbhid_output_report() <-- arms window across suspend usbhid_output_report() submits a temporary URB via usb_interrupt_msg() without checking HID_SUSPENDED, so both commands can succeed before the port suspends. WRITE_PROFILE_DATA then runs inside the active delayed-ACK window, and SYNC_TO_ROM leaves rom_sync_pending and orphan_ack_pending set. --=20 Sashiko AI review =C2=B7 https://sashiko.dev/#/patchset/20261205062637.8407= 4-1-kenhou@kenhou.net?part=3D1