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=1796344729; b=X0cy9aV9voLzvXWqHdSjP+wTb7oECysTrcSyjBoPFY4csZlSCbOvXQhqSCivYF40x4BK IRi+qhrVj9MILfXGARF7Kg4MRh2bNYnwUKGZzgpyLAUzjenshEncEqtUwXsccyEK7NoBR Ar9BMN3CjbpdNj0flqz55jN2nUP87WuS8EvNez9stn/XoGGgSktbi0tHcGIxl+4m/XW1B ulpiykYvn8/9Dy+Zz+nYCqMI+Eran2ovRb44f3FrVpDLkpKYoOKkDZDt5qCYXqdFNFo1l lSQKoR0CvpJcRkerlrqVp30sFW/4jYCCvpmiREBFC8PSwO60rRaKV20LV06L79f+yOA== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796344729; h=Received:DKIM-Signature:Message-ID:From:Subject:Reply-To:To:Cc: In-Reply-To:References:Content-Type:Content-Transfer-Encoding:Date; bh=NSMKlimREWAFQ4oz8lUHxnS0O/meiAobkIibI1VZYzg=; b=48rnTjP2rBRXiWUrDDT7rP1SIipihwZn8jg+tPqx6jwsss0VvVYdk0xsY/TJYWC/ixpS pwoxnzS7jLudJ4ZbeMI3Ms38M9aMIlUZBTA849OperQt+zajlj8kZBNWLCptuygu/G+Bw YGFaG96dyRzp1UNsIBdmY9p9vhOG3rZx11rMdQSFF7grkDshfqJMZxIoaghAKu5VDnoAp 7Fadj9WYWE4uYajt6V3dj+GU1vFLShXKuBqBDQd6PojJNl/U8vZEUz5veYiQXTAbusd+A 97I3P3r8OnGAtCtGv+VKtq7MJuP+BcGx/raktj2YuwmuXRfN8TSjWbjfwwv32vpN7Lw== 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=ZEPUjLMZ; 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 3540F606A322; Fri, 4 Dec 2026 00:38:48 +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=ZEPUjLMZ Received: by smtp.kernel.org (Postfix) with ESMTPSA id A0AED1F000C2; Fri, 4 Dec 2026 00:38:48 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel.org; s=k20260515; t=1796344728; bh=NSMKlimREWAFQ4oz8lUHxnS0O/meiAobkIibI1VZYzg=; h=From:Subject:Reply-To:To:Cc:In-Reply-To:References:Date; b=ZEPUjLMZ5SfvkV+CV9Ekbchj2ymj6Kvb5KkJyHinPiMW4RzTVAn0dQwYtxS+1/MwM OCqlBHx5wIl6d2/bgAIwjCqQu8a4YByLjp4G/uK8jZHwyQmNsJeobB6/6ipCSR4WFz WFmwVCprI5aPI+/g968T1sqx2vOGf1no1CQWrB+/M+a+DYyXxvmyXomc/dWkmNEUmF dpy8khq4rd3aWp3WhvGC+YrKGGkHsVkfhmk69kawb+EZP6tod14fROVB+uUIyaX9Br eeDsgs366byQd3oBGZB29E8lhVoBFLJKfDshmi6PYwY0X9OynV+5NrBW2w807gfMRP NbxK2jQLtWu3A== Message-ID: From: sashiko-bot@kernel.org Subject: Re: [PATCH 5/8] HID: hid-msi: Drain in-flight MCU traffic before suspend Reply-To: sashiko-reviews@lists.linux.dev To: "Derek J. Clark" Cc: linux-input@vger.kernel.org, linux-usb@vger.kernel.org, dmitry.torokhov@gmail.com In-Reply-To: <20261204001846.3801336-6-derekjohn.clark@gmail.com> References: <20261204001846.3801336-1-derekjohn.clark@gmail.com> <20261204001846.3801336-6-derekjohn.clark@gmail.com> Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable Date: Fri, 04 Dec 2026 00:38:48 +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 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 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 =3D 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 =3D true. During USB autosuspend while userspace is sti= ll 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 =3D=3D false CLAW_COMMAND_TYPE_SYNC_TO_ROM <-- commits stale MCU RAM to flash mutex_lock(&rom_mutex) drvdata->suspended =3D 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 =3D container_of(dwork, struct claw_drvdat= a, cfg_resume); > bool gp_registered, rgb_registered, resync; > > + scoped_guard(mutex, &drvdata->rom_mutex) > + scoped_guard(mutex, &drvdata->cfg_mutex) > + drvdata->suspended =3D false; > + > /* Pairs with smp_store_release from claw_resume in process context */ > resync =3D 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. --=20 Sashiko AI review =C2=B7 https://sashiko.dev/#/patchset/20261204001846.3801= 336-1-derekjohn.clark@gmail.com?part=3D5