🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: linux.kernel.netdev
Article #26080

Re: [PATCH net v7 6/7] igb: resume the device before changing XDP or XSK settings

#26080
From: netdev-bot+sashiko
Date: Thu, 03 Dec 2026 01:04
261 lines
18246 bytes
Thank you for your contribution! Sashiko AI review found 5 potential
issue(s) to consider.

Critical: 0 · High: 3 · 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).

- [High] The new guards in igb_xsk_pool_enable() and
  igb_xsk_pool_disable() (drivers/net/ethernet/intel/igb/igb_xsk.c) use…
- [High] igb_xdp_setup() makes its close/open decision from one read of
  netif_device_present() under RTNL.
- [High] The new "only update the software state" path for a detached
  device in igb_xdp_setup() can lead to an out-of-bounds write in…
- [Medium] igb_xdp() now calls pm_runtime_get_sync() first.
- [Low] The new comment in igb_xdp() says that if resuming fails,
  igb_xdp_setup() and igb_xsk_pool_setup() "find the device down".

--

igb: resume the device before changing XDP or XSK settings

This patch holds a runtime PM reference for the whole of igb_xdp(). That
stops __igb_resume() from rebuilding the rings while XDP or XSK setup is
running. It also skips or refuses XSK ring changes when the rings have no
descriptors after a failed resume, makes igb_xdp_setup() update only the
software state on a detached device, and checks the Rx buffer size only
when a program is added or replaced.

> diff --git a/drivers/net/ethernet/intel/igb/igb_main.c b/drivers/net/ethernet/intel/igb/igb_main.c
> index 11c136d7bea75..a6fa33cb4521a 100644
> --- a/drivers/net/ethernet/intel/igb/igb_main.c
> +++ b/drivers/net/ethernet/intel/igb/igb_main.c
> @@ -2896,8 +2896,17 @@ static int igb_xdp_setup(struct net_device *dev, struct netdev_bpf *bpf)
>  	bool running = netif_running(dev);
>  	bool need_reset;
>  
> -	/* verify igb ring attributes are sufficient for XDP */
> -	for (i = 0; i < adapter->num_rx_queues; i++) {
> +	/* igb_close() doesn't close a detached device (after a failed resume,
> +	 * or during PCI error recovery): only update the software state
> +	 */
> +	if (!netif_device_present(dev))
> +		running = false;

[Severity: High]
Can this netif_device_present() check race with PCI error recovery? The
PCI error handlers change the present bit outside RTNL:

igb_io_error_detected() {
	netif_device_detach(netdev);
	...
	rtnl_lock();
	if (netif_running(netdev))
		igb_down(adapter);
	rtnl_unlock();
	...
}

igb_io_resume() {
	rtnl_lock();
	...
		if (igb_up(adapter)) {
	...
	rtnl_unlock();

	netif_device_attach(netdev);
	...
}

igb_close() also reads the bit again on its own:

int igb_close(struct net_device *netdev)
{
	if (netif_device_present(netdev) || netdev->dismantle)
		return __igb_close(netdev, false);
	return 0;
}

Suppose igb_xdp_setup() sees the device as present with need_reset true,
and igb_io_error_detected() then detaches it. igb_close() returns 0
without closing, and igb_xdp_setup() still calls igb_open() on an
interface that is already open. Isn't that the double open the commit
message says is fixed?

The reverse case can happen too. An ndo_bpf caller waiting on RTNL while
igb_io_resume() runs igb_up() can get the lock before
netif_device_attach() runs. It then sees !present, sets running to false
and only xchg()s ring->xdp_prog.

If a program is removed this way while a zero-copy pool is bound, the
ring stays in ZC mode and ring->xdp_prog becomes NULL:

igb_clean_rx_irq_zc() {
	...
	/* xdp_prog cannot be NULL in the ZC path */
	xdp_prog = READ_ONCE(rx_ring->xdp_prog);
	...
}

Would igb_run_xdp_zc() then call bpf_prog_run_xdp() with a NULL prog
from NAPI?

[Severity: High]
Can this software-only path leave the Rx rings with the wrong
rx_buffer_info layout?

With an XDP program attached and a zero-copy pool bound,
igb_xsk_pool_enable()->igb_realloc_rx_buffer_info(rx_ring, true) sizes
the array for ZC:

	int size = pool_present ?
		sizeof(*ring->rx_buffer_info_zc) * ring->count :
		sizeof(*ring->rx_buffer_info) * ring->count;

Then a PCI error hits. igb_io_error_detected() detaches the device and
calls igb_down(), which keeps the ring resources. If the XDP program is
removed before igb_io_resume(), this path only clears adapter->xdp_prog
and ring->xdp_prog. Nothing calls igb_realloc_rx_buffer_info(ring, false).

Later, igb_io_resume()->igb_up()->igb_configure()->igb_configure_rx()->
igb_configure_rx_ring() finds no pool, because igb_xsk_pool() returns
NULL once XDP is disabled:

	else
		memset(ring->rx_buffer_info, 0,
		       sizeof(*ring->rx_buffer_info) * ring->count);

Don't this memset() and the igb_alloc_rx_buffers() call that follows
write struct igb_rx_buffer entries past the end of the 8-byte-per-entry
ZC allocation?

Before this patch, this case went through igb_open()->
igb_setup_rx_resources(), which allocated a full-size igb_rx_buffer
array.

> +
> +	/* verify igb ring attributes are sufficient for XDP, only when adding
> +	 * or replacing a program: rings allocated by a resume don't know their
> +	 * buffer size until they are configured
> +	 */
> +	for (i = 0; prog && i < adapter->num_rx_queues; i++) {
>  		struct igb_ring *ring = adapter->rx_ring[i];
>  
>  		if (frame_size > igb_rx_bufsz(ring)) {

[Severity: Medium]
igb_xdp() now calls pm_runtime_get_sync() first. With that, can this
check refuse a valid attach on a down interface?

On a down, runtime suspended interface, __igb_resume()->
igb_init_interrupt_scheme() allocates fresh rings. netif_running() is
false, so igb_set_rx_buffer_len() never runs for them. Neither
IGB_RING_FLAG_RX_3K_BUFFER nor IGB_RING_FLAG_RX_BUILD_SKB_ENABLED gets
set, and igb_rx_bufsz() returns IGB_RXBUFFER_2048.

At open, igb_set_rx_buffer_len() would have chosen 3K buffers:

	if (adapter->max_frame_size > IGB_MAX_FRAME_BUILD_SKB ||
	    IGB_2K_TOO_SMALL_WITH_PADDING ||
	    rd32(E1000_RCTL) & E1000_RCTL_SBP)
		set_ring_uses_large_buffer(rx_ring);

So with PAGE_SIZE < 8192 and an MTU between 2023 and 3046, adding a
program now fails with "The RX buffer size is too small for the frame
size". Before this patch, runtime suspend had freed the rings and
num_rx_queues was 0 at this point, so the attach succeeded.

The new comment says rings allocated by a resume don't know their buffer
size, yet the check is skipped only for removal. Should it also be
skipped for rings that haven't been configured yet?

> @@ -2943,16 +2952,29 @@ static int igb_xdp_setup(struct net_device *dev, struct netdev_bpf *bpf)
>  static int igb_xdp(struct net_device *dev, struct netdev_bpf *xdp)
>  {
>  	struct igb_adapter *adapter = netdev_priv(dev);
> +	int err;
> +
> +	/* The rings only exist while the device is resumed, and resuming
> +	 * rebuilds them without RTNL. If resuming fails, igb_xdp_setup() and
> +	 * igb_xsk_pool_setup() find the device down.
> +	 */
> +	pm_runtime_get_sync(&adapter->pdev->dev);

[Severity: Low]
Is "find the device down" accurate here? When __igb_open() fails inside
__igb_resume(), nothing clears __LINK_STATE_START, so netif_running() is
still true. The device is only not attached, and its rings have no
resources.

The new checks depend on exactly that state: netif_running() &&
!rx_ring[qid]->desc in igb_xsk_pool_enable(), and netif_device_present()
in igb_xdp_setup().

Could the comment say that the device is detached but still running?

[ ... ]

> diff --git a/drivers/net/ethernet/intel/igb/igb_xsk.c b/drivers/net/ethernet/intel/igb/igb_xsk.c
> index b6234e349ef20..e70f8184debe6 100644
> --- a/drivers/net/ethernet/intel/igb/igb_xsk.c
> +++ b/drivers/net/ethernet/intel/igb/igb_xsk.c
> @@ -120,6 +120,10 @@ static int igb_xsk_pool_enable(struct igb_adapter *adapter,
>  	    qid >= netdev->real_num_tx_queues)
>  		return -EINVAL;
>  
> +	/* After a failed resume the rings have no resources */
> +	if (netif_running(netdev) && !adapter->rx_ring[qid]->desc)
> +		return -ENODEV;
> +
>  	err = xsk_pool_dma_map(pool, &adapter->pdev->dev, IGB_RX_DMA_ATTR);
>  	if (err)
>  		return err;
> @@ -160,11 +164,11 @@ static int igb_xsk_pool_disable(struct igb_adapter *adapter, u16 qid)
>  	rx_ring = adapter->rx_ring[qid];
>  	/* The stack can know more queues than the device has, e.g. while
>  	 * runtime suspended, which frees the rings: skip the rings it
> -	 * doesn't have.
> +	 * doesn't have, or that have no resources after a failed resume.
>  	 */
>  	if_running = netif_running(adapter->netdev) &&
>  		     igb_xdp_is_enabled(adapter) &&
> -		     qid < adapter->num_rx_queues;
> +		     qid < adapter->num_rx_queues && rx_ring->desc;
>  	if (if_running)
>  		igb_txrx_ring_disable(adapter, qid);

[Severity: High]
Does the rx_ring->desc check cover PCI error recovery?
igb_io_error_detected() detaches the device and calls igb_down(), which
disables every NAPI:

	for (i = 0; i < adapter->num_q_vectors; i++) {
		if (adapter->q_vector[i]) {
			napi_disable(&adapter->q_vector[i]->napi);

igb_down() doesn't free the descriptor rings, though, and netif_running()
stays true.

Now suppose a zero-copy AF_XDP socket is closed, or a new one is bound,
while an XDP program is attached. if_running is true here in
igb_xsk_pool_disable(), and the new !desc test in igb_xsk_pool_enable()
passes as well. Both paths then reach igb_txrx_ring_disable():

	/* Rx/Tx share the same napi context. */
	napi_disable(&rx_ring->q_vector->napi);

Won't this second napi_disable() spin forever in napi_disable_locked()
with RTNL held? igb_io_resume() also takes rtnl_lock(), so recovery would
hang as well.

igb_xdp_setup() handles the detached case with netif_device_present().
Would netif_device_present() or test_bit(__IGB_DOWN, &adapter->state) be
a better gate here than rx_ring->desc?

-- 
Sashiko AI review · https://netdev-ai.bots.linux.dev/sashiko/#/patchset/20261202002317.3140591-1-antonio%40mandelbit.com
Technical Details
Message-ID: <179625985576.3146.4302216571406577976@kernel.org>
Path: mbox-mo1.pugleaf.net!news-wdc.pugleaf.net!usenet.blueworldhosting.com!diablo1.usenet.blueworldhosting.com!usenet.network!.POSTED!vger.kernel.org!netdev+bounces-376189-linux-kernel-netdev=dewy.ru
References: <20261202002317.3140591-7-antonio@mandelbit.com>

Show Full Headers
Complete Article Headers
Path: mbox-mo1.pugleaf.net!news-wdc.pugleaf.net!usenet.blueworldhosting.com!diablo1.usenet.blueworldhosting.com!usenet.network!.POSTED!vger.kernel.org!netdev+bounces-376189-linux-kernel-netdev=dewy.ru
From: netdev-bot+sashiko@kernel.org
Newsgroups: linux.kernel.netdev
Subject: Re: [PATCH net v7 6/7] igb: resume the device before changing XDP or
 XSK settings
Date: Thu, 03 Dec 2026 01:04:15 +0000
Organization: Usenet Network
Message-ID: <179625985576.3146.4302216571406577976@kernel.org>
References: <20261202002317.3140591-7-antonio@mandelbit.com>
MIME-Version: 1.0
Content-Type: text/plain; charset="utf-8"
Content-Transfer-Encoding: 8bit
Injection-Info: usenet.network;
	logging-data="2101746"; mail-complaints-to="abuse@usenet.network"
Cancel-Lock: sha1:12Mryuq5vkZKnFe9JCT/+hGgcpU= sha256:AdgZjSEUW0bgibwIm/CtO4SH+xScjSoKD+Z3TwvL8NY=
	sha1:mmrXEuVH9JvefpB64OgMLugaR4c= sha256:hdGc050QBwXG4dlQqBLpu2UwvSh651jtQdcaWYTzxjw=
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 91E511177D0; Thu,  3 Dec 2026 04:04:52 +0300 (MSK)
X-Virus-Scanned: Debian amavisd-new at usenet.network
X-Spam-Flag: NO
X-Spam-Score: -3.401
X-Spam-Status: No, score=-3.401 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] 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 xUT03bOOhnRc;
	Thu,  3 Dec 2026 04:04:49 +0300 (MSK)
X-Received-SPF: Pass (mailfrom) identity=mailfrom; client-ip=172.234.253.10; helo=sea.lore.kernel.org; envelope-from=netdev+bounces-376189-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 885501177CB; Thu,  3 Dec 2026 04:04:40 +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 D8AE02B28F; Thu,  3 Dec 2026 01:04:21 +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=1796259859;
	b=1leNxyQ7F3eFnAkABc+TZOBUj+HoO0JpmU62ExJa68o1ZOvTou/yiIG9U3UDxxIZ4TP7
	 bs21ICSPDX0tGM640ISv9U4mASFonjkSaE8BofawrTbqXAHFAegGoQ1cSebWqD6LYsTxP
	 7IN8oCs1q6ro8SvhhVp50Lkjovi1KC49Wpjit1UBGDoxazyvSzlR8HPjGhwrLk23vqLfV
	 0hIAgxXxZX37a5eFbDSChIuE9r3e/TxUDMurjpP7JeRyx/Omz0ao1OSFZBrpqeBZ8Hs+1
	 rhRcH2pRSmp1emmUFu47rQqrILgYj7sBeNVqjrhAoIADWFIdTn+HPI/qFFjVwjv/nJw==
X-ARC-Message-Signature: i=2; d=subspace.kernel.org; s=arc20261015;
	a=rsa-sha256; c=relaxed/relaxed; t=1796259859;
	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=CR6P+5+WfHz0ocD1aUAs0jDEc9anQ5HL09pMcgQ00/s=;
	b=3YQkyse1KBjW61DtZQe4YWurTdTaipMO4oPxYZGs2JdC1zVF+vIj6qs8vc+wvww2Bdkj
	 aIv+YQ6xxo1fD+jhICx05cv9rg2Fx2glj1wWqZ70c5mEOK7sMFCNyRbwfHOqdEvMkz5Di
	 YUDiHUs13kKdugXKKwfJtFLLR1A13v3lDz0TAdAU67yCMYueB6+1Zs+AjmURJACLQ7woT
	 pv3y/jXfe4tRyIaC/1WIXoutFYLIWS4tda0auQjY8FYPDTXyd/0j13MsFTHutbyNTIox5
	 KpGFGeBJh3YkFD2JifLD+rgCa0MbdsyI3JsF+gH8sQ/A4Xp813WvKu57VTtmH/CR4sg==
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=crXMAsNP;
	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 2D28A606A68F;
	Thu,  3 Dec 2026 01:04:19 +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=crXMAsNP
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=1796259858;
	b=dQck88yZJPTDvP6K9Rr3tcmjXE+ThvjjPINU0oC8XPO4FB78lfS7WPf/+iHF+1yQ54um
	 RXS51K9wg5Q4XR784ouQlYtatcWFYR3HlcSGsgj+kOZRYDthgMUCZUf7FvA79nN2ejR8X
	 MIynGZMs7v/s9mAMkfGT0EL5Ko8r4TjQJFWWeH6hog0zMAthvwS2B9ypUGk6EwTz3TJem
	 V5zC5H2UCXc7KkdU198MXZ+fcLIYQw6OWWtJSm0HQENdBKLWB+Sv5rBwDZNAgpxSJNoiS
	 FCgcaodyYPa216RWM8E/+3v6QZvOxQol7pNP0TgYZiLxgjHWUWDrP9JgJRCS5ixogeQ==
X-ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015;
	a=rsa-sha256; c=relaxed/relaxed; t=1796259858;
	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=CR6P+5+WfHz0ocD1aUAs0jDEc9anQ5HL09pMcgQ00/s=;
	b=ZqCQDqBPu5W/4ZJ6Neievp2VJkXZ+0jmQHLCEeSG2HvfzoLB5L++bS7il699UfDW/ltc
	 q/4q5Ov/rlMYK77k3iIbRmI33G3bRvFgkP/z6kOn4CLCSFdaYkfcVGkD1l2DvvMHPQzZj
	 eTrf6mFAW3B89IdZlUveWSsdmNJZOtYndLpQeDbsqE00JfL4CugrMVWPK30dAnQ3jCJuQ
	 I0JDb+5n2Req+1I0/MimTmWoqfwkc5qIjKtPXfXsuqdpeBsMUdtTLC/ABMZwILKtnePv9
	 9e7Im0cTGr1x+3GQt2KtFsALzrg+LI5Elje/7gcM6sQ0GWZX0zM16WXMFnsRkU0kn3A==
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=crXMAsNP;
	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 4C7AA606A688;
	Thu,  3 Dec 2026 01:04:18 +0000 (UTC)
X-Received: by smtp.kernel.org (Postfix) with ESMTPSA id 41D0A1F000C1;
	Thu,  3 Dec 2026 01:04:16 +0000 (UTC)
X-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel.org;
	s=k20260515; t=1796259857;
	bh=CR6P+5+WfHz0ocD1aUAs0jDEc9anQ5HL09pMcgQ00/s=;
	h=Subject:From:To:Cc:Date:In-Reply-To:References;
	b=crXMAsNPVVOINZV6RE7JNZ2yoanJrpfE+2+E4aiunPwTJ2SNFrUemYTY6Q316w6Md
	 1jnF3dqiWvAHpbasANgk12FWEnY+LdnBeSH9XgEbYAwlFilf+lstaAWgRYJVfBeVA5
	 89aMbWvgLV3fvhpY2P1x/PUzIEa+cogBoLr3dLa2qhiZy+nN+jFxZ2h39DaF3ouBBQ
	 g4ExZLNNaDkF4EU5xaIzccragTtQpiRIwA/TTPIFeKYNIrCT/BMtCrMkLI4U2RnEz0
	 fSUhHAzusyDk+Cdv9VbzRSLD/3b1QJ8FeRrbux2PG3Hb0cd59+UZO9umnugVbnp2KY
	 DDyyX33GtvfMg==
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, ast@kernel.org, daniel@iogearbox.net, hawk@kernel.org,
 john.fastabend@gmail.com, sdf@fomichev.me, sriram.yagnaraman@ericsson.com,
 kurt@linutronix.de, maciej.fijalkowski@intel.com, hkallweit1@gmail.com,
 joe@dama.to, rafael@kernel.org, sven.auhagen@voleatech.de,
 netdev@vger.kernel.org, linux-pm@vger.kernel.org,
 linux-kernel@vger.kernel.org, bpf@vger.kernel.org, stable@vger.kernel.org
X-In-Reply-To: <20261202002317.3140591-7-antonio@mandelbit.com>
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