net/mlx5e: Fix the missing WQE count of large striding RQs
Subsystems (5)
Tariq Toukan
maintainerPATCH 1/1 net/mlx5e: Fix the missing WQE count of large striding RQs
mlx5e_post_rx_mpwqes() counts the WQEs to post in a u8, and the RQ keeps its in-flight UMR counters in u8 fields:
missing = mlx5_wq_ll_missing(wq) - rq->mpwqe.umr_in_progress;
A striding RQ can have more than 256 WQEs. Its size is set in packets of up to the MTU, up to 8K of them, and a WQE holds fewer such packets as the MTU grows: with 4K pages and an MTU of 9000, a WQE holds 16 of them, so a ring of 8K packets takes 512 WQEs. An XSK RQ can exceed 256 WQEs at any MTU: a WQE holds only 8 or 16 frames of an unaligned UMEM whose frame size is not a power of two, so a ring of 8K frames takes up to 1024 WQEs.
The first refill of such an RQ computes 511 missing WQEs, truncates that to 255 and posts them. From then on, the missing count is 256 plus the WQEs consumed since, which truncates to only the consumed ones, so each refill tops the RQ up to 255 WQEs again and never above. The RQ uses at most half of the ring that was configured, and drops bursts that the full ring would absorb.
Widen the missing count, the loop counter and the UMR counters to u16, which fits any RQ size. The counters take part of an existing hole, so struct mlx5e_rq keeps its size. The ICOSQ is already sized for the UMR WQEs of the whole RQ, so posting them in one refill fits.
Results on ConnectX-7 with an RX ring of 8K packets, at MTU 9000 for the regular RQ. Before this patch that ring behaves as one of 4K packets, and the XSK one as one of 2K frames.
Before After
Posted WQEs per RQ 255 511
Largest UDP burst with no drops
9000-byte packets 9,000 19,000
1500-byte packets 50,000 100,000 Longest NAPI period with no drops 20 ms 45 ms
TCP incast, 200 rounds
Dropped packets 22,313 0
Retransmitted segments 20,515 435
Rounds over 200 ms 42 0
Longest round 284 ms 53 ms
XSK RQ, MTU 1500, 3072-byte frames
Posted WQEs 255 1023
Largest UDP burst with no drops 2,000 8,000
The UDP bursts are of a single flow, and the drops are counted by rx_out_of_buffer. The NAPI period is gro_flush_timeout, with napi_defer_hard_irqs set, under a 21.7 Gb/s stream of 9000-byte packets. In the TCP test, 192 connections on one RX queue send 1MB each at the same time. The XSK frames are of an unaligned UMEM.
--- drivers/net/ethernet/mellanox/mlx5/core/en.h | 6 +++--- drivers/net/ethernet/mellanox/mlx5/core/en_rx.c | 6 +++--- 2 files changed, 6 insertions(+), 6 deletions(-)
drivers/net/ethernet/mellanox/mlx5/core/en.h +3 -3
@@ -687,9 +687,9 @@ struct mlx5e_rq {u16 num_strides;u16 actual_wq_head;u8 log_stride_sz; -u8 umr_in_progress; -u8 umr_last_bulk; -u8 umr_completed; +u16 umr_in_progress; +u16 umr_last_bulk; +u16 umr_completed;u8 min_wqe_bulk;u8 page_shift;u8 pages_per_wqe;
drivers/net/ethernet/mellanox/mlx5/core/en_rx.c +3 -3
@@ -626,7 +626,7 @@ mlx5e_free_rx_mpwqe(struct mlx5e_rq *rq, struct mlx5e_mpw_info *wi) } } -static void mlx5e_post_rx_mpwqe (struct mlx5e_rq *rq,u8 n) +static void mlx5e_post_rx_mpwqe (struct mlx5e_rq *rq,u16 n) {struct mlx5_wq_ll *wq = &rq->mpwqe.wq;
@@ -933,11 +933,11 @@ static void mlx5e_reclaim_mpwqe_pages(struct mlx5e_rq *rq, int head, INDIRECT_CALLABLE_SCOPE bool mlx5e_post_rx_mpwqes(struct mlx5e_rq *rq) {struct mlx5_wq_ll *wq = &rq->mpwqe.wq; -u8 umr_completed = rq->mpwqe.umr_completed; +u16 umr_completed = rq->mpwqe.umr_completed;struct mlx5e_icosq *sq = rq->icosq;bool reclaimed = false;int alloc_err =0 ; -u8 missing, i; +u16 missing, i;u16 head;if (unlikely (!test_bit (MLX5E_RQ_STATE_ENABLED , &rq->state)))
base-commit: b6c8f45ed340f00bf2004d407cf7316fe3e24c48
Signature · 1 line
2.44.0
[email protected]
AI reviewThis is an automated message. This series looks like a fix, but its commit messages seem to be missing some information:
Hi!
This is an automated message. This series looks like a fix, but its commit messages seem to be missing some information:
- How the issue was discovered, e.g. hit in production, hit during development, syzbot report, manual code inspection, LLM or static analysis tool scan.
Please do not repost the series just to address the above. Instead, reply to this email with the missing information, so that reviewers can take it into account.
*IMPORTANT*: If you do repost (for other reasons) - please include the relevant info in the cover letter or commit messages.
Signature · 2 lines
The evaluation is done by an LLM so it may be wrong, if you think that is the case please reply and explain.
[email protected]
AI reviewSashiko has reviewed this patch and found no issues.
Quoted 13 lines
mlx5e_post_rx_mpwqes()counts the WQEs to post in a u8, and the RQ keeps its in-flight UMR counters in u8 fields:missing = mlx5_wq_ll_missing(wq) - rq->mpwqe.umr_in_progress;A striding RQ can have more than 256 WQEs. Its size is set in packets of up to the MTU, up to 8K of them, and a WQE holds fewer such packets as the MTU grows: with 4K pages and an MTU of 9000, a WQE holds 16 of them, so a ring of 8K packets takes 512 WQEs. An XSK RQ can exceed 256 WQEs at any MTU: a WQE holds only 8 or 16 frames of an unaligned UMEM whose frame size is not a power of two, so a ring of 8K frames takes up to 1024 WQEs.
Quoted 8 lines
The first refill of such an RQ computes 511 missing WQEs, truncates that to 255 and posts them. From then on, the missing count is 256 [ ... ]
packets. In the TCP test, 192 connections on one RX queue send 1MB each at the same time. The XSK frames are of an unaligned UMEM.Fixes fd9b4be8002c ("net/mlx5e: RX, Support multiple outstanding UMR posts")Signed-off-by Tariq Toukan <[email protected]>
Sashiko has reviewed this patch and found no issues.
Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=1
[email protected]
AI reviewThank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider.
Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider.
Critical: 0 · High: 0 · 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 says "The ICOSQ is already sized for the UMR WQEs of the whole RQ, so posting them in one refill fits." That…
--
net/mlx5e: Fix the missing WQE count of large striding RQs
This commit widens the missing WQE count and loop counter in mlx5e_post_rx_mpwqes(), and the umr_in_progress, umr_last_bulk and umr_completed fields of struct mlx5e_rq, from u8 to u16. Before this, the u8 truncation limited each striding RQ to 255 posted WQEs even when the ring was configured larger.
Quoted 4 lines
drivers/net/ethernet/mellanox/mlx5/core/en_rx.c +0
-0
[ ... ]
drivers/net/ethernet/mellanox/mlx5/core/en_rx.c static void mlx5e_reclaim_mpwqe_pages(struct mlx5e_rq *rq, int head, · line 940
Quoted 11 lines
drivers/net/ethernet/mellanox/mlx5/core/en_rx.c +2
-2@@ -933,11 +933,11 @@ static void mlx5e_reclaim_mpwqe_pages(struct mlx5e_rq *rq, int head, INDIRECT_CALLABLE_SCOPE bool mlx5e_post_rx_mpwqes(struct mlx5e_rq *rq) {struct mlx5_wq_ll *wq = &rq->mpwqe.wq; -u8 umr_completed = rq->mpwqe.umr_completed; +u16 umr_completed = rq->mpwqe.umr_completed;struct mlx5e_icosq *sq = rq->icosq;bool reclaimed = false;int alloc_err =0 ; -u8 missing, i; +u16 missing, i;
[Severity: Medium]
The commit message says:
The ICOSQ is already sized for the UMR WQEs of the whole RQ, so posting them in one refill fits.
Now that missing and i are u16, mlx5e_post_rx_mpwqes() can post up to RQ size - 1 UMRs in a single refill. Before, the u8 capped that at 255. Is the ICOSQ sizing really enough to cover this?
In mlx5e_build_icosq_log_wq_sz() in en/params.c, the comment asks for (PAGE_SIZE - (max WQE size - MLX5_SEND_WQE_BB)) useful bytes per page. The code does this instead:
useful_space = PAGE_SIZE - mlx5e_get_max_sq_wqebbs(mdev) + MLX5_SEND_WQE_BB;
mlx5e_get_max_sq_wqebbs() returns a count of WQEBBs (up to 16), not bytes. With 4K pages that makes useful_space 4144, which is larger than PAGE_SIZE.
So the estimate reserves no room for the page-edge NOPs that mlx5e_icosq_get_next_pi() inserts. For 10-WQEBB UMRs that is 4 NOPs per 64-WQEBB page, about 6.7% overhead. This calculation dates back to commit 0b9c86c78586c2. The 255 in-flight cap has been hiding it until now.
Neither mlx5e_alloc_rx_mpwqe() nor mlx5e_xsk_alloc_rx_mpwqe() checks for room in the ICOSQ. Both just advance sq->pc and write sq->db.wqe_info[pi].
c->rq and c->xskrq share c->icosq, and both can be refilled from empty in the same NAPI poll. Two paths lead there:
mlx5e_xsk_disable_locked()
mlx5e_activate_rq(&c->rq); /* while the XSK RQ is still active */
mlx5e_rx_reporter_err_icosq_cqe_recover()
re-activates both RQs
I could not find a valid configuration that actually overflows. Power-of-two rounding and mlx5e_mpwrq_validate_xsk() seem to keep the footprint within the ICOSQ. The margins are thin, though. For example, with non-ECPF, 4K pages, umr_wqebbs = 10 and an XSK RQ twice the size of the regular RQ, the worst case is about 4081 of 4096 WQEBBs.
What if some device capability combination does go over? Then pc - cc would exceed the ICOSQ size, and in-flight UMR WQEs and wqe_info[] entries would be overwritten. mlx5e_poll_ico_cq() could also credit umr_completed to the wrong RQ, and this could underflow the u16:
rq->mpwqe.umr_in_progress -= umr_completed;
Would it make sense to fix the useful_space calculation, so that the max WQE size is in bytes, before full-ring refills rely on it? Or should the commit message be reworded so it does not depend on that sizing?
Quoted 3 lines
drivers/net/ethernet/mellanox/mlx5/core/en_rx.c +0
-0u16 head;if (unlikely (!test_bit (MLX5E_RQ_STATE_ENABLED , &rq->state)))
Signature · 1 line
Sashiko AI review · https://netdev-ai.bots.linux.dev/sashiko/#/patchset/20261202121422.3422569-1-tariqt%40nvidia.com