mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Oleksij Rempel <o.rempel@pengutronix.de>
To: Carlo Szelinsky <github@szelinsky.de>
Cc: Kory Maincent <kory.maincent@bootlin.com>,
	Andrew Lunn <andrew+netdev@lunn.ch>,
	"David S . Miller" <davem@davemloft.net>,
	Eric Dumazet <edumazet@kernel.org>,
	Jakub Kicinski <kuba@kernel.org>, Paolo Abeni <pabeni@redhat.com>,
	Simon Horman <horms@kernel.org>,
	Kyle Swenson <kyle.swenson@est.tech>, Ross Cawston <ross@r-sc.ca>,
	netdev-bot+sashiko@kernel.org, netdev@vger.kernel.org,
	linux-kernel@vger.kernel.org
Subject: Re: [PATCH net v2 10/14] net: pse-pd: keep the PI data until the PI regulators are gone
Date: Thu, 22 Oct 2026 09:34:11 +0200	[thread overview]
Message-ID: <atm8c3oJomYY3RH6@pengutronix.de> (raw)
In-Reply-To: <20261020171249.853085-11-github@szelinsky.de>

On Tue, Oct 20, 2026 at 07:12:45PM +0200, Carlo Szelinsky wrote:
> pse_controller_unregister() frees the PI array, but the PI regulators
> are only unregistered after it, by devres. Until then their ops still
> run, for example on a read of the regulator's sysfs "state" or when a
> consumer enables or disables the PI, and they read the freed array.
> 
> Free the PI array from a devm action that is added before the PI
> regulators, so devres frees it after them. This also frees it when
> registration fails, where it was leaked before.
> 
> While the controller goes away, the PSE core must not power a PI.
> pse_controller_unregister() now first sets pcdev->unregistering under
> pcdev->lock. After that, enabling a PI fails with -ENODEV, and so does
> _pse_pi_delivery_power_sw_pw_ctrl(), which pse_isr(), a priority change
> and the retry after a disable use to power a PI. Disabling a PI still
> switches it off and frees its budget.
> 
> pse_flush_pw_ds() also switches off each PI that holds budget and gives
> the budget back before it drops the power domain. Nothing controls such
> a PI once its controller is gone, and before, its budget stayed
> reserved on the supply. If a PI cannot be switched off, its budget
> stays reserved, as the PI may still draw it.
> 
> Triggered in QEMU (arm64, KASAN) with a test-only PSE controller:
> reading the PI regulators' sysfs "state" while the controller unbinds
> gives
> 
>   BUG: KASAN: slab-use-after-free in pse_pi_is_enabled+0x294/0x2d4
> 
> and unbinding it with budget reserved leaves that budget on the
> supply. With this patch both are gone, the PIs are off after the
> unbind, and a priority change during the unbind no longer powers a PI.
> pse_isr() is not covered by the test, as the test controller has no
> IRQ.
> 
> Fixes: d83e13761d5b ("net: pse-pd: Use regulator framework within PSE framework")
> Fixes: ffef61d6d273 ("net: pse-pd: Add support for budget evaluation strategies")
> Signed-off-by: Carlo Szelinsky <github@szelinsky.de>

Freeing the PI array from devres after the PI regulators, and refusing
to power a PI once unregistering has started, look good to me.

Please drop pse_pi_power_off() from this patch, and the text about it
in the commit message and the cover letter.

The PI regulators follow the regulator model. A regulator that goes
away does not switch its output off; the consumer has to disable it
before it calls regulator_put(). For a PI the consumer is the PSE core
itself, on pcdev->dev. So on unbind every enabled PI should go off
through the normal disable path, before pse_flush_pw_ds() clears
pi->pw_d. The disable path also gives the budget back.

pse_pi_power_off() switches off only the PIs that hold budget. That is
not enough: a PI under hardware control, or under software control
without pi_get_pw_req(), can deliver power with no budget allocated.

Switching the PIs off on unbind belongs to the fix for a pse_control
outliving its controller, not to this patch. Patch 11 calls
pse_pi_power_off() from pse_pi_take_pw_d(), so patch 11 needs to drop
that call, and the comment above it, too.

