Commit 1827f773 authored by Jakub Kicinski's avatar Jakub Kicinski Committed by Paolo Abeni
Browse files

net: xdp: pass full flags to xdp_update_skb_shared_info()



xdp_update_skb_shared_info() needs to update skb state which
was maintained in xdp_buff / frame. Pass full flags into it,
instead of breaking it out bit by bit. We will need to add
a bit for unreadable frags (even tho XDP doesn't support
those the driver paths may be common), at which point almost
all call sites would become:

    xdp_update_skb_shared_info(skb, num_frags,
                               sinfo->xdp_frags_size,
                               MY_PAGE_SIZE * num_frags,
                               xdp_buff_is_frag_pfmemalloc(xdp),
                               xdp_buff_is_frag_unreadable(xdp));

Keep a helper for accessing the flags, in case we need to
transform them somehow in the future (e.g. to cover up xdp_buff
vs xdp_frame differences).

While we are touching call callers - rename the helper to
xdp_update_skb_frags_info(), previous name may have implied that
it's shinfo that's updated. We are updating flags in struct sk_buff
based on frags that got attched.

Signed-off-by: default avatarJakub Kicinski <kuba@kernel.org>
Acked-by: default avatarJesper Dangaard Brouer <hawk@kernel.org>
Link: https://patch.msgid.link/20250905221539.2930285-2-kuba@kernel.org


