All of lore.kernel.org
 help / color / mirror / Atom feed
From: Yixun Lan <dlan@kernel.org>
To: sashiko-reviews@lists.linux.dev, Ulf Hansson <ulfh@kernel.org>
Cc: linux-pm@vger.kernel.org, spacemit@lists.linux.dev,
	devicetree@vger.kernel.org, robh@kernel.org, conor+dt@kernel.org
Subject: Re: [PATCH v5 2/2] pmdomain: spacemit: Add power domain driver
Date: Mon, 23 Nov 2026 11:45:12 +0000	[thread overview]
Message-ID: <20261123114512-GKC156439@kernel.org> (raw)
In-Reply-To: <sashiko-outbox-222182@kernel.org>

Hi All,

On 23:32 Wed 18 Nov     , sashiko-bot@kernel.org wrote:
> Thank you for your contribution! Sashiko AI review found 2 potential
> issues to consider:
> - [High] pmdomain: spacemit: devres frees active domains when
>   pm_genpd_remove() fails
> - [Medium] pmdomain: spacemit: unpowered always-on domain in
>   spacemit_pm_add_one_domain()
> --
> 
> commit 3dbb7292ceae5fc8cd5471f6a58e884045deb2ec
> Author: Yixun Lan <dlan@kernel.org>
> 
> pmdomain: spacemit: Add power domain driver
> 
> This commit adds a generic PM domain driver on the auxiliary bus for
> SpacemiT K1 and K3 SoCs, supporting software and hardware power-on/off
> sequences.
> 
> > diff --git a/drivers/pmdomain/spacemit/spacemit-pm-domains.c b/drivers/pmdomain/spacemit/spacemit-pm-domains.c
> > new file mode 100644
> > index 0000000000000..9d77d3f4c182b
> > --- /dev/null
> > +++ b/drivers/pmdomain/spacemit/spacemit-pm-domains.c
> > @@ -0,0 +1,422 @@
> 
> [ ... ]
> 
> > +static int spacemit_pm_add_one_domain(struct spacemit_pmu *pmu, int id,
> > +				      const struct spacemit_pm_domain_param *param)
> > +{
> > +	struct spacemit_pm_domain *pd;
> > +	int ret;
> > +
> > +	pd = devm_kzalloc(pmu->dev, sizeof(*pd), GFP_KERNEL);
> > +	if (!pd)
> > +		return -ENOMEM;
> > +
> > +	pd->param           = param;
> > +	pd->pmu             = pmu;
> > +	pd->genpd.name      = param->name;
> > +	pd->genpd.flags     = param->flags;
> > +	pd->genpd.power_off = spacemit_pd_power_off;
> > +	pd->genpd.power_on  = spacemit_pd_power_on;
> > +
> > +	ret = pm_genpd_init(&pd->genpd, NULL, spacemit_pm_is_off_state(pmu, pd));
> > +	if (ret)
> > +		return ret;
> > +
> > +	pmu->domains[id] = &pd->genpd;
> > +
> > +	return 0;
> > +}
> 
> [Severity: Medium]
> Can pm_genpd_init() fail with -EINVAL for a GENPD_FLAG_ALWAYS_ON domain
> such as K3_PMDOMAIN_AUDIO if it is powered off at boot?
> 

I've checked in U-Boot which before booting Linux,
=> md.l 0xd42828f0 1
d42828f0: 00000008
which shows bit[3]=1, audio power domain already in 'on' state..

So, K3 SoC should have no problem on this.

