Skip to content

Commit 8f12d11

Browse files
ameryhungMartin KaFai Lau
authored andcommitted
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 <[email protected]> Signed-off-by: Martin KaFai Lau <[email protected]> Reviewed-by: Maciej Fijalkowski <[email protected]> Link: https://patch.msgid.link/[email protected]
1 parent 54728bd commit 8f12d11

File tree

2 files changed

+6
-0
lines changed

2 files changed

+6
-0
lines changed

include/net/xdp.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -115,6 +115,11 @@ static __always_inline void xdp_buff_set_frag_pfmemalloc(struct xdp_buff *xdp)
115115
xdp->flags |= XDP_FLAGS_FRAGS_PF_MEMALLOC;
116116
}
117117

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+
118123
static __always_inline void
119124
xdp_init_buff(struct xdp_buff *xdp, u32 frame_sz, struct xdp_rxq_info *rxq)
120125
{

net/core/filter.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4210,6 +4210,7 @@ static int bpf_xdp_frags_shrink_tail(struct xdp_buff *xdp, int offset)
42104210

42114211
if (unlikely(!sinfo->nr_frags)) {
42124212
xdp_buff_clear_frags_flag(xdp);
4213+
xdp_buff_clear_frag_pfmemalloc(xdp);
42134214
xdp->data_end -= offset;
42144215
}
42154216

0 commit comments

Comments
 (0)