Acked-by: default avatarStanislav Fomichev <sdf@fomichev.me>
Reviewed-by: default avatarAlexander Lobakin <aleksander.lobakin@intel.com>
Signed-off-by: default avatarPaolo Abeni <pabeni@redhat.com>
parent db1b6006
Loading
Loading
Loading
Loading
+3 −4
Original line number Diff line number Diff line
@@ -468,9 +468,8 @@ bnxt_xdp_build_skb(struct bnxt *bp, struct sk_buff *skb, u8 num_frags,
	if (!skb)
		return NULL;

	xdp_update_skb_shared_info(skb, num_frags,
				   sinfo->xdp_frags_size,
	xdp_update_skb_frags_info(skb, num_frags, sinfo->xdp_frags_size,
				  BNXT_RX_PAGE_SIZE * num_frags,
				   xdp_buff_is_frag_pfmemalloc(xdp));
				  xdp_buff_get_skb_flags(xdp));
	return skb;
}
+7 −8
Original line number Diff line number Diff line
@@ -2151,10 +2151,10 @@ static struct sk_buff *i40e_construct_skb(struct i40e_ring *rx_ring,
		memcpy(&skinfo->frags[skinfo->nr_frags], &sinfo->frags[0],
		       sizeof(skb_frag_t) * nr_frags);

		xdp_update_skb_shared_info(skb, skinfo->nr_frags + nr_frags,
		xdp_update_skb_frags_info(skb, skinfo->nr_frags + nr_frags,
					  sinfo->xdp_frags_size,
					  nr_frags * xdp->frame_sz,
					   xdp_buff_is_frag_pfmemalloc(xdp));
					  xdp_buff_get_skb_flags(xdp));

		/* First buffer has already been processed, so bump ntc */
		if (++rx_ring->next_to_clean == rx_ring->count)
@@ -2206,10 +2206,9 @@ static struct sk_buff *i40e_build_skb(struct i40e_ring *rx_ring,
		skb_metadata_set(skb, metasize);

	if (unlikely(xdp_buff_has_frags(xdp))) {
		xdp_update_skb_shared_info(skb, nr_frags,
					   sinfo->xdp_frags_size,
		xdp_update_skb_frags_info(skb, nr_frags, sinfo->xdp_frags_size,
					  nr_frags * xdp->frame_sz,
					   xdp_buff_is_frag_pfmemalloc(xdp));
					  xdp_buff_get_skb_flags(xdp));

		i40e_process_rx_buffs(rx_ring, I40E_XDP_PASS, xdp);
	} else {
+7 −8
Original line number Diff line number Diff line
@@ -1035,10 +1035,9 @@ ice_build_skb(struct ice_rx_ring *rx_ring, struct xdp_buff *xdp)
		skb_metadata_set(skb, metasize);

	if (unlikely(xdp_buff_has_frags(xdp)))
		xdp_update_skb_shared_info(skb, nr_frags,
					   sinfo->xdp_frags_size,
		xdp_update_skb_frags_info(skb, nr_frags, sinfo->xdp_frags_size,
					  nr_frags * xdp->frame_sz,
					   xdp_buff_is_frag_pfmemalloc(xdp));
					  xdp_buff_get_skb_flags(xdp));

	return skb;
}
@@ -1115,10 +1114,10 @@ ice_construct_skb(struct ice_rx_ring *rx_ring, struct xdp_buff *xdp)
		memcpy(&skinfo->frags[skinfo->nr_frags], &sinfo->frags[0],
		       sizeof(skb_frag_t) * nr_frags);

		xdp_update_skb_shared_info(skb, skinfo->nr_frags + nr_frags,
		xdp_update_skb_frags_info(skb, skinfo->nr_frags + nr_frags,
					  sinfo->xdp_frags_size,
					  nr_frags * xdp->frame_sz,
					   xdp_buff_is_frag_pfmemalloc(xdp));
					  xdp_buff_get_skb_flags(xdp));
	}

	return skb;
+3 −4
Original line number Diff line number Diff line
@@ -2416,10 +2416,9 @@ mvneta_swbm_build_skb(struct mvneta_port *pp, struct page_pool *pool,
	skb->ip_summed = mvneta_rx_csum(pp, desc_status);

	if (unlikely(xdp_buff_has_frags(xdp)))
		xdp_update_skb_shared_info(skb, num_frags,
					   sinfo->xdp_frags_size,
		xdp_update_skb_frags_info(skb, num_frags, sinfo->xdp_frags_size,
					  num_frags * xdp->frame_sz,
					   xdp_buff_is_frag_pfmemalloc(xdp));
					  xdp_buff_get_skb_flags(xdp));

	return skb;
}
+11 −12
Original line number Diff line number Diff line
@@ -1796,10 +1796,9 @@ mlx5e_skb_from_cqe_nonlinear(struct mlx5e_rq *rq, struct mlx5e_wqe_frag_info *wi

	if (xdp_buff_has_frags(&mxbuf->xdp)) {
		/* sinfo->nr_frags is reset by build_skb, calculate again. */
		xdp_update_skb_shared_info(skb, wi - head_wi - 1,
		xdp_update_skb_frags_info(skb, wi - head_wi - 1,
					  sinfo->xdp_frags_size, truesize,
					   xdp_buff_is_frag_pfmemalloc(
						&mxbuf->xdp));
					  xdp_buff_get_skb_flags(&mxbuf->xdp));

		for (struct mlx5e_wqe_frag_info *pwi = head_wi + 1; pwi < wi; pwi++)
			pwi->frag_page->frags++;
@@ -2105,10 +2104,10 @@ mlx5e_skb_from_cqe_mpwrq_nonlinear(struct mlx5e_rq *rq, struct mlx5e_mpw_info *w
			struct mlx5e_frag_page *pagep;

			/* sinfo->nr_frags is reset by build_skb, calculate again. */
			xdp_update_skb_shared_info(skb, frag_page - head_page,
						   sinfo->xdp_frags_size, truesize,
						   xdp_buff_is_frag_pfmemalloc(
							&mxbuf->xdp));
			xdp_update_skb_frags_info(skb, frag_page - head_page,
						  sinfo->xdp_frags_size,
						  truesize,
						  xdp_buff_get_skb_flags(&mxbuf->xdp));

			pagep = head_page;
			do
@@ -2122,10 +2121,10 @@ mlx5e_skb_from_cqe_mpwrq_nonlinear(struct mlx5e_rq *rq, struct mlx5e_mpw_info *w
		if (xdp_buff_has_frags(&mxbuf->xdp)) {
			struct mlx5e_frag_page *pagep;

			xdp_update_skb_shared_info(skb, sinfo->nr_frags,
						   sinfo->xdp_frags_size, truesize,
						   xdp_buff_is_frag_pfmemalloc(
							&mxbuf->xdp));
			xdp_update_skb_frags_info(skb, sinfo->nr_frags,
						  sinfo->xdp_frags_size,
						  truesize,
						  xdp_buff_get_skb_flags(&mxbuf->xdp));

			pagep = frag_page - sinfo->nr_frags;
			do
Loading