The Linux Kernel Mailing List
 help / color / mirror / Atom feed
From: Cristian Marussi <cristian.marussi@arm.com>
To: Sudeep Holla <sudeep.holla@kernel.org>
Cc: Cristian Marussi <cristian.marussi@arm.com>,
	linux-kernel@vger.kernel.org,
	linux-arm-kernel@lists.infradead.org, arm-scmi@vger.kernel.org,
	philip.radford@arm.com, Sashiko <sashiko-bot@kernel.org>
Subject: Re: [PATCH 2/2] firmware: arm_scmi: Fix SCMI Power Control driver removal
Date: Tue, 17 Nov 2026 11:35:38 +0000	[thread overview]
Message-ID: <avw8CvBXXWNx4YGX@pluto> (raw)
In-Reply-To: <20261116-merry-hypersonic-skink-91109c@sudeepholla>

On Mon, Nov 16, 2026 at 06:14:50PM +0000, Sudeep Holla wrote:
> On Mon, Nov 16, 2026 at 08:42:11AM +0000, Cristian Marussi wrote:
> > Once a reboot is initiated following a graceful shutdown request received
> > from the SCMI platform server there are a couple of registered notifiers
> > and possibly a scheduled delayed work.
> > 

Hi,

> > Take care to properly stop, unregister and cleanup all such resources
> > when the driver is unbound.
> > 
> > Fixes: 2c4b97fee94a ("firmware: arm_scmi: Add SCMI System Power Control driver")
> > Reported-by: Sashiko <sashiko-bot@kernel.org>
> > Closes: https://sashiko.dev/#/bug/linux-dbe4eba7-1520-40a1-92e8-8892b6e47c4b
> > Tested-by: Cristian Marussi <cristian.marussi@arm.com>
> > Signed-off-by: Cristian Marussi <cristian.marussi@arm.com>
> > ---
> >  .../firmware/arm_scmi/scmi_power_control.c    | 76 +++++++++++++++++--
> >  1 file changed, 70 insertions(+), 6 deletions(-)
> > 
> > diff --git a/drivers/firmware/arm_scmi/scmi_power_control.c b/drivers/firmware/arm_scmi/scmi_power_control.c
> > index e0680e33180e..b0a10fd92fa6 100644
> > --- a/drivers/firmware/arm_scmi/scmi_power_control.c
> > +++ b/drivers/firmware/arm_scmi/scmi_power_control.c
> 
> [...]
> 
> > @@ -296,6 +310,10 @@ static int scmi_userspace_notifier(struct notifier_block *nb,
> >  	struct scmi_system_power_state_notifier_report *er = data;
> >  	struct scmi_syspower_conf *sc = userspace_nb_to_sconf(nb);
> >  
> > +	guard(srcu)(&sc->dead_srcu);
> > +	if (READ_ONCE(sc->dead))
> > +		return NOTIFY_DONE;
> > +
> >  	if (er->system_state >= SCMI_SYSTEM_MAX ||
> >  	    er->system_state == SCMI_SYSTEM_POWERUP) {
> >  		dev_err(sc->dev, "Ignoring unsupported system_state: 0x%X\n",
> > @@ -357,6 +375,10 @@ static int scmi_syspower_probe(struct scmi_device *sdev)
> >  	if (!sc)
> >  		return -ENOMEM;
> >  
> > +	ret = init_srcu_struct(&sc->dead_srcu);
> > +	if (ret)
> > +		return ret;
> > +
> >  	sc->state = SCMI_SYSPOWER_IDLE;
> >  	mutex_init(&sc->state_mtx);
> >  	sc->required_transition = SCMI_SYSTEM_MAX;
> > @@ -364,12 +386,53 @@ static int scmi_syspower_probe(struct scmi_device *sdev)
> >  	sc->dev = &sdev->dev;
> >  	dev_set_drvdata(&sdev->dev, sc);
> >  
> > +	INIT_DELAYED_WORK(&sc->forceful_work, scmi_forceful_work_func);
> >  	INIT_WORK(&sc->suspend_work, scmi_suspend_work_func);
> >  
> > -	return handle->notify_ops->devm_event_notifier_register(sdev,
> > -							   SCMI_PROTOCOL_SYSTEM,
> > -					 SCMI_EVENT_SYSTEM_POWER_STATE_NOTIFIER,
> > -						       NULL, &sc->userspace_nb);
> > +	ret = handle->notify_ops->event_notifier_register(handle, SCMI_PROTOCOL_SYSTEM,
> > +							  SCMI_EVENT_SYSTEM_POWER_STATE_NOTIFIER,
> > +							  NULL, &sc->userspace_nb);
> > +	if (ret) {
> > +		cleanup_srcu_struct(&sc->dead_srcu);
> > +		return ret;
> > +	}
> > +
> > +	return 0;
> > +}
> > +
> > +static void scmi_syspower_remove(struct scmi_device *sdev)
> > +{
> > +	struct scmi_handle *handle = sdev->handle;
> > +	struct scmi_syspower_conf *sc;
> > +	int ret;
> > +
> > +	sc = dev_get_drvdata(&sdev->dev);
> > +	if (!sc)
> > +		return;
> > +
> > +	/* Wait for any notifier to complete and inhibit further processing */
> > +	WRITE_ONCE(sc->dead, true);
> > +	synchronize_srcu(&sc->dead_srcu);
> > +
> > +	/*
> > +	 * Once here any possible in-flight userspace or reboot notifier
> > +	 * will have completed and further notifiers will bailout immediately.
> > +	 * Cancel any work which was possibly already scheduled.
> > +	 */
> > +	cancel_delayed_work_sync(&sc->forceful_work);
> > +
> 
> To keep it symmetric with probe, do we need cancelling of suspend_work as
> well here ?
> 

Yes, I was going to do that in V1, then I decided it was not
needed...without any good reason really O_o...
Sashiko pointed out the same...I'm adding in V2.

> > +
> > +	/* Unregister reboot notifier...if any */
> > +	unregister_reboot_notifier(&sc->reboot_nb);
> > +
> > +	/* Unregister userspace notifier */
> > +	ret = handle->notify_ops->event_notifier_unregister(handle,
> > +							    SCMI_PROTOCOL_SYSTEM,
> > +							    SCMI_EVENT_SYSTEM_POWER_STATE_NOTIFIER,
> > +							    NULL, &sc->userspace_nb);
> 
> Just wondering if it is better to stop receiving notifications from firmware
> first and then cancel any pending work ? Basically reverse order of probe
> for remove.
> 

I think the order is irrelevant given the dead_srcu gating, BUT indeed I
kept this order so as to keep the undo in reverse order: in fact the
probe at first issues some INIT_WORK, but the real schedule_work happens
only later after a notif is received, so the order is:

 - init_srcu
 - static WORK init
 - register SCMI notif callback
 - RX notify msg
 - register reboot notifier
 - schedule delayed work

Also, even if the notifiers are inhibited by dead_srcu, I felt better to
cancel that work as soon as possible.

Thoughts ?

Thanks,
Cristian

      reply	other threads:[~2026-11-17 11:35 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-11-16  8:42 [PATCH 0/2] SCMI Power Control fixes Cristian Marussi
2026-11-16  8:42 ` [PATCH 1/2] firmware: arm_scmi: Fix deadlock between reboot notifier and forceful work Cristian Marussi
2026-11-16 18:25   ` Sudeep Holla
2026-11-17 11:25     ` Cristian Marussi
2026-11-16  8:42 ` [PATCH 2/2] firmware: arm_scmi: Fix SCMI Power Control driver removal Cristian Marussi
2026-11-16 18:14   ` Sudeep Holla
2026-11-17 11:35     ` 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=avw8CvBXXWNx4YGX@pluto \
    --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=philip.radford@arm.com \
    --cc=sashiko-bot@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