Linux-ARM-Kernel Archive on lore.kernel.org
 help / color / mirror / Atom feed
From: Cristian Marussi <cristian.marussi@arm.com>
To: Chengyu Liu <lui2012qwq@gmail.com>
Cc: sudeep.holla@kernel.org, arm-scmi@vger.kernel.org,
	linux-arm-kernel@lists.infradead.org, stable@vger.kernel.org,
	cristian.marussi@arm.com
Subject: Re: [PATCH] firmware: arm_scmi: fix deadlock between reboot notifier and forceful work
Date: Mon, 16 Nov 2026 08:48:41 +0000	[thread overview]
Message-ID: <avrDaZKTkXKfono7@pluto> (raw)
In-Reply-To: <20261104053359.1613991-1-lui2012qwq@gmail.com>

On Wed, Nov 04, 2026 at 01:33:59PM +0800, Chengyu Liu wrote:
> scmi_reboot_notifier() calls cancel_delayed_work_sync() while holding
> sc->state_mtx, but the work it waits on - scmi_forceful_work_func() -
> takes the same mutex.  If a forceful transition work is in flight when
> the reboot notifier fires, the notifier holds the lock and waits for
> the callback while the callback waits for the lock: deadlock, and the
> reboot wedges.
> 
> Moving the cancel outside the lock is not sufficient on its own, as the
> callback also calls unregister_reboot_notifier() unconditionally, which
> blocks on the reboot chain rwsem (down_write vs. the in-progress
> chain's down_read) while the notifier waits for the callback - the
> deadlock would just move to a different lock.  Fix both sides:
> 
> - Notifier: compute the decision under state_mtx, drop the lock, then
>   cancel.  A callback that slips in between sees state ==
>   SCMI_SYSPOWER_REBOOTING (not IN_PROGRESS), skips the forceful
>   request and finishes, so the cancel cannot miss it.  (The callback's
>   own system_state early-return does not cover a work item that
>   started before the reboot began: kernel_restart_prepare() runs the
>   notifier chain before setting system_state.)
> 
> - Callback: only unregister the reboot notifier when actually forcing
>   the transition - that is the only case that needs it, because the
>   forceful kernel_restart()/kernel_power_off() would otherwise
>   re-enter scmi_reboot_notifier and self-deadlock on state_mtx.  When
>   the state is not IN_PROGRESS there is nothing to force, and skipping
>   the unregister keeps the callback from blocking on the reboot chain
>   rwsem while the notifier waits for it.
> 
> Found by static analysis.

Hi,

thanks for this, this looks good to me.

Sashiko flagged a residual issue in your patch:

https://sashiko.dev/#/patchset/20260916093527.2004594-1-vulab%40iscas.ac.cn

Since I am fixing some other issues around this driver I reposted your
patch within my own series, maintaining your authorship and adding
the additional fix needed (hopefully :P)

My series including your is at:

https://lore.kernel.org/arm-scmi/20261116084211.3066460-1-cristian.marussi@arm.com/T/#t

Thanks,
Cristian


      reply	other threads:[~2026-11-16  8:49 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-11-04  5:33 [PATCH] firmware: arm_scmi: fix deadlock between reboot notifier and forceful work Chengyu Liu
2026-11-16  8:48 ` Cristian Marussi [this message]

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=avrDaZKTkXKfono7@pluto \
    --to=cristian.marussi@arm.com \
    --cc=arm-scmi@vger.kernel.org \
    --cc=linux-arm-kernel@lists.infradead.org \
    --cc=lui2012qwq@gmail.com \
    --cc=stable@vger.kernel.org \
    --cc=sudeep.holla@kernel.org \
    /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