Linux Power Management development
 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 v6 6/7] igb: resume the device before changing XDP or XSK settings
Date: Tue, 01 Dec 2026 22:20:41 +0000	[thread overview]
Message-ID: <179616364113.3146.14418828915964343531@kernel.org> (raw)
In-Reply-To: <20261130213740.3323814-7-antonio@mandelbit.com>

Thank you for your contribution! Sashiko AI review found 4 potential
issue(s) to consider.

Critical: 0 · High: 1 (2) · Medium: 3 · 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 uses `desc != NULL` (plus `!netif_device_present()` in
  igb_xdp_setup) to decide that the queues are live and the NAPIs…
- [Medium] The commit message names the root cause as '__igb_resume()
  rebuilds the queue counts and the rings without RTNL', but the fix…
- [Medium] The patch deliberately ignores the return value of
  pm_runtime_get_sync() in igb_xdp().
- [Medium] igb: broken failed-resume and 3K-buffer checks in
  igb_xdp_setup()

Pre-existing issues:
- [High] This bug predates the patch, but the patch fixes the same bug
  class for igb_xdp() only.
- [High] This bug predates the patch, but the new guard does not cover
  it.

--

igb: resume the device before changing XDP or XSK settings

This commit holds a runtime PM reference for the duration of igb_xdp(),
so the rings exist while XDP and XSK settings are changed. It also adds
checks to igb_xdp_setup(), igb_xsk_pool_enable() and
igb_xsk_pool_disable(). These checks leave alone rings that have no
resources after a failed resume.

> diff --git a/drivers/net/ethernet/intel/igb/igb_main.c b/drivers/net/ethernet/intel/igb/igb_main.c
> index 11c136d7bea75..79652ccbfdf00 100644
> --- a/drivers/net/ethernet/intel/igb/igb_main.c
> +++ b/drivers/net/ethernet/intel/igb/igb_main.c
> @@ -2909,6 +2909,16 @@ static int igb_xdp_setup(struct net_device *dev, struct netdev_bpf *bpf)
>  		}
>  	}
>  
> +	/* After a failed resume the device is detached and its rings have no
> +	 * resources: only update the software state, and don't add a program
> +	 */
> +	if (running && !netif_device_present(dev) &&
> +	    (!adapter->num_rx_queues || !adapter->rx_ring[0]->desc)) {
> +		if (prog && !adapter->xdp_prog)
> +			return -ENODEV;
> +		running = false;
> +	}

[Severity: Medium]
Is this check in the right place, and is running the right condition
to gate it on?

It only runs when netif_running(dev) is true. __igb_shutdown() calls
igb_clear_interrupt_scheme() even when the interface is down, so if the
interface is down when __igb_resume() fails, adapter->num_rx_queues is
still 0. The frame size loop above then runs zero times and this check
is skipped. A new program therefore gets attached to a detached device
without any MTU validation.

The opposite case is also possible. IGB_RING_FLAG_RX_3K_BUFFER is only
set by igb_set_rx_buffer_len() from igb_configure_rx(). It is not set
when igb_init_interrupt_scheme() allocates the rings. __igb_resume()
reallocates the rings, but it doesn't reach igb_configure() when the
interface is down. It also doesn't get there when __igb_open() fails in
igb_setup_all_tx_resources() or igb_setup_all_rx_resources(). On
PAGE_SIZE < 8192, igb_rx_bufsz() then returns 2048 instead of 3072.

With a program attached and an MTU that needs 3K buffers, the frame
size loop then returns -EINVAL before this check is reached, even when
prog is NULL. Removing or replacing the program fails.
dev_xdp_uninstall() ignores that error at unregister time, so the
reference held in adapter->xdp_prog is never dropped. Isn't that the
leak this check is meant to avoid?

The down case can now be hit after a successful resume too. igb_xdp()
resumes the device, so the loop no longer sees num_rx_queues == 0.

