From: netdev-bot+sashiko@kernel.org
To: nikhil.rao@amd.com
Cc: brett.creeley@amd.com, andrew+netdev@lunn.ch,
davem@davemloft.net, edumazet@kernel.org, kuba@kernel.org,
pabeni@redhat.com, richardcochran@gmail.com,
netdev@vger.kernel.org, linux-kernel@vger.kernel.org,
eric.joyner@amd.com, abhijit.gangurde@amd.com,
allen.hubbe@amd.com
Subject: Re: [PATCH net v2 5/5] ionic: fix DIM work racing the queue teardown
Date: Sat, 05 Dec 2026 23:06:09 +0000 [thread overview]
Message-ID: <179651196901.3148.6541276687307414833@kernel.org> (raw)
In-Reply-To: <20261204-b4-pr60-v2-5-9e0b5408a68e@amd.com>
Thank you for your contribution! Sashiko AI review found 2 potential
issue(s) to consider.
Critical: 0 · High: 1 · Medium: 0 · 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 patch's stated claim, "Cancel the work once NAPI is
disabled, when no poll can queue it again", does not hold for ionic,…
- [Low] When cancel_work_sync(&qcq->dim.work) in ionic_qcq_disable()
drops a pending ionic_dim_work(), the patch copies only the handler's…
--
ionic: fix DIM work racing the queue teardown
This moves cancel_work_sync(&qcq->dim.work) in ionic_qcq_disable() so it
runs after napi_disable(). The goal is that a NAPI poll can no longer
requeue the DIM work on a queue that is about to be freed. It also resets
qcq->dim.state to DIM_START_MEASURE in place of a dropped work item.
Closes: https://lore.kernel.org/netdev/179625854521.3146.11030796304497825514@kernel.org/
> diff --git a/drivers/net/ethernet/pensando/ionic/ionic_lif.c b/drivers/net/ethernet/pensando/ionic/ionic_lif.c
> index 339a3c4c5b432..909781f064967 100644
> --- a/drivers/net/ethernet/pensando/ionic/ionic_lif.c
> +++ b/drivers/net/ethernet/pensando/ionic/ionic_lif.c
> @@ -358,13 +358,14 @@ static int ionic_qcq_disable(struct ionic_lif *lif, struct ionic_qcq *qcq, int f
>
> if (lif->doorbell_wa)
> cancel_work_sync(&qcq->doorbell_napi_work);
> - cancel_work_sync(&qcq->dim.work);
> ionic_intr_mask(idev->intr_ctrl, qcq->intr.index,
> IONIC_INTR_MASK_SET);
> synchronize_irq(qcq->intr.vector);
> irq_set_affinity_notifier(qcq->intr.vector, NULL);
> irq_set_affinity_hint(qcq->intr.vector, NULL);
> napi_disable(&qcq->napi);
> + cancel_work_sync(&qcq->dim.work);
[Severity: High]
The commit message says:
Cancel the work once NAPI is disabled, when no poll can queue it again.
Does that hold for ionic? In ionic_tx_napi(), ionic_rx_napi() and
ionic_txrx_napi(), ionic_dim_update() is only called after
napi_complete_done() has returned true:
drivers/net/ethernet/pensando/ionic/ionic_txrx.c:ionic_tx_napi() {
...
if (work_done < budget && napi_complete_done(napi, work_done)) {
ionic_dim_update(qcq, IONIC_LIF_F_TX_DIM_INTR);
...
}
At that point napi_complete_done() has already cleared NAPIF_STATE_SCHED.
napi_disable_locked() only waits while NAPIF_STATE_SCHED or
NAPIF_STATE_NPSVC is set.
So napi_disable() can return while the poll is still running on another
CPU. That poll may not yet have reached ionic_dim_update()->net_dim(),
which calls schedule_work(&dim->work).
Could this interleaving happen?
CPU0 (NAPI poll) CPU1 (ionic_qcq_disable)
napi_complete_done()
clears NAPIF_STATE_SCHED
ionic_intr_mask()
synchronize_irq()
napi_disable() /* returns */
cancel_work_sync(&qcq->dim.work)
qcq->dim.state = DIM_START_MEASURE
ionic_dim_update()
net_dim()
dim->state = DIM_APPLY_NEW_PROFILE
schedule_work(&dim->work)
This is the only cancel of dim.work in the driver. Teardown then goes
through ionic_txrx_deinit()->ionic_lif_qcq_deinit(). There,
netif_napi_del() waits for the poll to return, but by then the work is
already queued.
After that, ionic_txrx_free()->ionic_qcq_free() and devm_kfree() free the
qcq that embeds dim.work.
On the PCI reset path, ionic_reset_prepare() also reaches
ionic_clear_pci(), which does:
ionic->idev.intr_ctrl = NULL;
synchronize_rcu();
ionic_unmap_bars(ionic);
A late ionic_dim_work() would then use container_of() to get back to the
freed qcq. It could also call ionic_intr_coal_init() through a NULL or
unmapped intr_ctrl.
Isn't that the same use-after-free and unmapped BAR write this patch is
meant to fix?
The window is short on non-RT kernels. A hardirq on CPU0 makes it wider,
and on PREEMPT_RT the NAPI poll can be preempted.
Would either of these close it?
- Cancel dim.work and reset the DIM state only once the poll is known to
have returned, for example after netif_napi_del() in
ionic_lif_qcq_deinit().
- Add synchronize_net() between napi_disable() and cancel_work_sync().
> + qcq->dim.state = DIM_START_MEASURE;
[Severity: Low]
When cancel_work_sync() drops a pending ionic_dim_work(), this line copies
only the handler's last step. Is resetting dim.state alone enough to keep
DIM consistent with the hardware?
net_dim_decision() has already moved dim->profile_ix forward before
net_dim() sets DIM_APPLY_NEW_PROFILE and queues the work.
ionic_dim_work() is the only place where profile_ix is written to the
hardware:
drivers/net/ethernet/pensando/ionic/ionic_lif.c:ionic_dim_work() {
...
intr = &qcq->intr;
if (intr->dim_coal_hw != new_coal) {
intr->dim_coal_hw = new_coal;
ionic_intr_coal_init(lif->ionic->idev.intr_ctrl,
intr->index, intr->dim_coal_hw);
}
dim->state = DIM_START_MEASURE;
}
After the drop, the coalesce register and intr->dim_coal_hw still hold
the old profile's value, while profile_ix names the new profile.
The coalesce value is also not reapplied when the queues restart on the
same qcq. The path ionic_stop_queues(), then ionic_start_queues() and
ionic_qcq_enable(), never writes it.
If DIM then parks on top with steady traffic, it will not change profile
again. The hardware could stay on the value DIM decided to leave until
DIM changes profile again.
Would flush_work() here, or rolling profile_ix back, keep DIM in sync
with the hardware? flush_work() should still be safe at this point,
because ionic_intr_mask() earlier in the same block already writes
through intr_ctrl.
[ ... ]
--
Sashiko AI review · https://netdev-ai.bots.linux.dev/sashiko/#/patchset/20261204-b4-pr60-v2-0-9e0b5408a68e%40amd.com
prev parent reply other threads:[~2026-12-05 23:06 UTC|newest]
Thread overview: 9+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-12-04 22:04 [PATCH net v2 0/5] ionic: fix register reads racing the BAR unmap on PCI reset Nikhil P. Rao
2026-12-04 22:04 ` [PATCH net v2 1/5] ionic: fix devcmds " Nikhil P. Rao
2026-12-05 23:06 ` netdev-bot+sashiko
2026-12-04 22:04 ` [PATCH net v2 2/5] ionic: fix device info register reads " Nikhil P. Rao
2026-12-04 22:04 ` [PATCH net v2 3/5] ionic: fix PHC " Nikhil P. Rao
2026-12-04 22:04 ` [PATCH net v2 4/5] ionic: fix ethtool coalesce updates racing a reset Nikhil P. Rao
2026-12-05 23:06 ` netdev-bot+sashiko
2026-12-04 22:04 ` [PATCH net v2 5/5] ionic: fix DIM work racing the queue teardown Nikhil P. Rao
2026-12-05 23:06 ` netdev-bot+sashiko [this message]
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=179651196901.3148.6541276687307414833@kernel.org \
--to=netdev-bot+sashiko@kernel.org \
--cc=abhijit.gangurde@amd.com \
--cc=allen.hubbe@amd.com \
--cc=andrew+netdev@lunn.ch \
--cc=brett.creeley@amd.com \
--cc=davem@davemloft.net \
--cc=edumazet@kernel.org \
--cc=eric.joyner@amd.com \
--cc=kuba@kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=netdev@vger.kernel.org \
--cc=nikhil.rao@amd.com \
--cc=pabeni@redhat.com \
--cc=richardcochran@gmail.com \
/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