๐Ÿš€ go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: linux.kernel.netdev
Article #22097

Re: [PATCH net v4 4/4] igb: only allow runtime PM if the device can wake up

#22097
From: netdev-bot+sashiko
Date: Tue, 24 Nov 2026 21:38
140 lines
12819 bytes
Thank you for your contribution! Sashiko AI review found 1 potential
issue(s) to consider.

Critical: 0 ยท High: 0 ยท Medium: 1 ยท 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).

- [Medium] The runtime PM usage count can end up unbalanced, because the
  same decision is made twice.

--

igb: only allow runtime PM if the device can wake up

With this patch, igb_probe() drops the runtime PM reference taken by
local_pci_probe() only when pci_dev_run_wake() is true. Devices that
can't signal a wake-up from D3 are therefore never runtime suspended.
igb_remove() takes the reference back under the same condition.

Closes: https://bugzilla.ipfire.org/show_bug.cgi?id=13562

> diff --git a/drivers/net/ethernet/intel/igb/igb_main.c b/drivers/net/ethernet/intel/igb/igb_main.c
> index 4617aba5759d2..36bd395e36dab 100644
> --- a/drivers/net/ethernet/intel/igb/igb_main.c
> +++ b/drivers/net/ethernet/intel/igb/igb_main.c
> @@ -3654,7 +3654,11 @@ static int igb_probe(struct pci_dev *pdev, const struct pci_device_id *ent)
>  
>  	dev_pm_set_driver_flags(&pdev->dev, DPM_FLAG_NO_DIRECT_COMPLETE);
>  
> -	pm_runtime_put_noidle(&pdev->dev);
> +	/* A device that can't wake up wouldn't notice the link coming back
> +	 * while runtime suspended
> +	 */
> +	if (pci_dev_run_wake(pdev))
> +		pm_runtime_put_noidle(&pdev->dev);
>  	return 0;
>  
>  err_register:
> @@ -3876,7 +3880,8 @@ static void igb_remove(struct pci_dev *pdev)
>  	struct igb_adapter *adapter = netdev_priv(netdev);
>  	struct e1000_hw *hw = &adapter->hw;
>  
> -	pm_runtime_get_noresume(&pdev->dev);
> +	if (pci_dev_run_wake(pdev))
> +		pm_runtime_get_noresume(&pdev->dev);

[Severity: Medium]

Can the runtime PM usage count get out of balance here?

pci_dev_run_wake() runs once in igb_probe() and again in igb_remove(),
and the first result isn't stored. pci_device_remove() then always ends
with a put:

drivers/pci/pci-driver.c:pci_device_remove() {
    ...
	/* Undo the runtime PM settings in local_pci_probe() */
	pm_runtime_put_sync(dev);
    ...
}

The count only balances if both pci_dev_run_wake() calls return the
same value.

It looks like the result can change while the driver is bound.
pci_dev_run_wake() checks pci_pme_capable(dev, pci_target_state(dev,
true)). On ACPI-managed devices, acpi_pci_choose_state() caps the target
state using a flag that root can change through sysfs:

drivers/pci/pci-acpi.c:acpi_pci_choose_state() {
    ...
	if (pdev->no_d3cold || !pdev->d3cold_allowed)
		d_max = ACPI_STATE_D3_HOT;
	else
		d_max = ACPI_STATE_D3_COLD;
    ...
}

d3cold_allowed_store() writes pdev->d3cold_allowed, and nothing
serializes that write against probe or remove. On a device that can
raise PME from D3hot but not from D3cold, toggling the attribute flips
the result of pci_dev_run_wake().

A second case is a device not managed by the platform, for example an
igb NIC behind a Thunderbolt or USB4 dock. If it is surprise-removed
while runtime suspended, the result also seems to change.
pm_runtime_get_sync() in pci_device_remove() resumes the device, and
pci_power_up() does:

drivers/pci/pci.c:pci_power_up() {
    ...
	if (pci_dev_is_disconnected(dev)) {
		dev->current_state = PCI_D3cold;
		return -EIO;
	}
    ...
}

After that, pci_target_state() returns D3cold:

drivers/pci/pci.c:pci_target_state() {
    ...
	if (dev->current_state == PCI_D3cold)
		return PCI_D3cold;
    ...
}

So igb_remove() tests the PME-from-D3cold bit, while igb_probe() tested
the D3hot bit.

If the call returns false at probe and true at remove, igb_remove()
does an extra pm_runtime_get_noresume(). One usage count then leaks on
each bind/unbind cycle. The device can't runtime suspend again, even
after the driver is rebound.

If it returns true at probe and false at remove, the final
pm_runtime_put_sync() in pci_device_remove() underflows and logs
"Runtime PM usage count underflow!". With power/control set to on, the
extra put uses up the pm_runtime_forbid() reference instead, and a
later pm_runtime_allow() underflows.

