Before this patch, the linear striding RQ handler tested every page for a net_iov, to skip the prefetches of XDP-only pages and to release them after their last stride. RQs of system pages never get a net_iov, yet the test, and the values it keeps live across the program call, cost native XDP 7 instructions per packet on every RQ. An RQ gets an XDP-only provider only through a queue restart, which allocates new RQs, so whether an RQ receives into net_iovs is fixed when its page pool is created. Make the choice once per RQ. Build the linear handler in two variants and give an RQ the XDP-only one when its pool has such a provider. RQs of system pages then run the code they ran before XDP-only providers existed, and provider RQs skip the test as well. Binding or unbinding a provider restarts the queue and so picks the handler again. Swapping the program keeps the RQs, and a provider needs a program throughout. Signed-off-by: Björn Töpel --- Notes (v2changes): Changes in v2: - New in v2. drivers/net/ethernet/mellanox/mlx5/core/en.h | 1 + .../net/ethernet/mellanox/mlx5/core/en_main.c | 2 + .../net/ethernet/mellanox/mlx5/core/en_rx.c | 54 ++++++++++++++++--- 3 files changed, 50 insertions(+), 7 deletions(-) diff --git a/drivers/net/ethernet/mellanox/mlx5/core/en.h b/drivers/net/ethernet/mellanox/mlx5/core/en.h index 657a7d59c845..05d2216ab981 100644 --- a/drivers/net/ethernet/mellanox/mlx5/core/en.h +++ b/drivers/net/ethernet/mellanox/mlx5/core/en.h @@ -618,6 +618,7 @@ typedef void (*mlx5e_fp_dealloc_wqe)(struct mlx5e_rq*, u16); typedef void (*mlx5e_fp_shampo_dealloc_hd)(struct mlx5e_rq*, u16, u16, bool); int mlx5e_rq_set_handlers(struct mlx5e_rq *rq, struct mlx5e_params *params, bool xsk); +void mlx5e_rq_set_xdp_only(struct mlx5e_rq *rq); void mlx5e_rq_set_trap_handlers(struct mlx5e_rq *rq, struct mlx5e_params *params); enum mlx5e_rq_flag { diff --git a/drivers/net/ethernet/mellanox/mlx5/core/en_main.c b/drivers/net/ethernet/mellanox/mlx5/core/en_main.c index 74a2ae37a587..8fdd78f74f38 100644 --- a/drivers/net/ethernet/mellanox/mlx5/core/en_main.c +++ b/drivers/net/ethernet/mellanox/mlx5/core/en_main.c @@ -1050,6 +1050,8 @@ static int mlx5e_alloc_rq(struct mlx5e_params *params, MEM_TYPE_PAGE_POOL, rq->page_pool); if (err) goto err_destroy_page_pool; + if (rq->xdp_rxq.xdp_only_area) + mlx5e_rq_set_xdp_only(rq); } } diff --git a/drivers/net/ethernet/mellanox/mlx5/core/en_rx.c b/drivers/net/ethernet/mellanox/mlx5/core/en_rx.c index a93eefa581c0..3845c71c5680 100644 --- a/drivers/net/ethernet/mellanox/mlx5/core/en_rx.c +++ b/drivers/net/ethernet/mellanox/mlx5/core/en_rx.c @@ -70,6 +70,11 @@ static struct sk_buff * mlx5e_skb_from_cqe_mpwrq_nonlinear(struct mlx5e_rq *rq, struct mlx5e_mpw_info *wi, struct mlx5_cqe64 *cqe, u16 cqe_bcnt, u32 head_offset, u32 page_idx); +static struct sk_buff * +mlx5e_skb_from_cqe_mpwrq_linear_xo(struct mlx5e_rq *rq, + struct mlx5e_mpw_info *wi, + struct mlx5_cqe64 *cqe, u16 cqe_bcnt, + u32 head_offset, u32 page_idx); static void mlx5e_handle_rx_cqe(struct mlx5e_rq *rq, struct mlx5_cqe64 *cqe); static void mlx5e_handle_rx_cqe_mpwrq(struct mlx5e_rq *rq, struct mlx5_cqe64 *cqe); static void mlx5e_handle_rx_cqe_mpwrq_shampo(struct mlx5e_rq *rq, struct mlx5_cqe64 *cqe); @@ -2094,10 +2099,17 @@ mlx5e_skb_from_cqe_mpwrq_nonlinear(struct mlx5e_rq *rq, struct mlx5e_mpw_info *w return skb; } -static struct sk_buff * -mlx5e_skb_from_cqe_mpwrq_linear(struct mlx5e_rq *rq, struct mlx5e_mpw_info *wi, - struct mlx5_cqe64 *cqe, u16 cqe_bcnt, u32 head_offset, - u32 page_idx) +/* An RQ of an XDP-only memory provider has only its net_iovs, see + * mlx5e_rq_set_xdp_only(). A constant @xdp_only keeps the test out of RQs + * of system pages. + */ +/* Inlined into each handler below, so xdp_only is a compile-time constant */ +static __always_inline struct sk_buff * +__mlx5e_skb_from_cqe_mpwrq_linear(struct mlx5e_rq *rq, + struct mlx5e_mpw_info *wi, + struct mlx5_cqe64 *cqe, u16 cqe_bcnt, + u32 head_offset, u32 page_idx, + const bool xdp_only) { struct mlx5e_frag_page *frag_page = &wi->alloc_units.frag_pages[page_idx]; u16 rx_headroom = rq->buff.headroom; @@ -2107,7 +2119,6 @@ mlx5e_skb_from_cqe_mpwrq_linear(struct mlx5e_rq *rq, struct mlx5e_mpw_info *wi, void *va, *data; dma_addr_t addr; u32 frag_size; - bool xdp_only; /* Check packet size. Note LRO doesn't use linear SKB */ if (unlikely(cqe_bcnt > rq->hw_mtu)) { @@ -2125,7 +2136,6 @@ mlx5e_skb_from_cqe_mpwrq_linear(struct mlx5e_rq *rq, struct mlx5e_mpw_info *wi, /* The kernel reads an XDP-only head only if the program does, and a * prefetch may cost a page walk */ - xdp_only = netmem_is_net_iov(frag_page->netmem); if (!xdp_only) net_prefetch(data); @@ -2171,6 +2181,35 @@ mlx5e_skb_from_cqe_mpwrq_linear(struct mlx5e_rq *rq, struct mlx5e_mpw_info *wi, return skb; } +static struct sk_buff * +mlx5e_skb_from_cqe_mpwrq_linear(struct mlx5e_rq *rq, struct mlx5e_mpw_info *wi, + struct mlx5_cqe64 *cqe, u16 cqe_bcnt, + u32 head_offset, u32 page_idx) +{ + return __mlx5e_skb_from_cqe_mpwrq_linear(rq, wi, cqe, cqe_bcnt, + head_offset, page_idx, false); +} + +static struct sk_buff * +mlx5e_skb_from_cqe_mpwrq_linear_xo(struct mlx5e_rq *rq, + struct mlx5e_mpw_info *wi, + struct mlx5_cqe64 *cqe, u16 cqe_bcnt, + u32 head_offset, u32 page_idx) +{ + return __mlx5e_skb_from_cqe_mpwrq_linear(rq, wi, cqe, cqe_bcnt, + head_offset, page_idx, true); +} + +/* An XDP-only memory provider backs the page pool of @rq, which then + * receives into its net_iovs only + */ +void mlx5e_rq_set_xdp_only(struct mlx5e_rq *rq) +{ + if (rq->mpwqe.skb_from_cqe_mpwrq == mlx5e_skb_from_cqe_mpwrq_linear) + rq->mpwqe.skb_from_cqe_mpwrq = + mlx5e_skb_from_cqe_mpwrq_linear_xo; +} + static struct sk_buff * mlx5e_skb_from_cqe_shampo(struct mlx5e_rq *rq, struct mlx5e_mpw_info *wi, struct mlx5_cqe64 *cqe, u16 header_index) @@ -2398,10 +2437,11 @@ static void mlx5e_handle_rx_cqe_mpwrq(struct mlx5e_rq *rq, struct mlx5_cqe64 *cq cqe_bcnt = mpwrq_get_cqe_byte_cnt(cqe); - skb = INDIRECT_CALL_3(rq->mpwqe.skb_from_cqe_mpwrq, + skb = INDIRECT_CALL_4(rq->mpwqe.skb_from_cqe_mpwrq, mlx5e_skb_from_cqe_mpwrq_linear, mlx5e_skb_from_cqe_mpwrq_nonlinear, mlx5e_xsk_skb_from_cqe_mpwrq_linear, + mlx5e_skb_from_cqe_mpwrq_linear_xo, rq, wi, cqe, cqe_bcnt, head_offset, page_idx); if (!skb) -- 2.56.1