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 Closes: https://lore.kernel.org/all/20261021-b4-mlx5e-threaded-napi-stall-v1-1-d719c17b3ec4@toxicpanda.com/ Signed-off-by: Tariq Toukan Reviewed-by: Dragos Tatulea --- .../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