From: sashiko-bot@kernel.org
To: "Derek J. Clark" <derekjohn.clark@gmail.com>
Cc: linux-input@vger.kernel.org, linux-usb@vger.kernel.org,
dmitry.torokhov@gmail.com
Subject: Re: [PATCH 5/8] HID: hid-msi: Drain in-flight MCU traffic before suspend
Date: Fri, 04 Dec 2026 00:38:48 +0000 [thread overview]
Message-ID: <sashiko-outbox-248838@kernel.org> (raw)
In-Reply-To: <20261204001846.3801336-6-derekjohn.clark@gmail.com>
Thank you for your contribution! Sashiko AI review found 3 potential
issues to consider:
- [Medium] HID: hid-msi: apply_store() races with claw_suspend() and
cfg_resume_fn()
- [Medium] HID: hid-msi: cfg_resume_fn() clears suspended gate before
reset resync
- [Low] HID: hid-msi: commit message describes pre-series SYNC_TO_ROM
paths
--
commit 4d5656ee486cb7868f5c825b51fb8126a0c79c11
Author: Derek J. Clark <derekjohn.clark@gmail.com>
HID: hid-msi: Drain in-flight MCU traffic before suspend
This commit gates MCU commands on a suspended flag protected by rom_mutex
and cfg_mutex, changes command timeouts to return -ETIMEDOUT instead of
-EBUSY, and waits for any pending orphan ACK during suspend.
> Four write paths upstream end with SYNC_TO_ROM, a command sent with no
> timeout, so the MCU can still owe an ACK at any moment.
[Severity: Low]
Is this opening sentence still accurate after commit "HID: hid-msi: Move the
ROM commit to an explicit apply attribute" earlier in this series? That
commit removed CLAW_COMMAND_TYPE_SYNC_TO_ROM from the four write paths,
leaving apply_store() as the only caller that sends it.
> diff --git a/drivers/hid/hid-msi.c b/drivers/hid/hid-msi.c
> index 606ff7d652766..d6134ff310f3a 100644
> --- a/drivers/hid/hid-msi.c
> +++ b/drivers/hid/hid-msi.c
[ ... ]
> @@ -877,6 +881,8 @@ static ssize_t apply_store(struct device *dev, struct device_attribute *attr,
> flush_delayed_work(&drvdata->rgb_queue);
>
> guard(mutex)(&drvdata->rom_mutex);
> + if (drvdata->suspended)
> + return -EBUSY;
>
> ret = claw_hw_output_report(hdev, CLAW_COMMAND_TYPE_SYNC_TO_ROM, NULL, 0, 0);
> if (ret)
[Severity: Medium]
Can apply_store() commit stale MCU RAM to flash by racing with
claw_suspend() or cfg_resume_fn()?
claw_suspend() cancels rgb_queue before taking rom_mutex and setting
drvdata->suspended = true. During USB autosuspend while userspace is still
running, a concurrent apply_store() can slip in between the cancel and the
flag update:
CPU0 (claw_suspend) CPU1 (apply_store)
cancel_delayed_work_sync(rgb_queue)
flush_delayed_work(rgb_queue) (no-op)
mutex_lock(&rom_mutex)
drvdata->suspended == false
CLAW_COMMAND_TYPE_SYNC_TO_ROM
<-- commits stale MCU RAM to flash
mutex_lock(&rom_mutex)
drvdata->suspended = true
A similar race happens on resume: if apply_store() flushes rgb_queue while
drvdata->suspended is still true, claw_write_rgb_state() aborts with -EBUSY,
which flush_delayed_work() does not report back. If cfg_resume_fn() then
clears drvdata->suspended before apply_store() takes rom_mutex,
apply_store() sends SYNC_TO_ROM on stale MCU RAM and returns success.
Setting drvdata->suspended under the mutexes before cancelling rgb_queue
(after releasing the mutexes to avoid an ABBA deadlock) and checking under
rom_mutex that no RGB update failed or remains pending would close both
windows.
[ ... ]
> @@ -1818,6 +1836,10 @@ static void cfg_resume_fn(struct work_struct *work)
> struct claw_drvdata *drvdata = container_of(dwork, struct claw_drvdata, cfg_resume);
> bool gp_registered, rgb_registered, resync;
>
> + scoped_guard(mutex, &drvdata->rom_mutex)
> + scoped_guard(mutex, &drvdata->cfg_mutex)
> + drvdata->suspended = false;
> +
> /* Pairs with smp_store_release from claw_resume in process context */
> resync = smp_load_acquire(&drvdata->resync);
[Severity: Medium]
Should cfg_resume_fn() keep drvdata->suspended set until the post-reset
resync in cfg_setup_fn() completes?
On a reset-resume, cfg_resume_fn() clears drvdata->suspended at T+500 ms and
then schedules cfg_setup for another 500 ms later. Because gp_registered
stays true across suspend, a userspace store to gamepad_mode_store() or
mkeys_function_store() during that 500 ms window passes the suspended check
in __claw_hw_output_report(), combines the new value with the stale
pre-reset cached peer field in claw_switch_mode(), and overwrites the MCU
state before cfg_setup_fn() reads it back.
Keeping userspace writes gated until cfg_setup_fn() finishes resyncing (for
instance by letting internal resync reads bypass the gate) would prevent
writes from running against stale cached state.
--
Sashiko AI review · https://sashiko.dev/#/patchset/20261204001846.3801336-1-derekjohn.clark@gmail.com?part=5
next prev parent reply other threads:[~2026-12-04 0:38 UTC|newest]
Thread overview: 14+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-12-04 0:18 [PATCH 0/8] MSI Claw suspend, resume and ROM commit fixes Derek J. Clark
2026-12-04 0:18 ` [PATCH 1/8] HID: hid-msi: Queue the RGB work item on system_dfl_wq Derek J. Clark
2026-12-04 0:18 ` [PATCH 2/8] HID: hid-msi: Move the ROM commit to an explicit apply attribute Derek J. Clark
2026-12-04 0:35 ` sashiko-bot
2026-12-04 0:18 ` [PATCH 3/8] HID: hid-msi: Protect the RGB state with frame_lock Derek J. Clark
2026-12-04 0:18 ` [PATCH 4/8] HID: hid-msi: Re-init on reset during resume Derek J. Clark
2026-12-04 0:37 ` sashiko-bot
2026-12-04 0:18 ` [PATCH 5/8] HID: hid-msi: Drain in-flight MCU traffic before suspend Derek J. Clark
2026-12-04 0:38 ` sashiko-bot [this message]
2026-12-04 0:18 ` [PATCH 6/8] HID: hid-msi: Defer RGB updates while the MCU is suspended Derek J. Clark
2026-12-04 0:32 ` sashiko-bot
2026-12-04 0:18 ` [PATCH 7/8] HID: hid-msi: Switch the RGB LED to brightness_set_blocking Derek J. Clark
2026-12-04 0:39 ` sashiko-bot
2026-12-04 0:18 ` [PATCH 8/8] USB: core: quirks: Add RESET_RESUME quirk for MSI Claw Derek J. Clark
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=sashiko-outbox-248838@kernel.org \
--to=sashiko-bot@kernel.org \
--cc=derekjohn.clark@gmail.com \
--cc=dmitry.torokhov@gmail.com \
--cc=linux-input@vger.kernel.org \
--cc=linux-usb@vger.kernel.org \
--cc=sashiko-reviews@lists.linux.dev \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox