Intel-Wired-Lan Archive on lore.kernel.org
 help / color / mirror / Atom feed
From: netdev-bot+sashiko@kernel.org
To: antonio@mandelbit.com
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
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	[thread overview]
Message-ID: <179625985576.3146.4302216571406577976@kernel.org> (raw)
In-Reply-To: <20261202002317.3140591-7-antonio@mandelbit.com>

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

  parent reply	other threads:[~2026-12-03  1:04 UTC|newest]

Thread overview: 14+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-12-02  0:23 [PATCH net v7 0/7] igb: fix runtime PM resume issues Antonio Quartulli
2026-12-02  0:23 ` [PATCH net v7 1/7] igb: don't wait for RTNL when runtime suspending Antonio Quartulli
2026-12-03  1:04   ` netdev-bot+sashiko
2026-12-02  0:23 ` [PATCH net v7 2/7] igb: don't touch rings that don't exist when disabling an XSK pool Antonio Quartulli
2026-12-03  1:04   ` netdev-bot+sashiko
2026-12-02  0:23 ` [PATCH net v7 3/7] igb: fix RTNL assertion when resuming from runtime suspend Antonio Quartulli
2026-12-03  1:04   ` netdev-bot+sashiko
2026-12-02  0:23 ` [PATCH net v7 4/7] igb: keep the stack's Rx queues that still have an XSK pool Antonio Quartulli
2026-12-03  1:04   ` netdev-bot+sashiko
2026-12-02  0:23 ` [PATCH net v7 5/7] igb: link queues to NAPIs under RTNL after runtime resume Antonio Quartulli
2026-12-02  0:23 ` [PATCH net v7 6/7] igb: resume the device before changing XDP or XSK settings Antonio Quartulli
2026-12-03  0:23   ` sashiko-bot
2026-12-03  1:04   ` netdev-bot+sashiko [this message]
2026-12-02  0:23 ` [PATCH net v7 7/7] igb: only allow runtime PM if the device can wake up Antonio Quartulli

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=179625985576.3146.4302216571406577976@kernel.org \
    --to=netdev-bot+sashiko@kernel.org \
    --cc=andrew+netdev@lunn.ch \
    --cc=anthony.l.nguyen@intel.com \
    --cc=antonio@mandelbit.com \
    --cc=ast@kernel.org \
    --cc=bpf@vger.kernel.org \
    --cc=daniel@iogearbox.net \
    --cc=davem@davemloft.net \
    --cc=edumazet@kernel.org \
    --cc=hawk@kernel.org \
    --cc=hkallweit1@gmail.com \
    --cc=intel-wired-lan@lists.osuosl.org \
    --cc=janislacis06@gmail.com \
    --cc=joe@dama.to \
    --cc=john.fastabend@gmail.com \
    --cc=kuba@kernel.org \
    --cc=kurt@linutronix.de \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-pm@vger.kernel.org \
    --cc=maciej.fijalkowski@intel.com \
    --cc=netdev@vger.kernel.org \
    --cc=pabeni@redhat.com \
    --cc=przemyslaw.kitszel@intel.com \
    --cc=rafael@kernel.org \
    --cc=sdf@fomichev.me \
    --cc=sriram.yagnaraman@ericsson.com \
    --cc=stable@vger.kernel.org \
    --cc=sven.auhagen@voleatech.de \
    /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