Re: [PATCH net 4/4] ionic: fix ethtool coalesce updates racing a PCI reset
From: netdev-bot+sashiko
Date: Wed Dec 02 2026 - 19:42:36 EST
Thank you for your contribution! Sashiko AI review found 1 potential
issue(s) to consider.
Critical: 0 · High: 0 (2) · 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 commit message and the Fixes: tag cover only the PCI reset
(FLR) path: ionic_reset_prepare()/ionic_reset_done(), added by…
Pre-existing issues:
- [High] This problem wasn't introduced by this patch, but
ionic_get_stats() (ethtool -S) has the same check-then-use race with…
- [High] This problem wasn't introduced by this patch, but
ionic_qcq_disable() cancels the DIM work before it quiesces the…
--
ionic: fix ethtool coalesce updates racing a PCI reset
This patch holds lif->queue_lock for all of the update in
ionic_set_coalesce(). The PCI reset teardown frees the queues and unmaps
BAR0 under queue_lock without rtnl, and the restart reprograms the queues
from the saved coalesce settings. With the lock held, the ethtool update
can no longer race with either of them.
> A PCI reset clears LIF_F_UP, frees the queues and unmaps BAR0
> without rtnl, so an update that passed the test just before the reset
> reads freed queues and writes the unmapped BAR.
[ ... ]
> Fixes: a79b559e99be ("ionic: add FLR recovery support")
[Severity: Medium]
Is the PCI reset the only path where this race happens? The firmware reset
path does the same teardown, also without rtnl:
ionic_lif_deferred_work()
ionic_lif_handle_fw_down()
mutex_lock(&lif->queue_lock);
ionic_stop_queues(lif) <- clears IONIC_LIF_F_UP
ionic_txrx_free(lif) <- devm_kfree(lif->rxqcqs[i]), sets it NULL
ionic_qcqs_free(lif) <- frees the rxqcqs/txqcqs arrays
mutex_unlock(&lif->queue_lock);
Suppose an ionic_set_coalesce() call has already passed the
test_bit(IONIC_LIF_F_UP) check. It would then read lif->rxqcqs[i]->flags
after the qcq has been freed or set to NULL.
The fw_down teardown dates from c672412f6172 ("ionic: remove lifs on fw
reset"). ionic_lif_handle_fw_down() has held queue_lock since
2624d95972db ("ionic: widen queue_lock use around lif init and deinit").
So this patch closes the firmware reset race as well.
Could the commit message describe the firmware reset path too? Would it be
more accurate for the Fixes: tag to point at the commit that opened that
race?
With only the FLR commit in the tag, stable trees that have queue_lock in
fw_down but not FLR recovery, such as 6.1.y, won't pick this fix up
automatically.
> diff --git a/drivers/net/ethernet/pensando/ionic/ionic_ethtool.c b/drivers/net/ethernet/pensando/ionic/ionic_ethtool.c
> index 1360a3dfb7c66..bc0601dbcf63a 100644
> --- a/drivers/net/ethernet/pensando/ionic/ionic_ethtool.c
> +++ b/drivers/net/ethernet/pensando/ionic/ionic_ethtool.c
> @@ -555,6 +555,8 @@ static int ionic_set_coalesce(struct net_device *netdev,
> tx_coal > IONIC_INTR_CTRL_COAL_MAX)
> return -ERANGE;
>
> + mutex_lock(&lif->queue_lock);
> +
> /* Save the new values */
> lif->rx_coalesce_usecs = coalesce->rx_coalesce_usecs;
> lif->rx_coalesce_hw = rx_coal;
[ ... ]
> @@ -598,6 +600,7 @@ static int ionic_set_coalesce(struct net_device *netdev,
> }
> }
> }
> + mutex_unlock(&lif->queue_lock);
>
> return 0;
> }
[Severity: High]
This is a pre-existing issue, but does ionic_get_stats() have the same
check-then-use race with PCI reset and firmware reset? It runs under rtnl
only and tests the flag without any lock:
drivers/net/ethernet/pensando/ionic/ionic_ethtool.c:ionic_get_stats() {
...
if (test_bit(IONIC_LIF_F_FW_RESET, lif->state))
return;
memset(buf, 0, stats->n_stats * sizeof(*buf));
for (i = 0; i < ionic_num_stats_grps; i++)
ionic_stats_groups[i].get_values(lif, &buf);
}
The get_values path goes through ionic_sw_stats_get_values() into two
groups of helpers:
- ionic_get_lif_stats() dereferences lif->hwstamp_txq->q.index and
lif->hwstamp_rxq->q.index.
- ionic_sw_stats_get_txq_values() and ionic_sw_stats_get_rxq_values()
index &lif->txqstats[q_num] and &lif->rxqstats[q_num].
Meanwhile, ionic_reset_prepare() sets IONIC_LIF_F_FW_RESET and then does
this under queue_lock only:
ionic_reset_prepare()
set_bit(IONIC_LIF_F_FW_RESET, lif->state);
...
mutex_lock(&lif->queue_lock);
ionic_txrx_free(lif) <- devm_kfree() of hwstamp_txq/hwstamp_rxq
ionic_qcqs_free(lif) <- devm_kfree(dev, lif->rxqstats);
lif->rxqstats = NULL; (same for txqstats)
ionic_lif_handle_fw_down() does the same after test_and_set_bit() of
IONIC_LIF_F_FW_RESET.
Suppose an ETHTOOL_GSTATS request passes the flag test just before a
reset. Can it copy freed stats memory into the user's ethtool buffer, or
oops on a NULL lif->txqstats or lif->rxqstats?
[Severity: High]
This isn't a bug introduced by this patch, but ionic_dim_work() also writes
this coalesce register, and queue_lock doesn't serialize it. Can it run on
a freed qcq after BAR0 has been unmapped?
ionic_qcq_disable() cancels the DIM work before it masks the interrupt and
disables NAPI:
drivers/net/ethernet/pensando/ionic/ionic_lif.c:ionic_qcq_disable() {
...
cancel_work_sync(&qcq->dim.work);
ionic_intr_mask(idev->intr_ctrl, qcq->intr.index,
IONIC_INTR_MASK_SET);
synchronize_irq(qcq->intr.vector);
...
napi_disable(&qcq->napi);
...
}
At the cancel, the queue is still enabled in hardware and the interrupt is
still unmasked. A NAPI poll can complete between cancel_work_sync() and
napi_disable() and queue the work again:
ionic_rx_napi() / ionic_tx_napi() / ionic_txrx_napi()
ionic_dim_update()
net_dim()
dim->state = DIM_APPLY_NEW_PROFILE;
schedule_work(&dim->work);
DIM is on by default, since ionic_lif_alloc() sets IONIC_LIF_F_RX_DIM_INTR
and IONIC_LIF_F_TX_DIM_INTR. Nothing cancels or flushes dim.work after
this point.
ionic_stop(), ionic_reset_prepare() and ionic_lif_handle_fw_down() then
call ionic_txrx_free(). It devm_kfree()s the qcq that contains the still
queued work_struct.
When ionic_dim_work() runs later, it does this on the freed qcq:
ionic_intr_coal_init(lif->ionic->idev.intr_ctrl,
intr->index, intr->dim_coal_hw);
In the PCI reset case, ionic_reset_prepare() has also called
ionic_dev_teardown() and ionic_clear_pci() by then. That would make this
iowrite32 hit the unmapped BAR0.
This ordering seems to date back to 04a834592bf5 ("ionic: dynamic
interrupt moderation"). Should cancel_work_sync(&qcq->dim.work) be moved
after napi_disable()?
--
Sashiko AI review · https://netdev-ai.bots.linux.dev/sashiko/#/patchset/20261202-b4-pr60-v1-0-b1f6706e065b%40amd.com