igb_xsk_pool_enable() has a similar gap. Its new check only refuses
when netif_running(netdev) is true. If the interface is closed after
__igb_open() failed during resume, a pool can still be enabled on a
detached device whose rings have no resources.

Would it work to do the failed-resume check before the frame size
loop, base it on netif_device_present() rather than running, and only
validate the ring buffer sizes when a program is being added? Or should
the loop compute the buffer size the way igb_set_rx_buffer_len() does,
instead of reading ring flags that only igb_configure_rx() sets?

[Severity: High]

Does this guard cover a device that PCI error recovery has detached?
igb_io_error_detected() detaches the device and calls igb_down(), but it
leaves the rings and IRQs allocated:

igb_io_error_detected() {
	...
	netif_device_detach(netdev);

	if (state == pci_channel_io_perm_failure)
		return PCI_ERS_RESULT_DISCONNECT;

	rtnl_lock();
	if (netif_running(netdev))
		igb_down(adapter);
	rtnl_unlock();

	pci_disable_device(pdev);
	...
}

In that state the device is RPM_ACTIVE, so pm_runtime_get_sync() returns
immediately. rx_ring[0]->desc is non-NULL, so running stays true. When a
program is added or removed, igb_close() does nothing because the device
isn't present:

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

igb_open() then runs __igb_open() a second time on live rings. Isn't this
the same double open the commit message describes?

The second open overwrites and leaks the descriptor DMA memory and
buffer_info. With MSI-X, igb_request_msix() fails because the vectors are
still requested. The fallback in igb_request_irq() then calls
igb_clear_interrupt_scheme(). That frees q_vectors that the registered
ring IRQ handlers still use as dev_id.

The error path leaves tx_buffer_info and desc NULL and ring->dma stale,
and igb_xdp_setup() still returns 0. Later,
igb_io_resume()->igb_up()->igb_configure_tx_ring() writes the stale dma
into TDBAL/TDBAH and calls memset() on the NULL tx_buffer_info with RTNL
held.

The new XSK checks have the same gap. In igb_xsk_pool_disable(), and in
igb_xsk_pool_enable() when XDP is enabled, the desc test passes:

	if_running = netif_running(adapter->netdev) &&
		     igb_xdp_is_enabled(adapter) &&
		     qid < adapter->num_rx_queues && rx_ring->desc;

igb_txrx_ring_disable() then calls napi_disable() on a NAPI that
igb_down() already disabled. Wouldn't that wait forever with RTNL held?

igb_down() sets __IGB_DOWN on both the failed-resume path and the AER
path. Would testing __IGB_DOWN cover this case? Always skipping the
close/open pair on a detached device might also work.

[Severity: High]

This is a pre-existing issue, but this guard also requires
!netif_device_present(). Because of that, it doesn't catch the state left
when the igb_open() call at the end of igb_xdp_setup() fails:

	if (running)
		igb_open(dev);

	return 0;

__igb_open() can fail in igb_setup_all_tx_resources(),
igb_setup_all_rx_resources() or igb_request_irq(). Its error path frees
the rings, so desc becomes NULL, and it returns before napi_enable(). The
interface stays IFF_UP and present, and the NAPIs stay disabled from the
earlier igb_down().

On the next program add or remove, running and need_reset are both true,
and igb_close()->__igb_close()->igb_down() calls napi_disable() on the
already disabled NAPIs. Can napi_disable_locked() then loop forever on
NAPIF_STATE_SCHED with RTNL held? "ip link set down" looks like it would
hang the same way.

The new XSK checks treat netif_running() && !desc as "no resources" no
matter whether the device is present. Should igb_xdp_setup() match them?
Should the igb_open() error also be returned to the caller?

> +
>  	old_prog = xchg(&adapter->xdp_prog, prog);
>  	need_reset = (!!prog != !!old_prog);

[ ... ]

> @@ -2943,16 +2953,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: Medium]

The commit message gives the cause as "__igb_resume() rebuilds the queue
counts and the rings without RTNL". Does pm_runtime_get_sync() also
serialise against system resume?

