🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: linux.kernel.netdev
Article #19643

Re: [PATCH net v5 06/14] net: pse-pd: check the PI state under the lock when setting a power limit

#19643
From: netdev-bot+sashiko
Date: Fri, 20 Nov 2026 06:41
136 lines
12919 bytes
Thank you for your contribution! Sashiko AI review found 1 potential
issue(s) to consider.

Critical: 0 · High: 1 · Medium: 0 · Low: 0

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 patch moves the PI-state check into
  pse_pi_update_pw_budget(), under pcdev->lock, but the predicate is…

--

net: pse-pd: check the PI state under the lock when setting a power limit

This patch moves the "PI is enabled and has a PD detected" check from
pse_ethtool_set_pw_limit() into pse_pi_update_pw_budget(), so it runs
under pcdev->lock. It also adds an updated flag, so the rollback after a
failed regulator_set_current_limit() only runs when the budget was
actually changed.

> diff --git a/drivers/net/pse-pd/pse_core.c b/drivers/net/pse-pd/pse_core.c
> index b8cba6f86a7fd..342fb27e38319 100644
> --- a/drivers/net/pse-pd/pse_core.c
> +++ b/drivers/net/pse-pd/pse_core.c

[ ... ]

>  	/* We don't want pw_allocated_mW value change in the middle of an
>  	 * power budget update
>  	 */
>  	mutex_lock(&pcdev->lock);
> +	/* Only a PI under software power control that is enabled and has a
> +	 * PD detected gets a budget. Check this here, as pse_isr() changes
> +	 * it under the same lock.
> +	 */
> +	if (!pse_pw_d_is_sw_pw_control(pcdev, pi->pw_d) ||
> +	    !pi->admin_state_enabled || !pi->isr_pd_detected)
> +		goto out;
> +

[Severity: High]

The check now runs under the lock. Is admin_state_enabled &&
isr_pd_detected enough to show that the PI is powered and has a budget?

pse_pi_is_admin_enable_pending() describes a state where both flags are
set but the PI is off in hardware and pw_allocated_mW is 0:

pse_pi_is_admin_enable_pending() {
	if (!pcdev->pi[id].admin_state_enabled ||
	    !pcdev->pi[id].isr_pd_detected)
		return false;

	ret = pse_pi_is_hw_enabled(pcdev, id);
	if (ret == 1)
		return false;

	return true;
}

It looks like this state can be reached without any race:

- On classification, pse_set_config_isr() sets isr_pd_detected = true.
  If the static allocation then fails, it turns -ERANGE into 0.
  pse_pi_enable() also sets admin_state_enabled = 1 on -ERANGE.

- pse_disable_pi_pol()->_pse_pi_disable() sheds a lower priority PI and
  frees its budget, but leaves both flags set.

- If ops->pi_enable() fails after the budget was allocated, the budget
  is freed but the flags stay set.

In that state, pse_ethtool_set_pw_limit()->pse_pi_update_pw_budget()
passes the new check. pw_diff = pw_limit - 0 is positive, so
regulator_request_power_budget() is called and pi->pw_allocated_mW =
pw_limit is recorded for a port that is not powered.

The voltage == 0 early return in pse_ethtool_set_pw_limit() doesn't
seem to stop this on tps23881, because tps23881_pi_get_voltage() reads
the controller input voltage.

Later, pse_ethtool_set_prio() calls pse_pw_d_retry_power_delivery(), as
does the disable or disconnect of another PI in the same domain. That
function picks exactly these admin enable pending PIs:

pse_pw_d_retry_power_delivery()
  _pse_pi_delivery_power_sw_pw_ctrl()
    pse_pi_allocate_pw_budget_static_prio()

pse_pi_allocate_pw_budget_static_prio() then requests pw_req again and
does:

	pi->pw_allocated_mW = pw_req;
	return 0;

It does not free the reservation made by set_pw_limit first. Doesn't
this leak the power budget on the supply until the controller is bound
again? That is the same leak the commit message describes.

Until that retry runs, shedding can't reclaim the reservation either:
pse_disable_pi_prio() skips PIs where pse_pi_is_hw_enabled() <= 0. As a
result, powered ports could be shed or refused power.

The later patches in the series, such as "use each PI's own supply
handle for the power budget", only change the supply handle in these
functions. The predicate and the overwrite still appear to be there at
the end of the series.

Would it work to check under the lock that the PI is actually powered
or budgeted, for example pse_pi_is_hw_enabled(pcdev, id) == 1 or
pw_allocated_mW != 0? Another option is for
pse_pi_allocate_pw_budget_static_prio() to free an existing
pw_allocated_mW before overwriting it.

>  	previous_pw_allocated = pi->pw_allocated_mW;
>  	pw_diff = pw_req - previous_pw_allocated;
>  	if (!pw_diff) {

[ ... ]

> @@ -1846,6 +1859,7 @@ static int pse_pi_update_pw_budget(struct pse_controller_dev *pcdev, int id,
>  		regulator_free_power_budget(pi->pw_d->supply, -pw_diff);
>  	}
>  	pi->pw_allocated_mW = pw_req;
> +	*updated = true;
>  	ret = previous_pw_allocated;

[ ... ]

-- 
Sashiko AI review · https://netdev-ai.bots.linux.dev/sashiko/#/patchset/20261118183957.2031311-1-github%40szelinsky.de
Technical Details
Message-ID: <179515691045.3136.13671979747174463292@kernel.org>
Path: mbox-mo1.pugleaf.net!news-lax.pugleaf.net!srl.newsdeef.eu!newsfeed.bofh.team!news.nntp4.net!nntp.xenet.de!news.neodome.net!usenet.network!.POSTED!vger.kernel.org!netdev+bounces-367709-linux-kernel-netdev=dewy.ru
References: <20261118183957.2031311-7-github@szelinsky.de>

Show Full Headers
Complete Article Headers
Path: mbox-mo1.pugleaf.net!news-lax.pugleaf.net!srl.newsdeef.eu!newsfeed.bofh.team!news.nntp4.net!nntp.xenet.de!news.neodome.net!usenet.network!.POSTED!vger.kernel.org!netdev+bounces-367709-linux-kernel-netdev=dewy.ru
From: netdev-bot+sashiko@kernel.org
Newsgroups: linux.kernel.netdev
Subject: Re: [PATCH net v5 06/14] net: pse-pd: check the PI state under the
 lock when setting a power limit
Date: Fri, 20 Nov 2026 06:41:50 +0000
Organization: Usenet Network
Message-ID: <179515691045.3136.13671979747174463292@kernel.org>
References: <20261118183957.2031311-7-github@szelinsky.de>
MIME-Version: 1.0
Content-Type: text/plain; charset="utf-8"
Content-Transfer-Encoding: 8bit
Injection-Info: usenet.network;
	logging-data="3084561"; mail-complaints-to="abuse@usenet.network"
Cancel-Lock: sha1:zu9nA3mEVxaLoxKwcLbrRZM0GRI= sha256:Xv1Cn0T0i/Ubt6BMl9ABJ1JytueubF0et/RzFjoxJTw=
	sha1:7ro4AoRApYY6zGTbK82p7JrRlYA= sha256:uYXukrfsso6RC40FSO54+IHgP0OBhMyYQrLriVrFnbs=
List-ID: <netdev.vger.kernel.org>
X-Mailpost-Empty-Hdrs: X-Spam-Level
X-Received: from localhost (localhost [127.0.0.1])
	by mail.dewy.ru (Postfix) with ESMTP id B33E81158CC; Fri, 20 Nov 2026 09:42:13 +0300 (MSK)
X-Virus-Scanned: Debian amavisd-new at usenet.network
X-Spam-Flag: NO
X-Spam-Score: -3.5
X-Spam-Status: No, score=-3.5 tagged_above=-9999 required=6.31
	tests=[DKIMWL_WL_HIGH=-0.001, DKIM_SIGNED=0.1, DKIM_VALID=-0.1,
	DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, MAILING_LIST_MULTI=-1,
	RCVD_IN_DNSWL_MED=-2.3, SPF_HELO_NONE=0.001, SPF_PASS=-0.001,
	URIBL_BLOCKED=0.001] autolearn=ham autolearn_force=no
X-Authentication-Results: mail.dewy.ru (amavisd-new); dkim=pass (2048-bit key)
	header.d=kernel.org
X-Received: from mail.dewy.ru ([127.0.0.1])
	by localhost (mail.dewy.ru [127.0.0.1]) (amavisd-new, port 10024)
	with ESMTP id C_-T1MKNmL6F;
	Fri, 20 Nov 2026 09:42:10 +0300 (MSK)
X-Received-SPF: Pass (mailfrom) identity=mailfrom; client-ip=172.232.135.74; helo=sto.lore.kernel.org; envelope-from=netdev+bounces-367709-linux-kernel-netdev=dewy.ru@vger.kernel.org; receiver=<UNKNOWN> 
X-Authentication-Results: OpenDMARC; dmarc=pass (p=quarantine dis=none) header.from=kernel.org
X-Received: from sto.lore.kernel.org (sto.lore.kernel.org [172.232.135.74])
	by mail.dewy.ru (Postfix) with ESMTPS id E55DF1158B2; Fri, 20 Nov 2026 09:42:01 +0300 (MSK)
X-Received: from smtp.subspace.kernel.org (conduit.subspace.kernel.org [100.77.114.92])
	by sto.lore.kernel.org (Postfix) with ESMTP id 2FF77688A0F; Fri, 20 Nov 2026 06:42:01 +0000 (UTC)
X-Authentication-Results: smtp.subspace.kernel.org; arc=pass header.oldest-pass=0 smtp.remote-ip=127.0.0.1
X-ARC-Seal: i=2; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=pass;
	t=1795156913;
	b=LEOjc6fpydr+klhZnG1wDAoZn48qeDUfsTeLYVtNc6O2ehqaGlBNJgJGqAtxisWMQXN5
	 ouQFhvG+9yiXKb+jMTjkOCLcvNe8pCN5WKEhGuj+wV5+S75FqmLkCo7rUZ+rX9ZOK6yQR
	 Yk1uVR/jk8sKC8f5AVdSR3mWrNXNo5V1w0gx3CoBqZAn8u9LDqCC6pqFEmzGQWe5Jwv5A
	 0jSm+7Ykn83bMnGEkeQ0Rp8pSpQvkB2Sl6+kMUAZRpf0mYeLszNmwEU0H+y0BsCPoFCPq
	 O4hLiDJNus59eek8YGgrPuMzTreTdYWEckbUz5vGI2NyGGWQgAnRRj15u6EyaQZhegg==
X-ARC-Message-Signature: i=2; d=subspace.kernel.org; s=arc20261015;
	a=rsa-sha256; c=relaxed/relaxed; t=1795156913;
	h=X-Original-To:Received:Received:DKIM-Signature:Subject:From:To:Cc:
	 Date:Message-ID:In-Reply-To:References:X-sashiko-severity:
	 Content-Type:Content-Transfer-Encoding:X-Mailing-List:List-Id:
	 List-Post:List-Help:List-Subscribe:List-Unsubscribe:List-Owner:
	 Precedence:MIME-Version;
	bh=Mgw3XWwCWgtLNqGSpBZksw7IgPVhXJGfoOp08HyVngA=;
	b=1OMwEOVxjjIvXJLXSU7bGi131V83TXj+JqG1zNMuingyFQUC/ndhkYMnpdplphdZIzTk
	 ZgZpFU0iI7tZ/f+M5GTV/N+wVRHpYbVTMdkWQpDkuT9xqLdt2lqnZFV5uD2FnU0EQCPIN
	 swaVeBuwxicRr6jBc6QshE22QG8Ik6YExZ7oPJiyJWaKat0mv6xYSQ6/8N13dqBnqgWCG
	 vMyOTtedA+TQQKyPy1BC+QtB4Zvg1QV82tjWlU7VhIfbjyNy4ANKWlZTQwCVvLb6vDgsG
	 NJM0VYiwO+cgK82yTp2uIy/qmr5HCZaD9YytHtm964RUMRF60fFAzgIC/qNgbwVPoug==
X-ARC-Authentication-Results: i=2; smtp.subspace.kernel.org; 
	dkim=pass header.d=kernel.org header.i=@kernel.org header.a=rsa-sha256 header.s=k20260515 header.b=XtBnsxK6;
	arc=pass header.oldest-pass=0 smtp.remote-ip=127.0.0.1
X-Received: from localhost.localdomain (localhost [127.0.0.1])
	by smtp.subspace.kernel.org (Postfix) with ESMTP id EF21B606A330;
	Fri, 20 Nov 2026 06:41:52 +0000 (UTC)
X-Authentication-Results: smtp.subspace.kernel.org;
	dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.a=rsa-sha256 header.s=k20260515 header.b=XtBnsxK6
X-Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=100.103.45.18
X-ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none;
	t=1795156912;
	b=TBOHztlC0KWgmNLYhD3wVk4U5IBluyX7RHvZm8umo0uRT1nPXYVssovzIIGtsKIOZj/I
	 dpQ2+xoEL0PeV74I8lQcZw5sfVYVypDPruBAIEDleXX0OEokx/72NWFauxG17NrjvWhdF
	 Do01E2lL3BZcikcPSGjuQ6i481M8atBEZgYOCxkEs6rfJyRQaAqTKhg8DEo0v/CH7DZJT
	 vz+3dznoTH/UjXRTRNWnphnIdKoeGTyL2lmwM1QUXDH2xbWouMKwkZxdJMeJNx8W5lLjm
	 E4O6g5tTHuXAyA3ESIE94/4wmj7nYzBFEjBqArAqSDfsvYePyP8yeeV/ztE9mYU2Kbg==
X-ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015;
	a=rsa-sha256; c=relaxed/relaxed; t=1795156912;
	h=Received:DKIM-Signature:Subject:From:To:Cc:Date:Message-ID:
	 In-Reply-To:References:X-sashiko-severity:Content-Type:
	 Content-Transfer-Encoding:MIME-Version;
	bh=Mgw3XWwCWgtLNqGSpBZksw7IgPVhXJGfoOp08HyVngA=;
	b=XjEWjY0PdoKturETkobFXYPxirHL67qomUPLnFl9Oxc/l2tzeHvsGnbS5zvajEMcy1oy
	 H9sQcDHcGKk75fbVtDN0VZXAE1kKjvEaXjrr1JbZSt6czUVH+rsdNUVATu71LvbExgtlc
	 Ui8Cr05m6ZoUIeDocW3CJmwrAKWMvfn6WoCQQPMLhZQPB1KnalF3EFoUiQiuVWrPSq9DI
	 D9xIiECow8culwFO3TmBiDHSYH+iUwHOOnQPYopRI+TyyJILgpF4ve7BLD/D3ZTlDEMQs
	 UR3ModWICtaNxzagdkqHWixjWD9ckxDiaJhYXE5h1HqAqq0xoZvwXSIepwugCmYPm9w==
X-ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; 
	dkim=pass header.d=kernel.org header.i=@kernel.org header.a=rsa-sha256 header.s=k20260515 header.b=XtBnsxK6;
	arc=none smtp.remote-ip=100.103.45.18
X-Received: from smtp.kernel.org (quasi.space.kernel.org [100.103.45.18])
	(using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)
	 key-exchange X25519 server-signature ECDSA (prime256v1))
	(No client certificate requested)
	by smtp.subspace.kernel.org (Postfix) with ESMTPS id 1B14660A2607;
	Fri, 20 Nov 2026 06:41:51 +0000 (UTC)
X-Received: by smtp.kernel.org (Postfix) with ESMTPSA id D4BEC1F000C4;
	Fri, 20 Nov 2026 06:41:50 +0000 (UTC)
X-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel.org;
	s=k20260515; t=1795156911;
	bh=Mgw3XWwCWgtLNqGSpBZksw7IgPVhXJGfoOp08HyVngA=;
	h=Subject:From:To:Cc:Date:In-Reply-To:References;
	b=XtBnsxK6HMOE3b3Xlla7URoLK6E2FCScr1ttMwqYI5yBAltelAiqZt1kEYLiikXsx
	 CghSyBu0Fao5GFjHd95qWNMigi2Z8C5c3h90jRwShqgWnuGEhbJyvxoexmldoIJCry
	 sKXS8Qg0Syp9aWsjKTYfv6ODQOJQKqzpQ538hbP0iNYr/qenoVe5lJsTQQHz/MUm5x
	 ez2tdYmxj/776MGBmduwZ5q1M6YkuJ0nQoCjJ1gXhYcZkUYvNCoGshl9OoeNKIz6t/
	 ETQdBA7ofQXO+uM4Y3yeuqD7zj+rnf2kiZubYFdxe/MQEfnmyFIQFlQlHqiW71VkW5
	 CV/lzfxnksuog==
X-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
X-In-Reply-To: <20261118183957.2031311-7-github@szelinsky.de>
X-sashiko-severity: High
X-Mailing-List: netdev@vger.kernel.org
X-List-Post: <mailto:netdev@vger.kernel.org>
X-List-Help: <mailto:netdev+help@vger.kernel.org>
X-List-Subscribe: <mailto:netdev+subscribe@vger.kernel.org>
X-List-Unsubscribe: <mailto:netdev+unsubscribe@vger.kernel.org>
X-List-Owner: <mailto:netdev+owner@vger.kernel.org>
X-Precedence: list