mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Cristian Marussi <cristian.marussi@arm.com>
To: linux-kernel@vger.kernel.org,
	linux-arm-kernel@lists.infradead.org, arm-scmi@vger.kernel.org
Cc: sudeep.holla@kernel.org, philip.radford@arm.com,
	lui2012qwq@gmail.com, Cristian Marussi <cristian.marussi@arm.com>
Subject: [PATCH v3 1/3] firmware: arm_scmi: Avoid deadlocks between reboot notifier and forceful work
Date: Mon, 30 Nov 2026 14:49:22 +0000	[thread overview]
Message-ID: <20261130144924.343166-2-cristian.marussi@arm.com> (raw)
In-Reply-To: <20261130144924.343166-1-cristian.marussi@arm.com>

When an ongoing reboot is detected scmi_reboot_notifier() cancels the
scheduled pending delayed work by calling cancel_delayed_work_sync():
this is done while holding sc->state_mtx which is also taken by the
worker is trying to synchronously cancel.

Such locking, though, guarantees mutual exclusion between the conflicting
activities carried on by the two threads, but it is in turn leading to an
ABBA deadlock with the internal reboot notifier locking.

Stop synchronously waiting for the cancellation so as to avoid deadlock
and temporarily drop state_mtx while unregistering the reboot notfier.

Fixes: 2c4b97fee94a ("firmware: arm_scmi: Add SCMI System Power Control driver")
Reported-by: Chengyu Liu <lui2012qwq@gmail.com>
Signed-off-by: Cristian Marussi <cristian.marussi@arm.com>
---
v2 --> v3
 - drop mutex before unregistering reboot notifier
 - use dev_warn() to log forceful transititon
---
 .../firmware/arm/scmi/scmi_power_control.c    | 22 ++++++++++++++-----
 1 file changed, 16 insertions(+), 6 deletions(-)

diff --git a/drivers/firmware/arm/scmi/scmi_power_control.c b/drivers/firmware/arm/scmi/scmi_power_control.c
index e791a206768c..0be9ca01e3fe 100644
--- a/drivers/firmware/arm/scmi/scmi_power_control.c
+++ b/drivers/firmware/arm/scmi/scmi_power_control.c
@@ -140,7 +140,7 @@ static int scmi_reboot_notifier(struct notifier_block *nb,
 
 	if (sc->state == SCMI_SYSPOWER_REBOOTING) {
 		dev_dbg(sc->dev, "Reboot in progress...cancel delayed work.\n");
-		cancel_delayed_work_sync(&sc->forceful_work);
+		cancel_delayed_work(&sc->forceful_work);
 	}
 	mutex_unlock(&sc->state_mtx);
 
@@ -188,12 +188,22 @@ static void scmi_forceful_work_func(struct work_struct *work)
 	dwork = to_delayed_work(work);
 	sc = dwork_to_sconf(dwork);
 
-	dev_dbg(sc->dev, "Graceful request timed out...forcing !\n");
 	mutex_lock(&sc->state_mtx);
-	/* avoid deadlock by unregistering reboot notifier first */
-	unregister_reboot_notifier(&sc->reboot_nb);
-	if (sc->state == SCMI_SYSPOWER_IN_PROGRESS)
-		scmi_request_forceful_transition(sc);
+	if (sc->state == SCMI_SYSPOWER_IN_PROGRESS) {
+		mutex_unlock(&sc->state_mtx);
+		/*
+		 * Avoid deadlock by unregistering reboot notifier first
+		 * while NOT holding state_mtx.
+		 */
+		unregister_reboot_notifier(&sc->reboot_nb);
+		mutex_lock(&sc->state_mtx);
+		/* Re-evaluate current state after mutex re-acquired */
+		if (sc->state == SCMI_SYSPOWER_IN_PROGRESS) {
+			dev_warn(sc->dev,
+				 "Graceful request timed out...forcing !\n");
+			scmi_request_forceful_transition(sc);
+		}
+	}
 	mutex_unlock(&sc->state_mtx);
 }
 
-- 
2.54.0


  reply	other threads:[~2026-11-30 14:49 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-11-30 14:49 [PATCH v3 0/3] SCMI Power Control fixes Cristian Marussi
2026-11-30 14:49 ` Cristian Marussi [this message]
2026-11-30 14:49 ` [PATCH v3 2/3] firmware: arm_scmi: Rework SCMI Power Control driver removal Cristian Marussi
2026-11-30 14:49 ` [PATCH v3 3/3] firmware: arm_scmi: Ensure no reboot notifier is registered on suspend Cristian Marussi

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=20261130144924.343166-2-cristian.marussi@arm.com \
    --to=cristian.marussi@arm.com \
    --cc=arm-scmi@vger.kernel.org \
    --cc=linux-arm-kernel@lists.infradead.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=lui2012qwq@gmail.com \
    --cc=philip.radford@arm.com \
    --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

all inboxes | Powered by JetHome®