On system resume, igb_resume()->__igb_resume(dev, false) still rebuilds
the rings before it takes RTNL:

	if (igb_init_interrupt_scheme(adapter, true)) {
	...
	if (!rpm)
		rtnl_lock();

igb_set_interrupt_capability() sets adapter->num_rx_queues before
igb_alloc_q_vectors() fills adapter->rx_ring[]. The device is RPM_ACTIVE
at that point, so pm_runtime_get_sync() returns 1 immediately.

Kernel contexts that aren't frozen can still call ndo_bpf under RTNL in
that window. One example is xp_release_deferred() on system_wq, which
does rtnl_lock() and then xp_clear_dev().

Could such a caller see num_rx_queues > 0 while rx_ring[qid] is still
NULL? It would then dereference NULL through rx_ring->desc in
igb_xsk_pool_disable(), or through igb_rx_bufsz(ring) and
adapter->rx_ring[0]->desc in igb_xdp_setup().

[Severity: Medium]

The return value of pm_runtime_get_sync() is ignored because, after a
failed resume, the callees "find the device down". Does that state stay
the same for the rest of igb_xdp()?

__igb_resume() can fail with -EBUSY or -EAGAIN, for example from the
shared legacy request_irq() fallback in igb_request_irq(). rpm_callback()
treats those errors as transient, and the device goes back to
RPM_SUSPENDED.

The usage count held by igb_xdp() doesn't stop another rpm_resume() from
a context that doesn't take RTNL, such as writing "on" to power/control or
igb_rpm_retry_task().

That resume runs igb_runtime_resume()->__igb_resume(dev, true) without
RTNL. It re-runs igb_init_interrupt_scheme(), allocates desc and enables
NAPI. Meanwhile igb_xdp_setup() or igb_xsk_pool_*() read num_rx_queues,
rx_ring[] and desc without a lock.

Could the "no resources, don't touch NAPI" decision go stale here? Ring
memory could also be reinitialised under the reader, or program updates
could land on rings that are being replaced.

[Severity: High]

This isn't a bug introduced by this patch, but igb_xdp() is the only ndo
that this patch resumes. Do igb_change_mtu() and
igb_set_features()->igb_reinit_locked()/igb_reset() have the same problem
on a runtime suspended device?

While the device is runtime suspended, igb_free_q_vectors() has set
num_rx_queues, num_tx_queues and num_q_vectors to 0 and cleared
adapter->q_vector[]. netif_running() is still true. In igb_change_mtu():

	if (igb_xdp_is_enabled(adapter)) {
		int i;

		for (i = 0; i < adapter->num_rx_queues; i++) {
	...
	if (netif_running(netdev))
		igb_down(adapter);
	...
	if (netif_running(netdev))
		igb_up(adapter);

The XDP frame size loop runs zero times, so igb_change_mtu() accepts an
MTU that igb_xdp_setup() would reject.

Without MSI-X, igb_up() calls igb_assign_vector(adapter->q_vector[0], 0)
with a NULL q_vector. Is that a NULL dereference with RTNL held?

With MSI-X, igb_up() clears __IGB_DOWN while num_tx_queues is 0.
igb_xdp_xmit() only checks __IGB_DOWN before it calls
igb_xdp_tx_queue_mapping():

	if (r_idx >= adapter->num_tx_queues)
		r_idx = r_idx % adapter->num_tx_queues;

Can an XDP_REDIRECT into igb then divide by zero?

igb_down() also reads the registers of a device in D3. If those reads
return all-ones, igb_rd32() sets hw->hw_addr to NULL and warns.
__igb_resume() never restores hw_addr, so the NIC looks like it stays
unusable until the driver is reloaded.

-- 
Sashiko AI review · https://netdev-ai.bots.linux.dev/sashiko/#/patchset/20261130213740.3323814-1-antonio%40mandelbit.com

  reply	other threads:[~2026-12-01 22:20 UTC|newest]

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

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=179616364113.3146.14418828915964343531@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