bpf: Allow bpf_xdp_shrink_data to shrink a frag from head and tail
authorAmery Hung <ameryhung@gmail.com>
Mon, 22 Sep 2025 23:33:50 +0000 (16:33 -0700)
committerMartin KaFai Lau <martin.lau@kernel.org>
Tue, 23 Sep 2025 20:35:12 +0000 (13:35 -0700)
commitdea1526fbafb55099a788cde0b659530ee5b1c66
treea72ea9808528d036ee8fde223e14c184289b4004
parent8f12d1137c2382c80aada8e05d7cc650cd4e403c
bpf: Allow bpf_xdp_shrink_data to shrink a frag from head and tail

Move skb_frag_t adjustment into bpf_xdp_shrink_data() and extend its
functionality to be able to shrink an xdp fragment from both head and
tail. In a later patch, bpf_xdp_pull_data() will reuse it to shrink an
xdp fragment from head.

Additionally, in bpf_xdp_frags_shrink_tail(), breaking the loop when
bpf_xdp_shrink_data() returns false (i.e., not releasing the current
fragment) is not necessary as the loop condition, offset > 0, has the
same effect. Remove the else branch to simplify the code.

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-3-ameryhung@gmail.com
include/net/xdp_sock_drv.h
net/core/filter.c