mlx5 xsk updates part2 2022-09-28
Subsystems (6)
PATCH 1/16 xsk: Expose min chunk size to drivers
In reply to Saeed MahameedFrom: Maxim Mikityanskiy <[email protected]>
Drivers should be aware of the range of valid UMEM chunk sizes to be able to allocate their internal structures of an appropriate size. It will be used by mlx5e in the following patches.
--- include/net/xdp_sock_drv.h | 3 +++ net/xdp/xdp_umem.c | 2 -- 2 files changed, 3 insertions(+), 2 deletions(-)
include/net/xdp_sock_drv.h +3 -0
@@ -9,6 +9,9 @@#include <net/xdp_sock.h> #include <net/xsk_buff_pool.h> +#define XDP_UMEM_MIN_CHUNK_SHIFT 11 +#define XDP_UMEM_MIN_CHUNK_SIZE (1 << XDP_UMEM_MIN_CHUNK_SHIFT) +#ifdef CONFIG_XDP_SOCKETS void xsk_tx_completed (struct xsk_buff_pool *pool,u32 nb_entries);
net/xdp/xdp_umem.c +0 -2
@@ -19,8 +19,6 @@#include "xdp_umem.h" #include "xsk_queue.h" -#define XDP_UMEM_MIN_CHUNK_SIZE 2048 -static DEFINE_IDA (umem_ida);static void xdp_umem_unpin_pages (struct xdp_umem *umem)
Signature · 1 line
2.37.3
cover mlx5 xsk updates part2 2022-09-28
From: Saeed Mahameed <[email protected]>
XSK buffer improvements, This is part #2 of 4 parts series.
1) Expose xsk min chunk size to drivers, to allow the driver to adjust to a better buffer stride size
2) Adjust MTT page size to the XSK frame size, to avoid umem overrun in certain situations.
3) Use xsk frame size as the striding RQ page size for XSK RQs
4) KSM for unaligned XSK, KSM allows arbitrary buffer chunk lengths registration in HW, which makes more sense for unaligned XSK.
4) More cleanups and optimizations in preparation for next improvements in part3
part 1: https://lore.kernel.org/netdev/[email protected]/
Thanks,
Saeed.
Maxim Mikityanskiy (16):
xsk: Expose min chunk size to drivers
net/mlx5e: Use runtime page_shift for striding RQ net/mlx5e: xsk: Use XSK frame size as striding RQ page size net/mlx5e: Keep a separate MKey for striding RQ
net/mlx5: Add MLX5_FLEXIBLE_INLEN to safely calculate cmd inlen net/mlx5e: xsk: Use KSM for unaligned XSK
xsk: Remove unused xsk_buff_discard
net/mlx5e: Fix calculations for ICOSQ size
net/mlx5e: Optimize the page cache reducing its size 2x net/mlx5e: Rename mlx5e_dma_info to prepare for removal of DMA address net/mlx5e: Remove DMA address from mlx5e_alloc_unit net/mlx5e: Convert struct mlx5e_alloc_unit to a union net/mlx5e: xsk: Remove mlx5e_xsk_page_alloc_pool net/mlx5e: Split out channel (de)activation in rx_res net/mlx5e: Move repeating clear_bit in
mlx5e_rx_reporter_err_rq_cqe_recover
net/mlx5e: Clean up and fix error flows in mlx5e_alloc_rq
drivers/net/ethernet/mellanox/mlx5/core/en.h | 72 +++-- .../ethernet/mellanox/mlx5/core/en/params.c | 299 +++++++++++++++--- .../ethernet/mellanox/mlx5/core/en/params.h | 17 +- .../mellanox/mlx5/core/en/reporter_rx.c | 7 +- .../ethernet/mellanox/mlx5/core/en/rx_res.c | 106 +++---- .../ethernet/mellanox/mlx5/core/en/xsk/pool.c | 1 + .../ethernet/mellanox/mlx5/core/en/xsk/rx.c | 4 +- .../ethernet/mellanox/mlx5/core/en/xsk/rx.h | 31 -- .../mellanox/mlx5/core/en/xsk/setup.c | 13 +- .../ethernet/mellanox/mlx5/core/en_ethtool.c | 8 +- .../net/ethernet/mellanox/mlx5/core/en_main.c | 188 +++++++---- .../net/ethernet/mellanox/mlx5/core/en_rx.c | 253 +++++++++------ .../ethernet/mellanox/mlx5/core/mlx5_core.h | 30 ++ include/linux/mlx5/qp.h | 8 + include/net/xdp_sock_drv.h | 10 +- net/xdp/xdp_umem.c | 2 - 16 files changed, 683 insertions(+), 366 deletions(-)
Signature · 1 line
2.37.3
PATCH 3/16 net/mlx5e: xsk: Use XSK frame size as striding RQ page size
From: Maxim Mikityanskiy <[email protected]>
XSK RQs support striding RQ linear mode, but the stride size is always set to PAGE_SIZE. It may be larger than the XSK frame size, unnecessarily reducing the useful space in a WQE, but more importantly causing UMEM data corruption in certain cases.
Normally, stride size bigger than XSK frame size is not a problem if the hardware enforces the MTU. However, traffic between vports skips the hardware MTU check, and oversized packets may be received.
If an oversized packet is bigger than the XSK frame but not bigger than the stride, it will cause overwriting of the adjacent UMEM region. If the packet takes more than one stride, they can be recycled for reuse so it's not a problem when the XSK frame size matches the stride size.
To reduce the impact of the above issue, attempt to use the MTT page size for striding RQ that matches the XSK frame size, allowing to safely use 2048-byte frames on an up-to-date firmware.
--- .../ethernet/mellanox/mlx5/core/en/params.c | 37 ++++++++++++++++--- 1 file changed, 31 insertions(+), 6 deletions(-)
drivers/net/ethernet/mellanox/mlx5/core/en/params.c +31 -6
@@ -6,6 +6,7 @@#include "en/port.h" #include "en_accel/en_accel.h" #include "en_accel/ipsec.h" +#include <net/xdp_sock_drv.h> static u8 mlx5e_mpwrq_min_page_shift (struct mlx5_core_dev *mdev) {
@@ -16,8 +17,8 @@ static u8 mlx5e_mpwrq_min_page_shift(struct mlx5_core_dev *mdev)u8 mlx5e_mpwrq_page_shift (struct mlx5_core_dev *mdev,struct mlx5e_xsk_param *xsk) { +u8 req_page_shift = xsk ?order_base_2 (xsk->chunk_size) :PAGE_SHIFT ;u8 min_page_shift =mlx5e_mpwrq_min_page_shift (mdev); -u8 req_page_shift =PAGE_SHIFT ;/* Regular RQ uses order-0 pages, the NIC must be able to map them. */ if (WARN_ON_ONCE (!xsk && req_page_shift < min_page_shift))
@@ -933,12 +934,36 @@ static u8 mlx5e_build_icosq_log_wq_sz(struct mlx5_core_dev *mdev,/* If XDP program is attached, XSK may be turned on at any time without * restarting the channel. ICOSQ must be big enough to fit UMR WQEs of * both regular RQ and XSK RQ. -* Although mlx5e_mpwqe_get_log_rq_size accepts mlx5e_xsk_param, it -* doesn't affect its return value, as long as params->xdp_prog != NULL, -* so we can just multiply by 2. +* +* XSK uses different values of page_shift, and the total number of UMR +* WQEBBs depends on it. This dependency is complex and not monotonic, +* especially taking into consideration that some of the parameters come +* from capabilities. Hence, we have to try all valid values of XSK +* frame size (and page_shift) to find the maximum. */ -if (params->xdp_prog) - wqebbs *=2 ; +if (params->xdp_prog) { +u32 max_xsk_wqebbs =0 ; +u8 frame_shift; + +for (frame_shift =XDP_UMEM_MIN_CHUNK_SHIFT ; + frame_shift <=PAGE_SHIFT ; frame_shift++) { +/* The headroom doesn't affect the calculation. */ +struct mlx5e_xsk_param xsk = { + .chunk_size =1 << frame_shift, + }; +u32 xsk_wqebbs; +u8 page_shift; + + page_shift =mlx5e_mpwrq_page_shift (mdev, &xsk); + xsk_wqebbs =mlx5e_mpwrq_umr_wqebbs (mdev, page_shift) * + (1 <<mlx5e_mpwqe_get_log_rq_size (mdev, params, &xsk)); + +if (xsk_wqebbs > max_xsk_wqebbs) + max_xsk_wqebbs = xsk_wqebbs; + } + + wqebbs += max_xsk_wqebbs; + }if (params->packet_merge.type ==MLX5E_PACKET_MERGE_SHAMPO ) wqebbs +=mlx5e_shampo_icosq_sz (mdev, params, rqp);
Signature · 1 line
2.37.3
PATCH 5/16 net/mlx5: Add MLX5_FLEXIBLE_INLEN to safely calculate cmd inlen
In reply to Saeed MahameedFrom: Maxim Mikityanskiy <[email protected]>
Some commands use a flexible array after a common header. Add a macro to safely calculate the total input length of the command, detecting overflows and printing errors with specific values when such overflows happen.
--- .../ethernet/mellanox/mlx5/core/mlx5_core.h | 30 +++++++++++++++++++ 1 file changed, 30 insertions(+)
drivers/net/ethernet/mellanox/mlx5/core/mlx5_core.h +30 -0
@@ -143,6 +143,36 @@ enum mlx5_semaphore_space_address {#define MLX5_DEFAULT_PROF 2 +static inline int mlx5_flexible_inlen (struct mlx5_core_dev *dev,size_t fixed, +size_t item_size,size_t num_items, +const char *func,int line) +{ +int inlen; + +if (fixed >INT_MAX || item_size >INT_MAX || num_items >INT_MAX ) { +mlx5_core_err (dev,"%s: %s:%d: input values too big: %zu + %zu * %zu\n" , + __func__, func, line, fixed, item_size, num_items); +return -ENOMEM ; + } + +if (check_mul_overflow ((int )item_size, (int )num_items, &inlen)) { +mlx5_core_err (dev,"%s: %s:%d: multiplication overflow: %zu + %zu * %zu\n" , + __func__, func, line, fixed, item_size, num_items); +return -ENOMEM ; + } + +if (check_add_overflow ((int )fixed, inlen, &inlen)) { +mlx5_core_err (dev,"%s: %s:%d: addition overflow: %zu + %zu * %zu\n" , + __func__, func, line, fixed, item_size, num_items); +return -ENOMEM ; + } + +return inlen; +} + +#define MLX5_FLEXIBLE_INLEN (dev, fixed, item_size, num_items) \ + mlx5_flexible_inlen(dev, fixed, item_size, num_items, __func__, __LINE__) +int mlx5_query_hca_caps (struct mlx5_core_dev *dev);int mlx5_query_board_id (struct mlx5_core_dev *dev);int mlx5_cmd_init (struct mlx5_core_dev *dev);
Signature · 1 line
2.37.3
PATCH 2/16 net/mlx5e: Use runtime page_shift for striding RQ
In reply to Saeed MahameedFrom: Maxim Mikityanskiy <[email protected]>
This commit allows striding RQ to determine MTT page size at runtime, instead of sticking to the compile-time PAGE_SIZE. This functionality will be used by a following commit that adjusts the MTT page size to the XSK frame size.
Stick with PAGE_SIZE for XSK on legacy RQ, as frag_stride is not used in data path, it only helps calculate how pages are partitioned into fragments, and PAGE_SIZE will ensure each fragment starts at the beginning of a new allocation unit (XSK frame).
--- drivers/net/ethernet/mellanox/mlx5/core/en.h | 41 ++-- .../ethernet/mellanox/mlx5/core/en/params.c | 198 +++++++++++++++--- .../ethernet/mellanox/mlx5/core/en/params.h | 15 +- .../mellanox/mlx5/core/en/xsk/setup.c | 13 +- .../ethernet/mellanox/mlx5/core/en_ethtool.c | 8 +- .../net/ethernet/mellanox/mlx5/core/en_main.c | 55 ++--- .../net/ethernet/mellanox/mlx5/core/en_rx.c | 4 +- include/linux/mlx5/qp.h | 2 + 8 files changed, 242 insertions(+), 94 deletions(-)
drivers/net/ethernet/mellanox/mlx5/core/en.h +20 -21
@@ -93,28 +93,28 @@ struct page_pool;#define MLX5_MPWRQ_DEF_LOG_STRIDE_SZ (mdev) \ MLX5_MPWRQ_LOG_STRIDE_SZ(mdev, order_base_2(MLX5E_RX_MAX_HEAD)) -#define MLX5_MPWRQ_LOG_WQE_SZ 18 -#define MLX5_MPWRQ_WQE_PAGE_ORDER (MLX5_MPWRQ_LOG_WQE_SZ - PAGE_SHIFT > 0 ? \ - MLX5_MPWRQ_LOG_WQE_SZ - PAGE_SHIFT : 0) -#define MLX5_MPWRQ_PAGES_PER_WQE BIT(MLX5_MPWRQ_WQE_PAGE_ORDER) +#define MLX5_MPWRQ_MAX_LOG_WQE_SZ 18 + +/* Keep in sync with mlx5e_mpwrq_log_wqe_sz. +* These are theoretical maximums, which can be further restricted by +* capabilities. These values are used for static resource allocations and +* sanity checks. +* MLX5_SEND_WQE_MAX_SIZE is a bit bigger than the maximum cacheline-aligned WQE +* size actually used at runtime, but it's not a problem when calculating static +* array sizes. +*/ +#define MLX5_UMR_MAX_MTT_SPACE \ + (ALIGN_DOWN(MLX5_SEND_WQE_MAX_SIZE - sizeof(struct mlx5e_umr_wqe), \ + MLX5_UMR_MTT_ALIGNMENT)) +#define MLX5_MPWRQ_MAX_PAGES_PER_WQE \ + rounddown_pow_of_two(MLX5_UMR_MAX_MTT_SPACE / sizeof(struct mlx5_mtt))#define MLX5_ALIGN_MTTS (mtts) (ALIGN(mtts, 8))#define MLX5_ALIGNED_MTTS_OCTW (mtts) ((mtts) / 2)#define MLX5_MTT_OCTW (mtts) (MLX5_ALIGNED_MTTS_OCTW(MLX5_ALIGN_MTTS(mtts))) -/* Add another page to MLX5E_REQUIRED_WQE_MTTS as a buffer between -* WQEs, This page will absorb write overflow by the hardware, when -* receiving packets larger than MTU. These oversize packets are -* dropped by the driver at a later stage. -*/ -#define MLX5E_REQUIRED_WQE_MTTS (MLX5_ALIGN_MTTS(MLX5_MPWRQ_PAGES_PER_WQE + 1))#define MLX5E_MAX_RQ_NUM_MTTS \ (ALIGN_DOWN(U16_MAX, 4) * 2)/* So that MLX5_MTT_OCTW(num_mtts) fits into u16 */ #define MLX5E_ORDER2_MAX_PACKET_MTU (order_base_2(10 * 1024)) -#define MLX5E_PARAMS_MAXIMUM_LOG_RQ_SIZE_MPW \ - (ilog2(MLX5E_MAX_RQ_NUM_MTTS / MLX5E_REQUIRED_WQE_MTTS)) -#define MLX5E_LOG_MAX_RQ_NUM_PACKETS_MPW \ - (MLX5E_PARAMS_MAXIMUM_LOG_RQ_SIZE_MPW + \ - (MLX5_MPWRQ_LOG_WQE_SZ - MLX5E_ORDER2_MAX_PACKET_MTU))#define MLX5E_MIN_SKB_FRAG_SZ (MLX5_SKB_FRAG_SZ(MLX5_RX_HEADROOM))#define MLX5E_LOG_MAX_RX_WQE_BULK \
@@ -126,8 +126,7 @@ struct page_pool;#define MLX5E_PARAMS_MINIMUM_LOG_RQ_SIZE (1 + MLX5E_LOG_MAX_RX_WQE_BULK)#define MLX5E_PARAMS_DEFAULT_LOG_RQ_SIZE 0xa -#define MLX5E_PARAMS_MAXIMUM_LOG_RQ_SIZE min_t(u8, 0xd, \ - MLX5E_LOG_MAX_RQ_NUM_PACKETS_MPW) +#define MLX5E_PARAMS_MAXIMUM_LOG_RQ_SIZE 0xd#define MLX5E_PARAMS_MINIMUM_LOG_RQ_SIZE_MPW 0x2
@@ -613,7 +612,7 @@ struct mlx5e_wqe_frag_info {struct mlx5e_mpw_info {u16 consumed_strides; - DECLARE_BITMAP(xdp_xmit_bitmap, MLX5_MPWRQ_PAGES_PER_WQE); + DECLARE_BITMAP(xdp_xmit_bitmap, MLX5_MPWRQ_MAX_PAGES_PER_WQE);struct mlx5e_dma_info dma_info[]; };
@@ -622,8 +621,8 @@ struct mlx5e_mpw_info {/* a single cache unit is capable to serve one napi call (for non-striding rq) * or a MPWQE (for striding rq). */ -#define MLX5E_CACHE_UNIT (MLX5_MPWRQ_PAGES_PER_WQE > NAPI_POLL_WEIGHT ? \ - MLX5_MPWRQ_PAGES_PER_WQE : NAPI_POLL_WEIGHT) +#define MLX5E_CACHE_UNIT (MLX5_MPWRQ_MAX_PAGES_PER_WQE > NAPI_POLL_WEIGHT ? \ + MLX5_MPWRQ_MAX_PAGES_PER_WQE : NAPI_POLL_WEIGHT)#define MLX5E_CACHE_SIZE (4 * roundup_pow_of_two(MLX5E_CACHE_UNIT))struct mlx5e_page_cache {u32 head;
@@ -1008,7 +1007,7 @@ struct mlx5e_profile {void mlx5e_build_ptys2ethtool_map (void ); -bool mlx5e_check_fragmented_striding_rq_cap (struct mlx5_core_dev *mdev); +bool mlx5e_check_fragmented_striding_rq_cap (struct mlx5_core_dev *mdev,u8 page_shift);void mlx5e_shampo_dealloc_hd (struct mlx5e_rq *rq,u16 len,u16 start,bool close);void mlx5e_get_stats (struct net_device *dev,struct rtnl_link_stats64 *stats);
drivers/net/ethernet/mellanox/mlx5/core/en/params.c +164 -34
346 lines not on this page · raw message
drivers/net/ethernet/mellanox/mlx5/core/en/params.h +11 -4
@@ -86,8 +86,13 @@ static inline bool mlx5e_qid_validate(const struct mlx5e_profile *profile,/* Striding RQ dynamic parameters */ -u16 mlx5e_mpwrq_umr_wqe_sz (u8 pages_per_wqe); -u8 mlx5e_mpwrq_umr_wqebbs (u8 pages_per_wqe); +u8 mlx5e_mpwrq_page_shift (struct mlx5_core_dev *mdev,struct mlx5e_xsk_param *xsk); +u8 mlx5e_mpwrq_log_wqe_sz (struct mlx5_core_dev *mdev,u8 page_shift); +u8 mlx5e_mpwrq_pages_per_wqe (struct mlx5_core_dev *mdev,u8 page_shift); +u16 mlx5e_mpwrq_umr_wqe_sz (struct mlx5_core_dev *mdev,u8 page_shift); +u8 mlx5e_mpwrq_umr_wqebbs (struct mlx5_core_dev *mdev,u8 page_shift); +u8 mlx5e_mpwrq_mtts_per_wqe (struct mlx5_core_dev *mdev,u8 page_shift); +u8 mlx5e_mpwrq_max_log_rq_pkts (struct mlx5_core_dev *mdev,u8 page_shift);/* Parameter calculations */
@@ -106,12 +111,14 @@ void mlx5e_init_rq_type_params(struct mlx5_core_dev *mdev, struct mlx5e_params *u16 mlx5e_get_linear_rq_headroom (struct mlx5e_params *params,struct mlx5e_xsk_param *xsk); -bool mlx5e_rx_is_linear_skb (struct mlx5e_params *params, +bool mlx5e_rx_is_linear_skb (struct mlx5_core_dev *mdev, +struct mlx5e_params *params,struct mlx5e_xsk_param *xsk);bool mlx5e_rx_mpwqe_is_linear_skb (struct mlx5_core_dev *mdev,struct mlx5e_params *params,struct mlx5e_xsk_param *xsk); -u8 mlx5e_mpwqe_get_log_rq_size (struct mlx5e_params *params, +u8 mlx5e_mpwqe_get_log_rq_size (struct mlx5_core_dev *mdev, +struct mlx5e_params *params,struct mlx5e_xsk_param *xsk);u8 mlx5e_shampo_get_log_hd_entry_size (struct mlx5_core_dev *mdev,struct mlx5e_params *params);
drivers/net/ethernet/mellanox/mlx5/core/en/xsk/setup.c +6 -7
@@ -5,20 +5,19 @@#include "en/params.h" #include "en/txrx.h" #include "en/health.h" +#include <net/xdp_sock_drv.h> -/* It matches XDP_UMEM_MIN_CHUNK_SIZE, but as this constant is private and may -* change unexpectedly, and mlx5e has a minimum valid stride size for striding -* RQ, keep this check in the driver. +/* The limitation of 2048 can be altered, but shouldn't go beyond the minimal +* stride size of striding RQ. */ -#define MLX5E_MIN_XSK_CHUNK_SIZE 2048 +#define MLX5E_MIN_XSK_CHUNK_SIZE max(2048, XDP_UMEM_MIN_CHUNK_SIZE)bool mlx5e_validate_xsk_param (struct mlx5e_params *params,struct mlx5e_xsk_param *xsk,struct mlx5_core_dev *mdev) {/* AF_XDP doesn't support frames larger than PAGE_SIZE. */ -if (xsk->chunk_size >PAGE_SIZE || - xsk->chunk_size <MLX5E_MIN_XSK_CHUNK_SIZE ) +if (xsk->chunk_size >PAGE_SIZE || xsk->chunk_size <MLX5E_MIN_XSK_CHUNK_SIZE )return false;/* frag_sz is different for regular and XSK RQs, so ensure that linear
@@ -28,7 +27,7 @@ bool mlx5e_validate_xsk_param(struct mlx5e_params *params,case MLX5_WQ_TYPE_LINKED_LIST_STRIDING_RQ :return !mlx5e_mpwrq_validate_xsk (mdev, params, xsk);default :/* MLX5_WQ_TYPE_CYCLIC */ -return mlx5e_rx_is_linear_skb (params, xsk); +return mlx5e_rx_is_linear_skb (mdev, params, xsk); } }
drivers/net/ethernet/mellanox/mlx5/core/en_ethtool.c +7 -1
@@ -311,7 +311,13 @@ void mlx5e_ethtool_get_ringparam(struct mlx5e_priv *priv,struct ethtool_ringparam *param, struct kernel_ethtool_ringparam *kernel_param) { - param->rx_max_pending = 1 << MLX5E_PARAMS_MAXIMUM_LOG_RQ_SIZE; +/* Limitation for regular RQ. XSK RQ may clamp the queue length in +* mlx5e_mpwqe_get_log_rq_size. +*/ + u8 max_log_mpwrq_pkts = mlx5e_mpwrq_max_log_rq_pkts(priv->mdev, PAGE_SHIFT); + + param->rx_max_pending =1 <<min_t (u8,MLX5E_PARAMS_MAXIMUM_LOG_RQ_SIZE , + max_log_mpwrq_pkts); param->tx_max_pending =1 <<MLX5E_PARAMS_MAXIMUM_LOG_SQ_SIZE ; param->rx_pending =1 << priv->channels.params.log_rq_mtu_frames; param->tx_pending =1 << priv->channels.params.log_sq_size;
drivers/net/ethernet/mellanox/mlx5/core/en_main.c +30 -25
118 lines not on this page · raw message
drivers/net/ethernet/mellanox/mlx5/core/en_rx.c +2 -2
@@ -2431,7 +2431,7 @@ int mlx5e_rq_set_handlers(struct mlx5e_rq *rq, struct mlx5e_params *params, booldefault :/* MLX5_WQ_TYPE_CYCLIC */ rq->wqe.skb_from_cqe = xsk ? mlx5e_xsk_skb_from_cqe_linear : -mlx5e_rx_is_linear_skb (params,NULL ) ? +mlx5e_rx_is_linear_skb (mdev, params,NULL ) ? mlx5e_skb_from_cqe_linear : mlx5e_skb_from_cqe_nonlinear; rq->post_wqes = mlx5e_post_rx_wqes;
@@ -2485,7 +2485,7 @@ static void mlx5e_trap_handle_rx_cqe(struct mlx5e_rq *rq, struct mlx5_cqe64 *cqevoid mlx5e_rq_set_trap_handlers (struct mlx5e_rq *rq,struct mlx5e_params *params) { - rq->wqe.skb_from_cqe =mlx5e_rx_is_linear_skb (params,NULL ) ? + rq->wqe.skb_from_cqe =mlx5e_rx_is_linear_skb (rq->mdev, params,NULL ) ? mlx5e_skb_from_cqe_linear : mlx5e_skb_from_cqe_nonlinear; rq->post_wqes = mlx5e_post_rx_wqes;
include/linux/mlx5/qp.h +2 -0
@@ -162,6 +162,8 @@ enum { MLX5_SEND_WQE_MAX_WQEBBS = 16, }; +#define MLX5_SEND_WQE_MAX_SIZE (MLX5_SEND_WQE_MAX_WQEBBS * MLX5_SEND_WQE_BB) +enum {MLX5_WQE_FMR_PERM_LOCAL_READ =1 <<27 ,MLX5_WQE_FMR_PERM_LOCAL_WRITE =1 <<28 ,
Signature · 1 line
2.37.3
PATCH 4/16 net/mlx5e: Keep a separate MKey for striding RQ
In reply to Saeed MahameedFrom: Maxim Mikityanskiy <[email protected]>
Currently, rq->mkey_be keeps a big-endian value of either the PA MKey (for legacy RQ, no address translation) or MTT MKey (for striding RQ, direct address translation). Striding RQ stores the same value in rq->umr_mkey in the native endianness.
The next commit will make striding RQ use KSM MKey (indirect address translation) for the unaligned mode of XSK, which will require storing both KSM MKey and PA MKey in the RQ struct. This commit optimizes fields of mlx5e_rq: umr_mkey is removed (it's redundant), mkey_be always points to the PA MKey, and mpwqe.umr_mkey_be points to the MTT MKey (or to the KSM MKey, starting from the next commit).
--- drivers/net/ethernet/mellanox/mlx5/core/en.h | 2 +- .../net/ethernet/mellanox/mlx5/core/en_main.c | 21 +++++++++++-------- 2 files changed, 13 insertions(+), 10 deletions(-)
drivers/net/ethernet/mellanox/mlx5/core/en.h +1 -1
@@ -696,6 +696,7 @@ struct mlx5e_rq {struct mlx5e_umr_wqe 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;
@@ -757,7 +758,6 @@ struct mlx5e_rq {u32 rqn;struct mlx5_core_dev *mdev;struct mlx5e_channel *channel; -u32 umr_mkey;struct mlx5e_dma_info wqe_overflow;/* XDP read-mostly */
drivers/net/ethernet/mellanox/mlx5/core/en_main.c +12 -9
@@ -215,7 +215,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->mkey_be; + cseg->umr_mkey = rq->mpwqe.umr_mkey_be; ucseg->flags =MLX5_UMR_TRANSLATION_OFFSET_EN |MLX5_UMR_INLINE ; ucseg->xlt_octowords =
@@ -365,9 +365,13 @@ static int mlx5e_create_umr_klm_mkey(struct mlx5_core_dev *mdev,static int mlx5e_create_rq_umr_mkey (struct mlx5_core_dev *mdev,struct mlx5e_rq *rq) {u64 num_mtts =mlx5_wq_ll_get_size (&rq->mpwqe.wq) * rq->mpwqe.mtts_per_wqe; +u32 umr_mkey; +int err; -return mlx5e_create_umr_mtt_mkey (mdev, num_mtts, rq->mpwqe.page_shift, - &rq->umr_mkey, rq->wqe_overflow.addr); + err =mlx5e_create_umr_mtt_mkey (mdev, num_mtts, rq->mpwqe.page_shift, + &umr_mkey, rq->wqe_overflow.addr); + rq->mpwqe.umr_mkey_be =cpu_to_be32 (umr_mkey); +return err; } static int mlx5e_create_rq_hd_umr_mkey(struct mlx5_core_dev *mdev,
@@ -575,6 +579,8 @@ static int mlx5e_alloc_rq(struct mlx5e_params *params, rq->buff.headroom =mlx5e_get_rq_headroom (mdev, params, xsk); pool_size =1 << params->log_rq_mtu_frames; + rq->mkey_be =cpu_to_be32 (mdev->mlx5e_res.hw_objs.mkey); +switch (rq->wq_type) {case MLX5_WQ_TYPE_LINKED_LIST_STRIDING_RQ : err = mlx5_wq_ll_create(mdev, &rqp->wq, rqc_wq, &rq->mpwqe.wq,
@@ -611,7 +617,6 @@ static int mlx5e_alloc_rq(struct mlx5e_params *params, err =mlx5e_create_rq_umr_mkey (mdev, rq);if (err) goto err_rq_drop_page; - rq->mkey_be =cpu_to_be32 (rq->umr_mkey); err =mlx5e_rq_alloc_mpwqe_info (rq, node);if (err)
@@ -647,8 +652,6 @@ static int mlx5e_alloc_rq(struct mlx5e_params *params, err =mlx5e_init_di_list (rq, wq_sz, node);if (err) goto err_rq_frags; - - rq->mkey_be =cpu_to_be32 (mdev->mlx5e_res.hw_objs.mkey); }if (xsk) {
@@ -695,7 +698,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->mkey_be; + wqe->data[0 ].lkey = rq->mpwqe.umr_mkey_be; }else {struct mlx5e_rx_wqe_cyc *wqe =mlx5_wq_cyc_get_wqe (&rq->wqe.wq, i);
@@ -740,7 +743,7 @@ static int mlx5e_alloc_rq(struct mlx5e_params *params,case MLX5_WQ_TYPE_LINKED_LIST_STRIDING_RQ :kvfree (rq->mpwqe.info); err_rq_mkey: -mlx5_core_destroy_mkey (mdev, rq->umr_mkey); +mlx5_core_destroy_mkey (mdev,be32_to_cpu (rq->mpwqe.umr_mkey_be)); err_rq_drop_page:mlx5e_free_mpwqe_rq_drop_page (rq);break ;
@@ -773,7 +776,7 @@ static void mlx5e_free_rq(struct mlx5e_rq *rq)switch (rq->wq_type) {case MLX5_WQ_TYPE_LINKED_LIST_STRIDING_RQ :kvfree (rq->mpwqe.info); -mlx5_core_destroy_mkey (rq->mdev, rq->umr_mkey); +mlx5_core_destroy_mkey (rq->mdev,be32_to_cpu (rq->mpwqe.umr_mkey_be));mlx5e_free_mpwqe_rq_drop_page (rq);mlx5e_rq_free_shampo (rq);break ;
Signature · 1 line
2.37.3
PATCH 7/16 xsk: Remove unused xsk_buff_discard
In reply to Saeed MahameedFrom: Maxim Mikityanskiy <[email protected]>
The previous commit removed the last usage of xsk_buff_discard in mlx5e, so the function that is no longer used can be removed.
--- include/net/xdp_sock_drv.h | 7 ------- 1 file changed, 7 deletions(-)
include/net/xdp_sock_drv.h +0 -7
@@ -107,13 +107,6 @@ static inline void xsk_buff_free(struct xdp_buff *xdp)xp_free (xskb); } -static inline void xsk_buff_discard (struct xdp_buff *xdp) -{ - struct xdp_buff_xsk *xskb = container_of(xdp, struct xdp_buff_xsk, xdp); - -xp_release (xskb); -} -static inline void xsk_buff_set_size (struct xdp_buff *xdp,u32 size) { xdp->data = xdp->data_hard_start +XDP_PACKET_HEADROOM ;
Signature · 1 line
2.37.3
PATCH 8/16 net/mlx5e: Fix calculations for ICOSQ size
In reply to Saeed MahameedFrom: Maxim Mikityanskiy <[email protected]>
WQEs must not cross page boundaries, they are padded with NOPs if they don't fit the page. mlx5e_mpwrq_total_umr_wqebbs doesn't take into account this padding, risking reserving not enough space.
The padding is not straightforward to add to this calculation, because WQEs of different sizes may be mixed together in the queue. If each page ends with a big WQE that doesn't fit and requires at most its size minus 1 WQEBB of padding, the total space can be much bigger than in case when smaller WQEs take advantage of this padding.
Replace the wrong exact calculation by the following estimation. Each padding can be at most the size of the maximum WQE used in the queue minus one WQEBB. Let's call the rest of the page "useful space". If we divide the total size of all needed WQEs by this useful space, rounding up, we'll get the number of pages, which is enough to contain all these WQEs. It's correct, because every WQE that appeared on the boundary between two blocks of useful space would start in the useful space of one page and end in the padding of the same page, while our estimation reserved space for its tail in the next space, making the estimation not smaller than the real space occupied in the queue.
The code actually uses a looser estimation: instead of taking the maximum size of all used WQE types minus 1 WQEBB, it takes the maximum hardware size of a WQE. It's made for simplicity and extensibility.
--- .../net/ethernet/mellanox/mlx5/core/en/params.c | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-)
drivers/net/ethernet/mellanox/mlx5/core/en/params.c +13 -1
@@ -951,7 +951,7 @@ static u8 mlx5e_build_icosq_log_wq_sz(struct mlx5_core_dev *mdev,struct mlx5e_params *params, struct mlx5e_rq_param *rqp) { - u32 wqebbs; + u32 wqebbs, total_pages, useful_space;/* MLX5_WQ_TYPE_CYCLIC */ if (params->rq_wq_type !=MLX5_WQ_TYPE_LINKED_LIST_STRIDING_RQ )
@@ -998,6 +998,18 @@ static u8 mlx5e_build_icosq_log_wq_sz(struct mlx5_core_dev *mdev,if (params->packet_merge.type ==MLX5E_PACKET_MERGE_SHAMPO ) wqebbs +=mlx5e_shampo_icosq_sz (mdev, params, rqp); +/* UMR WQEs don't cross the page boundary, they are padded with NOPs. +* This padding is always smaller than the max WQE size. That gives us +* at least (PAGE_SIZE - (max WQE size - MLX5_SEND_WQE_BB)) useful bytes +* per page. The number of pages is estimated as the total size of WQEs +* divided by the useful space in page, rounding up. If some WQEs don't +* fully fit into the useful space, they can occupy part of the padding, +* which proves this estimation to be correct (reserve enough space). +*/ + useful_space =PAGE_SIZE -mlx5e_get_max_sq_wqebbs (mdev) +MLX5_SEND_WQE_BB ; + total_pages =DIV_ROUND_UP (wqebbs *MLX5_SEND_WQE_BB , useful_space); + wqebbs = total_pages * (PAGE_SIZE /MLX5_SEND_WQE_BB ); +return max_t (u8,MLX5E_PARAMS_MINIMUM_LOG_SQ_SIZE ,order_base_2 (wqebbs)); }
Signature · 1 line
2.37.3
PATCH 6/16 net/mlx5e: xsk: Use KSM for unaligned XSK
In reply to Saeed MahameedFrom: Maxim Mikityanskiy <[email protected]>
UMR MTTs used in striding RQ have certain alignment requirements. While it's guaranteed to work when UMR pages are aligned to the UMR page size, in practice it works then UMR pages are aligned to 8 bytes. However, it's still not enough flexibility for the unaligned mode of XSK. This patch leverages KSM to map UMR pages without alignment requirements, when unaligned XSK is active. The downside is that KSM entries are twice as big as MTTs, which limits the maximum WQE size, so regular RQs and aligned XSK continue using MTTs.
--- drivers/net/ethernet/mellanox/mlx5/core/en.h | 7 +- .../ethernet/mellanox/mlx5/core/en/params.c | 122 +++++++++++------- .../ethernet/mellanox/mlx5/core/en/params.h | 14 +- .../ethernet/mellanox/mlx5/core/en/xsk/pool.c | 1 + .../ethernet/mellanox/mlx5/core/en/xsk/rx.h | 14 -- .../ethernet/mellanox/mlx5/core/en_ethtool.c | 2 +- .../net/ethernet/mellanox/mlx5/core/en_main.c | 91 +++++++++---- .../net/ethernet/mellanox/mlx5/core/en_rx.c | 34 +++-- include/linux/mlx5/qp.h | 6 + 9 files changed, 191 insertions(+), 100 deletions(-)
drivers/net/ethernet/mellanox/mlx5/core/en.h +6 -1
@@ -112,8 +112,10 @@ struct page_pool;#define MLX5_ALIGN_MTTS (mtts) (ALIGN(mtts, 8))#define MLX5_ALIGNED_MTTS_OCTW (mtts) ((mtts) / 2)#define MLX5_MTT_OCTW (mtts) (MLX5_ALIGNED_MTTS_OCTW(MLX5_ALIGN_MTTS(mtts))) +#define MLX5_KSM_OCTW (ksms) (ksms)#define MLX5E_MAX_RQ_NUM_MTTS \ (ALIGN_DOWN(U16_MAX, 4) * 2)/* So that MLX5_MTT_OCTW(num_mtts) fits into u16 */ +#define MLX5E_MAX_RQ_NUM_KSMS (U16_MAX - 1)/* So that num_ksms fits into u16. */ #define MLX5E_ORDER2_MAX_PACKET_MTU (order_base_2(10 * 1024))#define MLX5E_MIN_SKB_FRAG_SZ (MLX5_SKB_FRAG_SZ(MLX5_RX_HEADROOM))
@@ -265,6 +267,7 @@ struct mlx5e_umr_wqe {union { DECLARE_FLEX_ARRAY(struct mlx5_mtt, inline_mtts); DECLARE_FLEX_ARRAY(struct mlx5_klm, inline_klms); + DECLARE_FLEX_ARRAY(struct mlx5_ksm, inline_ksms); }; };
@@ -708,6 +711,7 @@ struct mlx5e_rq {u8 pages_per_wqe;u8 umr_wqebbs;u8 mtts_per_wqe; +u8 unaligned;struct mlx5e_shampo_hd *shampo; } mpwqe; };
@@ -1007,7 +1011,8 @@ struct mlx5e_profile {void mlx5e_build_ptys2ethtool_map (void ); -bool mlx5e_check_fragmented_striding_rq_cap (struct mlx5_core_dev *mdev,u8 page_shift); +bool mlx5e_check_fragmented_striding_rq_cap (struct mlx5_core_dev *mdev,u8 page_shift, +bool unaligned);void mlx5e_shampo_dealloc_hd (struct mlx5e_rq *rq,u16 len,u16 start,bool close);void mlx5e_get_stats (struct net_device *dev,struct rtnl_link_stats64 *stats);
drivers/net/ethernet/mellanox/mlx5/core/en/params.c +76 -46
279 lines not on this page · raw message
drivers/net/ethernet/mellanox/mlx5/core/en/params.h +8 -6
@@ -9,6 +9,7 @@struct mlx5e_xsk_param {u16 headroom;u16 chunk_size; +bool unaligned; };struct mlx5e_cq_param {
@@ -87,12 +88,13 @@ static inline bool mlx5e_qid_validate(const struct mlx5e_profile *profile,/* Striding RQ dynamic parameters */ u8 mlx5e_mpwrq_page_shift (struct mlx5_core_dev *mdev,struct mlx5e_xsk_param *xsk); -u8 mlx5e_mpwrq_log_wqe_sz (struct mlx5_core_dev *mdev,u8 page_shift); -u8 mlx5e_mpwrq_pages_per_wqe (struct mlx5_core_dev *mdev,u8 page_shift); -u16 mlx5e_mpwrq_umr_wqe_sz (struct mlx5_core_dev *mdev,u8 page_shift); -u8 mlx5e_mpwrq_umr_wqebbs (struct mlx5_core_dev *mdev,u8 page_shift); -u8 mlx5e_mpwrq_mtts_per_wqe (struct mlx5_core_dev *mdev,u8 page_shift); -u8 mlx5e_mpwrq_max_log_rq_pkts (struct mlx5_core_dev *mdev,u8 page_shift); +u8 mlx5e_mpwrq_log_wqe_sz (struct mlx5_core_dev *mdev,u8 page_shift,bool unaligned); +u8 mlx5e_mpwrq_pages_per_wqe (struct mlx5_core_dev *mdev,u8 page_shift,bool unaligned); +u16 mlx5e_mpwrq_umr_wqe_sz (struct mlx5_core_dev *mdev,u8 page_shift,bool unaligned); +u8 mlx5e_mpwrq_umr_wqebbs (struct mlx5_core_dev *mdev,u8 page_shift,bool unaligned); +u8 mlx5e_mpwrq_mtts_per_wqe (struct mlx5_core_dev *mdev,u8 page_shift,bool unaligned); +u32 mlx5e_mpwrq_max_num_entries (struct mlx5_core_dev *mdev,bool unaligned); +u8 mlx5e_mpwrq_max_log_rq_pkts (struct mlx5_core_dev *mdev,u8 page_shift,bool unaligned);/* Parameter calculations */
drivers/net/ethernet/mellanox/mlx5/core/en/xsk/pool.c +1 -0
@@ -72,6 +72,7 @@ void mlx5e_build_xsk_param(struct xsk_buff_pool *pool, struct mlx5e_xsk_param *x { xsk->headroom =xsk_pool_get_headroom (pool); xsk->chunk_size =xsk_pool_get_chunk_size (pool); + xsk->unaligned = pool->unaligned; } static int mlx5e_xsk_enable_locked(struct mlx5e_priv *priv,
drivers/net/ethernet/mellanox/mlx5/core/en/xsk/rx.h +0 -14
@@ -7,8 +7,6 @@#include "en.h" #include <net/xdp_sock_drv.h> -#define MLX5E_MTT_PTAG_MASK 0xfffffffffffffff8ULL -/* RX data path */ struct sk_buff *mlx5e_xsk_skb_from_cqe_mpwrq_linear(struct mlx5e_rq *rq,
@@ -23,7 +21,6 @@ struct sk_buff *mlx5e_xsk_skb_from_cqe_linear(struct mlx5e_rq *rq,static inline int mlx5e_xsk_page_alloc_pool (struct mlx5e_rq *rq,struct mlx5e_dma_info *dma_info) { -retry: dma_info->xsk =xsk_buff_alloc (rq->xsk_pool);if (!dma_info->xsk)return -ENOMEM ;
@@ -35,17 +32,6 @@ static inline int mlx5e_xsk_page_alloc_pool(struct mlx5e_rq *rq,*/ dma_info->addr =xsk_buff_xdp_get_frame_dma (dma_info->xsk); -/* MTT page mapping has alignment requirements. If they are not -* satisfied, leak the descriptor so that it won't come again, and try -* to allocate a new one. -*/ -if (rq->wq_type ==MLX5_WQ_TYPE_LINKED_LIST_STRIDING_RQ ) { -if (unlikely (dma_info->addr & ~MLX5E_MTT_PTAG_MASK )) { -xsk_buff_discard (dma_info->xsk); - goto retry; - } - } -return 0 ; }
drivers/net/ethernet/mellanox/mlx5/core/en_ethtool.c +1 -1
@@ -314,7 +314,7 @@ void mlx5e_ethtool_get_ringparam(struct mlx5e_priv *priv,/* Limitation for regular RQ. XSK RQ may clamp the queue length in * mlx5e_mpwqe_get_log_rq_size. */ -u8 max_log_mpwrq_pkts =mlx5e_mpwrq_max_log_rq_pkts (priv->mdev,PAGE_SHIFT ); +u8 max_log_mpwrq_pkts =mlx5e_mpwrq_max_log_rq_pkts (priv->mdev,PAGE_SHIFT , false); param->rx_max_pending =1 <<min_t (u8,MLX5E_PARAMS_MAXIMUM_LOG_RQ_SIZE , max_log_mpwrq_pkts);
drivers/net/ethernet/mellanox/mlx5/core/en_main.c +67 -24
177 lines not on this page · raw message
drivers/net/ethernet/mellanox/mlx5/core/en_rx.c +26 -8
@@ -673,6 +673,7 @@ static int mlx5e_alloc_rx_mpwqe(struct mlx5e_rq *rq, u16 ix)struct mlx5e_icosq *sq = rq->icosq;struct mlx5_wq_cyc *wq = &sq->wq;struct mlx5e_umr_wqe *umr_wqe; +u32 offset;/* 17-bit value with MTT. */ u16 pi;int err;int i;
@@ -694,13 +695,27 @@ static int mlx5e_alloc_rx_mpwqe(struct mlx5e_rq *rq, u16 ix) 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, offsetof(struct mlx5e_umr_wqe , inline_mtts)); +memcpy (umr_wqe, &rq->mpwqe.umr_wqe,sizeof (struct mlx5e_umr_wqe )); -for (i =0 ; i < rq->mpwqe.pages_per_wqe; i++, dma_info++) { - err =mlx5e_page_alloc (rq, dma_info); -if (unlikely (err)) - goto err_unmap; - umr_wqe->inline_mtts[i].ptag =cpu_to_be64 (dma_info->addr |MLX5_EN_WR ); +if (unlikely (rq->mpwqe.unaligned)) { +for (i =0 ; i < rq->mpwqe.pages_per_wqe; i++, dma_info++) { + err =mlx5e_page_alloc (rq, dma_info); +if (unlikely (err)) + goto err_unmap; + umr_wqe->inline_ksms[i] = (struct mlx5_ksm ) { + .key = rq->mkey_be, + .va =cpu_to_be64 (dma_info->addr), + }; + } + }else { +for (i =0 ; i < rq->mpwqe.pages_per_wqe; i++, dma_info++) { + err =mlx5e_page_alloc (rq, dma_info); +if (unlikely (err)) + goto err_unmap; + umr_wqe->inline_mtts[i] = (struct mlx5_mtt ) { + .ptag =cpu_to_be64 (dma_info->addr |MLX5_EN_WR ), + }; + } }bitmap_zero (wi->xdp_xmit_bitmap, rq->mpwqe.pages_per_wqe);
@@ -709,8 +724,11 @@ static int mlx5e_alloc_rx_mpwqe(struct mlx5e_rq *rq, u16 ix) umr_wqe->ctrl.opmod_idx_opcode =cpu_to_be32 ((sq->pc <<MLX5_WQE_CTRL_WQE_INDEX_SHIFT ) |MLX5_OPCODE_UMR ); - umr_wqe->uctrl.xlt_offset = -cpu_to_be16 (MLX5_ALIGNED_MTTS_OCTW (ix * rq->mpwqe.mtts_per_wqe)); + + offset = ix * rq->mpwqe.mtts_per_wqe; +if (!rq->mpwqe.unaligned) + offset =MLX5_ALIGNED_MTTS_OCTW (offset); + umr_wqe->uctrl.xlt_offset =cpu_to_be16 (offset); sq->db.wqe_info[pi] = (struct mlx5e_icosq_wqe_info ) { .wqe_type =MLX5E_ICOSQ_WQE_UMR_RX ,
include/linux/mlx5/qp.h +6 -0
@@ -478,6 +478,12 @@ struct mlx5_klm {__be64 va; }; +struct mlx5_ksm { +__be32 reserved; +__be32 key; +__be64 va; +}; +struct mlx5_stride_block_entry {__be16 stride;__be16 bcount;
Signature · 1 line
2.37.3
PATCH 9/16 net/mlx5e: Optimize the page cache reducing its size 2x
In reply to Saeed MahameedFrom: Maxim Mikityanskiy <[email protected]>
RX page cache stores dma_info structs, that consist of a pointer to struct page and a DMA address. In fact, the DMA address is extracted from struct page using page_pool_get_dma_addr when a page is pushed to the cache. By moving this call to the point when a page is popped from the cache, we can avoid storing the DMA address in the cache, effectively reducing its size by two times without losing any functionality.
--- drivers/net/ethernet/mellanox/mlx5/core/en.h | 2 +- drivers/net/ethernet/mellanox/mlx5/core/en_main.c | 4 +--- drivers/net/ethernet/mellanox/mlx5/core/en_rx.c | 8 ++++---- 3 files changed, 6 insertions(+), 8 deletions(-)
drivers/net/ethernet/mellanox/mlx5/core/en.h +1 -1
@@ -630,7 +630,7 @@ struct mlx5e_mpw_info {struct mlx5e_page_cache {u32 head;u32 tail; -struct mlx5e_dma_info page_cache[MLX5E_CACHE_SIZE ]; +struct page *page_cache[MLX5E_CACHE_SIZE ]; };struct mlx5e_rq ;
drivers/net/ethernet/mellanox/mlx5/core/en_main.c +1 -3
@@ -830,13 +830,11 @@ static void mlx5e_free_rq(struct mlx5e_rq *rq)for (i = rq->page_cache.head; i != rq->page_cache.tail; i = (i +1 ) & (MLX5E_CACHE_SIZE -1 )) { -struct mlx5e_dma_info *dma_info = &rq->page_cache.page_cache[i]; -/* With AF_XDP, page_cache is not used, so this loop is not * entered, and it's safe to call mlx5e_page_release_dynamic * directly. */ -mlx5e_page_release_dynamic (rq, dma_info->page, false); +mlx5e_page_release_dynamic (rq, rq->page_cache.page_cache[i], false); }xdp_rxq_info_unreg (&rq->xdp_rxq);
drivers/net/ethernet/mellanox/mlx5/core/en_rx.c +4 -4
@@ -245,8 +245,7 @@ static inline bool mlx5e_rx_cache_put(struct mlx5e_rq *rq, struct page *page)return false; } - cache->page_cache[cache->tail].page = page; - cache->page_cache[cache->tail].addr =page_pool_get_dma_addr (page); + cache->page_cache[cache->tail] = page; cache->tail = tail_next;return true; }
@@ -262,12 +261,13 @@ static inline bool mlx5e_rx_cache_get(struct mlx5e_rq *rq,return false; } -if (page_ref_count (cache->page_cache[cache->head].page) !=1 ) { +if (page_ref_count (cache->page_cache[cache->head]) !=1 ) { stats->cache_busy++;return false; } - *dma_info = cache->page_cache[cache->head]; + dma_info->page = cache->page_cache[cache->head]; + dma_info->addr =page_pool_get_dma_addr (dma_info->page); cache->head = (cache->head +1 ) & (MLX5E_CACHE_SIZE -1 ); stats->cache_reuse++;
Signature · 1 line
2.37.3
PATCH 11/16 net/mlx5e: Remove DMA address from mlx5e_alloc_unit
In reply to Saeed MahameedFrom: Maxim Mikityanskiy <[email protected]>
mlx5e_alloc_unit stores the DMA address and a pointer to either struct page (regular RQ) or struct xdp_buff (XSK RQ). This DMA address is redundant, because when a page or an XSK frame is allocated, the same address is also stored there. Some flows take the address from struct mlx5e_alloc_unit, and some take it from struct page or xdp_buff.
This commit removes the address from struct mlx5e_alloc_unit, which makes it twice as small and improves locality (this struct is used in an array), also saving on unnecessary stores to the addr field. Almost all flows know unambiguously whether the DMA address should be taken from page or from xdp_buff. The exception is the allocation flows, where a new branch appeared, which will be optimized out in the next commits.
struct mlx5e_alloc_unit used to be called mlx5e_dma_info.
--- drivers/net/ethernet/mellanox/mlx5/core/en.h | 1 - .../ethernet/mellanox/mlx5/core/en/xsk/rx.h | 7 --- .../net/ethernet/mellanox/mlx5/core/en_rx.c | 57 +++++++++++++------ 3 files changed, 40 insertions(+), 25 deletions(-)
drivers/net/ethernet/mellanox/mlx5/core/en.h +0 -1
@@ -475,7 +475,6 @@ struct mlx5e_txqsq { }____cacheline_aligned_in_smp ;struct mlx5e_alloc_unit { -dma_addr_t addr;union {struct page *page;struct xdp_buff *xsk;
drivers/net/ethernet/mellanox/mlx5/core/en/xsk/rx.h +0 -7
@@ -25,13 +25,6 @@ static inline int mlx5e_xsk_page_alloc_pool(struct mlx5e_rq *rq,if (!au->xsk)return -ENOMEM ; -/* Store the DMA address without headroom. In striding RQ case, we just -* provide pages for UMR, and headroom is counted at the setup stage -* when creating a WQE. In non-striding RQ case, headroom is accounted -* in mlx5e_alloc_rx_wqe. -*/ - au->addr =xsk_buff_xdp_get_frame_dma (au->xsk); -return 0 ; }
drivers/net/ethernet/mellanox/mlx5/core/en_rx.c +40 -17
179 lines not on this page · raw message
Signature · 1 line
2.37.3
PATCH 10/16 net/mlx5e: Rename mlx5e_dma_info to prepare for removal of DMA address
In reply to Saeed MahameedFrom: Maxim Mikityanskiy <[email protected]>
The next commit will remove the DMA address from the struct currently called mlx5e_dma_info, because the same value can be retrieved with page_pool_get_dma_addr(page) in almost all cases, with the notable exception of SHAMPO (HW GRO implementation) that modifies this address on the fly, after the initial allocation.
To keep the SHAMPO logic intact, struct mlx5e_dma_info remains in the SHAMPO code, consisting of addr and page (XSK is not compatible with SHAMPO). The struct used in all other places is renamed to mlx5e_alloc_unit, allowing the next commit to remove the addr field without affecting SHAMPO.
The new name means "allocation unit", and it's more appropriate after the field with the DMA address gets removed.
--- drivers/net/ethernet/mellanox/mlx5/core/en.h | 15 +- .../ethernet/mellanox/mlx5/core/en/xsk/rx.c | 4 +- .../ethernet/mellanox/mlx5/core/en/xsk/rx.h | 8 +- .../net/ethernet/mellanox/mlx5/core/en_main.c | 17 +- .../net/ethernet/mellanox/mlx5/core/en_rx.c | 190 +++++++++--------- 5 files changed, 123 insertions(+), 111 deletions(-)
drivers/net/ethernet/mellanox/mlx5/core/en.h +9 -6
@@ -474,7 +474,7 @@ struct mlx5e_txqsq {cqe_ts_to_ns ptp_cyc2time; }____cacheline_aligned_in_smp ; -struct mlx5e_dma_info { +struct mlx5e_alloc_unit {dma_addr_t addr;union {struct page *page;
@@ -608,7 +608,7 @@ struct mlx5e_icosq { }____cacheline_aligned_in_smp ;struct mlx5e_wqe_frag_info { -struct mlx5e_dma_info *di; +struct mlx5e_alloc_unit *au;u32 offset;bool last_in_page; };
@@ -616,7 +616,7 @@ struct mlx5e_wqe_frag_info {struct mlx5e_mpw_info {u16 consumed_strides; DECLARE_BITMAP(xdp_xmit_bitmap, MLX5_MPWRQ_MAX_PAGES_PER_WQE); -struct mlx5e_dma_info dma_info[]; +struct mlx5e_alloc_unit alloc_units[]; };#define MLX5E_MAX_RX_FRAGS 4
@@ -665,6 +665,11 @@ struct mlx5e_rq_frags_info {u8 wqe_bulk; }; +struct mlx5e_dma_info { +dma_addr_t addr; +struct page *page; +}; +struct mlx5e_shampo_hd {u32 mkey;struct mlx5e_dma_info *info;
@@ -690,7 +695,7 @@ struct mlx5e_rq {struct {struct mlx5_wq_cyc wq;struct mlx5e_wqe_frag_info *frags; -struct mlx5e_dma_info *di; +struct mlx5e_alloc_unit *alloc_units;struct mlx5e_rq_frags_info info;mlx5e_fp_skb_from_cqe skb_from_cqe; } wqe;
@@ -1142,8 +1147,6 @@ void mlx5e_destroy_q_counters(struct mlx5e_priv *priv);int mlx5e_open_drop_rq (struct mlx5e_priv *priv,struct mlx5e_rq *drop_rq);void mlx5e_close_drop_rq (struct mlx5e_rq *drop_rq); -int mlx5e_init_di_list (struct mlx5e_rq *rq,int wq_sz,int node); -void mlx5e_free_di_list (struct mlx5e_rq *rq);int mlx5e_create_tis (struct mlx5_core_dev *mdev,void *in,u32 *tisn);void mlx5e_destroy_tis (struct mlx5_core_dev *mdev,u32 tisn);
drivers/net/ethernet/mellanox/mlx5/core/en/xsk/rx.c +2 -2
@@ -30,7 +30,7 @@ struct sk_buff *mlx5e_xsk_skb_from_cqe_mpwrq_linear(struct mlx5e_rq *rq, u32 head_offset, u32 page_idx) { -struct xdp_buff *xdp = wi->dma_info[page_idx].xsk; +struct xdp_buff *xdp = wi->alloc_units[page_idx].xsk;struct bpf_prog *prog;/* Check packet size. Note LRO doesn't use linear SKB */
@@ -83,7 +83,7 @@ struct sk_buff *mlx5e_xsk_skb_from_cqe_linear(struct mlx5e_rq *rq, struct mlx5e_wqe_frag_info *wi, u32 cqe_bcnt) { -struct xdp_buff *xdp = wi->di->xsk; +struct xdp_buff *xdp = wi->au->xsk;struct bpf_prog *prog;/* wi->offset is not used in this function, because xdp->data and the
drivers/net/ethernet/mellanox/mlx5/core/en/xsk/rx.h +4 -4
@@ -19,10 +19,10 @@ struct sk_buff *mlx5e_xsk_skb_from_cqe_linear(struct mlx5e_rq *rq, u32 cqe_bcnt);static inline int mlx5e_xsk_page_alloc_pool (struct mlx5e_rq *rq, -struct mlx5e_dma_info *dma_info) +struct mlx5e_alloc_unit *au) { - dma_info->xsk =xsk_buff_alloc (rq->xsk_pool); -if (!dma_info->xsk) + au->xsk =xsk_buff_alloc (rq->xsk_pool); +if (!au->xsk)return -ENOMEM ;/* Store the DMA address without headroom. In striding RQ case, we just
@@ -30,7 +30,7 @@ static inline int mlx5e_xsk_page_alloc_pool(struct mlx5e_rq *rq,* when creating a WQE. In non-striding RQ case, headroom is accounted * in mlx5e_alloc_rx_wqe. */ - dma_info->addr =xsk_buff_xdp_get_frame_dma (dma_info->xsk); + au->addr =xsk_buff_xdp_get_frame_dma (au->xsk);return 0 ; }
drivers/net/ethernet/mellanox/mlx5/core/en_main.c +9 -8
@@ -271,7 +271,7 @@ static int mlx5e_rq_alloc_mpwqe_info(struct mlx5e_rq *rq, int node)int wq_sz =mlx5_wq_ll_get_size (&rq->mpwqe.wq);size_t alloc_size; - alloc_size =array_size (wq_sz,struct_size (rq->mpwqe.info, dma_info, + alloc_size =array_size (wq_sz,struct_size (rq->mpwqe.info, alloc_units, rq->mpwqe.pages_per_wqe)); rq->mpwqe.info =kvzalloc_node (alloc_size,GFP_KERNEL , node);
@@ -433,7 +433,7 @@ static void mlx5e_init_frags_partition(struct mlx5e_rq *rq)struct mlx5e_wqe_frag_info *prev =NULL ;int i; - next_frag.di = &rq->wqe.di[0 ]; + next_frag.au = &rq->wqe.alloc_units[0 ];for (i =0 ; i <mlx5_wq_cyc_get_size (&rq->wqe.wq); i++) {struct mlx5e_rq_frag_info *frag_info = &rq->wqe.info.arr[0 ];
@@ -443,7 +443,7 @@ static void mlx5e_init_frags_partition(struct mlx5e_rq *rq)for (f =0 ; f < rq->wqe.info.num_frags; f++, frag++) {if (next_frag.offset + frag_info[f].frag_stride >PAGE_SIZE ) { - next_frag.di++; + next_frag.au++; next_frag.offset =0 ;if (prev) prev->last_in_page = true;
@@ -460,12 +460,13 @@ static void mlx5e_init_frags_partition(struct mlx5e_rq *rq) prev->last_in_page = true; } -int mlx5e_init_di_list (struct mlx5e_rq *rq,int wq_sz,int node) +static int mlx5e_init_di_list (struct mlx5e_rq *rq,int wq_sz,int node) {int len = wq_sz << rq->wqe.info.log_num_frags; - rq->wqe.di =kvzalloc_node (array_size (len,sizeof (*rq->wqe.di)),GFP_KERNEL , node); -if (!rq->wqe.di) + rq->wqe.alloc_units =kvzalloc_node (array_size (len,sizeof (*rq->wqe.alloc_units)), +GFP_KERNEL , node); +if (!rq->wqe.alloc_units)return -ENOMEM ;mlx5e_init_frags_partition (rq);
@@ -473,9 +474,9 @@ int mlx5e_init_di_list(struct mlx5e_rq *rq, int wq_sz, int node)return 0 ; } -void mlx5e_free_di_list (struct mlx5e_rq *rq) +static void mlx5e_free_di_list (struct mlx5e_rq *rq) { -kvfree (rq->wqe.di); +kvfree (rq->wqe.alloc_units); }static void mlx5e_rq_err_cqe_work (struct work_struct *recover_work)
drivers/net/ethernet/mellanox/mlx5/core/en_rx.c +99 -91
506 lines not on this page · raw message
Signature · 1 line
2.37.3
PATCH 12/16 net/mlx5e: Convert struct mlx5e_alloc_unit to a union
In reply to Saeed MahameedFrom: Maxim Mikityanskiy <[email protected]>
struct mlx5e_alloc_unit consists of a single union. Convert it to a union itself to simplify casting it to struct xdp_buff *, which will be used to implement XSK batching on striding RQ.
--- drivers/net/ethernet/mellanox/mlx5/core/en.h | 14 ++++---- .../ethernet/mellanox/mlx5/core/en/xsk/rx.h | 2 +- .../net/ethernet/mellanox/mlx5/core/en_main.c | 10 +++--- .../net/ethernet/mellanox/mlx5/core/en_rx.c | 36 +++++++++---------- 4 files changed, 30 insertions(+), 32 deletions(-)
drivers/net/ethernet/mellanox/mlx5/core/en.h +6 -8
@@ -474,11 +474,9 @@ struct mlx5e_txqsq {cqe_ts_to_ns ptp_cyc2time; }____cacheline_aligned_in_smp ; -struct mlx5e_alloc_unit { -union { -struct page *page; -struct xdp_buff *xsk; - }; +union mlx5e_alloc_unit { +struct page *page; +struct xdp_buff *xsk; };/* XDP packets can be transmitted in different ways. On completion, we need to
@@ -607,7 +605,7 @@ struct mlx5e_icosq { }____cacheline_aligned_in_smp ;struct mlx5e_wqe_frag_info { -struct mlx5e_alloc_unit *au; +union mlx5e_alloc_unit *au;u32 offset;bool last_in_page; };
@@ -615,7 +613,7 @@ struct mlx5e_wqe_frag_info {struct mlx5e_mpw_info {u16 consumed_strides; DECLARE_BITMAP(xdp_xmit_bitmap, MLX5_MPWRQ_MAX_PAGES_PER_WQE); -struct mlx5e_alloc_unit alloc_units[]; +union mlx5e_alloc_unit alloc_units[]; };#define MLX5E_MAX_RX_FRAGS 4
@@ -694,7 +692,7 @@ struct mlx5e_rq {struct {struct mlx5_wq_cyc wq;struct mlx5e_wqe_frag_info *frags; -struct mlx5e_alloc_unit *alloc_units; +union mlx5e_alloc_unit *alloc_units;struct mlx5e_rq_frags_info info;mlx5e_fp_skb_from_cqe skb_from_cqe; } wqe;
drivers/net/ethernet/mellanox/mlx5/core/en/xsk/rx.h +1 -1
@@ -19,7 +19,7 @@ struct sk_buff *mlx5e_xsk_skb_from_cqe_linear(struct mlx5e_rq *rq, u32 cqe_bcnt);static inline int mlx5e_xsk_page_alloc_pool (struct mlx5e_rq *rq, -struct mlx5e_alloc_unit *au) +union mlx5e_alloc_unit *au) { au->xsk =xsk_buff_alloc (rq->xsk_pool);if (!au->xsk)
drivers/net/ethernet/mellanox/mlx5/core/en_main.c +5 -5
@@ -460,7 +460,7 @@ static void mlx5e_init_frags_partition(struct mlx5e_rq *rq) prev->last_in_page = true; } -static int mlx5e_init_di_list (struct mlx5e_rq *rq,int wq_sz,int node) +static int mlx5e_init_au_list (struct mlx5e_rq *rq,int wq_sz,int node) {int len = wq_sz << rq->wqe.info.log_num_frags;
@@ -474,7 +474,7 @@ static int mlx5e_init_di_list(struct mlx5e_rq *rq, int wq_sz, int node)return 0 ; } -static void mlx5e_free_di_list (struct mlx5e_rq *rq) +static void mlx5e_free_au_list (struct mlx5e_rq *rq) {kvfree (rq->wqe.alloc_units); }
@@ -693,7 +693,7 @@ static int mlx5e_alloc_rq(struct mlx5e_params *params, goto err_rq_wq_destroy; } - err =mlx5e_init_di_list (rq, wq_sz, node); + err =mlx5e_init_au_list (rq, wq_sz, node);if (err) goto err_rq_frags; }
@@ -792,7 +792,7 @@ static int mlx5e_alloc_rq(struct mlx5e_params *params,mlx5e_free_mpwqe_rq_drop_page (rq);break ;default :/* MLX5_WQ_TYPE_CYCLIC */ -mlx5e_free_di_list (rq); +mlx5e_free_au_list (rq); err_rq_frags:kvfree (rq->wqe.frags); }
@@ -826,7 +826,7 @@ static void mlx5e_free_rq(struct mlx5e_rq *rq)break ;default :/* MLX5_WQ_TYPE_CYCLIC */ kvfree (rq->wqe.frags); -mlx5e_free_di_list (rq); +mlx5e_free_au_list (rq); } for (i = rq->page_cache.head; i != rq->page_cache.tail;
drivers/net/ethernet/mellanox/mlx5/core/en_rx.c +18 -18
@@ -250,7 +250,7 @@ static inline bool mlx5e_rx_cache_put(struct mlx5e_rq *rq, struct page *page)return true; } -static inline bool mlx5e_rx_cache_get (struct mlx5e_rq *rq,struct mlx5e_alloc_unit *au) +static inline bool mlx5e_rx_cache_get (struct mlx5e_rq *rq,union mlx5e_alloc_unit *au) {struct mlx5e_page_cache *cache = &rq->page_cache;struct mlx5e_rq_stats *stats = rq->stats;
@@ -276,7 +276,7 @@ static inline bool mlx5e_rx_cache_get(struct mlx5e_rq *rq, struct mlx5e_alloc_unreturn true; } -static inline int mlx5e_page_alloc_pool (struct mlx5e_rq *rq,struct mlx5e_alloc_unit *au) +static inline int mlx5e_page_alloc_pool (struct mlx5e_rq *rq,union mlx5e_alloc_unit *au) {dma_addr_t addr;
@@ -300,7 +300,7 @@ static inline int mlx5e_page_alloc_pool(struct mlx5e_rq *rq, struct mlx5e_alloc_return 0 ; } -static inline int mlx5e_page_alloc (struct mlx5e_rq *rq,struct mlx5e_alloc_unit *au) +static inline int mlx5e_page_alloc (struct mlx5e_rq *rq,union mlx5e_alloc_unit *au) {if (rq->xsk_pool)return mlx5e_xsk_page_alloc_pool (rq, au);
@@ -333,7 +333,7 @@ void mlx5e_page_release_dynamic(struct mlx5e_rq *rq, struct page *page, bool rec }static inline void mlx5e_page_release (struct mlx5e_rq *rq, -struct mlx5e_alloc_unit *au, +union mlx5e_alloc_unit *au,bool recycle) {if (rq->xsk_pool)
@@ -458,7 +458,7 @@ static int mlx5e_alloc_rx_wqes(struct mlx5e_rq *rq, u16 ix, u8 wqe_bulk)static inline void mlx5e_add_skb_frag (struct mlx5e_rq *rq,struct sk_buff *skb, -struct mlx5e_alloc_unit *au,u32 frag_offset,u32 len, +union mlx5e_alloc_unit *au,u32 frag_offset,u32 len,unsigned int truesize) {dma_addr_t addr =page_pool_get_dma_addr (au->page);
@@ -485,7 +485,7 @@ mlx5e_copy_skb_header(struct device *pdev, struct sk_buff *skb,static void mlx5e_free_rx_mpwqe (struct mlx5e_rq *rq,struct mlx5e_mpw_info *wi,bool recycle) { -struct mlx5e_alloc_unit *alloc_units = wi->alloc_units; +union mlx5e_alloc_unit *alloc_units = wi->alloc_units;bool no_xdp_xmit;int i;
@@ -582,7 +582,7 @@ static int mlx5e_build_shampo_hd_umr(struct mlx5e_rq *rq, header_offset = (index & (MLX5E_SHAMPO_WQ_HEADER_PER_PAGE -1 )) <<MLX5E_SHAMPO_LOG_MAX_HEADER_ENTRY_SIZE ;if (!(header_offset & (PAGE_SIZE -1 ))) { -struct mlx5e_alloc_unit au; +union mlx5e_alloc_unit au; err =mlx5e_page_alloc (rq, &au);if (unlikely (err))
@@ -620,7 +620,7 @@ static int mlx5e_build_shampo_hd_umr(struct mlx5e_rq *rq,while (--i >=0 ) { dma_info = &shampo->info[--index];if (!(i & (MLX5E_SHAMPO_WQ_HEADER_PER_PAGE -1 ))) { -struct mlx5e_alloc_unit au = { +union mlx5e_alloc_unit au = { .page = dma_info->page, };
@@ -674,7 +674,7 @@ static int mlx5e_alloc_rx_hd_mpwqe(struct mlx5e_rq *rq)static int mlx5e_alloc_rx_mpwqe (struct mlx5e_rq *rq,u16 ix) {struct mlx5e_mpw_info *wi =mlx5e_get_mpw_info (rq, ix); -struct mlx5e_alloc_unit *au = &wi->alloc_units[0 ]; +union mlx5e_alloc_unit *au = &wi->alloc_units[0 ];struct mlx5e_icosq *sq = rq->icosq;struct mlx5_wq_cyc *wq = &sq->wq;struct mlx5e_umr_wqe *umr_wqe;
@@ -791,7 +791,7 @@ void mlx5e_shampo_dealloc_hd(struct mlx5e_rq *rq, u16 len, u16 start, bool close hd_info = &shampo->info[index]; hd_info->addr =ALIGN_DOWN (hd_info->addr,PAGE_SIZE );if (hd_info->page != deleted_page) { -struct mlx5e_alloc_unit au = { +union mlx5e_alloc_unit au = { .page = hd_info->page, };
@@ -1571,7 +1571,7 @@ static struct sk_buff * mlx5e_skb_from_cqe_linear(struct mlx5e_rq *rq, struct mlx5e_wqe_frag_info *wi, u32 cqe_bcnt) { - struct mlx5e_alloc_unit *au = wi->au; + union mlx5e_alloc_unit *au = wi->au;u16 rx_headroom = rq->buff.headroom;struct bpf_prog *prog;struct sk_buff *skb;
@@ -1619,7 +1619,7 @@ mlx5e_skb_from_cqe_nonlinear(struct mlx5e_rq *rq, struct mlx5e_wqe_frag_info *wi {struct mlx5e_rq_frag_info *frag_info = &rq->wqe.info.arr[0 ];struct mlx5e_wqe_frag_info *head_wi = wi; -struct mlx5e_alloc_unit *au = wi->au; +union mlx5e_alloc_unit *au = wi->au;u16 rx_headroom = rq->buff.headroom;struct skb_shared_info *sinfo;u32 frag_consumed_bytes;
@@ -1899,7 +1899,7 @@ const struct mlx5e_rx_handlers mlx5e_rx_handlers_rep = {static void mlx5e_fill_skb_data (struct sk_buff *skb,struct mlx5e_rq *rq, -struct mlx5e_alloc_unit *au,u32 data_bcnt,u32 data_offset) +union mlx5e_alloc_unit *au,u32 data_bcnt,u32 data_offset) {net_prefetchw (skb->data);
@@ -1926,11 +1926,11 @@ static struct sk_buff * mlx5e_skb_from_cqe_mpwrq_nonlinear(struct mlx5e_rq *rq, struct mlx5e_mpw_info *wi, u16 cqe_bcnt, u32 head_offset, u32 page_idx) { - struct mlx5e_alloc_unit *au = &wi->alloc_units[page_idx]; + union mlx5e_alloc_unit *au = &wi->alloc_units[page_idx];u16 headlen =min_t (u16,MLX5E_RX_MAX_HEAD , cqe_bcnt);u32 frag_offset = head_offset + headlen;u32 byte_cnt = cqe_bcnt - headlen; -struct mlx5e_alloc_unit *head_au = au; +union mlx5e_alloc_unit *head_au = au;struct sk_buff *skb;dma_addr_t addr;
@@ -1965,7 +1965,7 @@ static struct sk_buff * mlx5e_skb_from_cqe_mpwrq_linear(struct mlx5e_rq *rq, struct mlx5e_mpw_info *wi, u16 cqe_bcnt, u32 head_offset, u32 page_idx) { - struct mlx5e_alloc_unit *au = &wi->alloc_units[page_idx]; + union mlx5e_alloc_unit *au = &wi->alloc_units[page_idx];u16 rx_headroom = rq->buff.headroom;struct bpf_prog *prog;struct sk_buff *skb;
@@ -2107,7 +2107,7 @@ mlx5e_free_rx_shampo_hd_entry(struct mlx5e_rq *rq, u16 header_index)u64 addr = shampo->info[header_index].addr;if (((header_index +1 ) & (MLX5E_SHAMPO_WQ_HEADER_PER_PAGE -1 )) ==0 ) { -struct mlx5e_alloc_unit au = { +union mlx5e_alloc_unit au = { .page = shampo->info[header_index].page, };
@@ -2133,7 +2133,7 @@ static void mlx5e_handle_rx_cqe_mpwrq_shampo(struct mlx5e_rq *rq, struct mlx5_cqbool match = cqe->shampo.match;struct mlx5e_rq_stats *stats = rq->stats;struct mlx5e_rx_wqe_ll *wqe; -struct mlx5e_alloc_unit *au; +union mlx5e_alloc_unit *au;struct mlx5e_mpw_info *wi;struct mlx5_wq_ll *wq;
Signature · 1 line
2.37.3
PATCH 15/16 net/mlx5e: Move repeating clear_bit in mlx5e_rx_reporter_err_rq_cqe_recover
In reply to Saeed MahameedFrom: Maxim Mikityanskiy <[email protected]>
The same clear_bit is called in both error and success flows. Move the call to do it only once and remove the out label.
--- drivers/net/ethernet/mellanox/mlx5/core/en/reporter_rx.c | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-)
drivers/net/ethernet/mellanox/mlx5/core/en/reporter_rx.c +2 -5
@@ -162,10 +162,10 @@ static int mlx5e_rx_reporter_err_rq_cqe_recover(void *ctx)mlx5e_free_rx_descs (rq); err =mlx5e_rq_to_ready (rq,MLX5_RQC_STATE_ERR ); +clear_bit (MLX5E_RQ_STATE_RECOVERING , &rq->state);if (err) - goto out; +return err; -clear_bit (MLX5E_RQ_STATE_RECOVERING , &rq->state);mlx5e_activate_rq (rq); rq->stats->recover++;if (rq->channel)
@@ -173,9 +173,6 @@ static int mlx5e_rx_reporter_err_rq_cqe_recover(void *ctx)else mlx5e_trigger_napi_sched (rq->cq.napi);return 0 ; -out: -clear_bit (MLX5E_RQ_STATE_RECOVERING , &rq->state); -return err; }static int mlx5e_rx_reporter_timeout_recover (void *ctx)
Signature · 1 line
2.37.3
PATCH 14/16 net/mlx5e: Split out channel (de)activation in rx_res
In reply to Saeed MahameedFrom: Maxim Mikityanskiy <[email protected]>
To decrease the nesting level and reduce duplication of code, create functions to redirect direct RQTs to the actual RQs or drop_rq, which are used in the activation and deactivation flows of channels.
--- .../ethernet/mellanox/mlx5/core/en/rx_res.c | 106 +++++++++--------- 1 file changed, 53 insertions(+), 53 deletions(-)
drivers/net/ethernet/mellanox/mlx5/core/en/rx_res.c +53 -53
@@ -523,6 +523,53 @@ static u32 mlx5e_rx_res_get_rqtn_direct(struct mlx5e_rx_res *res, unsigned int ireturn mlx5e_rqt_get_rqtn (&res->channels[ix].direct_rqt); } +static void mlx5e_rx_res_channel_activate_direct (struct mlx5e_rx_res *res, +struct mlx5e_channels *chs, +unsigned int ix) +{ +u32 rqn; +int err; + +mlx5e_channels_get_regular_rqn (chs, ix, &rqn); + err =mlx5e_rqt_redirect_direct (&res->channels[ix].direct_rqt, rqn); +if (err) +mlx5_core_warn (res->mdev,"Failed to redirect direct RQT %#x to RQ %#x (channel %u): err = %d\n" , +mlx5e_rqt_get_rqtn (&res->channels[ix].direct_rqt), + rqn, ix, err); + +if (!(res->features &MLX5E_RX_RES_FEATURE_XSK )) +return ; + +if (!mlx5e_channels_get_xsk_rqn (chs, ix, &rqn)) + rqn = res->drop_rqn; + err =mlx5e_rqt_redirect_direct (&res->channels[ix].xsk_rqt, rqn); +if (err) +mlx5_core_warn (res->mdev,"Failed to redirect XSK RQT %#x to RQ %#x (channel %u): err = %d\n" , +mlx5e_rqt_get_rqtn (&res->channels[ix].xsk_rqt), + rqn, ix, err); +} + +static void mlx5e_rx_res_channel_deactivate_direct (struct mlx5e_rx_res *res, +unsigned int ix) +{ +int err; + + err =mlx5e_rqt_redirect_direct (&res->channels[ix].direct_rqt, res->drop_rqn); +if (err) +mlx5_core_warn (res->mdev,"Failed to redirect direct RQT %#x to drop RQ %#x (channel %u): err = %d\n" , +mlx5e_rqt_get_rqtn (&res->channels[ix].direct_rqt), + res->drop_rqn, ix, err); + +if (!(res->features &MLX5E_RX_RES_FEATURE_XSK )) +return ; + + err =mlx5e_rqt_redirect_direct (&res->channels[ix].xsk_rqt, res->drop_rqn); +if (err) +mlx5_core_warn (res->mdev,"Failed to redirect XSK RQT %#x to drop RQ %#x (channel %u): err = %d\n" , +mlx5e_rqt_get_rqtn (&res->channels[ix].xsk_rqt), + res->drop_rqn, ix, err); +} +void mlx5e_rx_res_channels_activate (struct mlx5e_rx_res *res,struct mlx5e_channels *chs) {unsigned int nch, ix;
@@ -536,43 +583,10 @@ void mlx5e_rx_res_channels_activate(struct mlx5e_rx_res *res, struct mlx5e_channmlx5e_rx_res_rss_enable (res); -for (ix =0 ; ix < nch; ix++) { -u32 rqn; - -mlx5e_channels_get_regular_rqn (chs, ix, &rqn); - err =mlx5e_rqt_redirect_direct (&res->channels[ix].direct_rqt, rqn); -if (err) -mlx5_core_warn (res->mdev,"Failed to redirect direct RQT %#x to RQ %#x (channel %u): err = %d\n" , -mlx5e_rqt_get_rqtn (&res->channels[ix].direct_rqt), - rqn, ix, err); - -if (!(res->features &MLX5E_RX_RES_FEATURE_XSK )) -continue ; - -if (!mlx5e_channels_get_xsk_rqn (chs, ix, &rqn)) - rqn = res->drop_rqn; - err =mlx5e_rqt_redirect_direct (&res->channels[ix].xsk_rqt, rqn); -if (err) -mlx5_core_warn (res->mdev,"Failed to redirect XSK RQT %#x to RQ %#x (channel %u): err = %d\n" , -mlx5e_rqt_get_rqtn (&res->channels[ix].xsk_rqt), - rqn, ix, err); - } -for (ix = nch; ix < res->max_nch; ix++) { - err =mlx5e_rqt_redirect_direct (&res->channels[ix].direct_rqt, res->drop_rqn); -if (err) -mlx5_core_warn (res->mdev,"Failed to redirect direct RQT %#x to drop RQ %#x (channel %u): err = %d\n" , -mlx5e_rqt_get_rqtn (&res->channels[ix].direct_rqt), - res->drop_rqn, ix, err); - -if (!(res->features &MLX5E_RX_RES_FEATURE_XSK )) -continue ; - - err =mlx5e_rqt_redirect_direct (&res->channels[ix].xsk_rqt, res->drop_rqn); -if (err) -mlx5_core_warn (res->mdev,"Failed to redirect XSK RQT %#x to drop RQ %#x (channel %u): err = %d\n" , -mlx5e_rqt_get_rqtn (&res->channels[ix].xsk_rqt), - res->drop_rqn, ix, err); - } +for (ix =0 ; ix < nch; ix++) +mlx5e_rx_res_channel_activate_direct (res, chs, ix); +for (ix = nch; ix < res->max_nch; ix++) +mlx5e_rx_res_channel_deactivate_direct (res, ix);if (res->features &MLX5E_RX_RES_FEATURE_PTP ) {u32 rqn;
@@ -595,22 +609,8 @@ void mlx5e_rx_res_channels_deactivate(struct mlx5e_rx_res *res)mlx5e_rx_res_rss_disable (res); -for (ix =0 ; ix < res->max_nch; ix++) { - err =mlx5e_rqt_redirect_direct (&res->channels[ix].direct_rqt, res->drop_rqn); -if (err) -mlx5_core_warn (res->mdev,"Failed to redirect direct RQT %#x to drop RQ %#x (channel %u): err = %d\n" , -mlx5e_rqt_get_rqtn (&res->channels[ix].direct_rqt), - res->drop_rqn, ix, err); - -if (!(res->features &MLX5E_RX_RES_FEATURE_XSK )) -continue ; - - err =mlx5e_rqt_redirect_direct (&res->channels[ix].xsk_rqt, res->drop_rqn); -if (err) -mlx5_core_warn (res->mdev,"Failed to redirect XSK RQT %#x to drop RQ %#x (channel %u): err = %d\n" , -mlx5e_rqt_get_rqtn (&res->channels[ix].xsk_rqt), - res->drop_rqn, ix, err); - } +for (ix =0 ; ix < res->max_nch; ix++) +mlx5e_rx_res_channel_deactivate_direct (res, ix);if (res->features &MLX5E_RX_RES_FEATURE_PTP ) { err =mlx5e_rqt_redirect_direct (&res->ptp.rqt, res->drop_rqn);
Signature · 1 line
2.37.3
PATCH 13/16 net/mlx5e: xsk: Remove mlx5e_xsk_page_alloc_pool
In reply to Saeed MahameedFrom: Maxim Mikityanskiy <[email protected]>
mlx5e_xsk_page_alloc_pool became a thin wrapper around xsk_buff_alloc. Drop it and call xsk_buff_alloc directly.
--- drivers/net/ethernet/mellanox/mlx5/core/en/xsk/rx.h | 10 ---------- drivers/net/ethernet/mellanox/mlx5/core/en_rx.c | 8 +++++--- 2 files changed, 5 insertions(+), 13 deletions(-)
drivers/net/ethernet/mellanox/mlx5/core/en/xsk/rx.h +0 -10
@@ -18,16 +18,6 @@ struct sk_buff *mlx5e_xsk_skb_from_cqe_linear(struct mlx5e_rq *rq,struct mlx5e_wqe_frag_info *wi, u32 cqe_bcnt); -static inline int mlx5e_xsk_page_alloc_pool (struct mlx5e_rq *rq, -union mlx5e_alloc_unit *au) -{ - au->xsk =xsk_buff_alloc (rq->xsk_pool); -if (!au->xsk) -return -ENOMEM ; - -return 0 ; -} -static inline bool mlx5e_xsk_update_rx_wakeup (struct mlx5e_rq *rq,bool alloc_err) {if (!xsk_uses_need_wakeup (rq->xsk_pool))
drivers/net/ethernet/mellanox/mlx5/core/en_rx.c +5 -3
@@ -302,10 +302,12 @@ static inline int mlx5e_page_alloc_pool(struct mlx5e_rq *rq, union mlx5e_alloc_ustatic inline int mlx5e_page_alloc (struct mlx5e_rq *rq,union mlx5e_alloc_unit *au) { -if (rq->xsk_pool) -return mlx5e_xsk_page_alloc_pool (rq, au); -else +if (rq->xsk_pool) { + au->xsk =xsk_buff_alloc (rq->xsk_pool); +return likely (au->xsk) ?0 : -ENOMEM ; + }else {return mlx5e_page_alloc_pool (rq, au); + } }void mlx5e_page_dma_unmap (struct mlx5e_rq *rq,struct page *page)
Signature · 1 line
2.37.3
PATCH 16/16 net/mlx5e: Clean up and fix error flows in mlx5e_alloc_rq
In reply to Saeed MahameedFrom: Maxim Mikityanskiy <[email protected]>
Although mlx5e_rq_free_shampo can be called unconditionally, it belongs to case MLX5_WQ_TYPE_LINKED_LIST_STRIDING_RQ. Move it there to allow to add more init/cleanup actions to the striding RQ case.
If xdp_rxq_info_reg_mem_model fails, don't forget to destroy the page pool.
--- drivers/net/ethernet/mellanox/mlx5/core/en_main.c | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-)
drivers/net/ethernet/mellanox/mlx5/core/en_main.c +7 -5
@@ -668,7 +668,7 @@ static int mlx5e_alloc_rq(struct mlx5e_params *params, err =mlx5_rq_shampo_alloc (mdev, params, rqp, rq, &pool_size, node);if (err) - goto err_free_by_rq_type; + goto err_free_mpwqe_info;break ;default :/* MLX5_WQ_TYPE_CYCLIC */
@@ -720,14 +720,14 @@ static int mlx5e_alloc_rq(struct mlx5e_params *params,if (IS_ERR (rq->page_pool)) { err =PTR_ERR (rq->page_pool); rq->page_pool =NULL ; - goto err_free_shampo; + goto err_free_by_rq_type; }if (xdp_rxq_info_is_reg (&rq->xdp_rxq)) err =xdp_rxq_info_reg_mem_model (&rq->xdp_rxq,MEM_TYPE_PAGE_POOL , rq->page_pool); }if (err) - goto err_free_shampo; + goto err_destroy_page_pool;for (i =0 ; i < wq_sz; i++) {if (rq->wq_type ==MLX5_WQ_TYPE_LINKED_LIST_STRIDING_RQ ) {
@@ -780,11 +780,13 @@ static int mlx5e_alloc_rq(struct mlx5e_params *params,return 0 ; -err_free_shampo: -mlx5e_rq_free_shampo (rq); +err_destroy_page_pool: +page_pool_destroy (rq->page_pool); err_free_by_rq_type:switch (rq->wq_type) {case MLX5_WQ_TYPE_LINKED_LIST_STRIDING_RQ : +mlx5e_rq_free_shampo (rq); +err_free_mpwqe_info:kvfree (rq->mpwqe.info); err_rq_mkey:mlx5_core_destroy_mkey (mdev,be32_to_cpu (rq->mpwqe.umr_mkey_be));
Signature · 1 line
2.37.3
Jakub Kicinski
maintainerQuoted 10 lines · On Thu, 29 Sep 2022 00:21:40 -0700 Saeed Mahameed wrote:
XSK buffer improvements, This is part #2 of 4 parts series.
1) Expose xsk min chunk size to drivers, to allow the driver to adjust to a better buffer stride size
2) Adjust MTT page size to the XSK frame size, to avoid umem overrun in certain situations.
3) Use xsk frame size as the striding RQ page size for XSK RQs
Quoted 7 lines
4) KSM for unaligned XSK, KSM allows arbitrary buffer chunk lengths registration in HW, which makes more sense for unaligned XSK.
4) More cleanups and optimizations in preparation for next improvements in part3
LGTM
This series was applied to netdev/net-next.git (master) by Jakub Kicinski <[email protected]>:
Hello:
This series was applied to netdev/net-next.git (master) by Jakub Kicinski <[email protected]>:
Quoted 8 lines · On Thu, 29 Sep 2022 00:21:40 -0700 you wrote:
From: Saeed Mahameed <[email protected]>
XSK buffer improvements, This is part #2 of 4 parts series.
1) Expose xsk min chunk size to drivers, to allow the driver to adjust to a better buffer stride size
[...]
Here is the summary with links:
- [net-next,01/16] xsk: Expose min chunk size to drivers
https://git.kernel.org/netdev/net-next/c/9ca66afe73da - [net-next,02/16] net/mlx5e: Use runtime page_shift for striding RQ https://git.kernel.org/netdev/net-next/c/e5a3cc83d540 - [net-next,03/16] net/mlx5e: xsk: Use XSK frame size as striding RQ page size https://git.kernel.org/netdev/net-next/c/fa5573359aae - [net-next,04/16] net/mlx5e: Keep a separate MKey for striding RQ https://git.kernel.org/netdev/net-next/c/ecc7ad2eab35 - [net-next,05/16] net/mlx5: Add MLX5_FLEXIBLE_INLEN to safely calculate cmd inlen https://git.kernel.org/netdev/net-next/c/c4418f349554 - [net-next,06/16] net/mlx5e: xsk: Use KSM for unaligned XSK https://git.kernel.org/netdev/net-next/c/6470d2e7e8ed - [net-next,07/16] xsk: Remove unused xsk_buff_discard https://git.kernel.org/netdev/net-next/c/f2f167583601 - [net-next,08/16] net/mlx5e: Fix calculations for ICOSQ size https://git.kernel.org/netdev/net-next/c/0b9c86c78586 - [net-next,09/16] net/mlx5e: Optimize the page cache reducing its size 2x https://git.kernel.org/netdev/net-next/c/707f908e31d7 - [net-next,10/16] net/mlx5e: Rename mlx5e_dma_info to prepare for removal of DMA address https://git.kernel.org/netdev/net-next/c/79008676d533 - [net-next,11/16] net/mlx5e: Remove DMA address from mlx5e_alloc_unit https://git.kernel.org/netdev/net-next/c/6bdeb963822a - [net-next,12/16] net/mlx5e: Convert struct mlx5e_alloc_unit to a union https://git.kernel.org/netdev/net-next/c/672db0243349 - [net-next,13/16] net/mlx5e: xsk: Remove mlx5e_xsk_page_alloc_pool https://git.kernel.org/netdev/net-next/c/2d0765f78c13 - [net-next,14/16] net/mlx5e: Split out channel (de)activation in rx_res https://git.kernel.org/netdev/net-next/c/d32c225316d4 - [net-next,15/16] net/mlx5e: Move repeating clear_bit in mlx5e_rx_reporter_err_rq_cqe_recover https://git.kernel.org/netdev/net-next/c/e64d71d055ca - [net-next,16/16] net/mlx5e: Clean up and fix error flows in mlx5e_alloc_rq https://git.kernel.org/netdev/net-next/c/8f5ed1c140f8
You are awesome, thank you!
Signature · 2 lines
Deet-doot-dot, I am a bot. https://korg.docs.kernel.org/patchwork/pwbot.html