Linux RDMA and InfiniBand development
 help / color / mirror / Atom feed
* [PATCH net 0/2] net/mlx5e: Fix channel stall on affinity change
@ 2026-12-02 11:02 Tariq Toukan
  2026-12-02 11:02 ` [PATCH net 1/2] net/mlx5e: RX, Drop ICOSQ padding NOPs on UMR allocation failure Tariq Toukan
                   ` (2 more replies)
  0 siblings, 3 replies; 4+ messages in thread
From: Tariq Toukan @ 2026-12-02 11:02 UTC (permalink / raw)
  To: Andrew Lunn, David S. Miller, Eric Dumazet, Jakub Kicinski,
	netdev, Paolo Abeni, Willem de Bruijn
  Cc: Aya Levin, Dragos Tatulea, Gal Pressman, Jiri Pirko,
	Jonathan Corbet, Josef Bacik, Leon Romanovsky, linux-doc,
	linux-rdma, Mark Bloch, Randy Dunlap, Saeed Mahameed,
	Saeed Mahameed, Shuah Khan, Simon Horman, Tariq Toukan,
	Tariq Toukan

Hi,

This series fixes a channel stall in mlx5e_napi_poll(), reported by
Josef Bacik with threaded NAPI [1].

When the 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. The
device raises no event when all the unconsumed CQEs were already
reported, and the channel stalls.

Patch 1 drops the ICOSQ padding NOPs when a UMR allocation fails. It
fixes a timeout in the ICOSQ recovery flow, and patch 2 relies on it.

Patch 2 fixes the stall: before the arm, it makes sure that an event is
still to come on the ICOSQ CQ, posting a NOP if needed.

Not handled here, left for net-next:
- Threaded NAPI still takes this path on every poll with more work
  outside the mask, paying a NOP and an interrupt each time, although
  the interrupt cannot move the poll thread. Josef's patch [1] skips
  the path there.
- With deferred hard IRQs, napi_complete_done() returns false after the
  NOP was posted, so the NOP is wasted and NAPI does not move either. A
  core helper that tells whether a poll follows the IRQ would cover
  both cases.

[1]
https://lore.kernel.org/all/20261021-b4-mlx5e-threaded-napi-stall-v1-1-d719c17b3ec4@toxicpanda.com/

Regards,
Tariq

Tariq Toukan (2):
  net/mlx5e: RX, Drop ICOSQ padding NOPs on UMR allocation failure
  net/mlx5e: Fix channel stall after NAPI moves to another CPU

 .../ethernet/mellanox/mlx5/counters.rst       |  7 ++--
 .../net/ethernet/mellanox/mlx5/core/en_rx.c   |  7 +++-
 .../net/ethernet/mellanox/mlx5/core/en_txrx.c | 39 +++++++++++++++----
 3 files changed, 41 insertions(+), 12 deletions(-)


base-commit: b6c8f45ed340f00bf2004d407cf7316fe3e24c48
-- 
2.44.0


^ permalink raw reply	[flat|nested] 4+ messages in thread

* [PATCH net 1/2] net/mlx5e: RX, Drop ICOSQ padding NOPs on UMR allocation failure
  2026-12-02 11:02 [PATCH net 0/2] net/mlx5e: Fix channel stall on affinity change Tariq Toukan
@ 2026-12-02 11:02 ` Tariq Toukan
  2026-12-02 11:02 ` [PATCH net 2/2] net/mlx5e: Fix channel stall after NAPI moves to another CPU Tariq Toukan
  2026-12-02 11:16 ` [PATCH net 0/2] net/mlx5e: Fix channel stall on affinity change sashiko-bot
  2 siblings, 0 replies; 4+ messages in thread
From: Tariq Toukan @ 2026-12-02 11:02 UTC (permalink / raw)
  To: Andrew Lunn, David S. Miller, Eric Dumazet, Jakub Kicinski,
	netdev, Paolo Abeni, Willem de Bruijn
  Cc: Aya Levin, Dragos Tatulea, Gal Pressman, Jiri Pirko,
	Jonathan Corbet, Josef Bacik, Leon Romanovsky, linux-doc,
	linux-rdma, Mark Bloch, Randy Dunlap, Saeed Mahameed,
	Saeed Mahameed, Shuah Khan, Simon Horman, Tariq Toukan,
	Tariq Toukan

mlx5e_alloc_rx_mpwqe() takes its ICOSQ slot before it allocates the
pages, and mlx5e_icosq_get_next_pi() may pad the SQ with NOPs up to a
page boundary on the way. When the allocation fails, the producer
counter is not restored, and the NOPs stay with no WQE after them to
request their completion. The ICOSQ recovery flow, which waits for
the SQ to become empty, can then time out and leave the RQ
deactivated.

Restore the producer counter when the allocation fails. The NOPs were
not submitted yet, as the doorbell is rung only after the refill loop.
The XSK flavor allocates its frames before it takes the slot, so it is
not affected.

The next patch relies on this: it posts a NOP only on an empty ICOSQ,
and takes a non-empty one as having a completion to come.

Fixes: be5323c8379f ("net/mlx5e: Report and recover from CQE error on ICOSQ")
Signed-off-by: Tariq Toukan <tariqt@nvidia.com>
Reviewed-by: Dragos Tatulea <dtatulea@nvidia.com>
---
 drivers/net/ethernet/mellanox/mlx5/core/en_rx.c | 7 ++++++-
 1 file changed, 6 insertions(+), 1 deletion(-)

diff --git a/drivers/net/ethernet/mellanox/mlx5/core/en_rx.c b/drivers/net/ethernet/mellanox/mlx5/core/en_rx.c
index 1586cb2404c0..3f6b11da486b 100644
--- a/drivers/net/ethernet/mellanox/mlx5/core/en_rx.c
+++ b/drivers/net/ethernet/mellanox/mlx5/core/en_rx.c
@@ -651,11 +651,12 @@ static int mlx5e_alloc_rx_mpwqe(struct mlx5e_rq *rq, u16 ix)
 	struct mlx5e_umr_wqe *umr_wqe;
 	u32 offset; /* 17-bit value with MTT. */
 	bool sync_locked;
-	u16 pi;
+	u16 pc, pi;
 	int err;
 	int i;
 
 	sync_locked = mlx5e_icosq_sync_lock(sq);
+	pc = sq->pc;
 	pi = mlx5e_icosq_get_next_pi(sq, rq->mpwqe.umr_wqebbs);
 	umr_wqe = mlx5_wq_cyc_get_wqe(wq, pi);
 	memcpy(umr_wqe, &rq->mpwqe.umr_wqe, sizeof(struct mlx5e_umr_wqe));
@@ -710,6 +711,10 @@ static int mlx5e_alloc_rx_mpwqe(struct mlx5e_rq *rq, u16 ix)
 	return 0;
 
 err_unmap:
+	/* Drop the padding NOPs of mlx5e_icosq_get_next_pi(), no WQE follows
+	 * them to request their completion.
+	 */
+	sq->pc = pc;
 	mlx5e_icosq_sync_unlock(sq, sync_locked);
 	while (--i >= 0) {
 		frag_page--;
-- 
2.44.0


^ permalink raw reply related	[flat|nested] 4+ messages in thread

* [PATCH net 2/2] net/mlx5e: Fix channel stall after NAPI moves to another CPU
  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
  2026-12-02 11:16 ` [PATCH net 0/2] net/mlx5e: Fix channel stall on affinity change sashiko-bot
  2 siblings, 0 replies; 4+ messages in thread
From: Tariq Toukan @ 2026-12-02 11:02 UTC (permalink / raw)
  To: Andrew Lunn, David S. Miller, Eric Dumazet, Jakub Kicinski,
	netdev, Paolo Abeni, Willem de Bruijn
  Cc: Aya Levin, Dragos Tatulea, Gal Pressman, Jiri Pirko,
	Jonathan Corbet, Josef Bacik, Leon Romanovsky, linux-doc,
	linux-rdma, Mark Bloch, Randy Dunlap, Saeed Mahameed,
	Saeed Mahameed, Shuah Khan, Simon Horman, Tariq Toukan,
	Tariq Toukan

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


^ permalink raw reply related	[flat|nested] 4+ messages in thread

* Re: [PATCH net 0/2] net/mlx5e: Fix channel stall on affinity change
  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 ` [PATCH net 2/2] net/mlx5e: Fix channel stall after NAPI moves to another CPU Tariq Toukan
@ 2026-12-02 11:16 ` sashiko-bot
  2 siblings, 0 replies; 4+ messages in thread
From: sashiko-bot @ 2026-12-02 11:16 UTC (permalink / raw)
  To: Tariq Toukan; +Cc: linux-rdma

Sashiko has reviewed this 2-patch series and found no issues.

-- 
Sashiko AI review · https://sashiko.dev/#/patchset/20261202110207.3387859-1-tariqt@nvidia.com

^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2026-12-02 11:16 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
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 ` [PATCH net 2/2] net/mlx5e: Fix channel stall after NAPI moves to another CPU Tariq Toukan
2026-12-02 11:16 ` [PATCH net 0/2] net/mlx5e: Fix channel stall on affinity change sashiko-bot

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox