Netdev List
 help / color / mirror / Atom feed
* [PATCH RFC net-next 0/6] skb extension for BPF metadata
@ 2026-07-14 17:48 Jakub Sitnicki
  2026-07-14 17:48 ` [PATCH RFC net-next 1/6] bpf: Introduce per-packet metadata storage for BPF programs Jakub Sitnicki
                   ` (5 more replies)
  0 siblings, 6 replies; 11+ messages in thread
From: Jakub Sitnicki @ 2026-07-14 17:48 UTC (permalink / raw)
  To: netdev; +Cc: bpf, kernel-team

BPF programs attached at different points in the network stack have no way
to pass data between each other on a per-packet basis. xdp/skb->data_meta
covers the XDP-to-TC handoff, but is not available to programs at later
hooks like cgroup/skb, sock_ops, socket filters, tracing, or LSM.

This series adds a per-packet metadata byte buffer for BPF, carried inline
in a new skb extension (struct bpf_skb_ext). Programs access it through a
bpf_dynptr returned by the bpf_dynptr_from_skb_ext() kfunc.

Pass BPF_SKB_EXT_F_CREATE to allocate (or COW) the extension and get a
read-write dynptr; omit the flag to get a read-only view of existing
metadata, or -ENOENT if none has been attached. The inline buffer is up to
256 bytes, sized at build time via CONFIG_BPF_SKB_EXT_SIZE (default 64).

Metadata survives across hooks (TC -> socket filter) and, when opted in
with BPF_SKB_EXT_F_NO_SCRUB, across tunnel encap/decap and cross-netns
forwarding. Without the flag the extension is scrubbed at the usual
points (skb_scrub_packet).

This is our third attempt at the problem. We first tried to make XDP/skb
metadata persist across network layers and expose it as a dynptr [1], then
turned to BPF local storage for skb's [2]. Based on the feedback from both,
we converged on the simpler skb extension + dynptr approach.

We are posting this RFC to accompany a Netdev talk on the topic [3]. We are
currently running an experiment in a production environment to evaluate the
performance of this approach and will follow up with results and a
comparison to alternatives.

Thanks,
-jkbs

[1] https://lore.kernel.org/all/20260107-skb-meta-safeproof-netdevs-rx-only-v3-0-0d461c5e4764@cloudflare.com/
[2] https://lore.kernel.org/all/20260226-skb-local-storage-v1-0-4ca44f0dd9d1@cloudflare.com/
[3] https://www.netdevconf.info/0x1A/sessions/talk/thrice-the-charm-an-skb-extension-for-bpf-metadata.html

Signed-off-by: Jakub Sitnicki <jakub@cloudflare.com>
---
Jakub Sitnicki (6):
      bpf: Introduce per-packet metadata storage for BPF programs
      bpf: Allow access to bpf_sock_ops_kern->skb
      bpf: Allow skb extensions to survive packet scrubbing
      selftests/bpf: Add tests for bpf_dynptr_from_skb_ext
      selftests/bpf: Test skb_ext scrubbing across tunnels and veths
      selftests/bpf: Use non-trivial test payload in xdp_context tests

 include/linux/bpf.h                                |  11 +
 include/linux/filter.h                             |  26 +
 include/linux/skbuff.h                             |   5 +
 include/uapi/linux/bpf.h                           |   6 +
 kernel/bpf/helpers.c                               |   7 +
 kernel/bpf/log.c                                   |   2 +
 kernel/bpf/verifier.c                              |  15 +-
 net/Kconfig                                        |  20 +
 net/core/filter.c                                  | 134 +++++
 net/core/skbuff.c                                  |  85 ++-
 net/ipv4/udp.c                                     |   2 +-
 .../bpf/prog_tests/xdp_context_test_run.c          | 592 ++++++++++++++++++++-
 tools/testing/selftests/bpf/progs/test_xdp_meta.c  | 418 ++++++++++++++-
 13 files changed, 1303 insertions(+), 20 deletions(-)


^ permalink raw reply	[flat|nested] 11+ messages in thread

end of thread, other threads:[~2026-07-16 12:59 UTC | newest]

Thread overview: 11+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-07-14 17:48 [PATCH RFC net-next 0/6] skb extension for BPF metadata Jakub Sitnicki
2026-07-14 17:48 ` [PATCH RFC net-next 1/6] bpf: Introduce per-packet metadata storage for BPF programs Jakub Sitnicki
2026-07-16 12:10   ` Stanislav Fomichev
2026-07-16 12:35     ` Jakub Sitnicki
2026-07-14 17:48 ` [PATCH RFC net-next 2/6] bpf: Allow access to bpf_sock_ops_kern->skb Jakub Sitnicki
2026-07-14 17:48 ` [PATCH RFC net-next 3/6] bpf: Allow skb extensions to survive packet scrubbing Jakub Sitnicki
2026-07-16 12:11   ` Stanislav Fomichev
2026-07-16 12:59     ` Jakub Sitnicki
2026-07-14 17:48 ` [PATCH RFC net-next 4/6] selftests/bpf: Add tests for bpf_dynptr_from_skb_ext Jakub Sitnicki
2026-07-14 17:48 ` [PATCH RFC net-next 5/6] selftests/bpf: Test skb_ext scrubbing across tunnels and veths Jakub Sitnicki
2026-07-14 17:48 ` [PATCH RFC net-next 6/6] selftests/bpf: Use non-trivial test payload in xdp_context tests Jakub Sitnicki

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox