Re: [PATCH iwl-net v2] ice: release IRQs and rings in ice_dis_vsi() when the VSI is already down

From: Przemek Kitszel

Date: Wed Nov 25 2026 - 05:51:47 EST


On 11/24/26 9:35 AM, Ionut Nechita (Wind River) wrote:
From: Ionut Nechita <ionut.nechita@xxxxxxxxxxxxx>

Since commit d8c40b9d3a6c ("ice: check ICE_VSI_DOWN under rtnl_lock when
preparing for reset"), ice_dis_vsi() sets ICE_VSI_NEEDS_RESTART
unconditionally, but still skips ice_vsi_close() when ICE_VSI_DOWN is
already set. For a running netdev, ice_ena_vsi() then calls
ice_open_internal() -> ice_vsi_open(), which does a full open: it sets
up the rings and requests the IRQs again.

A running netdev with ICE_VSI_DOWN set is not always a closed VSI.
ice_down() only cleans the rings. It keeps the ring memory and the IRQs
so that ice_up() can restart the VSI quickly. If the restart fails, the
VSI stays in that state while the netdev is still running, for example:

- ice_down_up(), when ice_down() or ice_up() fails (the latter also
via ice_change_mtu());
- ice_xdp_setup_prog(), when ice_down() fails.

If ice_dis_vsi()/ice_ena_vsi() are called on such a VSI without an
ice_vsi_rebuild() in between, which is the case for the DCB
reconfiguration in ice_pf_dcb_cfg() and
ice_dcb_process_lldp_set_mib_change(), ice_vsi_open() runs on rings and
IRQs that were never released:

- ice_setup_tx_ring() hits WARN_ON(tx_ring->tx_buf) and overwrites
tx_buf and desc, leaking the previous arrays;
- ice_setup_rx_ring() overwrites desc, leaking the previous descriptor
memory;
- ice_vsi_req_irq_msix() requests the PF vectors again without
IRQF_SHARED and fails with -EBUSY, so the open fails and the
interface stays down until it is closed and opened again.

On the reset and mqprio paths, ice_vsi_rebuild() frees the ring
structures in between, so there is no WARN, but the ring memory still
held by them is not released until the device is unbound.

Call ice_vsi_close() unconditionally for a running netdev, under
rtnl_lock. ice_vsi_close() already handles a VSI that is down: it only
calls ice_down() if ICE_VSI_DOWN was not set, ice_vsi_free_irq() returns
early when the IRQs are not requested, and ice_vsi_free_{tx,rx}_rings()
only free rings that have a descriptor ring. This is also what
ice_stop() does for a VSI in this state. The race fixed by the commit
above does not come back: ICE_VSI_DOWN is still tested, by
ice_vsi_close(), under rtnl_lock.

The non-running and ICE_VSI_CTRL branches are left as they are. In both
cases ice_ena_vsi() either does not reopen the VSI or, for the control
VSI, the only paths that set ICE_VSI_DOWN also release its rings and
IRQs.

Fixes: d8c40b9d3a6c ("ice: check ICE_VSI_DOWN under rtnl_lock when preparing for reset")
Signed-off-by: Ionut Nechita <ionut.nechita@xxxxxxxxxxxxx>
---
v1 -> v2:
- Shorten the code comment to one line (Przemek)
- Drop the Assisted-by tag (Przemek, Jacob); an LLM (Claude) was
used to help with the code analysis and the changelog
v1: https://lore.kernel.org/all/20261106171657.583713-1-ionut.nechita@xxxxxxxxxxxxx/

thank you
I've run your patch through our local sashiko instance, and it reports
that your patch adds new problems on edge cases. The same issues were
reported both on your patch just on top of netdev/main and
tony/dev-queue+some more fixes (meaning those problems are not "already
resolved elsewhere"). For the first issue (DCB) both my and Petr Oros
patches were applied (not yet on netdev main (aka -net)).


Found while chasing the same WARN_ON() in ice_setup_{rx,tx}_ring() with
the out-of-tree ice driver on an E830 port without a module installed,
where ice_vsi_cfg_lan() fails and ice_dis_vsi()/ice_ena_vsi() then
reopen a VSI that ice_down() left with its rings allocated. The
in-tree paths above were found by code reading.

Based on net (f66469d9905b, "Merge tag 'net-7.4-rc2'").
Tested: build only (W=1, no new warnings).

drivers/net/ethernet/intel/ice/ice_lib.c | 5 ++---
1 file changed, 2 insertions(+), 3 deletions(-)

diff --git a/drivers/net/ethernet/intel/ice/ice_lib.c b/drivers/net/ethernet/intel/ice/ice_lib.c
index 7cd2dd066ef5e..92a086aa629d6 100644
--- a/drivers/net/ethernet/intel/ice/ice_lib.c
+++ b/drivers/net/ethernet/intel/ice/ice_lib.c
@@ -2852,9 +2852,8 @@ void ice_dis_vsi(struct ice_vsi *vsi, bool locked)
if (netif_running(vsi->netdev)) {
if (!locked)
rtnl_lock();
- already_down = test_bit(ICE_VSI_DOWN, vsi->state);
- if (!already_down)
- ice_vsi_close(vsi);
+ /* ice_ena_vsi() reopens the VSI, release it even if down */
+ ice_vsi_close(vsi);


[Severity: High]
[Finding: gpt-6-astra-7-20]
[Sources: gpt-6-astra, opus-5-5]
Can this free DMA memory that enabled hardware queues still own?

When ICE_VSI_DOWN is already set, ice_vsi_close() skips ice_down() but
still frees the rings:

if (!test_and_set_bit(ICE_VSI_DOWN, vsi->state))
ice_down(vsi);

ice_vsi_clear_napi_queues(vsi);
ice_vsi_free_irq(vsi);
ice_vsi_free_tx_rings(vsi);
ice_vsi_free_rx_rings(vsi);

So ice_vsi_dis_irq(), ice_vsi_stop_lan_tx_rings() and
ice_vsi_stop_all_rx_rings() never run.

A failed restart, which is the state this patch targets, can leave
queues enabled with ICE_VSI_DOWN set. In ice_up(), ice_vsi_cfg_lan() has
FW enable the Tx queues, and ice_vsi_cfg_rxqs() posts the Rx buffers.
Then ice_up_complete() does:

err = ice_vsi_start_all_rx_rings(vsi);
if (err)
return err;

ice_vsi_ctrl_all_rx_rings() requests enable on every Rx queue before it
waits on any of them. It returns on the first queue that times out, with
no rollback. Failures in ice_down() (a Tx disable AQ error, or
QENA_STAT not clearing) can also leave queues enabled while DOWN is set.

After ice_down_up() or ice_change_mtu() fails like this, a DCB change
can reach:

ice_dcb_process_lldp_set_mib_change() or ice_pf_dcb_cfg()
ice_dcb_ena_dis_vsi()
ice_dis_vsi()
ice_vsi_close()
ice_vsi_free_rx_rings()
ice_free_rx_ring()
ice_clean_rx_ring()
dmam_free_coherent(dev, size, rx_ring->desc, rx_ring->dma)

Could the NIC then DMA received packets into the freed pages, and write
back into the freed descriptor ring, until ice_ena_vsi() reprograms the
queues?

Before this patch the memory was leaked, but it stayed allocated and
mapped. The commit message cites ice_stop() as precedent, but ice_stop()
appears to have the same hazard.

[Severity: Medium]
[Finding: gpt-6-astra-3-9]
[Sources: gpt-6-astra, opus-5-5]
Can this now reach a NULL vsi->q_vectors?

ice_vsi_close() always calls ice_vsi_clear_napi_queues(), which has no
NULL check on q_vectors:

ice_for_each_q_vector(vsi, v_idx) {
struct ice_q_vector *q_vector = vsi->q_vectors[v_idx];

netif_napi_set_irq(&q_vector->napi, -1);
}

A failed ice_vsi_rebuild() can leave a running VSI with q_vectors ==
NULL and num_q_vectors > 0. ice_vsi_cfg_def()->ice_vsi_alloc_def()->
ice_vsi_set_num_qs() sets num_q_vectors.

A later failure in any of these unrolls through ice_vsi_free_arrays():

ice_vsi_alloc_arrays()
ice_vsi_alloc_stat_arrays()
ice_vsi_get_qs()
ice_vsi_init()
ice_vsi_alloc_q_vectors()

ice_vsi_free_arrays() sets q_vectors to NULL. Only
ice_vsi_free_q_vectors() resets num_q_vectors to 0.

ice_setup_tc_mqprio_qdisc() returns with the netdev still running when
both rebuild attempts fail:

if (ice_vsi_rebuild(vsi, ICE_VSI_FLAG_NO_INIT)) {
dev_err(dev, "Rebuild of main VSI failed again\n");
return ret;
}

A later DCB reconfiguration, for example from an LLDP MIB change, would
then go through ice_dis_vsi()->ice_vsi_close()->
ice_vsi_clear_napi_queues() and dereference NULL. Before this patch, the
already_down check skipped ice_vsi_close() in this state.

The stale num_q_vectors is older, and ice_stop() can already hit it, but
this patch adds a new path to it. The commit message says "ice_vsi_close()
already handles a VSI that is down". That holds for the IRQs and rings,
but does it hold for a partially deconfigured VSI?

[Severity: Medium]
[Finding: gpt-6-astra-5-14]
[Sources: gpt-6-astra, opus-5-5]
Does removing the already_down check widen races with code that brings
the VSI down without rtnl_lock?

The reset path is ice_prepare_for_reset()->ice_pf_dis_all_vsi(pf, false)
->ice_dis_vsi(). It holds rtnl_lock but not the devlink lock. Before this
patch it skipped a VSI that another context had already marked
ICE_VSI_DOWN. Now it always tears the VSI down.

ice_sf_dev_remove() closes a running SF VSI holding only the devlink
lock:

devl_lock(devlink);

ice_vsi_close(vsi);

With a concurrent reset, can both threads pass the plain check in
ice_vsi_free_irq() before either clears it?

if (!vsi->q_vectors || !vsi->irqs_ready)
return;

ice_vsi_release_msix(vsi);
if (vsi->type == ICE_VSI_VF)
return;

vsi->irqs_ready = false;

The ring->desc checks in ice_vsi_free_tx_rings() and
ice_vsi_free_rx_rings() have the same shape. That could double
devm_free_irq() and double free the descriptor DMA and buffer memory.

ice_eswitch_setup_env() runs under the PF devlink lock without rtnl:

if (if_running && !test_and_set_bit(ICE_VSI_DOWN, uplink_vsi->state))
if (ice_down(uplink_vsi))
return -ENODEV;
...
if (if_running && ice_up(uplink_vsi))

If a reset lands between ice_down() and ice_up(), ice_dis_vsi() now
frees the IRQs, ring descriptors and Rx buffers. Would
ice_up()->ice_vsi_cfg_lan()->ice_vsi_cfg_rxqs() then refill and program
rings whose desc is NULL and whose buffers have been freed?

These races existed before in a narrower window, when the reset path
sampled DOWN before the other thread set it.

if (!locked)
rtnl_unlock();