From: Tariq Toukan <tariqt@nvidia.com>
To: Andrew Lunn <andrew+netdev@lunn.ch>,
"David S. Miller" <davem@davemloft.net>,
Eric Dumazet <edumazet@kernel.org>,
Jakub Kicinski <kuba@kernel.org>, <netdev@vger.kernel.org>,
Paolo Abeni <pabeni@redhat.com>,
Willem de Bruijn <willemb@google.com>
Cc: Aya Levin <ayal@mellanox.com>,
Dragos Tatulea <dtatulea@nvidia.com>,
"Gal Pressman" <gal@nvidia.com>, Jiri Pirko <jiri@resnulli.us>,
Jonathan Corbet <corbet@lwn.net>,
Josef Bacik <josef@toxicpanda.com>,
Leon Romanovsky <leon@kernel.org>, <linux-doc@vger.kernel.org>,
<linux-rdma@vger.kernel.org>, Mark Bloch <mbloch@nvidia.com>,
Randy Dunlap <rdunlap@infradead.org>,
"Saeed Mahameed" <saeedm@mellanox.com>,
Saeed Mahameed <saeedm@nvidia.com>,
"Shuah Khan" <skhan@linuxfoundation.org>,
Simon Horman <horms@kernel.org>,
"Tariq Toukan" <tariqt@mellanox.com>,
Tariq Toukan <tariqt@nvidia.com>
Subject: [PATCH net 2/2] net/mlx5e: Fix channel stall after NAPI moves to another CPU
Date: Wed, 2 Dec 2026 13:02:07 +0200 [thread overview]
Message-ID: <20261202110207.3387859-3-tariqt@nvidia.com> (raw)
In-Reply-To: <20261202110207.3387859-1-tariqt@nvidia.com>
When mlx5e_napi_poll() has more work but runs on a CPU outside the
IRQ's affinity mask, it completes NAPI and re-arms the CQs, counting on
the arm to raise an event that reschedules NAPI on the right CPU.
However, the device raises an event on arm only for CQEs that no
previous event reported [1]. If all the unconsumed CQEs were already
reported, the arm raises nothing and the channel stalls: RX drops once
the RQ runs dry, and a sender blocked on its socket buffer never gets
its TX completions.
With threaded NAPI the poll thread runs wherever the scheduler puts it,
so a busy channel takes this path on nearly every poll, as Josef Bacik
reported. Softirq NAPI can hit the stall when the IRQ affinity changes
under load.
Fix it by making sure, before the arm, that an event is still to come
on the ICOSQ CQ. Once the poll drained that CQ, any WQE still in flight
completes with a CQE that no event has reported. If none is in flight,
post a NOP; an idle ICOSQ always has room for it. If the ICOSQ CQ was
not drained, or the ICOSQ is disabled or in recovery, poll another
round instead.
Don't take this path under busy polling, where napi_complete_done()
returns false and the NOP would be posted for nothing. The poll that
hands NAPI back when busy polling stops still takes it.
This also covers busy XSK, so the NOP posted for it on the async ICOSQ
is redundant. Remove it. ch_force_irq, which counted those NOPs, now
counts every interrupt forced by this path.
For threaded NAPI and for deferred hard IRQs this only prevents the
stall. Taking this path still cannot move the poll there, and it now
costs a NOP every time.
Tested on ConnectX-6 Dx with threaded NAPI, the NAPI thread and the
channel IRQ pinned to different CPUs. Before the fix, RX stalled under
a UDP flood in 4 of 5 runs, and TX completions stopped within 16 s in
5 of 6 runs. With the fix, no run stalled, also with AF_XDP zero-copy,
with busy polling, and with an IRQ or NAPI thread moved every 2 s.
[1] https://lore.kernel.org/all/20210222155559.GH2643399@ziepe.ca/
Fixes: a8c2eb15797a ("net/mlx5e: Stop NAPI when irq balancer changes affinity")
Reported-by: Josef Bacik <josef@toxicpanda.com>
Closes: https://lore.kernel.org/all/20261021-b4-mlx5e-threaded-napi-stall-v1-1-d719c17b3ec4@toxicpanda.com/
Signed-off-by: Tariq Toukan <tariqt@nvidia.com>
Reviewed-by: Dragos Tatulea <dtatulea@nvidia.com>
---
.../ethernet/mellanox/mlx5/counters.rst | 7 ++--
.../net/ethernet/mellanox/mlx5/core/en_txrx.c | 39 +++++++++++++++----
2 files changed, 35 insertions(+), 11 deletions(-)
diff --git a/Documentation/networking/device_drivers/ethernet/mellanox/mlx5/counters.rst b/Documentation/networking/device_drivers/ethernet/mellanox/mlx5/counters.rst
index cc498895f92e..518b171db46e 100644
--- a/Documentation/networking/device_drivers/ethernet/mellanox/mlx5/counters.rst
+++ b/Documentation/networking/device_drivers/ethernet/mellanox/mlx5/counters.rst
@@ -427,9 +427,10 @@ the software port.
- Error
* - `ch[i]_force_irq`
- - Number of times NAPI is triggered by XSK wakeups by posting a NOP to
- ICOSQ.
- - Acceleration
+ - The number of times the NAPI poll function stopped execution on a CPU
+ due to a change in affinity and forced an interrupt to reschedule NAPI,
+ on channel i.
+ - Informative
* - `rx[i]_congst_umr`
- The number of times an outstanding UMR request is delayed due to
diff --git a/drivers/net/ethernet/mellanox/mlx5/core/en_txrx.c b/drivers/net/ethernet/mellanox/mlx5/core/en_txrx.c
index 185105606469..a357c1ee24bc 100644
--- a/drivers/net/ethernet/mellanox/mlx5/core/en_txrx.c
+++ b/drivers/net/ethernet/mellanox/mlx5/core/en_txrx.c
@@ -43,6 +43,10 @@ static inline bool mlx5e_channel_no_affinity_change(struct mlx5e_channel *c)
{
int current_cpu = smp_processor_id();
+ /* Busy polling can't complete NAPI, so the IRQ can't move it. */
+ if (test_bit(NAPI_STATE_IN_BUSY_POLL, &c->napi.state))
+ return true;
+
return cpumask_test_cpu(current_cpu, c->aff_mask);
}
@@ -85,6 +89,23 @@ void mlx5e_trigger_irq(struct mlx5e_icosq *sq)
mlx5e_notify_hw(wq, sq->pc, sq->uar_map, &nopwqe->ctrl);
}
+static bool mlx5e_channel_force_irq(struct mlx5e_channel *c)
+{
+ struct mlx5e_icosq *icosq = &c->icosq;
+ bool sync_locked, forced = false;
+
+ sync_locked = mlx5e_icosq_sync_lock(icosq);
+ if (likely(test_bit(MLX5E_SQ_STATE_ENABLED, &icosq->state) &&
+ !test_bit(MLX5E_SQ_STATE_RECOVERING, &icosq->state))) {
+ if (icosq->pc == icosq->cc)
+ mlx5e_trigger_irq(icosq);
+ forced = true;
+ }
+ mlx5e_icosq_sync_unlock(icosq, sync_locked);
+
+ return forced;
+}
+
static bool mlx5e_napi_xsk_post(struct mlx5e_xdpsq *xsksq, struct mlx5e_rq *xskrq)
{
bool need_wakeup = xsk_uses_need_wakeup(xskrq->xsk_pool);
@@ -132,7 +153,7 @@ int mlx5e_napi_poll(struct napi_struct *napi, int budget)
struct mlx5e_rq *xskrq = &c->xskrq;
struct mlx5e_rq *rq = &c->rq;
bool aff_change = false;
- bool busy_xsk = false;
+ bool icosq_drained;
bool busy = false;
int work_done = 0;
u16 qos_sqs_size;
@@ -179,7 +200,8 @@ int mlx5e_napi_poll(struct napi_struct *napi, int budget)
busy |= work_done == budget;
- mlx5e_poll_ico_cq(&c->icosq.cq);
+ icosq_drained = mlx5e_poll_ico_cq(&c->icosq.cq) <
+ MLX5E_TX_CQ_POLL_BUDGET;
if (aicosq) {
if (mlx5e_poll_ico_cq(&aicosq->cq))
/* Don't clear the flag if nothing was polled to prevent
@@ -195,9 +217,7 @@ int mlx5e_napi_poll(struct napi_struct *napi, int budget)
if (xsk_open) {
busy |= mlx5e_poll_xdpsq_cq(&xsksq->cq);
- busy_xsk |= mlx5e_napi_xsk_post(xsksq, xskrq);
-
- busy |= busy_xsk;
+ busy |= mlx5e_napi_xsk_post(xsksq, xskrq);
}
}
@@ -211,6 +231,11 @@ int mlx5e_napi_poll(struct napi_struct *napi, int budget)
work_done = budget;
goto out;
}
+ if (unlikely(!icosq_drained || !mlx5e_channel_force_irq(c))) {
+ /* No guaranteed event; poll another round. */
+ work_done = budget;
+ goto out;
+ }
ch_stats->aff_change++;
aff_change = true;
if (work_done == budget)
@@ -252,10 +277,8 @@ int mlx5e_napi_poll(struct napi_struct *napi, int budget)
mlx5e_cq_arm(&c->xdpsq->cq);
}
- if (unlikely(aff_change && busy_xsk)) {
- mlx5e_trigger_napi_async_icosq(c);
+ if (unlikely(aff_change))
ch_stats->force_irq++;
- }
out:
rcu_read_unlock();
--
2.44.0
next prev parent reply other threads:[~2026-12-02 11:03 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-12-02 11:02 [PATCH net 0/2] net/mlx5e: Fix channel stall on affinity change Tariq Toukan
2026-12-02 11:02 ` [PATCH net 1/2] net/mlx5e: RX, Drop ICOSQ padding NOPs on UMR allocation failure Tariq Toukan
2026-12-02 11:02 ` Tariq Toukan [this message]
2026-12-02 11:16 ` [PATCH net 0/2] net/mlx5e: Fix channel stall on affinity change sashiko-bot
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=20261202110207.3387859-3-tariqt@nvidia.com \
--to=tariqt@nvidia.com \
--cc=andrew+netdev@lunn.ch \
--cc=ayal@mellanox.com \
--cc=corbet@lwn.net \
--cc=davem@davemloft.net \
--cc=dtatulea@nvidia.com \
--cc=edumazet@kernel.org \
--cc=gal@nvidia.com \
--cc=horms@kernel.org \
--cc=jiri@resnulli.us \
--cc=josef@toxicpanda.com \
--cc=kuba@kernel.org \
--cc=leon@kernel.org \
--cc=linux-doc@vger.kernel.org \
--cc=linux-rdma@vger.kernel.org \
--cc=mbloch@nvidia.com \
--cc=netdev@vger.kernel.org \
--cc=pabeni@redhat.com \
--cc=rdunlap@infradead.org \
--cc=saeedm@mellanox.com \
--cc=saeedm@nvidia.com \
--cc=skhan@linuxfoundation.org \
--cc=tariqt@mellanox.com \
--cc=willemb@google.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