]> git.ipfire.org Git - thirdparty/kernel/stable.git/commitdiff
bpf: Clear pfmemalloc flag when freeing all fragments
authorAmery Hung <ameryhung@gmail.com>
Mon, 22 Sep 2025 23:33:49 +0000 (16:33 -0700)
committerMartin KaFai Lau <martin.lau@kernel.org>
Tue, 23 Sep 2025 20:35:11 +0000 (13:35 -0700)
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
include/net/xdp.h
net/core/filter.c

index b40f1f96cb117703df17cf9ef659851d4b357a4f..f288c348a6c13226903e705119b0df2045662c7d 100644 (file)
@@ -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)
 {
index 63f3baee2dafa7266594a51e2cf82768550d34ca..5837534f4352bf297a03cd5240361fdcbff101a3 100644 (file)
@@ -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;
        }