Commit 8f12d113 authored by Amery Hung's avatar Amery Hung Committed by Martin KaFai Lau
Browse files

bpf: Clear pfmemalloc flag when freeing all fragments



It is possible for bpf_xdp_adjust_tail() to free all fragments. The
kfunc currently clears the XDP_FLAGS_HAS_FRAGS bit, but not
XDP_FLAGS_FRAGS_PF_MEMALLOC. So far, this has not caused a issue when
building sk_buff from xdp_buff since all readers of xdp_buff->flags
use the flag only when there are fragments. Clear the
XDP_FLAGS_FRAGS_PF_MEMALLOC bit as well to make the flags correct.

Signed-off-by: default avatarAmery Hung <ameryhung@gmail.com>
Signed-off-by: default avatarMartin KaFai Lau <martin.lau@kernel.org>
Reviewed-by: default avatarMaciej Fijalkowski <maciej.fijalkowski@intel.com>
Link: https://patch.msgid.link/20250922233356.3356453-2-ameryhung@gmail.com
parent 54728bd5
Loading
Loading
Loading
Loading
+5 −0
Original line number Diff line number Diff line
@@ -115,6 +115,11 @@ static __always_inline void xdp_buff_set_frag_pfmemalloc(struct xdp_buff *xdp)
	xdp->flags |= XDP_FLAGS_FRAGS_PF_MEMALLOC;
}

static __always_inline void xdp_buff_clear_frag_pfmemalloc(struct xdp_buff *xdp)
{
	xdp->flags &= ~XDP_FLAGS_FRAGS_PF_MEMALLOC;
}

static __always_inline void
xdp_init_buff(struct xdp_buff *xdp, u32 frame_sz, struct xdp_rxq_info *rxq)
{
+1 −0
Original line number Diff line number Diff line
@@ -4210,6 +4210,7 @@ static int bpf_xdp_frags_shrink_tail(struct xdp_buff *xdp, int offset)

	if (unlikely(!sinfo->nr_frags)) {
		xdp_buff_clear_frags_flag(xdp);
		xdp_buff_clear_frag_pfmemalloc(xdp);
		xdp->data_end -= offset;
	}