bpf: Support pulling non-linear xdp data
authorAmery Hung <ameryhung@gmail.com>
Mon, 22 Sep 2025 23:33:51 +0000 (16:33 -0700)
committerMartin KaFai Lau <martin.lau@kernel.org>
Tue, 23 Sep 2025 20:35:12 +0000 (13:35 -0700)
commit4dce1a0d7cf39575a5880414ea882890edd8d26f
tree64c0fb7fc7497c06ae071b6cfef8377c715a9a36
parentdea1526fbafb55099a788cde0b659530ee5b1c66
bpf: Support pulling non-linear xdp data

Add kfunc, bpf_xdp_pull_data(), to support pulling data from xdp
fragments. Similar to bpf_skb_pull_data(), bpf_xdp_pull_data() makes
the first len bytes of data directly readable and writable in bpf
programs. If the "len" argument is larger than the linear data size,
data in fragments will be copied to the linear data area when there
is enough room. Specifically, the kfunc will try to use the tailroom
first. When the tailroom is not enough, metadata and data will be
shifted down to make room for pulling data.

A use case of the kfunc is to decapsulate headers residing in xdp
fragments. It is possible for a NIC driver to place headers in xdp
fragments. To keep using direct packet access for parsing and
decapsulating headers, users can pull headers into the linear data
area by calling bpf_xdp_pull_data() and then pop the header with
bpf_xdp_adjust_head().

Signed-off-by: Amery Hung <ameryhung@gmail.com>
Signed-off-by: Martin KaFai Lau <martin.lau@kernel.org>
Reviewed-by: Jakub Kicinski <kuba@kernel.org>
Link: https://patch.msgid.link/20250922233356.3356453-4-ameryhung@gmail.com
net/core/filter.c