Would it be safer to call pci_dev_run_wake() once in igb_probe(), store
the result (for example as a bool in struct igb_adapter), and test that
stored value in igb_remove()?

e1000e and r8169 call pci_dev_run_wake() again at remove in the same
way, so this pattern already exists in the tree. In igb, though, this
would be a new imbalance, added by a fix that is tagged for stable.

>  #ifdef CONFIG_IGB_HWMON
>  	igb_sysfs_exit(adapter);
>  #endif

-- 
Sashiko AI review ยท https://netdev-ai.bots.linux.dev/sashiko/#/patchset/20261120210134.133238-1-antonio%40mandelbit.com
Technical Details
Message-ID: <179555632736.3135.1658046091917963917@kernel.org>
Path: mbox-mo1.pugleaf.net!news-can.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-370776-linux-kernel-netdev=dewy.ru
References: <20261120210134.133238-5-antonio@mandelbit.com>

Show Full Headers
Complete Article Headers
Path: mbox-mo1.pugleaf.net!news-can.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-370776-linux-kernel-netdev=dewy.ru
From: netdev-bot+sashiko@kernel.org
Newsgroups: linux.kernel.netdev
Subject: Re: [PATCH net v4 4/4] igb: only allow runtime PM if the device can wake up
Date: Tue, 24 Nov 2026 21:38:47 +0000
Organization: Usenet Network
Message-ID: <179555632736.3135.1658046091917963917@kernel.org>
References: <20261120210134.133238-5-antonio@mandelbit.com>
MIME-Version: 1.0
Content-Type: text/plain; charset="utf-8"
Content-Transfer-Encoding: 8bit
Injection-Info: usenet.network;
	logging-data="43862"; mail-complaints-to="abuse@usenet.network"