> pm_genpd_init() requires always-on domains to already be powered on
> (is_off == false) and rejects them with -EINVAL otherwise, aborting
> spacemit_pm_domain_probe().  Also, because genpd never powers an
> always-on domain off or on after initialization, the power control
> parameters defined on K3_PMDOMAIN_AUDIO are unused unless
> spacemit_pm_add_one_domain() powers the domain on before calling
> pm_genpd_init() (note that spacemit_pd_power_on() logs with &domain->dev,
> which is not initialized until pm_genpd_init(), so pmu->dev would need to
> be used for logging).
> 
> > +
> > +static void spacemit_pm_domain_cleanup(struct spacemit_pmu *pmu)
> > +{
> > +	struct spacemit_pm_domain *pd;
> > +	int i, ret;
> > +
> > +	for (i = 0; i < pmu->genpd_data.num_domains; i++) {
> > +		if (!pmu->domains[i])
> > +			continue;
> > +
> > +		pd = to_spacemit_pd(pmu->domains[i]);
> > +		ret = pm_genpd_remove(pmu->domains[i]);
> > +		if (ret)
> > +			dev_err(pmu->dev, "failed to remove domain %s: %d - state may be inconsistent\n",
> > +				pd->param->name, ret);
> > +	}
> > +}
> 
> [ ... ]
> 
> > +static void spacemit_pm_domain_remove(struct auxiliary_device *adev)
> > +{
> > +	struct spacemit_pmu *pmu = auxiliary_get_drvdata(adev);
> > +	struct device *dev = &adev->dev;
> > +
> > +	of_genpd_del_provider(dev->of_node);
> > +	spacemit_pm_domain_cleanup(pmu);
> > +}
> 
> [Severity: High]
> As reported by Troy Mitchell on v3 [1], can unbinding the driver or
> unloading the module while a consumer device is attached cause a
> use-after-free on pd->genpd?
> 
I don't want to combine into this series, see cover letter or the link below
https://lore.kernel.org/r/20261112-01-pm-device-link-v1-1-8932e0862378@kernel.org

I'm trying to address in a separate patch

> Because adev->dev shares the parent CCU device's of_node, fw_devlink
> links consumers to the parent CCU platform device rather than adev->dev,
> so unbinding spacemit_pm_domain_driver does not detach consumer devices
> first.  When genpd->device_count > 0, pm_genpd_remove() fails with -EBUSY
> and leaves pd->genpd linked in the global gpd_list and referenced by
> consumers' dev->pm_domain pointers right before devres frees the
> devm_kzalloc()-allocated struct spacemit_pm_domain.
> 
> [1] https://lore.kernel.org/r/DMQHSDTR177I.1HWHAF4FWTFQ5@linux.spacemit.com
> 
> -- 
> Sashiko AI review · https://sashiko.dev/#/patchset/20261118-04-k3-pm-support-v5-0-42394acdf3e3@kernel.org?part=2

-- 
Yixun Lan (dlan)

  reply	other threads:[~2026-11-23 11:45 UTC|newest]

Thread overview: 12+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-11-18 23:13 [PATCH v5 0/2] PM: spacemit: Add power domain support Yixun Lan
2026-11-18 23:13 ` Yixun Lan
2026-11-18 23:13 ` [PATCH v5 1/2] dt-bindings: power: spacemit: Add power domain controller IDs Yixun Lan
2026-11-18 23:13   ` Yixun Lan
2026-11-18 23:13 ` [PATCH v5 2/2] pmdomain: spacemit: Add power domain driver Yixun Lan
2026-11-18 23:13   ` Yixun Lan
2026-11-18 23:32   ` sashiko-bot
2026-11-23 11:45     ` Yixun Lan [this message]
2026-11-25 15:24 ` [PATCH v5 0/2] PM: spacemit: Add power domain support Ulf Hansson
2026-11-25 15:24   ` Ulf Hansson
2026-11-26 17:01 ` Frédéric Mahé
2026-11-26 17:01   ` Frédéric Mahé

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=20261123114512-GKC156439@kernel.org \
    --to=dlan@kernel.org \
    --cc=conor+dt@kernel.org \
    --cc=devicetree@vger.kernel.org \
    --cc=linux-pm@vger.kernel.org \
    --cc=robh@kernel.org \
    --cc=sashiko-reviews@lists.linux.dev \
    --cc=spacemit@lists.linux.dev \
    --cc=ulfh@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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.