Here "off" means what IEEE 802.3 calls mr_pse_enable = disable: no
power and no detection, as if there was no PSE. pi_disable() does not
do this on every driver today. tps23881 turns detection and
classification back on after power off, and the core relies on
detection staying on, since it also uses pi_disable() to power off a
PI that stays admin enabled. Fixing tps23881 is not part of this
series.

pw-bot: cr

-- 
Pengutronix e.K.                           |                             |
Steuerwalder Str. 21                       | http://www.pengutronix.de/  |
31137 Hildesheim, Germany                  | Phone: +49-5121-206917-0    |
Amtsgericht Hildesheim, HRA 2686           | Fax:   +49-5121-206917-5555 |

  reply	other threads:[~2026-10-22  7:34 UTC|newest]

Thread overview: 28+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-10-20 17:12 [PATCH net v2 00/14] net: pse-pd: assorted lifetime and error-path fixes Carlo Szelinsky
2026-10-20 17:12 ` [PATCH net v2 01/14] net: pse-pd: size the notification kfifo after defaulting nr_lines Carlo Szelinsky
2026-10-21  5:17   ` Oleksij Rempel
2026-10-20 17:12 ` [PATCH net v2 02/14] net: pse-pd: remove dead pi_get_admin_state() checks Carlo Szelinsky
2026-10-21  5:19   ` Oleksij Rempel
2026-10-20 17:12 ` [PATCH net v2 03/14] net: pse-pd: fix module refcount leak in pse_control_get_internal() Carlo Szelinsky
2026-10-21  5:24   ` Oleksij Rempel
2026-10-20 17:12 ` [PATCH net v2 04/14] net: pse-pd: do not keep a failed IRQ in pcdev->irq Carlo Szelinsky
2026-10-21  5:26   ` Oleksij Rempel
2026-10-20 17:12 ` [PATCH net v2 05/14] net: pse-pd: do not reach a freed PHY from the notification worker Carlo Szelinsky
2026-10-21  9:17   ` Oleksij Rempel
2026-10-20 17:12 ` [PATCH net v2 06/14] net: pse-pd: check the PI state under the lock when setting a power limit Carlo Szelinsky
2026-10-22  4:46   ` Oleksij Rempel
2026-10-20 17:12 ` [PATCH net v2 07/14] net: pse-pd: do not tie a shared power domain to its creator's devres Carlo Szelinsky
2026-10-22  5:13   ` Oleksij Rempel
2026-10-20 17:12 ` [PATCH net v2 08/14] net: pse-pd: stop async event sources before freeing PI data in unregister Carlo Szelinsky
2026-10-22  5:20   ` Oleksij Rempel
2026-10-20 17:12 ` [PATCH net v2 09/14] net: pse-pd: unregister from the controller list before freeing PI data Carlo Szelinsky
2026-10-22  5:28   ` Oleksij Rempel
2026-10-20 17:12 ` [PATCH net v2 10/14] net: pse-pd: keep the PI data until the PI regulators are gone Carlo Szelinsky
2026-10-22  7:34   ` Oleksij Rempel [this message]
2026-10-20 17:12 ` [PATCH net v2 11/14] net: pse-pd: unwind allocations when controller registration fails Carlo Szelinsky
2026-10-22  7:47   ` Oleksij Rempel
2026-10-22  8:21   ` Oleksij Rempel
2026-10-20 17:12 ` [PATCH net v2 12/14] net: pse-pd: use each PI's own supply handle for the power budget Carlo Szelinsky
2026-10-22  8:36   ` Oleksij Rempel
2026-10-20 17:12 ` [PATCH net v2 13/14] net: pse-pd: pd692x0: release the manager power budget through devres Carlo Szelinsky
2026-10-20 17:12 ` [PATCH net v2 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=atm8c3oJomYY3RH6@pengutronix.de \
    --to=o.rempel@pengutronix.de \
    --cc=andrew+netdev@lunn.ch \
    --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=linux-kernel@vger.kernel.org \
    --cc=netdev-bot+sashiko@kernel.org \
    --cc=netdev@vger.kernel.org \
    --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®