From: netdev-bot+sashiko@kernel.org
To: github@szelinsky.de
Cc: o.rempel@pengutronix.de, kory.maincent@bootlin.com,
andrew+netdev@lunn.ch, davem@davemloft.net, edumazet@kernel.org,
kuba@kernel.org, pabeni@redhat.com, horms@kernel.org,
broonie@kernel.org, lgirdwood@gmail.com,
maxime.chevallier@bootlin.com, kyle.swenson@est.tech,
ross@r-sc.ca, netdev-bot+sashiko@kernel.org,
netdev@vger.kernel.org, linux-kernel@vger.kernel.org
Subject: Re: [PATCH net v5 07/14] net: pse-pd: do not tie a shared power domain to its creator's devres
Date: Fri, 20 Nov 2026 06:41:51 +0000 [thread overview]
Message-ID: <179515691186.3136.7466953769773810210@kernel.org> (raw)
In-Reply-To: <20261118183957.2031311-8-github@szelinsky.de>
Thank you for your contribution! Sashiko AI review found 1 potential
issue(s) to consider.
Critical: 0 · High: 1 · Medium: 0 (1) · Low: 0 (1)
If you believe none of the issues are legitimate, please reply to each
issue of Medium severity or higher and explain why the AI is wrong.
If any of them are legitimate and you plan to respin, please let patchwork
know by including "pw-bot: cr" as a separate line at the end of your reply
(one such reply per series is enough).
- [High] The shared domain can now outlive its creator, but its supply
handle still cannot.
Pre-existing issues:
- [Medium] pse_flush_pw_ds() clears pcdev->pi[i].pw_d via
pse_pi_take_pw_d() and drops the domain reference without first…
- [Low] pse_register_pw_ds() publishes pcdev->pi[i].pw_d at line 997
(shared-domain branch) and line 1026 (new-domain branch) holding only…
--
net: pse-pd: do not tie a shared power domain to its creator's devres
This patch allocates PSE power domains with kzalloc() instead of devm
memory of the creating controller, and frees them on the last kref_put().
It also unwinds the domains on a partial pse_register_pw_ds() failure
while pse_pw_d_mutex is held. Before dropping the reference it clears
pi[].pw_d under pcdev->lock.
> diff --git a/drivers/net/pse-pd/pse_core.c b/drivers/net/pse-pd/pse_core.c
> index 342fb27e38319..8041ad3e330b9 100644
> --- a/drivers/net/pse-pd/pse_core.c
> +++ b/drivers/net/pse-pd/pse_core.c
> @@ -875,17 +875,41 @@ devm_pse_pi_regulator_register(struct pse_controller_dev *pcdev,
[ ... ]
> +/* Clear pi[id].pw_d before the domain's reference is dropped. The PI
> + * regulator ops and pse_isr() hold pcdev->lock while they use it.
> + */
> +static struct pse_power_domain *
> +pse_pi_take_pw_d(struct pse_controller_dev *pcdev, int id)
> +{
> + struct pse_power_domain *pw_d;
> +
> + mutex_lock(&pcdev->lock);
> + pw_d = pcdev->pi[id].pw_d;
> + pcdev->pi[id].pw_d = NULL;
^^^^
[Severity: Medium]
This is a pre-existing issue and was not introduced by this patch, but
does pse_flush_pw_ds() leak the PI's reserved power budget on the shared
supply?
After pse_pi_take_pw_d() sets pi[id].pw_d to NULL,
pse_pi_deallocate_pw_budget() does nothing:
static void pse_pi_deallocate_pw_budget(struct pse_pi *pi)
{
if (!pi->pw_d || !pi->pw_allocated_mW)
return;
...
}
pse_pi_update_pw_budget() also bails out, because
pse_pw_d_is_sw_pw_control(pcdev, NULL) is false.
pse_controller_unregister() does this:
pse_flush_pw_ds(pcdev);
pse_release_pis(pcdev);
Nothing on that path returns pi->pw_allocated_mW with
regulator_free_power_budget(). regulator_put() and regulator_unregister()
do not release it either.
Say a controller under software power control unbinds while a PD is
powered. Does the vpwr supply's pw_requested_mW then stay charged? A
sibling controller on the same supply would see less available budget,
and each unbind/rebind would make the drift worse.
The baseline pse_controller_unregister() never released per-PI budgets
either, and the same is true at the end of this series.
> + mutex_unlock(&pcdev->lock);
> +
> + return pw_d;
> +}
[ ... ]
> @@ -981,6 +1012,7 @@ static int pse_register_pw_ds(struct pse_controller_dev *pcdev)
> supply = regulator_get(&rdev->dev, rdev->supply_name);
^^^^
[Severity: High]
The new kernel-doc for pse_alloc_pw_d() says the domain "must not be tied
to the lifetime of the controller that happened to create it". Does that
hold for pw_d->supply?
The supply handle is taken with the creating controller's own PI
regulator device as the consumer. That rdev comes from
devm_regulator_register() on pcdev->dev, so it is freed when that
controller unbinds.
Take controller A, which creates domain D on supply S, and controller B,
which joins D through kref_get(). When A unbinds, pse_flush_pw_ds() drops
only A's references, so D and D->supply stay alive. Devres still
unregisters and frees A's rdev. D->supply then stays on S's consumer_list
with a stale ->dev.
Can a read of /sys/kernel/debug/regulator/regulator_summary then hit a
use-after-free in regulator_summary_show_subtree()? That function reads
consumer->dev->class and dev_name(consumer->dev).
When B later drops the last reference, this chain passes the same stale
dev to device_link_remove():
pse_pw_d_release_locked()->regulator_put()->destroy_regulator()
The dangling consumer also existed before this patch, back when the whole
domain was freed. The later commit in this series, "net: pse-pd: use
each PI's own supply handle for the power budget", removes pw_d->supply
and uses pi->rdev->supply instead. Its commit message shows this same
KASAN report in regulator_summary_show_subtree().
Could the kernel-doc here be adjusted, or could the commit note that it
depends on that later change for the supply handle?
> if (IS_ERR(supply)) {
> xa_erase(&pse_pw_d_map, pw_d->id);
> + kfree(pw_d);
> ret = PTR_ERR(supply);
> goto out;
> }
[ ... ]
> @@ -995,6 +1027,13 @@ static int pse_register_pw_ds(struct pse_controller_dev *pcdev)
> }
>
[Severity: Low]
This isn't a bug introduced by this patch, but the commit message says
the PI regulator ops use pw_d under pcdev->lock. Is the publication side
in pse_register_pw_ds() covered too?
Both the shared-domain branch and the new-domain branch store
pcdev->pi[i].pw_d with only pse_pw_d_mutex held:
pw_d->supply = supply;
if (pcdev->supp_budget_eval_strategies)
pw_d->budget_eval_strategy = pcdev->supp_budget_eval_strategies;
...
kref_init(&pw_d->refcnt);
pcdev->pi[i].pw_d = pw_d;
By this point devm_pse_pi_regulator_register() has already registered
the PI regulators. pse_pi_is_enabled() can be reached through the
regulator sysfs state attribute. It reads pi[id].pw_d and dereferences
budget_eval_strategy under pcdev->lock, which is a different lock from
the writer's.
On a weakly ordered CPU, could a reader see the new pointer before the
budget_eval_strategy store? The impact looks limited to a wrong state
value for a short window during probe, plus a possible KCSAN report.
The pointer only ever goes from NULL to a live object.
> out:
[ ... ]
--
Sashiko AI review · https://netdev-ai.bots.linux.dev/sashiko/#/patchset/20261118183957.2031311-1-github%40szelinsky.de
next prev parent reply other threads:[~2026-11-20 6:41 UTC|newest]
Thread overview: 20+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-11-18 18:39 [PATCH net v5 00/14] net: pse-pd: assorted lifetime and error-path fixes Carlo Szelinsky
2026-11-18 18:39 ` [PATCH net v5 01/14] net: pse-pd: size the notification kfifo after defaulting nr_lines Carlo Szelinsky
2026-11-18 18:39 ` [PATCH net v5 02/14] net: pse-pd: remove dead pi_get_admin_state() checks Carlo Szelinsky
2026-11-18 18:39 ` [PATCH net v5 03/14] net: pse-pd: fix module refcount leak in pse_control_get_internal() Carlo Szelinsky
2026-11-18 18:39 ` [PATCH net v5 04/14] net: pse-pd: do not keep a failed IRQ in pcdev->irq Carlo Szelinsky
2026-11-20 6:41 ` netdev-bot+sashiko
2026-11-18 18:39 ` [PATCH net v5 05/14] net: pse-pd: do not reach a freed PHY from the notification worker Carlo Szelinsky
2026-11-20 6:41 ` netdev-bot+sashiko
2026-11-18 18:39 ` [PATCH net v5 06/14] net: pse-pd: check the PI state under the lock when setting a power limit Carlo Szelinsky
2026-11-20 6:41 ` netdev-bot+sashiko
2026-11-18 18:39 ` [PATCH net v5 07/14] net: pse-pd: do not tie a shared power domain to its creator's devres Carlo Szelinsky
2026-11-20 6:41 ` netdev-bot+sashiko [this message]
2026-11-18 18:39 ` [PATCH net v5 08/14] net: pse-pd: stop async event sources before freeing PI data in unregister Carlo Szelinsky
2026-11-20 6:41 ` netdev-bot+sashiko
2026-11-18 18:39 ` [PATCH net v5 09/14] net: pse-pd: unregister from the controller list before freeing PI data Carlo Szelinsky
2026-11-18 18:39 ` [PATCH net v5 10/14] net: pse-pd: keep the PI data until the PI regulators are gone Carlo Szelinsky
2026-11-18 18:39 ` [PATCH net v5 11/14] net: pse-pd: free the notification kfifo when registration fails Carlo Szelinsky
2026-11-18 18:39 ` [PATCH net v5 12/14] net: pse-pd: use each PI's own supply handle for the power budget Carlo Szelinsky
2026-11-18 18:39 ` [PATCH net v5 13/14] net: pse-pd: pd692x0: release the manager power budget through devres Carlo Szelinsky
2026-11-18 18:39 ` [PATCH net v5 14/14] net: pse-pd: pd692x0: defer probe while a manager supply is unresolved Carlo Szelinsky
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=179515691186.3136.7466953769773810210@kernel.org \
--to=netdev-bot+sashiko@kernel.org \
--cc=andrew+netdev@lunn.ch \
--cc=broonie@kernel.org \
--cc=davem@davemloft.net \
--cc=edumazet@kernel.org \
--cc=github@szelinsky.de \
--cc=horms@kernel.org \
--cc=kory.maincent@bootlin.com \
--cc=kuba@kernel.org \
--cc=kyle.swenson@est.tech \
--cc=lgirdwood@gmail.com \
--cc=linux-kernel@vger.kernel.org \
--cc=maxime.chevallier@bootlin.com \
--cc=netdev@vger.kernel.org \
--cc=o.rempel@pengutronix.de \
--cc=pabeni@redhat.com \
--cc=ross@r-sc.ca \
/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®