net/mlx5e: Improve channel creation time via fast-path MKEY initialization
Subsystems (5)
Tariq Toukan
maintainercover net/mlx5e: Improve channel creation time via fast-path MKEY initialization
Hi,
This series improves channel creation time by moving per-channel MKEY initialization from a slow-path FW command to a fast-path UMR WQE.
The benefit becomes more significant with larger MKEYs and a higher number of channels.
On my setup with the maximum configuration (248 channels, MTU 9000, RX/TX ring size 8K), the "interface up" operation is 2.081 seconds faster:
Before: 5.618 seconds After: 3.537 seconds
This corresponds to ~8.4 msec saved per channel.
Regards,
Tariq
Tariq Toukan (3):
net/mlx5e: Move RX MPWQE slowpath fields into a separate struct net/mlx5e: RX, Pre-calculate pad value in MPWQE
net/mlx5e: Speed up channel creation by initializing MKEY entries via
UMR WQE
drivers/net/ethernet/mellanox/mlx5/core/en.h | 11 +- .../net/ethernet/mellanox/mlx5/core/en/txrx.h | 1 + .../net/ethernet/mellanox/mlx5/core/en_main.c | 263 +++++++++++++----- .../net/ethernet/mellanox/mlx5/core/en_rx.c | 9 +- 4 files changed, 212 insertions(+), 72 deletions(-)
base-commit: a7fb05cbb8f989fa5a81818be9680464cff9d717
Signature · 1 line
2.44.0
Tariq Toukan
maintainerPATCH 1/3 net/mlx5e: Move RX MPWQE slowpath fields into a separate struct
Move fields that are not read/written in fast path to a different struct / cacheline in the RQ structure.
--- drivers/net/ethernet/mellanox/mlx5/core/en.h | 4 +++- drivers/net/ethernet/mellanox/mlx5/core/en_main.c | 12 +++++++----- 2 files changed, 10 insertions(+), 6 deletions(-)
drivers/net/ethernet/mellanox/mlx5/core/en.h +3 -1
@@ -676,7 +676,6 @@ struct mlx5e_rq {struct mlx5e_umr_wqe_hdr umr_wqe;struct mlx5e_mpw_info *info;mlx5e_fp_skb_from_cqe_mpwrq skb_from_cqe_mpwrq; -__be32 umr_mkey_be;u16 num_strides;u16 actual_wq_head;u8 log_stride_sz;
@@ -745,6 +744,9 @@ struct mlx5e_rq {struct mlx5_core_dev *mdev;struct mlx5e_channel *channel;struct mlx5e_dma_info wqe_overflow; +struct { +__be32 umr_mkey_be; + } mpwqe_sp;/* XDP read-mostly */ struct xdp_rxq_info xdp_rxq;
drivers/net/ethernet/mellanox/mlx5/core/en_main.c +7 -5
@@ -332,7 +332,7 @@ static inline void mlx5e_build_umr_wqe(struct mlx5e_rq *rq, cseg->qpn_ds =cpu_to_be32 ((sq->sqn <<MLX5_WQE_CTRL_QPN_SHIFT ) | ds_cnt); - cseg->umr_mkey = rq->mpwqe.umr_mkey_be; + cseg->umr_mkey = rq->mpwqe_sp.umr_mkey_be; ucseg->flags =MLX5_UMR_TRANSLATION_OFFSET_EN |MLX5_UMR_INLINE ; octowords =mlx5e_mpwrq_umr_octowords (rq->mpwqe.pages_per_wqe, rq->mpwqe.umr_mode);
@@ -513,7 +513,7 @@ static int mlx5e_create_rq_umr_mkey(struct mlx5_core_dev *mdev, struct mlx5e_rq err =mlx5e_create_umr_mkey (mdev, num_entries, rq->mpwqe.page_shift, &umr_mkey, rq->wqe_overflow.addr, rq->mpwqe.umr_mode, xsk_chunk_size); - rq->mpwqe.umr_mkey_be =cpu_to_be32 (umr_mkey); + rq->mpwqe_sp.umr_mkey_be =cpu_to_be32 (umr_mkey);return err; }
@@ -1024,7 +1024,7 @@ static int mlx5e_alloc_rq(struct mlx5e_params *params, wqe->data[0 ].addr =cpu_to_be64 (dma_offset + headroom); wqe->data[0 ].byte_count =cpu_to_be32 (byte_count); - wqe->data[0 ].lkey = rq->mpwqe.umr_mkey_be; + wqe->data[0 ].lkey = rq->mpwqe_sp.umr_mkey_be; }else {struct mlx5e_rx_wqe_cyc *wqe =mlx5_wq_cyc_get_wqe (&rq->wqe.wq, i);
@@ -1057,7 +1057,8 @@ static int mlx5e_alloc_rq(struct mlx5e_params *params, err_free_mpwqe_info:kvfree (rq->mpwqe.info); err_rq_mkey: -mlx5_core_destroy_mkey (mdev,be32_to_cpu (rq->mpwqe.umr_mkey_be)); +mlx5_core_destroy_mkey (mdev, +be32_to_cpu (rq->mpwqe_sp.umr_mkey_be)); err_rq_drop_page:mlx5e_free_mpwqe_rq_drop_page (rq);break ;
@@ -1082,7 +1083,8 @@ static void mlx5e_free_rq(struct mlx5e_rq *rq)case MLX5_WQ_TYPE_LINKED_LIST_STRIDING_RQ :mlx5e_rq_free_shampo (rq);kvfree (rq->mpwqe.info); -mlx5_core_destroy_mkey (rq->mdev,be32_to_cpu (rq->mpwqe.umr_mkey_be)); +mlx5_core_destroy_mkey (rq->mdev, +be32_to_cpu (rq->mpwqe_sp.umr_mkey_be));mlx5e_free_mpwqe_rq_drop_page (rq);break ;default :/* MLX5_WQ_TYPE_CYCLIC */
Signature · 1 line
2.44.0
Re: [PATCH net-next 1/3] net/mlx5e: Move RX MPWQE slowpath fields into a separate struct
Quoted 9 lines · Tariq Toukan
Move fields that are not read/written in fast path to a different struct / cacheline in the RQ structure.
Signed-off-by Tariq Toukan <[email protected]>Reviewed-by Dragos Tatulea <[email protected]>--- drivers/net/ethernet/mellanox/mlx5/core/en.h | 4 +++- drivers/net/ethernet/mellanox/mlx5/core/en_main.c | 12 +++++++----- 2 files changed, 10 insertions(+), 6 deletions(-)
Tariq Toukan
maintainerPATCH 2/3 net/mlx5e: RX, Pre-calculate pad value in MPWQE
In reply to Tariq ToukanIntroduce a dedicated function that calculates the needed entries padding in a UMR WQE.
Use it to pre-calculate the padding value and save it on the RQ struct.
--- drivers/net/ethernet/mellanox/mlx5/core/en.h | 1 + drivers/net/ethernet/mellanox/mlx5/core/en_main.c | 14 ++++++++++++++ drivers/net/ethernet/mellanox/mlx5/core/en_rx.c | 8 ++------ 3 files changed, 17 insertions(+), 6 deletions(-)
drivers/net/ethernet/mellanox/mlx5/core/en.h +1 -0
@@ -685,6 +685,7 @@ struct mlx5e_rq {u8 min_wqe_bulk;u8 page_shift;u8 pages_per_wqe; +u8 entries_pad;u8 umr_wqebbs;u8 mtts_per_wqe;u8 umr_mode;
drivers/net/ethernet/mellanox/mlx5/core/en_main.c +14 -0
@@ -307,6 +307,17 @@ static void mlx5e_disable_blocking_events(struct mlx5e_priv *priv)mlx5_blocking_notifier_unregister (priv->mdev, &priv->blocking_events_nb); } +static u8 mlx5e_mpwrq_umr_entries_pad (u32 entries, +enum mlx5e_mpwrq_umr_mode umr_mode) +{ +u8 umr_entry_size =mlx5e_mpwrq_umr_entry_size (umr_mode); +u32 sz; + + sz = entries * umr_entry_size; + +return ALIGN (sz,MLX5_UMR_FLEX_ALIGNMENT ) - sz; +} +static u16 mlx5e_mpwrq_umr_octowords (u32 entries,enum mlx5e_mpwrq_umr_mode umr_mode) {u8 umr_entry_size =mlx5e_mpwrq_umr_entry_size (umr_mode);
@@ -904,6 +915,9 @@ static int mlx5e_alloc_rq(struct mlx5e_params *params, rq->mpwqe.pages_per_wqe =mlx5e_mpwrq_pages_per_wqe (mdev, rq->mpwqe.page_shift, rq->mpwqe.umr_mode); + rq->mpwqe.entries_pad = +mlx5e_mpwrq_umr_entries_pad (rq->mpwqe.pages_per_wqe, + rq->mpwqe.umr_mode); rq->mpwqe.umr_wqebbs =mlx5e_mpwrq_umr_wqebbs (mdev, rq->mpwqe.page_shift, rq->mpwqe.umr_mode);
drivers/net/ethernet/mellanox/mlx5/core/en_rx.c +2 -6
@@ -645,13 +645,9 @@ static int mlx5e_alloc_rx_mpwqe(struct mlx5e_rq *rq, u16 ix)/* Pad if needed, in case the value set to ucseg->xlt_octowords * in mlx5e_build_umr_wqe() needed alignment. */ -if (rq->mpwqe.pages_per_wqe & (MLX5_UMR_MTT_NUM_ENTRIES_ALIGNMENT -1 )) { -int pad =ALIGN (rq->mpwqe.pages_per_wqe,MLX5_UMR_MTT_NUM_ENTRIES_ALIGNMENT ) - - rq->mpwqe.pages_per_wqe; - +if (rq->mpwqe.entries_pad)memset (&umr_wqe->inline_mtts[rq->mpwqe.pages_per_wqe],0 , -sizeof (*umr_wqe->inline_mtts) * pad); - } + rq->mpwqe.entries_pad);bitmap_zero (wi->skip_release_bitmap, rq->mpwqe.pages_per_wqe); wi->consumed_strides =0 ;
Signature · 1 line
2.44.0
Re: [PATCH net-next 2/3] net/mlx5e: RX, Pre-calculate pad value in MPWQE
Quoted 11 lines · Tariq Toukan
Introduce a dedicated function that calculates the needed entries padding in a UMR WQE.
Use it to pre-calculate the padding value and save it on the RQ struct.Signed-off-by Tariq Toukan <[email protected]>Reviewed-by Dragos Tatulea <[email protected]>--- drivers/net/ethernet/mellanox/mlx5/core/en.h | 1 + drivers/net/ethernet/mellanox/mlx5/core/en_main.c | 14 ++++++++++++++ drivers/net/ethernet/mellanox/mlx5/core/en_rx.c | 8 ++------ 3 files changed, 17 insertions(+), 6 deletions(-)
Tariq Toukan
maintainerPATCH 3/3 net/mlx5e: Speed up channel creation by initializing MKEY entries via UMR WQE
In reply to Tariq ToukanInitializing all UMR MKEY entries as part of the CREATE_MKEY firmware command is relatively slow. Since this operation is performed per RQ, the cumulative latency becomes significant with a large number of queues.
Move the entries initialization out of the CREATE_MKEY command and perform it in the fast path by posting an appropriate UMR WQE on the ICOSQ.
The UMR WQE is prepared and written to the ICOSQ before activation, making it safe without additional locking, as it does not race with NOP postings or early NAPI refills.
Performance results:
Setup: 248 channels, MTU 9000, RX/TX ring size 8K.
Interface up:
Before: 5.618 secs After: 3.537 secs (2.081 secs faster)
Saves ~8.4 msec per channel.
--- drivers/net/ethernet/mellanox/mlx5/core/en.h | 6 + .../net/ethernet/mellanox/mlx5/core/en/txrx.h | 1 + .../net/ethernet/mellanox/mlx5/core/en_main.c | 237 +++++++++++++----- .../net/ethernet/mellanox/mlx5/core/en_rx.c | 1 + 4 files changed, 185 insertions(+), 60 deletions(-)
drivers/net/ethernet/mellanox/mlx5/core/en.h +6 -0
@@ -247,6 +247,7 @@ struct mlx5e_umr_wqe { DECLARE_FLEX_ARRAY(struct mlx5_mtt, inline_mtts); DECLARE_FLEX_ARRAY(struct mlx5_klm, inline_klms); DECLARE_FLEX_ARRAY(struct mlx5_ksm, inline_ksms); + DECLARE_FLEX_ARRAY(struct mlx5_wqe_data_seg, dseg); }; }; static_assert(offsetof(struct mlx5e_umr_wqe, inline_mtts) == sizeof(struct mlx5e_umr_wqe_hdr),
@@ -747,6 +748,11 @@ struct mlx5e_rq {struct mlx5e_dma_info wqe_overflow;struct {__be32 umr_mkey_be; +struct { +void *p_unaligned; +int sz; +dma_addr_t addr; + } init_data; } mpwqe_sp;/* XDP read-mostly */
drivers/net/ethernet/mellanox/mlx5/core/en/txrx.h +1 -0
@@ -64,6 +64,7 @@ ktime_t mlx5e_cqe_ts_to_ns(cqe_ts_to_ns func, struct mlx5_clock *clock, u64 cqe_enum mlx5e_icosq_wqe_type {MLX5E_ICOSQ_WQE_NOP , +MLX5E_ICOSQ_WQE_UMR_RX_INIT ,MLX5E_ICOSQ_WQE_UMR_RX ,#ifdef CONFIG_MLX5_EN_TLS MLX5E_ICOSQ_WQE_UMR_TLS ,
drivers/net/ethernet/mellanox/mlx5/core/en_main.c +177 -60
319 lines not on this page · raw message
drivers/net/ethernet/mellanox/mlx5/core/en_rx.c +1 -0
@@ -837,6 +837,7 @@ int mlx5e_poll_ico_cq(struct mlx5e_cq *cq) wi->umr.rq->mpwqe.umr_completed++;break ;case MLX5E_ICOSQ_WQE_NOP : +case MLX5E_ICOSQ_WQE_UMR_RX_INIT :break ;#ifdef CONFIG_MLX5_EN_TLS case MLX5E_ICOSQ_WQE_UMR_TLS :
Signature · 1 line
2.44.0
Jakub Kicinski
maintainerRe: [PATCH net-next 3/3] net/mlx5e: Speed up channel creation by initializing MKEY entries via UMR WQE
Quoted 9 lines · On Thu, 19 Mar 2026 09:43:38 +0200 Tariq Toukan wrote:
Initializing all UMR MKEY entries as part of the
CREATE_MKEYfirmware command is relatively slow. Since this operation is performed per RQ, the cumulative latency becomes significant with a large number of queues.Move the entries initialization out of the
CREATE_MKEYcommand and perform it in the fast path by posting an appropriate UMR WQE on the ICOSQ.
Quoted 6 lines
The UMR WQE is prepared and written to the ICOSQ before activation, making it safe without additional locking, as it does not race with NOP postings or early NAPI refills.
Performance results:
Setup: 248 channels, MTU 9000, RX/TX ring size 8K.
AI says:
drivers/net/ethernet/mellanox/mlx5/core/en_main.c static u8 mlx5e_mpwrq_access_mode(enum mlx5e_mpwrq_umr_mode umr_mode) · line 406
Quoted 13 lines
drivers/net/ethernet/mellanox/mlx5/core/en_main.c +10
-1@@ -397,57 +396,61 @@ static u8 mlx5e_mpwrq_access_mode(enum mlx5e_mpwrq_umr_mode umr_mode) +static int mlx5e_rq_umr_mkey_data_alloc (struct mlx5e_rq *rq,u32 npages, +struct mlx5_wqe_data_seg *dseg) +{ +dma_addr_t data_addr; +int data_sz; +void *data; - octwords =mlx5e_mpwrq_umr_octowords (npages, umr_mode); + data_sz =mlx5e_mpwrq_umr_octowords (npages, rq->mpwqe.umr_mode) * +MLX5_OCTWORD ; + rq->mpwqe_sp.init_data.p_unaligned = +kzalloc (data_sz +MLX5_UMR_ALIGN -1 ,GFP_KERNEL );
Is this allocation safe for large setups?
For setups with large ring sizes like 8K WQEs in OVERSIZED mode, the data size can reach 256KB to 1MB. Requesting physically contiguous high-order allocations across many channels during interface bring-up might fail on memory-fragmented systems.
Should this continue to fall back to vmalloc like the previous kvzalloc code did?
Quoted 28 lines
drivers/net/ethernet/mellanox/mlx5/core/en_main.c +27
-0@@ -455,48 +458,152 @@ static int mlx5e_create_umr_mkey(struct mlx5_core_dev *mdev, +static int mlx5e_rq_umr_mkey_data_init (struct mlx5e_rq *rq,u32 npages) +{ +struct mlx5_wqe_ctrl_seg *cseg; +struct mlx5_wqe_umr_ctrl_seg *ucseg; +struct mlx5e_icosq *sq = rq->icosq; +struct mlx5e_umr_wqe *umr_wqe; +u16 pi, num_wqebbs, octowords; +u8 ds_cnt; +int err; + +/* + 1 for the data segment */ + ds_cnt =1 +DIV_ROUND_UP (offsetof(struct mlx5e_umr_wqe , dseg), +MLX5_SEND_WQE_DS ); + num_wqebbs =DIV_ROUND_UP (ds_cnt,MLX5_SEND_WQEBB_NUM_DS ); + pi =mlx5e_icosq_get_next_pi (sq, num_wqebbs); + umr_wqe =mlx5_wq_cyc_get_wqe (&sq->wq, pi); +memset (umr_wqe,0 , num_wqebbs *MLX5_SEND_WQE_BB ); + + cseg = &umr_wqe->hdr.ctrl; + ucseg = &umr_wqe->hdr.uctrl; + + cseg->opmod_idx_opcode = +cpu_to_be32 ((sq->pc <<MLX5_WQE_CTRL_WQE_INDEX_SHIFT ) | +MLX5_OPCODE_UMR ); + cseg->qpn_ds =cpu_to_be32 ((sq->sqn <<MLX5_WQE_CTRL_QPN_SHIFT ) | + ds_cnt); + cseg->umr_mkey = rq->mpwqe_sp.umr_mkey_be;
drivers/net/ethernet/mellanox/mlx5/core/en_main.c static int mlx5e_create_umr_mkey(struct mlx5_core_dev *mdev, · line 494
Quoted 10 lines
drivers/net/ethernet/mellanox/mlx5/core/en_main.c +10
-0+ + octowords =mlx5e_mpwrq_umr_octowords (npages, rq->mpwqe.umr_mode); + ucseg->xlt_octowords =cpu_to_be16 (octowords); + ucseg->mkey_mask =cpu_to_be64 (MLX5_MKEY_MASK_FREE ); + + err =mlx5e_rq_umr_mkey_data_alloc (rq, npages, umr_wqe->dseg); +if (err) +return err; + +mlx5e_rq_umr_mkey_data_fill (rq, npages);
Could this sequence violate DMA coherency rules?
The buffer is mapped to the device with dma_map_single inside mlx5e_rq_umr_mkey_data_alloc, but then mlx5e_rq_umr_mkey_data_fill writes the MKEY translation data into the buffer.
On architectures without hardware cache coherency, the CPU writes might remain in the cache, causing the NIC to read stale memory instead of the actual MKEY data.
drivers/net/ethernet/mellanox/mlx5/core/en_main.c static int mlx5e_create_umr_mkey(struct mlx5_core_dev *mdev, · line 563
Quoted 10 lines
drivers/net/ethernet/mellanox/mlx5/core/en_main.c +10
-0+ + sq->db.wqe_info[pi] = (struct mlx5e_icosq_wqe_info ) { + .wqe_type =MLX5E_ICOSQ_WQE_UMR_RX_INIT , + .num_wqebbs = num_wqebbs, + .umr.rq = rq, + }; + + sq->pc += num_wqebbs; + + sq->doorbell_cseg = cseg;
Can this leave a stale pointer in sq->doorbell_cseg?
If a NOP WQE is later pushed to the ICOSQ but fails to clear this pointer, and a subsequent allocation error occurs during the first iteration of mlx5e_post_rx_mpwqes, the error path might use this stale doorbell_cseg. Modifying an already-executed WQE could desynchronize the queue and stall the ICOSQ.
Quoted 16 lines
drivers/net/ethernet/mellanox/mlx5/core/en_main.c +2
-3@@ -505,7 +612,6 @@ static int mlx5e_create_umr_mkey(struct mlx5_core_dev *mdev,static int mlx5e_create_rq_umr_mkey (struct mlx5_core_dev *mdev,struct mlx5e_rq *rq) { -u32 xsk_chunk_size = rq->xsk_pool ? rq->xsk_pool->chunk_size :0 ;u32 wq_size =mlx5_wq_ll_get_size (&rq->mpwqe.wq);u32 num_entries, max_num_entries;u32 umr_mkey;@@ -522,9 +628,16 @@ static int mlx5e_create_rq_umr_mkey(struct mlx5_core_dev *mdev, struct mlx5e_rq max_num_entries); err =mlx5e_create_umr_mkey (mdev, num_entries, rq->mpwqe.page_shift, - &umr_mkey, rq->wqe_overflow.addr, - rq->mpwqe.umr_mode, xsk_chunk_size); + &umr_mkey, rq->mpwqe.umr_mode); +if (err)
drivers/net/ethernet/mellanox/mlx5/core/en_main.c static int mlx5e_create_rq_umr_mkey(struct mlx5_core_dev *mdev, struct mlx5e_rq · line 642
Quoted 10 lines
drivers/net/ethernet/mellanox/mlx5/core/en_main.c +7
-0+return err; + rq->mpwqe_sp.umr_mkey_be =cpu_to_be32 (umr_mkey); + + err =mlx5e_rq_umr_mkey_data_init (rq, num_entries); +if (err) +mlx5_core_destroy_mkey (mdev, umr_mkey); +return err; }
Does this code leak the initialization data and DMA mapping if a failure happens later during queue creation?
If mlx5e_create_rq_umr_mkey completes successfully, but the broader mlx5e_alloc_rq fails on a subsequent step like page pool creation, the teardown seems to miss calling mlx5e_rq_umr_mkey_data_free for the newly allocated buffer.
drivers/net/ethernet/mellanox/mlx5/core/en_main.c int mlx5e_wait_for_min_rx_wqes(struct mlx5e_rq *rq, int wait_time) · line 1399
Quoted 13 lines
drivers/net/ethernet/mellanox/mlx5/core/en_main.c +4
-1@@ -1275,8 +1389,11 @@ int mlx5e_wait_for_min_rx_wqes(struct mlx5e_rq *rq, int wait_time)u16 min_wqes =mlx5_min_rx_wqes (rq->wq_type,mlx5e_rqwq_get_size (rq));do { -if (mlx5e_rqwq_get_cur_sz (rq) >= min_wqes) +if (mlx5e_rqwq_get_cur_sz (rq) >= min_wqes) { +/* memory usage completed, can be freed already */ +mlx5e_rq_umr_mkey_data_free (rq);return 0 ; + }msleep (20 ); }while (time_before (jiffies, exp_time));
Does this prematurely free the initialization buffer?
The condition checking that cur_sz is greater than min_wqes tracks the CPU's NAPI thread pushing RX WQEs to the RQ, but it does not appear to guarantee that the hardware has actually finished executing the asynchronous MLX5E_ICOSQ_WQE_UMR_RX_INIT WQE on the ICOSQ.
If unmapped and freed while the NIC DMA engine is still fetching the data, could this result in a DMA use-after-free and potential IOMMU faults?
Quoted 17 lines · Tariq Toukan
Hi,
This series improves channel creation time by moving per-channel MKEY initialization from a slow-path FW command to a fast-path UMR WQE.
The benefit becomes more significant with larger MKEYs and a higher number of channels.
On my setup with the maximum configuration (248 channels, MTU 9000, RX/TX ring size 8K), the "interface up" operation is 2.081 seconds faster:
Before: 5.618 seconds After: 3.537 secondsThis corresponds to ~8.4 msec saved per channel.
Quoted 8 lines
Regards,
TariqTariq Toukan (3):
net/mlx5e: Move RX MPWQE slowpath fields into a separate struct net/mlx5e: RX, Pre-calculate pad value in MPWQE
net/mlx5e: Speed up channel creation by initializing MKEY entries via
UMR WQE
Thanks,
For the series: