Article View: linux.kernel.netdev
Article #4794Re: [PATCH net 05/10] net: pse-pd: check the PI state under the lock when setting a power limit
From: netdev-bot+sashiko
Date: Mon, 19 Oct 2026 08:51
Date: Mon, 19 Oct 2026 08:51
170 lines
12002 bytes
12002 bytes
Thank you for your contribution! Sashiko AI review found 2 potential
issue(s) to consider.
Critical: 0 · High: 0 · Medium: 1 · Low: 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).
- [Medium] The patch puts the PD-state check and the budget change in one
pcdev->lock critical section inside pse_pi_update_pw_budget().
- [Low] The kernel-doc for pse_pi_update_pw_budget() (drivers/net/pse-
pd/pse_core.c:1835) still says "Return: Previous power allocated on…
--
net: pse-pd: check the PI state under the lock when setting a power limit
This moves the software power control, admin state and PD detected checks
from pse_ethtool_set_pw_limit() into pse_pi_update_pw_budget(), so they now
run under pcdev->lock. A new updated output parameter reports whether the
budget changed. The rollback after a failed regulator_set_current_limit()
now runs only when updated is true.
> diff --git a/drivers/net/pse-pd/pse_core.c b/drivers/net/pse-pd/pse_core.c
> index 336f00d82b5f8..d5f863834179c 100644
> --- a/drivers/net/pse-pd/pse_core.c
> +++ b/drivers/net/pse-pd/pse_core.c
> @@ -1829,22 +1829,32 @@ EXPORT_SYMBOL_GPL(pse_ethtool_set_config);
> * @pcdev: a pointer to the PSE controller device
> * @id: index of the PSE PI
> * @pw_req: power requested
> + * @updated: set to true if the budget was changed
> * @extack: extack for reporting useful error messages
> *
> * Return: Previous power allocated on success and failure value on error
> */
> static int pse_pi_update_pw_budget(struct pse_controller_dev *pcdev, int id,
> - const unsigned int pw_req,
> + const unsigned int pw_req, bool *updated,
> struct netlink_ext_ack *extack)
> {
[ ... ]
> mutex_lock(&pcdev->lock);
> + /* Only a powered PI under software power control holds a budget.
> + * Check it 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: Low]
This isn't a bug, but the kernel-doc for pse_pi_update_pw_budget() still
says:
* Return: Previous power allocated on success and failure value on error
This new early exit returns 0 with *updated = false, whatever
pi->pw_allocated_mW holds. The existing !pw_diff exit also returns 0.
pw_allocated_mW can be non-zero when this check fails. For example,
_pse_pi_disable() returns before pse_pi_deallocate_pw_budget() if
ops->pi_disable() fails, but pse_set_config_isr() still clears
isr_pd_detected on disconnection.
Could the Return description say that 0 can also mean no change was made?
It could also say that callers should check *updated, not the return
value, before rolling back.
> previous_pw_allocated = pi->pw_allocated_mW;
> pw_diff = pw_req - previous_pw_allocated;
> if (!pw_diff) {
[ ... ]
> @@ -1908,21 +1920,17 @@ int pse_ethtool_set_pw_limit(struct pse_control *psec,
> /* Update power budget only in software power control case and
> * if a Power Device is powered.
> */
> - if (pse_pw_d_is_sw_pw_control(psec->pcdev,
> - psec->pcdev->pi[psec->id].pw_d) &&
> - psec->pcdev->pi[psec->id].admin_state_enabled &&
> - psec->pcdev->pi[psec->id].isr_pd_detected) {
> - ret = pse_pi_update_pw_budget(psec->pcdev, psec->id,
> - pw_limit, extack);
> - if (ret < 0)
> - return ret;
> - previous_pw_allocated = ret;
> - }
> + ret = pse_pi_update_pw_budget(psec->pcdev, psec->id, pw_limit,
> + &updated, extack);
> + if (ret < 0)
> + return ret;
> + previous_pw_allocated = ret;
>
> ret = regulator_set_current_limit(psec->ps, 0, uA);
[Severity: Medium]
The scenario in the commit message, where budget is reserved for a port
that is no longer powered, looks closed now. But can the budget and the
hardware limit still drift apart in the other direction?
The state check and the budget change now share one pcdev->lock critical
section. The hardware limit is still written in a separate one:
pse_ethtool_set_pw_limit()
pse_pi_update_pw_budget() <- takes and drops pcdev->lock
regulator_set_current_limit()
pse_pi_set_current_limit() <- takes pcdev->lock again
ops->pi_set_pw_limit()
The threaded pse_isr() only needs pcdev->lock, so it can run in between:
CPU0 (ethtool set_pw_limit)
pse_pi_update_pw_budget()
sees isr_pd_detected == false
*updated = false, nothing reserved
mutex_unlock(&pcdev->lock)
CPU1 (pse_isr, classification event)
pse_set_config_isr()
isr_pd_detected = true
_pse_pi_delivery_power_sw_pw_ctrl()
pw_req = min(pi_get_pw_req(), pi_get_pw_limit()) <- old hw limit
pse_pi_allocate_pw_budget(pcdev, id, pw_req, extack)
ops->pi_enable()
CPU0
regulator_set_current_limit()
pse_pi_set_current_limit()
ops->pi_set_pw_limit() <- new, higher limit
The port would then be powered with a hardware limit above its reserved
budget, and nothing later corrects pi->pw_allocated_mW. Could that
over-subscribe the power domain?
A disconnect followed by a reconnect between the two sections seems to end
the same way. If regulator_set_current_limit() then fails, this rollback
writes back the previous_pw_allocated value that was read before the
reconnect:
if (ret < 0 && updated) {
pse_pi_update_pw_budget(psec->pcdev, psec->id,
previous_pw_allocated, &updated,
extack);
Would a full fix need the state check, the budget update and
ops->pi_set_pw_limit() in a single pcdev->lock critical section?
pse_pi_set_current_limit() takes pcdev->lock itself, so that looks like it
needs a different structure from calling regulator_set_current_limit()
after pse_pi_update_pw_budget().
> - if (ret < 0 && previous_pw_allocated) {
> + if (ret < 0 && updated) {
> pse_pi_update_pw_budget(psec->pcdev, psec->id,
> - previous_pw_allocated, extack);
> + previous_pw_allocated, &updated,
> + extack);
> }
>
> return ret;
--
Sashiko AI review · https://netdev-ai.bots.linux.dev/sashiko/#/patchset/20261018082314.48950-1-github%40szelinsky.de
Technical Details
Message-ID:
<179239987339.3135.11130245905103238734@kernel.org>Path:
mbox-mo1.pugleaf.net!archive.usenet.blueworldhosting.com!usenet.blueworldhosting.com!diablo1.usenet.blueworldhosting.com!usenet.network!.POSTED!vger.kernel.org!netdev+bounces-348357-linux-kernel-netdev=dewy.ruReferences:
<20261018082314.48950-6-github@szelinsky.de>Show Full Headers
Complete Article Headers
Path: mbox-mo1.pugleaf.net!archive.usenet.blueworldhosting.com!usenet.blueworldhosting.com!diablo1.usenet.blueworldhosting.com!usenet.network!.POSTED!vger.kernel.org!netdev+bounces-348357-linux-kernel-netdev=dewy.ru From: netdev-bot+sashiko@kernel.org Newsgroups: linux.kernel.netdev Subject: Re: [PATCH net 05/10] net: pse-pd: check the PI state under the lock when setting a power limit Date: Mon, 19 Oct 2026 08:51:13 +0000 Organization: Usenet Network Message-ID: <179239987339.3135.11130245905103238734@kernel.org> References: <20261018082314.48950-6-github@szelinsky.de> MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: 8bit Injection-Info: usenet.network; logging-data="3549606"; mail-complaints-to="abuse@usenet.network" Cancel-Lock: sha1:XixpFkH7Ozc0TcMKYHNvMAas508= sha256:oqQ6uJQ9HJlGLTywcWKXy3uY044o4re57rElq1NvMko= sha1:S3lptKzCa1taLS8C8ENeudgsBqs= sha256:d47TQqxOrgrAOfBInc7L9TPG8TiC84tY+mWkwu25aDY= 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 C297F110959; Mon, 19 Oct 2026 11:56:33 +0300 (MSK) X-Virus-Scanned: Debian amavisd-new at usenet.network X-Spam-Flag: NO X-Spam-Score: -3.74 X-Spam-Status: No, score=-3.74 tagged_above=-9999 required=6.31 tests=[DCC_REPUT_70_89=0.1, DKIMWL_WL_HIGH=-0.34, 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] 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 ly4Mjl6CtnpK; Mon, 19 Oct 2026 11:56:30 +0300 (MSK) X-Received-SPF: Pass (mailfrom) identity=mailfrom; client-ip=172.234.253.10; helo=sea.lore.kernel.org; envelope-from=netdev+bounces-348357-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 sea.lore.kernel.org (sea.lore.kernel.org [172.234.253.10]) by mail.dewy.ru (Postfix) with ESMTPS id 5A45D110954; Mon, 19 Oct 2026 11:56:22 +0300 (MSK) X-Received: from smtp.subspace.kernel.org (conduit.subspace.kernel.org [100.90.174.1]) by sea.lore.kernel.org (Postfix) with ESMTP id 0B82F63A85; Mon, 19 Oct 2026 08:51:18 +0000 (UTC) X-Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 39F0F4A43F1; Mon, 19 Oct 2026 08:51:16 +0000 (UTC) X-Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="TlVjn1EK" X-Received: from smtp.kernel.org (aws-us-west-2-korg-mail-alma10-1.taild15c8.ts.net [100.103.45.18]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id D658E49E5ED; Mon, 19 Oct 2026 08:51:14 +0000 (UTC) X-Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=100.103.45.18 X-ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1792399876; cv=none; b=cQJmR3/tDA8QFxrpNworDKti64ybbhjlmwIP6rQo4o2PZYckNX3DaGIWRjM8IuELhsvcDVKhCbOY4TdaviAjo1y9dZTTkd/dVAEa7RJ6YF4W4JqmsPEMORzKS8vhky/daksXNNoJg6O3SeVPlBTnoCpWCQzyamp9m23ZmoIJskQ= X-ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1792399876; c=relaxed/simple; bh=yRgOBFy+C4uubMACqMsY2X2MvN2h2hsDnJ/97y/CgI0=; h=Subject:From:To:Cc:Date:Message-ID:In-Reply-To:References: Content-Type:MIME-Version; b=e4nW8ydflESbRqrMKUkQSqDHlq4/TsqP8vYekRPqTHmYfK8tBHBjHhwE2+wIwNkOmD2p2llGLQ8c7ePWAqlzbH6e8+KXwsVMygYoMNg/rhpxO3I6yZL2nOuc7asoyJberhrQhWbdoH0079hXNjhkkrlRZrZl/prMDEzvVAJreKc= X-ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=TlVjn1EK; arc=none smtp.client-ip=100.103.45.18 X-Received: by smtp.kernel.org (Postfix) with ESMTPSA id C6B841F000C4; Mon, 19 Oct 2026 08:51:13 +0000 (UTC) X-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel.org; s=k20260515; t=1792399874; bh=dEEd7H/7kkXmUvradk6puKO4yMY6sZvcHlBFoHhJaSQ=; h=Subject:From:To:Cc:Date:In-Reply-To:References; b=TlVjn1EKSEDeUkmSnT9W8pcFM6crnhDlHMpGRl3bPOqPL/FA3FjGJrwRyGQgXBuuE Evv4At+/1L5E12wUyZ/J5UI5X1ANs3vWF6JO2DIrbTd6XR5ZMc1ndoiN88PxD+serW 1zerS671tM7FguwwgKg5Vhe5lJDPKIxXwT9AROQ5OMgrngKNFqU3NtFbSO42YUxbtL k/CwlfrrhC6D1AOZN0YkvsJ2UzXAnBP9W1+Vf0LDNoLVbZ49dtfpHVCgDKgpR2TDeN tNAx1Jua52JBd9s/E97GzS3G5u3Q3OyegFOVS67cwVFELkhEgpbXN80wBLS4WfcZp8 rUraj8VZkNmFw== 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, piotr.kubik@adtran.com, saikrishnag@marvell.com, horms@kernel.org, kyle.swenson@est.tech, netdev-bot+sashiko@kernel.org, netdev@vger.kernel.org, linux-kernel@vger.kernel.org X-In-Reply-To: <20261018082314.48950-6-github@szelinsky.de> X-sashiko-severity: Medium X-Precedence: bulk X-Mailing-List: netdev@vger.kernel.org X-List-Subscribe: <mailto:netdev+subscribe@vger.kernel.org> X-List-Unsubscribe: <mailto:netdev+unsubscribe@vger.kernel.org>