Cancel-Lock: sha1:Sg9443JtrJZrH+pP8MuPvgzx+gk= sha256:Zf5H82jsuLkU/81mg5gDHemZ+qIjKbPveUKl0X+9KRo=
	sha1:DCE2GbeuXLKRhvcUNgn706YeRMY= sha256:UarktLSA5100XP/Gua4zjM0kyvqswpx5tlWSQ62zyMA=
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 E45CB125E36; Wed, 25 Nov 2026 00:39:24 +0300 (MSK)
X-Virus-Scanned: Debian amavisd-new at usenet.network
X-Spam-Flag: NO
X-Spam-Score: -3.4
X-Spam-Status: No, score=-3.4 tagged_above=-9999 required=6.31
	tests=[DCC_REPUT_70_89=0.1, 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 FT4zScOVsOCI;
	Wed, 25 Nov 2026 00:39:21 +0300 (MSK)
X-Received-SPF: Pass (mailfrom) identity=mailfrom; client-ip=172.234.253.10; helo=sea.lore.kernel.org; envelope-from=netdev+bounces-370776-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 9B2BA125E34; Wed, 25 Nov 2026 00:39:11 +0300 (MSK)
X-Received: from smtp.subspace.kernel.org (conduit.subspace.kernel.org [100.77.114.92])
	by sea.lore.kernel.org (Postfix) with ESMTP id 4B0A93C5A5; Tue, 24 Nov 2026 21:38:56 +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=1795556334;
	b=GphP9/nTfVweislS+oINTl6vvLMVUpl795sU1R6aVVe2mkUbwR0NWgf9+XnIow+L+8t7
	 m24wLvb0V3eTtoeoc26dWtC35Fl+PjpWdyXSGz62f6HFqmDoFmIFg0kk0FZmNXpfMIkm4
	 cXM0I4f2sXQZxOTqqJtQ6HJ80lGVusWF6QOEkiE09Z85eF1R4nbPbpqs0MMDVyO+i/LRC
	 J5ScWl/X9zNHLiYtWITl5d39dIHmVWwWVtJWzQqL/7TryFpzaaE0vew0CNJTzsqlMsOLy
	 96Ohd6iFeleLD409VTHmIDeCRE25PyP26TFug9q7T1PugWckSkSVeb2MIZVBN/dgSwQ==
X-ARC-Message-Signature: i=2; d=subspace.kernel.org; s=arc20261015;
	a=rsa-sha256; c=relaxed/relaxed; t=1795556334;
	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=UDznTv7tvXw7e6fmTZhMJ4Cm4gT1kF7rLrwjGIShnwY=;
	b=Jac8v43e6KAUju57x8PK4UO5Iamw8eo1EYR1kcDulQDjzf48/tprXbi1xDbThuTPpYYE
	 n9WAh3gc/5GPFHMclK1Gg/XFplKqpxIAPAStjSx9xUdLV8v/sUi4Umo9yviaUtH3fAPL8
	 cq9VC2bm3V3PYpcpo9S2Ceig5MnGqlPE6R3RqZu/dIspPyYP2OADTZsUsn+l4zhFtHVsb
	 E5x1t7KizaiE5FnW2rKmwuls2UNyw2VfUz7+kcVe+1NwmvaVCpBHl0dJlFMm3n8WkyEV2
	 r8ETnFbIXLo9Gz6bY41715rghktwsw5BpeQvh5e5HMWh1Lj3hJvU65LMhz5UefP7R/g==
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=aucOB2zf;
	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 B617E606A6A1;
	Tue, 24 Nov 2026 21:38:54 +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=aucOB2zf
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=1795556328;
	b=2gG/XHRbV60A27ukXPMUe8AlcZ5DQHpLjH+km89ZrEVR/F1qGRyyVqy2mIIQsEJOWbSi
	 5Tdj3XNkZOohH754rp6AvDswYZD/eXvNbijlNetwONMpULOSHz3QhBXCj3vN8CKeT0PV7
	 UmSt/OjRm7PwhqIBddjTJEzRp2s9MR9eH9EDR8fQ/JqyQ0+lwbcxzRBtaVg2FbcdbJvV/
	 cMWf/ZiVYmQXPHDvLhpYJly0t7sE4gUcz9P4v5snRRo7Q+Nc3trDYNkqfxTeM1qn8R4TT
	 Y3EvGUcGJkEe0zVuRIwDimuN+rVHAHdzrYZQwMlfQ9s/14o0MFPJvjcF4HpTk6xh1Uw==
X-ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015;
	a=rsa-sha256; c=relaxed/relaxed; t=1795556328;
	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=UDznTv7tvXw7e6fmTZhMJ4Cm4gT1kF7rLrwjGIShnwY=;
	b=vmWgnrC6BNb9RVSwmu0k1OoTltjbnEQ/gC1STR2vfuDzCEeN305Dcf7vvuCUceh0S+w/
	 3ij+43yUlcnEMkNiUKU4LoVJ556p8HmBXRuVgnI9Y8uGK4KZ1DjgR2tkDBl4lmyHTznqw
	 7xKxaj+aJChvPPqR3LA7f50fvHD6WXPBe28EseiuJC26OIEinGrAjgXM4qo3hRYjXkLR9
	 DoprE99MR60B2yahbaex0BrRecbhTn75BtteYxLh4SVQTUxuIYzsW0d7kB1hv/rIIKO0j
	 CAuizvM/fUYbzBIePpJvr69j0x6+BD/c7zt0FmF+jCpDv7plLnGWaNQXx3oFN1IdwvQ==
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=aucOB2zf;
	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 D4E6E606A691;
	Tue, 24 Nov 2026 21:38:48 +0000 (UTC)
X-Received: by smtp.kernel.org (Postfix) with ESMTPSA id C97231F0089E;
	Tue, 24 Nov 2026 21:38:47 +0000 (UTC)
X-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel.org;
	s=k20260515; t=1795556328;
	bh=UDznTv7tvXw7e6fmTZhMJ4Cm4gT1kF7rLrwjGIShnwY=;
	h=Subject:From:To:Cc:Date:In-Reply-To:References;
	b=aucOB2zfnLBk8rLtyw/N5Epc20E2KqRxx+ZKX47RHV/9XWcFgAWwS8sD7BtrLr/8F
	 HAZKdXCwENrM4q0q4cw2tDPw6nf/2MTzYo1eWPsJnKvMUMRIKrJ3x2wsrqzdppNHs7
	 IqRWTY1IfX8UGVl2KSpmGYRRUoUmlznIuKexnSWhH967yb15jFrP+Q48UWL55kTIkC
	 Q60imLaVhJdxKonCtFb1iPw3gFJ5Psw63EuSG9LTSAhP1n8D2pnQzgVbTbMUP48Mfq
	 Ov3mj+Ja1ER1DBPvDe7zvqGj72+sKcQJx7Ksk1Z2EnEFp42LYPKhWkDC2RRISSX4oe
	 eH+kKc9jkDzTw==
X-Cc: intel-wired-lan@lists.osuosl.org, anthony.l.nguyen@intel.com,
 przemyslaw.kitszel@intel.com, andrew+netdev@lunn.ch, davem@davemloft.net,
 edumazet@kernel.org, kuba@kernel.org, pabeni@redhat.com,
 janislacis06@gmail.com, netdev@vger.kernel.org, linux-kernel@vger.kernel.org,
 stable@vger.kernel.org
X-In-Reply-To: <20261120210134.133238-5-antonio@mandelbit.com>
X-sashiko-severity: Medium
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