Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

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: Amery Hung <ameryhung@gmail.com>
Signed-off-by: Martin KaFai Lau <martin.lau@kernel.org>
Reviewed-by: Maciej Fijalkowski <maciej.fijalkowski@intel.com>
Link: https://patch.msgid.link/20250922233356.3356453-2-ameryhung@gmail.com

authored by

Amery Hung and committed by
Martin KaFai Lau
8f12d113 54728bd5

+6
+5
include/net/xdp.h
··· 115 115 xdp->flags |= XDP_FLAGS_FRAGS_PF_MEMALLOC; 116 116 } 117 117 118 + static __always_inline void xdp_buff_clear_frag_pfmemalloc(struct xdp_buff *xdp) 119 + { 120 + xdp->flags &= ~XDP_FLAGS_FRAGS_PF_MEMALLOC; 121 + } 122 + 118 123 static __always_inline void 119 124 xdp_init_buff(struct xdp_buff *xdp, u32 frame_sz, struct xdp_rxq_info *rxq) 120 125 {
+1
net/core/filter.c
··· 4210 4210 4211 4211 if (unlikely(!sinfo->nr_frags)) { 4212 4212 xdp_buff_clear_frags_flag(xdp); 4213 + xdp_buff_clear_frag_pfmemalloc(xdp); 4213 4214 xdp->data_end -= offset; 4214 4215 } 4215 4216