skb extension for BPF metadata
Subsystems (9)
v2 cover skb extension for BPF metadata
This is the second spin of the per-packet metadata for BPF. See the RFC cover letter for the full overview and motivation [1].
Since v1 the focus has been on getting skb scrubbing and extension sharing right, driven by Sashiko's review:
1) skb scrubbing now simply deactivates all the extensions but the BPF metadata. Made possible due to recent change in skb_ext_del semantics [2] that already landed in net-next. Thanks to Florian and Paolo for guidance on this.
2) Clones made by bpf_clone_redirect() share the extension block. A write through a previously acquired writable dynptr would land in the shared block and become visible to the clone, so v2 makes such writes fail until the program re-acquires the dynptr with BPF_SKB_EXT_F_CREATE, which COWs the block into a private writable copy.
3) Re-acquiring the extension with BPF_SKB_EXT_F_CREATE can COW and free the old block, so a dynptr slice taken before that re-acquire would be left pointing into freed memory. bpf_dynptr_from_skb_ext() is therefore marked packet-changing, making the verifier invalidate such slices and forcing the program to re-take them after the re-acquire.
4) Tracing and LSM programs can run on a shared skb concurrently on another CPU, so creating the extension there would mutate skb->extensions without synchronization. v2 rejects BPF_SKB_EXT_F_CREATE in these program types at load time; read-only access remains available.
Regarding performance compared to consume_skb+kfree_skb tracepoints, I have not yet re-run the experiment measuring the overhead when attaching metadata to 5% instead of 1% of skbs in flight; happy to do so if it is a blocker.
That said, as things stand we have already established in v1 [3] that for our existing use case - attaching metadata to <1% of skbs - the tracepoint-based approach is prohibitively expensive (+5% of CPU time), as Jesper noted.
The skb-extension-based solution, in contrast, shows comparable-or-lower overhead, making it a viable drop-in replacement that enables new use cases for us and potentially offers a performance win.
Thanks,
-jkbs
[1] https://patch.msgid.link/20260714-bpf-meta-inside-skb-ext-v1-0-5871c07a8dd6@cloudflare.com
[2] https://lore.kernel.org/all/[email protected]/
[3] https://patch.msgid.link/20260814-bpf-meta-inside-skb-ext-v1-0-767edd862656@cloudflare.com
---
Changes in v2:
- Rework skb_ext_scrub() to simply delete all extensions but bpf_skb_ext
now that the delete operation is idempotent. (Florian, sashiko)
- Fail writes through a dynptr while the extension block is shared with
clones: bpf_dynptr_write() now returns -EBUSY and bpf_dynptr_slice_rdwr()
returns NULL; re-acquiring the dynptr with BPF_SKB_EXT_F_CREATE COWs the
block and restores write access. (sashiko)
- Mark bpf_dynptr_from_skb_ext() as packet-changing so the verifier
invalidates slices from an earlier dynptr when a re-open with F_CREATE
can COW the block and leave them dangling (use-after-free). (sashiko)
- Reject bpf_dynptr_from_skb_ext(BPF_SKB_EXT_F_CREATE) in tracing and LSM
programs, which can run on a shared skb concurrently on another CPU;
require a constant flags argument without F_CREATE at load time, keeping
read-only access. (sashiko)
- selftests: Add verifier negative tests for the new tracing/LSM
restrictions (F_CREATE and non-constant flags rejected). (sashiko)
- selftests: Add clone_redirect coverage into the cloned-skbs test (clone_redir_ext_write_after / clone_redir_ext_slice_write_after),
queueing the clone on a netem-delayed loopback; enable
CONFIG_NET_SCH_NETEM.
- selftests: Fix if_nametoindex() assertions to use ASSERT_GT(..., 0) so a
lookup failure is not silently accepted as ifindex 0. (sashiko)
- selftests: Use int (not __be16) for get_socket_local_port() so a negative
error is not truncated and masked. (sashiko)
- selftests: Validate send()/recv() return values and switch the sk_skb
stream test to recv_timeout() to avoid a hang when the data path
regresses. (Jack Wang, sashiko)
- selftests: Split the LWT test cleanup so bpf_tc_hook_destroy() does not
delete the base-namespace clsact qdisc on the error path. (sashiko)
- selftests: Unify multi-line function comments to the "/*" on its own line
style. (sashiko)
- Link to v1: https://patch.msgid.link/20260814-bpf-meta-inside-skb-ext-v1-0-767edd862656@cloudflare.com
Changes in v1:
- Don't scrub BPF skb extension. Remove F_NO_SCRUB flag. (Stan)
- Allow calling bpf_dynptr_from_skb_ext from NETFILTER, LWT_*, SK_SKB progs.
- Reorg tests into smaller commits. Add missing coverage.
- Link to RFC: https://patch.msgid.link/20260714-bpf-meta-inside-skb-ext-v1-0-5871c07a8dd6@cloudflare.com
---
Jakub Sitnicki (14):
bpf: Introduce per-packet metadata storage for BPF programs
bpf: Allow access to bpf_sock_ops_kern->skb
bpf: Make BPF skb extension survive packet scrubbing selftests/bpf: Add tests for bpf_dynptr_from_skb_ext selftests/bpf: Test skb_ext on cloned skbs selftests/bpf: Test skb_ext survival across veth and GRE selftests/bpf: Test skb_ext read from cgroup_skb and sk_filter hooks selftests/bpf: Test skb_ext read from sock_ops and LSM hooks selftests/bpf: Test skb_ext read from kfree_skb tracepoint selftests/bpf: Test skb_ext read from netfilter hook selftests/bpf: Test skb_ext from LWT in, out, and xmit hooks selftests/bpf: Test skb_ext read from seg6local End.BPF hook selftests/bpf: Test skb_ext read from sk_skb stream verdict hook selftests/bpf: Use non-trivial test payload in xdp_context tests
include/linux/bpf.h | 10 + include/linux/filter.h | 27 + include/linux/skbuff.h | 13 + include/uapi/linux/bpf.h | 5 + kernel/bpf/helpers.c | 21 +- kernel/bpf/log.c | 2 + kernel/bpf/verifier.c | 25 +- net/Kconfig | 20 + net/core/filter.c | 149 +++ net/core/skbuff.c | 27 +- net/ipv4/udp.c | 6 +- tools/testing/selftests/bpf/config | 2 + .../selftests/bpf/prog_tests/socket_helpers.h | 1 + tools/testing/selftests/bpf/prog_tests/verifier.c | 2 + .../bpf/prog_tests/xdp_context_test_run.c | 1117 +++++++++++++++++++- tools/testing/selftests/bpf/progs/test_xdp_meta.c | 569 +++++++++- .../testing/selftests/bpf/progs/verifier_skb_ext.c | 122 +++ 17 files changed, 2094 insertions(+), 24 deletions(-)
PATCH v2 1/14 bpf: Introduce per-packet metadata storage for BPF programs
BPF programs attached at different points in the network stack have no way to pass data between each other on a per-packet basis, other than by stashing it into a shared BPF map. xdp/skb->data_meta works for XDP-to-TC handoff, but is not available to programs running at later hooks like cgroup/skb, sock_ops, socket filters, tracing or LSM.
Add a new skb extension (struct bpf_skb_ext) that provides up to 256 bytes of per-packet storage. Size is configurable at build time through the CONFIG_BPF_SKB_EXT_SIZE option. The storage is embedded inside the extension chunk itself.
Expose the storage to BPF programs via bpf_dynptr_from_skb_ext() kfunc. The caller passes BPF_SKB_EXT_F_CREATE to allocate or COW (unshare) the extension and get a read-write dynptr. Without the flag, it gets a read-only dynptr to the existing extension, or -ENOENT if none exists.
Two corner cases need special handling:
First, a clone made by bpf_clone_redirect() shares the extension block, so a write through a writable dynptr acquired beforehand would land in the shared block and leak into the clone's copy. Refuse such writes: fail bpf_dynptr_write() with -EBUSY and bpf_dynptr_slice_rdwr() with NULL while the block is shared. Re-acquiring the dynptr with BPF_SKB_EXT_F_CREATE COWs the block and restores write access. For the same reason, mark bpf_dynptr_from_skb_ext() as packet-changing so the verifier invalidates slices acquired from an earlier dynptr when a re-open with BPF_SKB_EXT_F_CREATE can COW the block and leave them dangling.
Second, tracing and LSM programs can run on a shared skb concurrently on another CPU, and bpf_dynptr_from_skb_ext() with BPF_SKB_EXT_F_CREATE would mutate skb->extensions without synchronization. Disallow it at load time:
for these program types require the flags argument to be a known constant without BPF_SKB_EXT_F_CREATE. Read-only access remains available.
Guard the feature behind a new CONFIG_BPF_SKB_EXT option.
--- include/linux/bpf.h | 10 ++++ include/linux/filter.h | 27 +++++++++ include/linux/skbuff.h | 11 ++++ include/uapi/linux/bpf.h | 5 ++ kernel/bpf/helpers.c | 21 ++++++- kernel/bpf/log.c | 2 + kernel/bpf/verifier.c | 20 ++++++- net/Kconfig | 20 +++++++ net/core/filter.c | 149 +++++++++++++++++++++++++++++++++++++++++++++++ net/core/skbuff.c | 3 + 10 files changed, 263 insertions(+), 5 deletions(-)
include/linux/bpf.h +10 -0
@@ -1481,6 +1481,8 @@ enum bpf_dynptr_type {BPF_DYNPTR_TYPE_SKB_META ,/* Underlying data is a file */ BPF_DYNPTR_TYPE_FILE , +/* Underlying data is a bpf_skb_ext chunk */ + BPF_DYNPTR_TYPE_SKB_EXT, };int bpf_dynptr_check_size (u64 size);
@@ -4216,4 +4218,12 @@ static inline int bpf_map_check_op_flags(struct bpf_map *map, u64 flags, u64 all return 0; } +#ifdef CONFIG_BPF_SKB_EXT + +struct bpf_skb_ext { +u8 buf[CONFIG_BPF_SKB_EXT_SIZE ]__aligned(8) ; +}; + +#endif /* CONFIG_BPF_SKB_EXT */ +#endif /* _LINUX_BPF_H */
include/linux/filter.h +27 -0
@@ -1958,4 +1958,31 @@ static inline void *bpf_skb_meta_pointer(struct sk_buff *skb, u32 offset) }#endif /* CONFIG_NET */ +#ifdef CONFIG_BPF_SKB_EXT +void *bpf_skb_ext_pointer (struct sk_buff *skb,u32 offset,bool wr); +int __bpf_skb_ext_load_bytes (const struct sk_buff *skb,u32 offset,void *to, +u32 len); +int __bpf_skb_ext_store_bytes (struct sk_buff *skb,u32 offset,const void *from, +u32 len,u64 flags); +#else /* CONFIG_BPF_SKB_EXT */ +static inline void *bpf_skb_ext_pointer (struct sk_buff *skb,u32 offset, +bool wr) +{ +return NULL ; +} + +static inline int __bpf_skb_ext_load_bytes (const struct sk_buff *skb, +u32 offset,void *to,u32 len) +{ +return -EOPNOTSUPP ; +} + +static inline int __bpf_skb_ext_store_bytes (struct sk_buff *skb,u32 offset, +const void *from,u32 len, +u64 flags) +{ +return -EOPNOTSUPP ; +} +#endif /* CONFIG_BPF_SKB_EXT */ +#endif /* __LINUX_FILTER_H__ */
include/linux/skbuff.h +11 -0
@@ -5061,6 +5061,9 @@ enum skb_ext_id {#endif #if IS_ENABLED (CONFIG_CAN ) SKB_EXT_CAN, +#endif +#if IS_ENABLED (CONFIG_BPF_SKB_EXT ) +SKB_EXT_BPF , #endif SKB_EXT_NUM, /* must be last */ };
@@ -5153,6 +5156,13 @@ static inline bool skb_has_extensions(struct sk_buff *skb) {return unlikely (skb->active_extensions); } + +/* True if the extension block is shared with cloned skbs */ +static inline bool skb_ext_shared (const struct sk_buff *skb) +{ +return skb->active_extensions && +refcount_read (&skb->extensions->refcnt) !=1 ; +}#else static inline void __skb_ext_put (struct skb_ext *ext) {}static inline void skb_ext_put (struct sk_buff *skb) {}
@@ -5161,6 +5171,7 @@ static inline void skb_ext_del(struct sk_buff *skb, int unused) {}static inline void __skb_ext_copy (struct sk_buff *d,const struct sk_buff *s) {}static inline void skb_ext_copy (struct sk_buff *dst,const struct sk_buff *s) {}static inline bool skb_has_extensions (struct sk_buff *skb) {return false; } +static inline bool skb_ext_shared (const struct sk_buff *skb) {return false; }#endif /* CONFIG_SKB_EXTENSIONS */ static inline void nf_reset_ct (struct sk_buff *skb)
include/uapi/linux/bpf.h +5 -0
@@ -7825,4 +7825,9 @@ struct bpf_insn_array_value { __u32 :32; }; +/* Flags to control bpf_dynptr_from_skb_ext() behavior. */ +enum { +BPF_SKB_EXT_F_CREATE = (1ULL <<0 ), +}; +#endif /* _UAPI__LINUX_BPF_H__ */
kernel/bpf/helpers.c +18 -3
@@ -1926,6 +1926,8 @@ static int __bpf_dynptr_read(void *dst, u64 len, const struct bpf_dynptr_kern *sreturn 0 ;case BPF_DYNPTR_TYPE_FILE :return bpf_file_fetch_bytes (src->data, offset, dst, len); +case BPF_DYNPTR_TYPE_SKB_EXT : +return __bpf_skb_ext_load_bytes (src->data, src->offset + offset, dst, len);default :WARN_ONCE (true,"bpf_dynptr_read: unknown dynptr type %d\n" , type);return -EFAULT ;
@@ -1985,6 +1987,8 @@ int __bpf_dynptr_write(const struct bpf_dynptr_kern *dst, u64 offset, void *src,case BPF_DYNPTR_TYPE_SKB_META :return __bpf_skb_meta_store_bytes (dst->data, dst->offset + offset, src, len, flags); +case BPF_DYNPTR_TYPE_SKB_EXT : +return __bpf_skb_ext_store_bytes (dst->data, dst->offset + offset, src, len, flags);default :WARN_ONCE (true,"bpf_dynptr_write: unknown dynptr type %d\n" , type);return -EFAULT ;
@@ -2032,6 +2036,7 @@ BPF_CALL_3(bpf_dynptr_data, const struct bpf_dynptr_kern *, ptr, u64, offset, u6case BPF_DYNPTR_TYPE_SKB :case BPF_DYNPTR_TYPE_XDP :case BPF_DYNPTR_TYPE_SKB_META : +case BPF_DYNPTR_TYPE_SKB_EXT :/* skb and xdp dynptrs should use bpf_dynptr_slice / bpf_dynptr_slice_rdwr */ return 0 ;default :
@@ -3048,8 +3053,8 @@ __bpf_kfunc struct task_struct *bpf_task_from_vpid(s32 vpid)* provided buffer, with its contents containing the data, if unable to obtain * direct pointer) */ -__bpf_kfunc void *bpf_dynptr_slice(const struct bpf_dynptr *p, u64 offset, -void *buffer__nullable,u64 buffer__szk) +static void *__bpf_dynptr_slice (const struct bpf_dynptr *p,u64 offset, +void *buffer__nullable,u64 buffer__szk,bool wr) {const struct bpf_dynptr_kern *ptr = (struct bpf_dynptr_kern *)p;enum bpf_dynptr_type type;
@@ -3087,6 +3092,8 @@ __bpf_kfunc void *bpf_dynptr_slice(const struct bpf_dynptr *p, u64 offset, }case BPF_DYNPTR_TYPE_SKB_META :return bpf_skb_meta_pointer (ptr->data, ptr->offset + offset); +case BPF_DYNPTR_TYPE_SKB_EXT : +return bpf_skb_ext_pointer (ptr->data, ptr->offset + offset, wr);case BPF_DYNPTR_TYPE_FILE : err =bpf_file_fetch_bytes (ptr->data, offset, buffer__nullable, buffer__szk);return err ?NULL : buffer__nullable;
@@ -3096,6 +3103,13 @@ __bpf_kfunc void *bpf_dynptr_slice(const struct bpf_dynptr *p, u64 offset, } } +__bpf_kfunc void *bpf_dynptr_slice(const struct bpf_dynptr *p, u64 offset, +void *buffer__nullable,u64 buffer__szk) +{ +return __bpf_dynptr_slice (p, offset, buffer__nullable, buffer__szk, + false); +} +/** * bpf_dynptr_slice_rdwr() - Obtain a writable pointer to the dynptr data. * @p: The dynptr whose data slice to retrieve
@@ -3168,7 +3182,8 @@ __bpf_kfunc void *bpf_dynptr_slice_rdwr(const struct bpf_dynptr *p, u64 offset,* will be copied out into the buffer and the user will need to call * bpf_dynptr_write() to commit changes. */ -return bpf_dynptr_slice (p, offset, buffer__nullable, buffer__szk); +return __bpf_dynptr_slice (p, offset, buffer__nullable, buffer__szk, + true); } __bpf_kfunc int bpf_dynptr_adjust(struct bpf_dynptr *p, u64 start, u64 end)
kernel/bpf/log.c +2 -0
@@ -462,6 +462,8 @@ const char *dynptr_type_str(enum bpf_dynptr_type type)return "skb_meta" ;case BPF_DYNPTR_TYPE_FILE :return "file" ; +case BPF_DYNPTR_TYPE_SKB_EXT : +return "skb_ext" ;case BPF_DYNPTR_TYPE_INVALID :return "<invalid>" ;default :
kernel/bpf/verifier.c +18 -2
@@ -621,6 +621,7 @@ static enum bpf_type_flag get_dynptr_type_flag(enum bpf_dynptr_type type)case BPF_DYNPTR_TYPE_XDP :return DYNPTR_TYPE_XDP ;case BPF_DYNPTR_TYPE_SKB_META : +case BPF_DYNPTR_TYPE_SKB_EXT :return DYNPTR_TYPE_SKB_META ;case BPF_DYNPTR_TYPE_FILE :return DYNPTR_TYPE_FILE ;
@@ -11615,6 +11616,7 @@ enum special_kfunc_type { KF_bpf_dynptr_from_xdp, KF_bpf_dynptr_from_skb_meta, KF_bpf_xdp_pull_data, + KF_bpf_dynptr_from_skb_ext, KF_bpf_dynptr_slice, KF_bpf_dynptr_slice_rdwr, KF_bpf_dynptr_clone,
@@ -11692,6 +11694,11 @@ BTF_ID_UNUSEDBTF_ID_UNUSED BTF_ID_UNUSED#endif +#ifdef CONFIG_BPF_SKB_EXT +BTF_ID(func, bpf_dynptr_from_skb_ext) +#else +BTF_ID_UNUSED +#endif BTF_ID(func, bpf_dynptr_slice) BTF_ID(func, bpf_dynptr_slice_rdwr) BTF_ID(func, bpf_dynptr_clone)
@@ -11824,7 +11831,8 @@ static bool is_kfunc_bpf_preempt_enable(struct bpf_call_arg_meta *meta)bool bpf_is_kfunc_pkt_changing (struct bpf_call_arg_meta *meta) { -return meta->func_id == special_kfunc_list[KF_bpf_xdp_pull_data]; +return meta->func_id == special_kfunc_list[KF_bpf_xdp_pull_data] || + meta->func_id == special_kfunc_list[KF_bpf_dynptr_from_skb_ext]; } static int
@@ -12835,7 +12843,8 @@ static int check_kfunc_args(struct bpf_verifier_env *env, struct bpf_call_arg_me dynptr_arg_type |=DYNPTR_TYPE_SKB ; }else if (meta->func_id == special_kfunc_list[KF_bpf_dynptr_from_xdp]) { dynptr_arg_type |=DYNPTR_TYPE_XDP ; - }else if (meta->func_id == special_kfunc_list[KF_bpf_dynptr_from_skb_meta]) { + }else if (meta->func_id == special_kfunc_list[KF_bpf_dynptr_from_skb_meta] || + meta->func_id == special_kfunc_list[KF_bpf_dynptr_from_skb_ext]) { dynptr_arg_type |=DYNPTR_TYPE_SKB_META ; }else if (meta->func_id == special_kfunc_list[KF_bpf_dynptr_from_file]) { dynptr_arg_type |=DYNPTR_TYPE_FILE ;
@@ -13763,6 +13772,13 @@ static int check_kfunc_call(struct bpf_verifier_env *env, struct bpf_insn *insn, } } +if (meta.func_id == special_kfunc_list[KF_bpf_dynptr_from_skb_ext] && + (prog_type ==BPF_PROG_TYPE_LSM || prog_type ==BPF_PROG_TYPE_TRACING ) && + (meta.arg_constant.value &BPF_SKB_EXT_F_CREATE )) { +verbose (env,"BPF_SKB_EXT_F_CREATE is not allowed in lsm/tracing programs\n" ); +return -EINVAL ; + } +if (is_bpf_rbtree_add_kfunc (meta.func_id)) { err =push_callback_call (env, insn, insn_idx, meta.subprogno, set_rbtree_add_callback_state);
net/Kconfig +20 -0
@@ -540,4 +540,24 @@ config NET_TEST If unsure, say N. +config BPF_SKB_EXT + bool "skb extension for BPF metadata" + depends on BPF_SYSCALL + select SKB_EXTENSIONS + help + Enable an sk_buff extension for storing BPF metadata. This allows BPF + programs to associate arbitrary data with individual packets as they + traverse the network stack. The storage is automatically freed when + the sk_buff is freed. + +config BPF_SKB_EXT_SIZE + int "Size of the BPF skb extension metadata buffer" + depends on BPF_SKB_EXT + range 1 256 + default 64 + help + Configures the size of the inline metadata buffer in struct + bpf_skb_ext, which is the maximum amount of data a BPF program can + store or retrieve with bpf_dynptr_from_skb_ext(). + endif # if NET
net/core/filter.c +149 -0
179 lines not on this page · raw message
net/core/skbuff.c +3 -0
@@ -5169,6 +5169,9 @@ static const u8 skb_ext_type_len[] = {#if IS_ENABLED (CONFIG_CAN ) [SKB_EXT_CAN] = SKB_EXT_CHUNKSIZEOF(struct can_skb_ext), #endif +#if IS_ENABLED(CONFIG_BPF_SKB_EXT) + [SKB_EXT_BPF] = SKB_EXT_CHUNKSIZEOF(struct bpf_skb_ext), +#endif }; static __always_inline __no_profile unsigned int skb_ext_total_length(void)
Signature · 1 line
2.43.0
Re: [PATCH net-next v2 01/14] bpf: Introduce per-packet metadata storage for BPF programs
Quoted 20 lines
net/Kconfig +11
-0@@ -540,4 +540,24 @@ config NET_TEST If unsure, say N. +config BPF_SKB_EXT + bool "skb extension for BPF metadata" + depends on BPF_SYSCALL + select SKB_EXTENSIONS + help + Enable an sk_buff extension for storing BPF metadata. This allows BPF + programs to associate arbitrary data with individual packets as they + traverse the network stack. The storage is automatically freed when + the sk_buff is freed. + +config BPF_SKB_EXT_SIZE
net/Kconfig config NET_TEST · line 563
Quoted 10 lines
net/Kconfig +9
-0+ int "Size of the BPF skb extension metadata buffer" + depends on BPF_SKB_EXT + range 1 256 + default 64 + help + Configures the size of the inline metadata buffer in struct + bpf_skb_ext, which is the maximum amount of data a BPF program can + store or retrieve with bpf_dynptr_from_skb_ext(). + endif # if NET
Can we do it like this? So that enabling BPF_SKB_EXT_SIZE only is enough and make it easier.
config BPF_SKB_EXT_SIZE
int "Per-packet BPF metadata in skb, in bytes (0 to disable)" depends on BPF_SYSCALL
range 0 256
default 0
help
Configures the size of the inline metadata buffer in struct
....
The skb extension chunk is sized in units of 8 bytes, so values that are not a multiple of 8 just waste the remainder.
config BPF_SKB_EXT
def_bool BPF_SKB_EXT_SIZE != 0
select SKB_EXTENSIONS
help
xxx
PATCH v2 2/14 bpf: Allow access to bpf_sock_ops_kern->skb
In reply to Jakub Sitnickisock_ops programs receive bpf_sock_ops_kern as their kernel context, which holds a pointer to the sk_buff being processed. Mark bpf_sock_ops_kern->skb as BTF_TYPE_SAFE_TRUSTED_OR_NULL so that BPF programs can dereference it and pass it to kfuncs expecting a trusted sk_buff pointer, such as bpf_dynptr_from_skb_ext().
--- kernel/bpf/verifier.c | 5 +++++ 1 file changed, 5 insertions(+)
kernel/bpf/verifier.c +5 -0
@@ -5891,6 +5891,10 @@ BTF_TYPE_SAFE_TRUSTED_OR_NULL(struct vm_area_struct) {struct file *vm_file; }; +BTF_TYPE_SAFE_TRUSTED_OR_NULL(struct bpf_sock_ops_kern) { +struct sk_buff *skb; +}; +static bool type_is_rcu (struct bpf_verifier_env *env,struct bpf_reg_state *reg,const char *field_name,u32 btf_id)
@@ -5933,6 +5937,7 @@ static bool type_is_trusted_or_null(struct bpf_verifier_env *env,BTF_TYPE_EMIT (BTF_TYPE_SAFE_TRUSTED_OR_NULL(struct socket ));BTF_TYPE_EMIT (BTF_TYPE_SAFE_TRUSTED_OR_NULL(struct dentry ));BTF_TYPE_EMIT (BTF_TYPE_SAFE_TRUSTED_OR_NULL(struct vm_area_struct )); +BTF_TYPE_EMIT (BTF_TYPE_SAFE_TRUSTED_OR_NULL(struct bpf_sock_ops_kern ));return btf_nested_type_is_trusted (&env->log, reg, field_name, btf_id,"__safe_trusted_or_null" );
Signature · 1 line
2.43.0
PATCH v2 3/14 bpf: Make BPF skb extension survive packet scrubbing
In reply to Jakub Sitnickiskb_scrub_packet() drops all skb extensions unconditionally via skb_ext_reset(). It runs on tunnel encap/decap (ip_tunnel_rcv, vxlan_rcv, etc.) and cross-netns forwarding (dev_forward_skb).
This makes it impossible for a BPF program to pass metadata via bpf_skb_ext through a tunnel or across a netns boundary. The extension is always lost at the scrub point.
Introduce skb_ext_scrub(), a selective variant of skb_ext_reset(). It deletes every extension except SKB_EXT_BPF. Scrubbing is safe when the extension slab is shared with clones: deleting an extension only clears the per-skb active_extensions bit, and the shared slab payload is released lazily by __skb_ext_put() once the last reference goes away.
Replace the skb_ext_reset() call in skb_scrub_packet() with skb_ext_scrub() and also switch udp_try_make_stateless() to skb_ext_scrub() as well, so the BPF metadata survives queueing onto a UDP socket receive queue and stays readable there (e.g. for a sockmap verdict program). Only mark the skb stateless when no extension survives the scrub. Otherwise skb_consume_udp() would take the __consume_stateless_skb() fast path, which skips skb_release_head_state(), and leak the extension slab.
--- include/linux/skbuff.h | 2 ++ net/core/skbuff.c | 24 ++++++++++++++++++++++-- net/ipv4/udp.c | 6 ++---- 3 files changed, 26 insertions(+), 6 deletions(-)
include/linux/skbuff.h +2 -0
@@ -5091,6 +5091,7 @@ void *__skb_ext_set(struct sk_buff *skb, enum skb_ext_id id,void *skb_ext_add (struct sk_buff *skb,enum skb_ext_id id);void __skb_ext_del (struct sk_buff *skb,enum skb_ext_id id);void __skb_ext_put (struct skb_ext *ext); +void skb_ext_scrub (struct sk_buff *skb);static inline void skb_ext_put (struct sk_buff *skb) {
@@ -5167,6 +5168,7 @@ static inline bool skb_ext_shared(const struct sk_buff *skb)static inline void __skb_ext_put (struct skb_ext *ext) {}static inline void skb_ext_put (struct sk_buff *skb) {}static inline void skb_ext_reset (struct sk_buff *skb) {} +static inline void skb_ext_scrub (struct sk_buff *skb) {}static inline void skb_ext_del (struct sk_buff *skb,int unused) {}static inline void __skb_ext_copy (struct sk_buff *d,const struct sk_buff *s) {}static inline void skb_ext_copy (struct sk_buff *dst,const struct sk_buff *s) {}
net/core/skbuff.c +22 -2
@@ -83,6 +83,7 @@#include <net/page_pool/helpers.h> #include <net/psp/types.h> #include <net/dropreason.h> +#include <linux/bpf.h> #include <net/xdp_sock.h> #include <linux/uaccess.h>
@@ -6290,7 +6291,8 @@ EXPORT_SYMBOL(skb_try_coalesce);* operations. * skb_scrub_packet can also be used to clean a skb before injecting it in * another namespace (@xnet == true). We have to clear all information in the -* skb that could impact namespace isolation. +* skb that could impact namespace isolation. Note that BPF skb extension is +* meant to carry information across namespaces by design. */ void skb_scrub_packet (struct sk_buff *skb,bool xnet) {
@@ -6298,7 +6300,7 @@ void skb_scrub_packet(struct sk_buff *skb, bool xnet) skb->skb_iif =0 ; skb->ignore_df =0 ;skb_dst_drop (skb); -skb_ext_reset (skb); +skb_ext_scrub (skb);nf_reset_ct (skb);nf_reset_trace (skb);
@@ -7307,6 +7309,24 @@ void __skb_ext_put(struct skb_ext *ext) kmem_cache_free(skbuff_ext_cache, ext); }EXPORT_SYMBOL (__skb_ext_put); + +void skb_ext_scrub (struct sk_buff *skb) +{ +unsigned int id; + +if (likely (!skb->active_extensions)) +return ; + +for (id =0 ; id <SKB_EXT_NUM ; id++) { +#if IS_ENABLED (CONFIG_BPF_SKB_EXT ) +if (id ==SKB_EXT_BPF ) +continue ; +#endif +skb_ext_del (skb, id); + } +} +EXPORT_SYMBOL (skb_ext_scrub); +#endif /* CONFIG_SKB_EXTENSIONS */ static void kfree_skb_napi_cache (struct sk_buff *skb)
net/ipv4/udp.c +2 -4
@@ -1540,8 +1540,6 @@ void udp_splice_eof(struct socket *sock)* * We need to preserve secpath, if present, to eventually process * IP_CMSG_PASSSEC at recvmsg() time. -* -* Other extensions can be cleared. */ static bool udp_try_make_stateless (struct sk_buff *skb) {
@@ -1549,8 +1547,8 @@ static bool udp_try_make_stateless(struct sk_buff *skb)return true;if (!secpath_exists (skb)) { -skb_ext_reset (skb); -return true; +skb_ext_scrub (skb); +return !skb_has_extensions (skb); }return false;
Signature · 1 line
2.43.0
Re: [PATCH net-next v2 03/14] bpf: Make BPF skb extension survive packet scrubbing
Quoted 22 lines · Jakub Sitnicki
skb_scrub_packet()drops all skb extensions unconditionally viaskb_ext_reset(). It runs on tunnel encap/decap (ip_tunnel_rcv,vxlan_rcv, etc.) and cross-netns forwarding (dev_forward_skb).This makes it impossible for a BPF program to pass metadata via
bpf_skb_extthrough a tunnel or across a netns boundary. The extension is always lost at the scrub point.Introduce
skb_ext_scrub(), a selective variant ofskb_ext_reset(). It deletes every extension exceptSKB_EXT_BPF. Scrubbing is safe when the extension slab is shared with clones: deleting an extension only clears the per-skbactive_extensionsbit, and the shared slab payload is released lazily by__skb_ext_put()once the last reference goes away.Replace the
skb_ext_reset()call inskb_scrub_packet()withskb_ext_scrub()and also switchudp_try_make_stateless()toskb_ext_scrub()as well, so the BPF metadata survives queueing onto a UDP socket receive queue and stays readable there (e.g. for a sockmap verdict program). Only mark the skb stateless when no extension survives the scrub. Otherwiseskb_consume_udp()would take the__consume_stateless_skb()fast path, which skipsskb_release_head_state(), and leak the extension slab.
Quoted 2 lines
Signed-off-by Jakub Sitnicki <[email protected]>---
Hello Jakub,
What are your current plans for this series? This commit solves the same problem I have with wanting to preserve the PSP skb extension across netns forwarding.
Daniel
Re: [PATCH net-next v2 03/14] bpf: Make BPF skb extension survive packet scrubbing
Hi Daniel,
Quoted 23 lines · Daniel Zahka
Quoted 22 lines · Jakub Sitnicki
skb_scrub_packet()drops all skb extensions unconditionally viaskb_ext_reset(). It runs on tunnel encap/decap (ip_tunnel_rcv,vxlan_rcv, etc.) and cross-netns forwarding (dev_forward_skb).This makes it impossible for a BPF program to pass metadata via
bpf_skb_extthrough a tunnel or across a netns boundary. The extension is always lost at the scrub point.Introduce
skb_ext_scrub(), a selective variant ofskb_ext_reset(). It deletes every extension exceptSKB_EXT_BPF. Scrubbing is safe when the extension slab is shared with clones: deleting an extension only clears the per-skbactive_extensionsbit, and the shared slab payload is released lazily by__skb_ext_put()once the last reference goes away.Replace the
skb_ext_reset()call inskb_scrub_packet()withskb_ext_scrub()and also switchudp_try_make_stateless()toskb_ext_scrub()as well, so the BPF metadata survives queueing onto a UDP socket receive queue and stays readable there (e.g. for a sockmap verdict program). Only mark the skb stateless when no extension survives the scrub. Otherwiseskb_consume_udp()would take the__consume_stateless_skb()fast path, which skipsskb_release_head_state(), and leak the extension slab.
Quoted 7 lines
Quoted 2 lines
Signed-off-by Jakub Sitnicki <[email protected]>---
Hello Jakub,
What are your current plans for this series? This commit solves the same problem I have with wanting to preserve the PSP skb extension across netns forwarding.
I've implemented Alexei's idea of skb-lifecycle tracepoints that run only when an skb is marked/traced. Currently putting final touches on it before sending it out for the first round of feedback. You can take sneak peek at it on GH [1] to see if it meets your needs.
The CPU overhead is lower compared to the skb extension, at least in my local runs, and the kernel changes are simpler, so it seems like a win overall:
| | gated skb tps | bpf skb ext | |------------------|------------------|------------------| | **busy** | **+5.44 ± 3.16** | **+8.01 ± 4.75** | | sys | +2.62 ± 2.06 | +3.67 ± 2.76 | | soft | +2.89 ± 1.43 | +3.83 ± 2.10 | | ns/pkt @146k pps | **+≈ 373** | **+≈ 549** |
I'll be giving an update on it at LPC [1], if you're attending, and of course will keep you posted here on the ML.
-jkbs
[1] https://github.com/jsitnicki/linux/commits/gated-skb-tracepoints-2026-09-24/
[2] https://lpc.events/event/20/contributions/2549/
Re: [PATCH net-next v2 03/14] bpf: Make BPF skb extension survive packet scrubbing
Quoted 50 lines · Jakub Sitnicki
Hi Daniel,
Quoted 23 lines · Daniel Zahka
Quoted 22 lines · Jakub Sitnicki
skb_scrub_packet()drops all skb extensions unconditionally viaskb_ext_reset(). It runs on tunnel encap/decap (ip_tunnel_rcv,vxlan_rcv, etc.) and cross-netns forwarding (dev_forward_skb).This makes it impossible for a BPF program to pass metadata via
bpf_skb_extthrough a tunnel or across a netns boundary. The extension is always lost at the scrub point.Introduce
skb_ext_scrub(), a selective variant ofskb_ext_reset(). It deletes every extension exceptSKB_EXT_BPF. Scrubbing is safe when the extension slab is shared with clones: deleting an extension only clears the per-skbactive_extensionsbit, and the shared slab payload is released lazily by__skb_ext_put()once the last reference goes away.Replace the
skb_ext_reset()call inskb_scrub_packet()withskb_ext_scrub()and also switchudp_try_make_stateless()toskb_ext_scrub()as well, so the BPF metadata survives queueing onto a UDP socket receive queue and stays readable there (e.g. for a sockmap verdict program). Only mark the skb stateless when no extension survives the scrub. Otherwiseskb_consume_udp()would take the__consume_stateless_skb()fast path, which skipsskb_release_head_state(), and leak the extension slab.Quoted 7 lines
Quoted 2 lines
Signed-off-by Jakub Sitnicki <[email protected]>---
Hello Jakub,
What are your current plans for this series? This commit solves the same problem I have with wanting to preserve the PSP skb extension across netns forwarding.I've implemented Alexei's idea of skb-lifecycle tracepoints that run only when an skb is marked/traced. Currently putting final touches on it before sending it out for the first round of feedback. You can take sneak peek at it on GH [1] to see if it meets your needs.
The CPU overhead is lower compared to the skb extension, at least in my local runs, and the kernel changes are simpler, so it seems like a win overall:
| | gated skb tps | bpf skb ext | |------------------|------------------|------------------| | **busy** | **+5.44 ± 3.16** | **+8.01 ± 4.75** | | sys | +2.62 ± 2.06 | +3.67 ± 2.76 | | soft | +2.89 ± 1.43 | +3.83 ± 2.10 | | ns/pkt @146k pps | **+≈ 373** | **+≈ 549** |
Quoted 2 lines
I'll be giving an update on it at LPC [1], if you're attending, and of course will keep you posted here on the ML.
Well, the numbers speak for themselves. I think :)
Jakub Kicinski
maintainerRe: [PATCH net-next v2 03/14] bpf: Make BPF skb extension survive packet scrubbing
Quoted 16 lines · On Fri, 25 Sep 2026 01:07:47 +0000 Alexei Starovoitov wrote:
Quoted 16 lines
I've implemented Alexei's idea of skb-lifecycle tracepoints that run only when an skb is marked/traced. Currently putting final touches on it before sending it out for the first round of feedback. You can take sneak peek at it on GH [1] to see if it meets your needs.
The CPU overhead is lower compared to the skb extension, at least in my local runs, and the kernel changes are simpler, so it seems like a win overall:
| | gated skb tps | bpf skb ext | |------------------|------------------|------------------| | **busy** | **+5.44 ± 3.16** | **+8.01 ± 4.75** | | sys | +2.62 ± 2.06 | +3.67 ± 2.76 | | soft | +2.89 ± 1.43 | +3.83 ± 2.10 | | ns/pkt @146k pps | **+≈ 373** | **+≈ 549** |
Quoted 4 lines
Quoted 2 lines
I'll be giving an update on it at LPC [1], if you're attending, and of course will keep you posted here on the ML.
Well, the numbers speak for themselves. I think :)
Instead of improving the existing infra we're adding more BPF-specific glue and another bit to the skb. Matter of perspective I suppose :/
Re: [PATCH net-next v2 03/14] bpf: Make BPF skb extension survive packet scrubbing
Quoted 2 lines · Jakub Kicinski
Instead of improving the existing infra we're adding more BPF-specific glue and another bit to the skb. Matter of perspective I suppose :/
skb_ext version needs a bit too. SKB_EXT_BPF is the 8th id, so it takes the last bit of u8 active_extensions.skbuff_ext_cache object is sized for all ids, so it also grows by BPF_SKB_EXT_SIZE for xfrm, mptcp, psp whether bpf is used or not.
As I said earlier skb_ext is fine from bpf pov. If it can be made as cheap as bit + tracepoint I don't mind it at all.
Which part of skb_ext would you improve?
Jakub Kicinski
maintainerRe: [PATCH net-next v2 03/14] bpf: Make BPF skb extension survive packet scrubbing
Quoted 4 lines · On Fri, 25 Sep 2026 19:51:37 +0000 Alexei Starovoitov wrote:
Quoted 2 lines · Jakub Kicinski
Instead of improving the existing infra we're adding more BPF-specific glue and another bit to the skb. Matter of perspective I suppose :/
Quoted 8 lines
skb_extversion needs a bit too.SKB_EXT_BPFis the 8th id, so it takes the last bit of u8active_extensions.skbuff_ext_cacheobject is sized for all ids, so it also grows byBPF_SKB_EXT_SIZEfor xfrm, mptcp, psp whether bpf is used or not.As I said earlier
skb_extis fine from bpf pov. If it can be made as cheap as bit + tracepoint I don't mind it at all.
Which part ofskb_extwould you improve?
Mostly allocation speed. Either a small per-CPU cache like we have for skbs or let the scalar matadata fields live inside the skb.
That said, the selective tracing approach is also tempting. It'd be great if we could have that for sockets. Could we possibly think of a way to build that into tracepoints instead of having the open coded
obj_maybe_trace_bla()
{
if (obj->trace)
trace_bla();
}Having both:
skb_maybe_trace_free(skb, SKB_CONSUMED); skb_release_data(skb, SKB_CONSUMED);
looks a little ugly
Re: [PATCH net-next v2 03/14] bpf: Make BPF skb extension survive packet scrubbing
Quoted 10 lines · Jakub Kicinski
Quoted 9 lines · On Fri, 25 Sep 2026 19:51:37 +0000 Alexei Starovoitov wrote:
Quoted 2 lines · Jakub Kicinski
Instead of improving the existing infra we're adding more BPF-specific glue and another bit to the skb. Matter of perspective I suppose :/
skb_extversion needs a bit too.SKB_EXT_BPFis the 8th id, so it takes the last bit of u8active_extensions.skbuff_ext_cacheobject is sized for all ids, so it also grows byBPF_SKB_EXT_SIZEfor xfrm, mptcp, psp whether bpf is used or not.
Quoted 6 lines
Quoted 3 lines
As I said earlier
skb_extis fine from bpf pov. If it can be made as cheap as bit + tracepoint I don't mind it at all.
Which part ofskb_extwould you improve?Mostly allocation speed. Either a small per-CPU cache like we have for skbs or let the scalar matadata fields live inside the skb.
makes sense to me. Speeding up generic infra is always a good thing.
Quoted 11 lines
That said, the selective tracing approach is also tempting. It'd be great if we could have that for sockets. Could we possibly think of a way to build that into tracepoints instead of having the open coded
obj_maybe_trace_bla(){ if (obj->trace) trace_bla(); }
Quoted 4 lines
Having both:
skb_maybe_trace_free(skb, SKB_CONSUMED); skb_release_data(skb, SKB_CONSUMED);
with a 3rd enum argument for different use cases? As a way to generalize different bits / different users?
Also makes sense.
Re: [PATCH net-next v2 03/14] bpf: Make BPF skb extension survive packet scrubbing
Quoted 33 lines · Alexei Starovoitov
Quoted 10 lines · Jakub Kicinski
Quoted 9 lines · On Fri, 25 Sep 2026 19:51:37 +0000 Alexei Starovoitov wrote:
Quoted 2 lines · Jakub Kicinski
Instead of improving the existing infra we're adding more BPF-specific glue and another bit to the skb. Matter of perspective I suppose :/
skb_extversion needs a bit too.SKB_EXT_BPFis the 8th id, so it takes the last bit of u8active_extensions.skbuff_ext_cacheobject is sized for all ids, so it also grows byBPF_SKB_EXT_SIZEfor xfrm, mptcp, psp whether bpf is used or not.Quoted 6 lines
Quoted 3 lines
As I said earlier
skb_extis fine from bpf pov. If it can be made as cheap as bit + tracepoint I don't mind it at all.
Which part ofskb_extwould you improve?Mostly allocation speed. Either a small per-CPU cache like we have for skbs or let the scalar matadata fields live inside the skb.
makes sense to me. Speeding up generic infra is always a good thing.
Quoted 13 lines
That said, the selective tracing approach is also tempting. It'd be great if we could have that for sockets. Could we possibly think of a way to build that into tracepoints instead of having the open coded
obj_maybe_trace_bla(){ if (obj->trace) trace_bla(); }Having both:
Quoted 7 lines
Quoted 2 lines
skb_maybe_trace_free(skb, SKB_CONSUMED); skb_release_data(skb, SKB_CONSUMED);with a 3rd enum argument for different use cases? As a way to generalize different bits / different users?
Also makes sense.
The benchmarks from Friday were wrong. I got bit by KVM halt polling, which was randomly inflating the runtime cost by preventing batching.
The correct results - as in reproducible and with lower variance - are the other way around - BPF skb ext is cheaper CPU-wise than gated skb tracepoints. Please see:
https://patch.msgid.link/20260928-bpf-meta-gated-tracepoints-v1-0-844dbf3e1edf@cloudflare.com
Despite that, I agree that the tracepoint approach is tempting from the UX PoV.
While an skb extension seems like a natural continuation of the XDP/TC metadata pattern, I think that model is not a great fit for skbs traveling through the network stack.
For XDP hook, there will be usually a single owning process of the attached program, I think. While TC, cgroup, tracepoints can have independent program owners, each wanting to associate their own piece of metadata with the skb.
I can iterate on on cosmetic aspects so that we don't have blocks like:
if (reason == SKB_CONSUMED)
trace_consume_skb(...)
else
trace_kfree_skb(..., reason, ...)
skb_maybe_trace_free(..., reason, ...)... in a couple places where they appear in v1.
Thanks for feedback.
Re: [PATCH net-next v2 03/14] bpf: Make BPF skb extension survive packet scrubbing
Quoted 5 lines · Jakub Sitnicki
The correct results - as in reproducible and with lower variance - are the other way around - BPF skb ext is cheaper CPU-wise than gated skb tracepoints. Please see:
https://patch.msgid.link/20260928-bpf-meta-gated-tracepoints-v1-0-844dbf3e1edf@cloudflare.com
I don't think these numbers measure the mechanism either. cpustats.py divides busy by ncpus, so +16.4 and +6.6 are the mean over 6 cpus, while 146k pps is the total of 3 flows.
So it's 6.7 usec vs 2.7 usec per packet and not 1125 ns vs 450 ns. That's a lot for one kmem_cache_alloc/free and a 16 byte copy.
Pls share perf report for both and rerun.
Re: [PATCH net-next v2 03/14] bpf: Make BPF skb extension survive packet scrubbing
Quoted 7 lines · Alexei Starovoitov
Quoted 5 lines · Jakub Sitnicki
The correct results - as in reproducible and with lower variance - are the other way around - BPF skb ext is cheaper CPU-wise than gated skb tracepoints. Please see:
https://patch.msgid.link/20260928-bpf-meta-gated-tracepoints-v1-0-844dbf3e1edf@cloudflare.com
Quoted 7 lines
I don't think these numbers measure the mechanism either.
cpustats.pydivides busy by ncpus, so +16.4 and +6.6 are the mean over 6 cpus, while 146k pps is the total of 3 flows.
So it's 6.7 usec vs 2.7 usec per packet and not 1125 ns vs 450 ns. That's a lot for one kmem_cache_alloc/free and a 16 byte copy.Pls share perf report for both and rerun.
My mistake. Per-packet cost shouldn't have been normalized to CPU count.
I grabbed the perf reports and flamegraphs, and added another variant to the mix with per-CPU LRU hash instead of rhash to get an idea how much overhead comes from locking. Gated tracepoints + per-CPU LRU hash sits in the middle with ~1.5x the cost of skb extension:
| variant | Δ busy (mean/6) | ns/pkt @146k | |--------------------------------|--------------------|--------------| | gated tracepoints (rhash) | **+16.4 ± 2.8 pp** | **≈ 6750** | | gated tracepoints (percpu LRU) | **+10.0 ± 3.3 pp** | **≈ 4100** | | bpf skb ext | **+6.6 ± 1.1 pp** | **≈ 2720** |
% of perf samples breakdown looks like so:
| component | cnt | ext | gtplru | gtp | |----------------------------------------|------|------|--------|------| | tc dispatch (`tcf_classify`+`cls_bpf`) | 0.08 | 0.25 | 0.34 | 0.88 | | skb free path (`napi_consume_skb`) | 0.05 | 0.09 | 0.16 | 0.31 | | TX chain total (`udp_sendmsg`) | 2.51 | 2.53 | 2.98 | 3.27 |
Everything pushed to:
https://github.com/jsitnicki/skb-metadata-bench/tree/main/profile
If the numbers look fishy, after Plumbers I can set up a proper experiment in production to see what the CPU overhead is like on bare metal.
Re: [PATCH net-next v2 03/14] bpf: Make BPF skb extension survive packet scrubbing
Quoted 3 lines · Jakub Sitnicki
Everything pushed to:
https://github.com/jsitnicki/skb-metadata-bench/tree/main/profile
looks like you had lockdep on, so all the data and conclusions likely do not correlate to production.
Pls fix and remeasure everything.
Re: [PATCH net-next v2 03/14] bpf: Make BPF skb extension survive packet scrubbing
Quoted 8 lines · Alexei Starovoitov
Quoted 3 lines · Jakub Sitnicki
Everything pushed to:
https://github.com/jsitnicki/skb-metadata-bench/tree/main/profile
looks like you had lockdep on, so all the data and conclusions likely do not correlate to production.
Pls fix and remeasure everything.
Thanks. This makes much more sense now.
1) Lockdep was on. Fixed. Configs published to [1].
2) Switched from mpstat to bpf_stats since bpf-skb-ext cost was so low now that it was drowning in the noise. skb extension teardown is not accounted for.
3) With rhash, I noticed churn from auto-shrinking in map_update_elem (can be seen in gtpchurn profile [2]). LLM suggested a one-line fix to set min_size from map_extra hint. Benchmarks ran with this patch [3].
New results (prog runtime from bpf_stats in nsec):
~/bench $ just bpfstats
python3 tools/bpfstats.py --agg results-1 results-2 results-3
variant prog results-1 results-2 results-3 total mean ± spread
-------------------------------------------------------------------------------------------
ext-cnt cnt_ingress 35.9 35.6 35.5 106.7 ± 2.2
cnt_egress 70.3 73.5 69.2ext-ext ext_write 199.3 198.9 203.0 263.8 ± 1.9
ext_read 63.1 64.1 63.2
gtp-cnt cnt_ingress 34.4 34.3 34.6 94.6 ± 2.5
cnt_egress 59.9 58.1 62.7gtp-gtp gtp_write 531.0 555.9 567.2 920.9 ± 34.5
gtp_read 85.1 87.5 91.2
gtp_skb_free 267.1 283.9 293.9gtp-gtpchurn gtp_write 784.9 782.6 830.6 1190.8 ± 44.2
gtp_read 82.5 82.3 88.6
gtp_skb_free 297.5 294.7 328.7gtp-gtplru gtplru_write 394.9 391.9 394.5 542.8 ± 1.1
gtplru_read 48.2 49.4 48.9
gtplru_skb_free 99.9 100.4 100.5gtp-gtp is with nelem_hint+min_size hint set.
gtp-gtpchurn is without it (map_extra=0).
perf reports and flamegraphs also updated [4].
[1] https://github.com/jsitnicki/skb-metadata-bench/tree/main/configs
[2] https://raw.githubusercontent.com/jsitnicki/skb-metadata-bench/refs/heads/main/profile/perf.gtp-gtpchurn.svg
[3] https://github.com/jsitnicki/skb-metadata-bench/blob/main/patches/rht-no-shrink-churn.patch
[4] https://github.com/jsitnicki/skb-metadata-bench/tree/main/profile
Re: [PATCH net-next v2 03/14] bpf: Make BPF skb extension survive packet scrubbing
In reply to Jakub SitnickiQuoted 50 lines · Jakub Sitnicki
Hi Daniel,
Quoted 23 lines · Daniel Zahka
Quoted 22 lines · Jakub Sitnicki
skb_scrub_packet()drops all skb extensions unconditionally viaskb_ext_reset(). It runs on tunnel encap/decap (ip_tunnel_rcv,vxlan_rcv, etc.) and cross-netns forwarding (dev_forward_skb).This makes it impossible for a BPF program to pass metadata via
bpf_skb_extthrough a tunnel or across a netns boundary. The extension is always lost at the scrub point.Introduce
skb_ext_scrub(), a selective variant ofskb_ext_reset(). It deletes every extension exceptSKB_EXT_BPF. Scrubbing is safe when the extension slab is shared with clones: deleting an extension only clears the per-skbactive_extensionsbit, and the shared slab payload is released lazily by__skb_ext_put()once the last reference goes away.Replace the
skb_ext_reset()call inskb_scrub_packet()withskb_ext_scrub()and also switchudp_try_make_stateless()toskb_ext_scrub()as well, so the BPF metadata survives queueing onto a UDP socket receive queue and stays readable there (e.g. for a sockmap verdict program). Only mark the skb stateless when no extension survives the scrub. Otherwiseskb_consume_udp()would take the__consume_stateless_skb()fast path, which skipsskb_release_head_state(), and leak the extension slab.Quoted 7 lines
Quoted 2 lines
Signed-off-by Jakub Sitnicki <[email protected]>---
Hello Jakub,
What are your current plans for this series? This commit solves the same problem I have with wanting to preserve the PSP skb extension across netns forwarding.I've implemented Alexei's idea of skb-lifecycle tracepoints that run only when an skb is marked/traced. Currently putting final touches on it before sending it out for the first round of feedback. You can take sneak peek at it on GH [1] to see if it meets your needs.
The CPU overhead is lower compared to the skb extension, at least in my local runs, and the kernel changes are simpler, so it seems like a win overall:
| | gated skb tps | bpf skb ext | |------------------|------------------|------------------| | **busy** | **+5.44 ± 3.16** | **+8.01 ± 4.75** | | sys | +2.62 ± 2.06 | +3.67 ± 2.76 | | soft | +2.89 ± 1.43 | +3.83 ± 2.10 | | ns/pkt @146k pps | **+≈ 373** | **+≈ 549** |
Quoted 7 lines
I'll be giving an update on it at LPC [1], if you're attending, and of course will keep you posted here on the ML.
-jkbs
[1] https://github.com/jsitnicki/linux/commits/gated-skb-tracepoints-2026-09-24/
[2] https://lpc.events/event/20/contributions/2549/
Very cool. Thanks for sharing. So it seems your new approach will not use skb extensions, and this commit will go away :(
I still have a need for this behavior of persisting certain skb extensions through scrubbing. I haven't considered all of my options yet, but I suspect the approach in this commit will work basically as is. If you are going to abandon this commit, would you be ok if I included it in a series of my own for PSP? I would, of course, leave you as the commit author, or give you whatever other form attribution you prefer.
Re: [PATCH net-next v2 03/14] bpf: Make BPF skb extension survive packet scrubbing
Quoted 62 lines · Daniel Zahka
Quoted 50 lines · Jakub Sitnicki
Hi Daniel,
Quoted 23 lines · Daniel Zahka
Quoted 22 lines · Jakub Sitnicki
skb_scrub_packet()drops all skb extensions unconditionally viaskb_ext_reset(). It runs on tunnel encap/decap (ip_tunnel_rcv,vxlan_rcv, etc.) and cross-netns forwarding (dev_forward_skb).This makes it impossible for a BPF program to pass metadata via
bpf_skb_extthrough a tunnel or across a netns boundary. The extension is always lost at the scrub point.Introduce
skb_ext_scrub(), a selective variant ofskb_ext_reset(). It deletes every extension exceptSKB_EXT_BPF. Scrubbing is safe when the extension slab is shared with clones: deleting an extension only clears the per-skbactive_extensionsbit, and the shared slab payload is released lazily by__skb_ext_put()once the last reference goes away.Replace the
skb_ext_reset()call inskb_scrub_packet()withskb_ext_scrub()and also switchudp_try_make_stateless()toskb_ext_scrub()as well, so the BPF metadata survives queueing onto a UDP socket receive queue and stays readable there (e.g. for a sockmap verdict program). Only mark the skb stateless when no extension survives the scrub. Otherwiseskb_consume_udp()would take the__consume_stateless_skb()fast path, which skipsskb_release_head_state(), and leak the extension slab.Quoted 7 lines
Quoted 2 lines
Signed-off-by Jakub Sitnicki <[email protected]>---
Hello Jakub,
What are your current plans for this series? This commit solves the same problem I have with wanting to preserve the PSP skb extension across netns forwarding.I've implemented Alexei's idea of skb-lifecycle tracepoints that run only when an skb is marked/traced. Currently putting final touches on it before sending it out for the first round of feedback. You can take sneak peek at it on GH [1] to see if it meets your needs.
The CPU overhead is lower compared to the skb extension, at least in my local runs, and the kernel changes are simpler, so it seems like a win overall:
| | gated skb tps | bpf skb ext | |------------------|------------------|------------------| | **busy** | **+5.44 ± 3.16** | **+8.01 ± 4.75** | | sys | +2.62 ± 2.06 | +3.67 ± 2.76 | | soft | +2.89 ± 1.43 | +3.83 ± 2.10 | | ns/pkt @146k pps | **+≈ 373** | **+≈ 549** |Quoted 7 lines
I'll be giving an update on it at LPC [1], if you're attending, and of course will keep you posted here on the ML.
-jkbs
[1] https://github.com/jsitnicki/linux/commits/gated-skb-tracepoints-2026-09-24/
[2] https://lpc.events/event/20/contributions/2549/Very cool. Thanks for sharing. So it seems your new approach will not use skb extensions, and this commit will go away :(
Quoted 7 lines
I still have a need for this behavior of persisting certain skb extensions through scrubbing. I haven't considered all of my options yet, but I suspect the approach in this commit will work basically as is. If you are going to abandon this commit, would you be ok if I included it in a series of my own for PSP? I would, of course, leave you as the commit author, or give you whatever other form attribution you prefer.
Ah, I see now. I thought for a moment we were talking about extracting some PSP state and passing it using BPF metadata.
Feel free to reuse & remix. I think it's enough if you link to the original posting.
PATCH v2 4/14 selftests/bpf: Add tests for bpf_dynptr_from_skb_ext
In reply to Jakub SitnickiCover the bpf_dynptr_from_skb_ext() kfunc and the dynptr interface to skb_ext with TC-to-TC tests on a tuntap device:
- write/read via bpf_dynptr_read and bpf_dynptr_write
- write/read via bpf_dynptr_slice and bpf_dynptr_slice_rdwr
- clone read via bpf_dynptr_clone
- error paths: no allocation without F_CREATE, invalid flags, read-only enforcement without F_CREATE
- double allocation: data from first alloc survives second skb_ext_add
Plus, exercise the verifier check for tracing and LSM programs that rejects bpf_dynptr_from_skb_ext(BPF_SKB_EXT_F_CREATE) in these contexts.
--- tools/testing/selftests/bpf/config | 1 + tools/testing/selftests/bpf/prog_tests/verifier.c | 2 + .../bpf/prog_tests/xdp_context_test_run.c | 73 +++++++- tools/testing/selftests/bpf/progs/test_xdp_meta.c | 185 +++++++++++++++++++++ .../testing/selftests/bpf/progs/verifier_skb_ext.c | 77 +++++++++ 5 files changed, 333 insertions(+), 5 deletions(-)
tools/testing/selftests/bpf/config +1 -0
@@ -7,6 +7,7 @@ CONFIG_BPF_JIT=y CONFIG_BPF_KPROBE_OVERRIDE=y CONFIG_BPF_LIRC_MODE2=y CONFIG_BPF_LSM=y +CONFIG_BPF_SKB_EXT=y CONFIG_BPF_STREAM_PARSER=y CONFIG_BPF_SYSCALL=y # CONFIG_BPF_UNPRIV_DEFAULT_OFF is not set
tools/testing/selftests/bpf/prog_tests/verifier.c +2 -0
@@ -94,6 +94,7 @@#include "verifier_scalar_ids.skel.h" #include "verifier_sdiv.skel.h" #include "verifier_search_pruning.skel.h" +#include "verifier_skb_ext.skel.h" #include "verifier_sock.skel.h" #include "verifier_sock_addr.skel.h" #include "verifier_sockmap_mutate.skel.h"
@@ -256,6 +257,7 @@ void test_verifier_runtime_jit(void) { RUN(verifier_runtime_jit); }void test_verifier_scalar_ids (void ) {RUN (verifier_scalar_ids); }void test_verifier_sdiv (void ) {RUN (verifier_sdiv); }void test_verifier_search_pruning (void ) {RUN (verifier_search_pruning); } +void test_verifier_skb_ext (void ) {RUN (verifier_skb_ext); }void test_verifier_sock (void ) {RUN (verifier_sock); }void test_verifier_sock_addr (void ) {RUN (verifier_sock_addr); }void test_verifier_sockmap_mutate (void ) {RUN (verifier_sockmap_mutate); }
tools/testing/selftests/bpf/prog_tests/xdp_context_test_run.c +68 -5
100 lines not on this page · raw message
tools/testing/selftests/bpf/progs/test_xdp_meta.c +185 -0
195 lines not on this page · raw message
tools/testing/selftests/bpf/progs/verifier_skb_ext.c new file +77 -0
77 lines not on this page · raw message
Signature · 1 line
2.43.0
[email protected]
AI reviewRe: [PATCH net-next v2 04/14] selftests/bpf: Add tests for bpf_dynptr_from_skb_ext
Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider: - [Low] Missing NULL check for `xdp_prog` in `__test_tuntap()` leads to unconditionally calling…
Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider:
- [Low] Missing NULL check for xdp_prog in __test_tuntap() leads to unconditionally calling bpf_xdp_attach() with an invalid file descriptor (-EINVAL). --
commit a1930ddb8537b804128c0b7705ce4372074cd5b6
Author: Jakub Sitnicki <[email protected]>
selftests/bpf: Add tests for bpf_dynptr_from_skb_ext
Cover the bpf_dynptr_from_skb_ext() kfunc and the dynptr interface to skb_ext with TC-to-TC tests on a tuntap device. This also exercises the verifier check for tracing and LSM programs that rejects bpf_dynptr_from_skb_ext(BPF_SKB_EXT_F_CREATE) in these contexts.
Quoted 4 lines
tools/testing/selftests/bpf/prog_tests/xdp_context_test_run.c +0
-0
[ ... ]
tools/testing/selftests/bpf/prog_tests/xdp_context_test_run.c void test_xdp_context_lwt_encap(void) · line 714
Quoted 12 lines
tools/testing/selftests/bpf/prog_tests/xdp_context_test_run.c +8
-0@@ -693,3 +704,55 @@ void test_xdp_context_lwt_encap(void)test_xdp_meta__destroy (skel); } + +static void test_skb_ext_tuntap (struct bpf_program *tc_prio_1_prog, +struct bpf_program *tc_prio_2_prog, +bool *test_pass) +{ +__test_tuntap (SKB_EXT_NETNS ,NULL /* xdp */ , tc_prio_1_prog, + tc_prio_2_prog, test_pass); +}
[Severity: Low]
When test_skb_ext_tuntap() calls __test_tuntap() with NULL for xdp_prog, does this cause an issue with the unconditional call to bpf_xdp_attach()?
Looking at __test_tuntap():
ret = bpf_xdp_attach(tap_ifindex, bpf_program__fd(xdp_prog), 0, NULL);
Since xdp_prog is NULL, bpf_program__fd(NULL) will return -EINVAL. This negative file descriptor is then passed directly to bpf_xdp_attach(), which violates the API contract.
Would it be better to add a NULL check for xdp_prog before attempting to attach it, similar to the existing check for tc_prio_2_prog in __test_tuntap()?
Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/20260910-bpf-meta-inside-skb-ext-v2-0-0b21e42180b0@cloudflare.com?part=4
PATCH v2 5/14 selftests/bpf: Test skb_ext on cloned skbs
In reply to Jakub SitnickiCover skb_ext behavior when an skb is cloned, by TC mirred (mirror to a dummy device) and by bpf_clone_redirect():
- clone_ext_read: the extension written at tap ingress is readable from the mirred clone at dummy ingress -- the clone shares the extension with the original
- clone_ext_cow: opening the extension with F_CREATE on the clone triggers copy-on-write, so overwriting the clone's data does not affect the original -- verified by a tp_btf/kfree_skb probe that checks the original skb still carries meta_want
- clone_redir_ext_write_after / clone_redir_ext_slice_write_after: a write to an skb_ext dynptr after bpf_clone_redirect() fails with -EBUSY/NULL while the clone is queued on a netem-delayed loopback and keeps the ext block shared, and dynptrs and pointers to backing memory get invalidated on skb clone; re-acquiring the dynptr with F_CREATE COWs the block and the write succeeds
--- tools/testing/selftests/bpf/config | 1 + .../bpf/prog_tests/xdp_context_test_run.c | 182 +++++++++++++++++++++ tools/testing/selftests/bpf/progs/test_xdp_meta.c | 126 ++++++++++++++ .../testing/selftests/bpf/progs/verifier_skb_ext.c | 45 +++++ 4 files changed, 354 insertions(+)
tools/testing/selftests/bpf/config +1 -0
@@ -137,3 +137,4 @@ CONFIG_SMC_HS_CTRL_BPF=y CONFIG_DIBS=y CONFIG_DIBS_LO=y CONFIG_PM_WAKELOCKS=y +CONFIG_NET_SCH_NETEM=y
tools/testing/selftests/bpf/prog_tests/xdp_context_test_run.c +182 -0
194 lines not on this page · raw message
tools/testing/selftests/bpf/progs/test_xdp_meta.c +126 -0
148 lines not on this page · raw message
tools/testing/selftests/bpf/progs/verifier_skb_ext.c +45 -0
51 lines not on this page · raw message
Signature · 1 line
2.43.0
[email protected]
AI reviewRe: [PATCH net-next v2 05/14] selftests/bpf: Test skb_ext on cloned skbs
Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider: - [Medium] Missing __msg() macro in __failure verifier tests. --
Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider:
- [Medium] Missing __msg() macro in __failure verifier tests.
--
commit 3dc92388d2fd6ba878aeec16668062f704faf681
Author: Jakub Sitnicki <[email protected]>
selftests/bpf: Test skb_ext on cloned skbs
This commit adds coverage for skb_ext behavior when an skb is cloned, using TC mirred and bpf_clone_redirect(). It tests whether extensions are readable across clones and verifies copy-on-write isolation.
[ ... ]
tools/testing/selftests/bpf/progs/verifier_skb_ext.c line 12
Quoted 11 lines
tools/testing/selftests/bpf/progs/verifier_skb_ext.c +3
-0@@ -7,6 +7,51 @@__u64 flags; +SEC("tc") +__description ("skb_ext slice is invalidated by bpf_clone_redirect" ) +__failure
[Severity: Medium]
Should this test include a __msg("...") macro to verify the exact error string from the verifier?
If the test fails to load due to an unrelated verifier error (such as a syntax issue, invalid BTF, or missing kfunc declarations), the test loader merely checks if loading fails for any reason. This can incorrectly report a PASS, hiding regressions in the specific slice invalidation logic it is designed to test.
Quoted 4 lines
tools/testing/selftests/bpf/progs/verifier_skb_ext.c +4
-0+int skb_ext_stale_slice_after_clone_redirect (struct __sk_buff *ctx) +{ +struct bpf_dynptr meta; +__u8 *slice;
[ ... ]
tools/testing/selftests/bpf/progs/verifier_skb_ext.c line 35
Quoted 11 lines
tools/testing/selftests/bpf/progs/verifier_skb_ext.c +11
-0+bpf_clone_redirect (ctx,1 ,0 ); + +/* Stale: the clone shares the ext block the slice points into. */ + *slice =0 ; + +return 0 ; +} + +SEC("tc") +__description ("skb_ext slice is invalidated when ext is re-opened with F_CREATE" ) +__failure
[Severity: Medium]
Similarly, does this test also need a __msg() macro?
Without exact error message string verification, the test infrastructure will pass this test if it fails to load for any reason, rather than verifying the intended failure reason.
Quoted 4 lines
tools/testing/selftests/bpf/progs/verifier_skb_ext.c +4
-0+int skb_ext_stale_slice_after_recreate (struct __sk_buff *ctx) +{ +struct bpf_dynptr d1, d2; +__u8 *slice;
[ ... ]
Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/20260910-bpf-meta-inside-skb-ext-v2-0-0b21e42180b0@cloudflare.com?part=5
PATCH v2 6/14 selftests/bpf: Test skb_ext survival across veth and GRE
In reply to Jakub SitnickiWrite skb_ext at TC egress and read it back at TC ingress after the packet crosses device boundaries:
- survives_veth: veth forwarding between two netns
- survives_gre: GRE encap/decap between two gretap endpoints over loopback in a single netns
--- .../bpf/prog_tests/xdp_context_test_run.c | 162 +++++++++++++++++++++ 1 file changed, 162 insertions(+)
tools/testing/selftests/bpf/prog_tests/xdp_context_test_run.c +162 -0
@@ -885,6 +885,164 @@ static void test_clone_redir_ext_write_after(struct test_xdp_meta *skel,netns_free (ns); } +/* Test if skb_ext survives veth cross-netns forward */ +static void test_skb_ext_scrub_veth (struct test_xdp_meta *skel) +{ + LIBBPF_OPTS(bpf_tc_hook, tx_hook, .attach_point = BPF_TC_EGRESS); + LIBBPF_OPTS(bpf_tc_opts, tx_opts, .handle = 1, .priority = 1); + LIBBPF_OPTS(bpf_tc_hook, rx_hook, .attach_point = BPF_TC_INGRESS); + LIBBPF_OPTS(bpf_tc_opts, rx_opts, .handle = 1, .priority = 1); +struct netns_obj *rx_ns =NULL , *tx_ns =NULL ; +struct nstoken *nstoken =NULL ; +int rx_ifindex, tx_ifindex; +int ret; +int i; + + tx_ns =netns_new (TX_NETNS , false); +if (!ASSERT_OK_PTR (tx_ns,"create tx_ns" )) +return ; + + rx_ns =netns_new (RX_NETNS , false); +if (!ASSERT_OK_PTR (rx_ns,"create rx_ns" )) + goto close; + +SYS (close,"ip link add " RX_NAME " netns " RX_NETNS +" type veth peer name " TX_NAME " netns " TX_NETNS ); + +/* Setup RX side: TC ingress reader */ + nstoken =open_netns (RX_NETNS ); +if (!ASSERT_OK_PTR (nstoken,"setns rx_ns" )) + goto close; + +SYS (close,"ip link set dev " RX_NAME " up" ); + + rx_ifindex =if_nametoindex (RX_NAME ); +if (!ASSERT_GT (rx_ifindex,0 ,"if_nametoindex rx" )) + goto close; + + rx_hook.ifindex = rx_ifindex; + ret =bpf_tc_hook_create (&rx_hook); +if (!ASSERT_OK (ret,"bpf_tc_hook_create rx" )) + goto close; + + rx_opts.prog_fd =bpf_program__fd (skel->progs.tc_skb_ext_read); + ret =bpf_tc_attach (&rx_hook, &rx_opts); +if (!ASSERT_OK (ret,"bpf_tc_attach rx" )) + goto close; + +close_netns (nstoken); + +/* Setup TX side: TC egress writer */ + nstoken =open_netns (TX_NETNS ); +if (!ASSERT_OK_PTR (nstoken,"setns tx_ns" )) + goto close; + +SYS (close,"ip link set dev " TX_NAME " up" ); + + tx_ifindex =if_nametoindex (TX_NAME ); +if (!ASSERT_GT (tx_ifindex,0 ,"if_nametoindex tx" )) + goto close; + + tx_hook.ifindex = tx_ifindex; + ret =bpf_tc_hook_create (&tx_hook); +if (!ASSERT_OK (ret,"bpf_tc_hook_create tx" )) + goto close; + + tx_opts.prog_fd =bpf_program__fd (skel->progs.tc_skb_ext_write); + ret =bpf_tc_attach (&tx_hook, &tx_opts); +if (!ASSERT_OK (ret,"bpf_tc_attach tx" )) + goto close; + + skel->bss->test_pass = false; + + ret =send_test_packet (tx_ifindex); +if (!ASSERT_OK (ret,"send_test_packet" )) + goto close; + +/* Poll every 10 msec up to 1 sec */ +for (i =0 ; i <100 && !skel->bss->test_pass; i++) +usleep (10000 ); +ASSERT_TRUE (skel->bss->test_pass,"test_pass" ); + +close: +close_netns (nstoken); +netns_free (rx_ns); +netns_free (tx_ns); +} + +/* Test if skb_ext survives GRE tunnel encap+decap */ +static void test_skb_ext_scrub_gre (struct test_xdp_meta *skel) +{ + LIBBPF_OPTS(bpf_tc_hook, tx_hook, .attach_point = BPF_TC_EGRESS); + LIBBPF_OPTS(bpf_tc_opts, tx_opts, .handle = 1, .priority = 1); + LIBBPF_OPTS(bpf_tc_hook, rx_hook, .attach_point = BPF_TC_INGRESS); + LIBBPF_OPTS(bpf_tc_opts, rx_opts, .handle = 1, .priority = 1); +struct netns_obj *ns =NULL ; +int tx_ifindex; +int rx_ifindex; +int ret; +int i; + + skel->bss->test_pass = false; + + ns =netns_new ("gre_test" , true); +if (!ASSERT_OK_PTR (ns,"netns_new" )) +return ; + +/* Setup: gre_tx -> lo -> gre_rx */ +SYS (close,"ip link set lo up" ); +SYS (close,"ip link add gre_tx type gretap" +" local 127.0.0.1 remote 127.0.0.2" ); +SYS (close,"ip link set gre_tx up" ); +SYS (close,"ip addr add 127.0.0.2/8 dev lo" ); +SYS (close,"ip link add gre_rx type gretap" +" local 127.0.0.2 remote 127.0.0.1" ); +SYS (close,"ip link set gre_rx up" ); + +/* Write skb_ext on TC egress on GRE tx */ + tx_ifindex =if_nametoindex ("gre_tx" ); +if (!ASSERT_GT (tx_ifindex,0 ,"tx_ifindex" )) + goto close; + + tx_hook.ifindex = tx_ifindex; + ret =bpf_tc_hook_create (&tx_hook); +if (!ASSERT_OK (ret,"tx_hook_create" )) + goto close; + + tx_opts.prog_fd =bpf_program__fd (skel->progs.tc_skb_ext_write); + ret =bpf_tc_attach (&tx_hook, &tx_opts); +if (!ASSERT_OK (ret,"tx_attach" )) + goto close; + +/* Read skb_ext on TC ingress on GRE rx */ + rx_ifindex =if_nametoindex ("gre_rx" ); +if (!ASSERT_GT (rx_ifindex,0 ,"rx_ifindex" )) + goto close; + + rx_hook.ifindex = rx_ifindex; + ret =bpf_tc_hook_create (&rx_hook); +if (!ASSERT_OK (ret,"rx_hook_create" )) + goto close; + + rx_opts.prog_fd =bpf_program__fd (skel->progs.tc_skb_ext_read); + ret =bpf_tc_attach (&rx_hook, &rx_opts); +if (!ASSERT_OK (ret,"rx_attach" )) + goto close; + +/* Then use send_test_packet on GRE tx */ + ret =send_test_packet (tx_ifindex); +if (!ASSERT_OK (ret,"send_test_packet" )) + goto close; + +/* Poll every 10 msec up to 1 sec */ +for (i =0 ; i <100 && !skel->bss->test_pass; i++) +usleep (10000 ); +ASSERT_TRUE (skel->bss->test_pass,"test_pass" ); + +close: +netns_free (ns); +} +void test_skb_ext_basic (void ) {struct test_xdp_meta *skel =NULL ;
@@ -935,6 +1093,10 @@ void test_skb_ext_basic(void)if (test__start_subtest ("clone_redir_ext_slice_write_after" ))test_clone_redir_ext_write_after (skel, skel->progs.tc_skb_ext_slice_write_after_clone_redir); +if (test__start_subtest ("survives_veth" )) +test_skb_ext_scrub_veth (skel); +if (test__start_subtest ("survives_gre" )) +test_skb_ext_scrub_gre (skel);test_xdp_meta__destroy (skel); }
Signature · 1 line
2.43.0
PATCH v2 7/14 selftests/bpf: Test skb_ext read from cgroup_skb and sk_filter hooks
In reply to Jakub SitnickiExtend skb_ext cross-hook coverage to UDP readers: attach a TC ingress program on loopback that writes the extension, send a UDP datagram over loopback, and read the extension back from a cgroup_skb/ingress program and from a socket filter attached with SO_ATTACH_BPF.
--- .../bpf/prog_tests/xdp_context_test_run.c | 121 +++++++++++++++++++++ tools/testing/selftests/bpf/progs/test_xdp_meta.c | 37 +++++++ 2 files changed, 158 insertions(+)
tools/testing/selftests/bpf/prog_tests/xdp_context_test_run.c +121 -0
@@ -1100,3 +1100,124 @@ void test_skb_ext_basic(void)test_xdp_meta__destroy (skel); } + +/* Send test_payload over loopback UDP to recv_fd */ +static int send_loopback_udp (int recv_fd) +{ +struct sockaddr_in addr = { + .sin_family =AF_INET , + .sin_addr.s_addr =htonl (INADDR_LOOPBACK ), + }; +char buf[TEST_PAYLOAD_LEN ]; +int ret =-1 ; +int fd =-1 ; +int port; + + port =get_socket_local_port (recv_fd); +if (!ASSERT_GE (port,0 ,"get_port" )) + goto out; + + fd =socket (AF_INET ,SOCK_DGRAM ,0 ); +if (!ASSERT_GE (fd,0 ,"socket" )) + goto out; + + addr.sin_port = port; +sendto (fd, test_payload,TEST_PAYLOAD_LEN ,0 , + (void *)&addr,sizeof (addr)); +recvfrom (recv_fd, buf,sizeof (buf),0 ,NULL ,NULL ); + ret =0 ; +out: +if (fd >=0 ) +close (fd); +return ret; +} + +enum udp_reader_type { +READER_CGRP_SKB , +READER_SK_FILTER , +}; + +/* Test skb_ext survival across TC ingress -> UDP reader hook */ +static void test_skb_ext_udp (struct test_xdp_meta *skel,const char *name, +enum udp_reader_type reader) +{ +LIBBPF_OPTS (bpf_tc_hook, tc_hook, + .ifindex = 1 /* IFINDEX_LO */, + .attach_point = BPF_TC_INGRESS); + LIBBPF_OPTS(bpf_tc_opts, tc_opts, .handle = 1, .priority = 1); +struct bpf_link *reader_link =NULL ; +struct netns_obj *ns =NULL ; +int server_fd =-1 ; +int cgroup_fd =-1 ; +int filter_fd; +int ret; + + ns =netns_new (name, true); +if (!ASSERT_OK_PTR (ns,"netns_new" )) +return ; + + cgroup_fd =test__join_cgroup ("/skb_ext_udp" ); +if (!ASSERT_GE (cgroup_fd,0 ,"join_cgroup" )) + goto cleanup; + + server_fd =start_server (AF_INET ,SOCK_DGRAM ,"127.0.0.1" ,0 ,0 ); +if (!ASSERT_GE (server_fd,0 ,"start_server" )) + goto cleanup; + + skel->bss->test_pass = false; + + ret =bpf_tc_hook_create (&tc_hook); +if (!ASSERT_OK (ret,"bpf_tc_hook_create" )) + goto cleanup; + + tc_opts.prog_fd =bpf_program__fd (skel->progs.tc_skb_ext_write); + ret =bpf_tc_attach (&tc_hook, &tc_opts); +if (!ASSERT_OK (ret,"bpf_tc_attach" )) + goto cleanup; + +switch (reader) { +case READER_CGRP_SKB : + reader_link =bpf_program__attach_cgroup (skel->progs.cgrp_skb_ext_read, + cgroup_fd); +if (!ASSERT_OK_PTR (reader_link,"attach_cgroup" )) + goto cleanup; +break ; +case READER_SK_FILTER : + filter_fd =bpf_program__fd (skel->progs.sk_filter_skb_ext_read); + ret =setsockopt (server_fd,SOL_SOCKET ,SO_ATTACH_BPF , + &filter_fd,sizeof (filter_fd)); +if (!ASSERT_OK (ret,"attach_socket_filter" )) + goto cleanup; +break ; + } + +if (send_loopback_udp (server_fd)) + goto cleanup; + +ASSERT_TRUE (skel->bss->test_pass,"test_pass" ); + +cleanup: +bpf_link__destroy (reader_link); +bpf_tc_hook_destroy (&tc_hook); +if (server_fd >=0 ) +close (server_fd); +if (cgroup_fd >=0 ) +close (cgroup_fd); +netns_free (ns); +} + +void test_skb_ext_cross_hook (void ) +{ +struct test_xdp_meta *skel =NULL ; + + skel =test_xdp_meta__open_and_load (); +if (!ASSERT_OK_PTR (skel,"open and load skeleton" )) +return ; + +if (test__start_subtest ("tc_to_cgrp_ingress" )) +test_skb_ext_udp (skel,"tc_to_cgrp_ingress" ,READER_CGRP_SKB ); +if (test__start_subtest ("tc_to_sk_filter" )) +test_skb_ext_udp (skel,"tc_to_sk_filter" ,READER_SK_FILTER ); + +test_xdp_meta__destroy (skel); +}
tools/testing/selftests/bpf/progs/test_xdp_meta.c +37 -0
@@ -1000,4 +1000,41 @@ int tc_skb_ext_slice_write_after_clone_redir(struct __sk_buff *ctx)return TC_ACT_UNSPEC ; } +/* Read skb_ext from cgroup/skb ingress -- tests cross-hook survival */ +SEC("cgroup_skb/ingress") +int cgrp_skb_ext_read (struct __sk_buff *ctx) +{ +__u8 meta_have[META_SIZE ]; +struct bpf_dynptr meta; + +if (bpf_dynptr_from_skb_ext (ctx,0 ,0 , &meta)) +return 1 ; +if (bpf_dynptr_read (meta_have,META_SIZE , &meta,0 ,0 )) +return 1 ; +if (!check_metadata (meta_have)) +return 1 ; + + test_pass = true; +return 1 ; +} + +/* Read skb_ext from socket filter -- tests TC -> sk_filter path */ +SEC("socket") +int sk_filter_skb_ext_read (struct __sk_buff *ctx) +{ +__u8 meta_have[META_SIZE ]; +struct bpf_dynptr meta; + +if (bpf_dynptr_from_skb_ext (ctx,0 ,0 , &meta)) + goto out; +if (bpf_dynptr_read (meta_have,META_SIZE , &meta,0 ,0 )) + goto out; +if (!check_metadata (meta_have)) + goto out; + + test_pass = true; +out: +return ctx->len; +} + char _license[] SEC("license") = "GPL";
Signature · 1 line
2.43.0
PATCH v2 8/14 selftests/bpf: Test skb_ext read from sock_ops and LSM hooks
In reply to Jakub SitnickiExtend skb_ext test coverage to hook on TCP ingress path: attach a TC ingress program on loopback that writes the metadata to packets, and read it back from a sock_ops program (BPF_SOCK_OPS_PASSIVE_ESTABLISHED_CB, reaching the skb via bpf_sock_ops_kern->skb) and from the LSM inet_conn_established hook.
--- .../bpf/prog_tests/xdp_context_test_run.c | 92 ++++++++++++++++++++++ tools/testing/selftests/bpf/progs/test_xdp_meta.c | 75 ++++++++++++++++++ 2 files changed, 167 insertions(+)
tools/testing/selftests/bpf/prog_tests/xdp_context_test_run.c +92 -0
@@ -1206,6 +1206,94 @@ static void test_skb_ext_udp(struct test_xdp_meta *skel, const char *name,netns_free (ns); } +enum tcp_reader_type { +READER_SKOPS , +READER_LSM , +}; + +/* Test skb_ext survival across TC ingress -> TCP reader hook */ +static void test_skb_ext_tcp (struct test_xdp_meta *skel,const char *name, +enum tcp_reader_type reader) +{ +LIBBPF_OPTS (bpf_tc_hook, tc_hook, + .ifindex = 1 /* IFINDEX_LO */, + .attach_point = BPF_TC_INGRESS); + LIBBPF_OPTS(bpf_tc_opts, tc_opts, .handle = 1, .priority = 1); +struct bpf_link *reader_link =NULL ; +struct netns_obj *ns =NULL ; +int server_fd =-1 ; +int cgroup_fd =-1 ; +int client_fd =-1 ; +int conn_fd =-1 ; +int port; +int ret; + + ns =netns_new (name, true); +if (!ASSERT_OK_PTR (ns,"netns_new" )) +return ; + + cgroup_fd =test__join_cgroup ("/skb_ext_tcp" ); +if (!ASSERT_GE (cgroup_fd,0 ,"join_cgroup" )) + goto cleanup; + + server_fd =start_server (AF_INET ,SOCK_STREAM ,"127.0.0.1" ,0 ,0 ); +if (!ASSERT_GE (server_fd,0 ,"start_server" )) + goto cleanup; + + port =get_socket_local_port (server_fd); +if (!ASSERT_GE (port,0 ,"get_port" )) + goto cleanup; + + skel->bss->target_port = port; + skel->bss->test_pass = false; + + ret =bpf_tc_hook_create (&tc_hook); +if (!ASSERT_OK (ret,"bpf_tc_hook_create" )) + goto cleanup; + + tc_opts.prog_fd =bpf_program__fd (skel->progs.tc_skb_ext_write_port); + ret =bpf_tc_attach (&tc_hook, &tc_opts); +if (!ASSERT_OK (ret,"bpf_tc_attach" )) + goto cleanup; + +switch (reader) { +case READER_SKOPS : + reader_link =bpf_program__attach_cgroup (skel->progs.skops_skb_ext_read, + cgroup_fd); +if (!ASSERT_OK_PTR (reader_link,"attach_skops" )) + goto cleanup; +break ; +case READER_LSM : + reader_link =bpf_program__attach_lsm (skel->progs.lsm_skb_ext_read); +if (!ASSERT_OK_PTR (reader_link,"attach_lsm" )) + goto cleanup; +break ; + } + + client_fd =connect_to_fd (server_fd,0 ); +if (!ASSERT_GE (client_fd,0 ,"connect" )) + goto cleanup; + + conn_fd =accept (server_fd,NULL ,NULL ); +if (!ASSERT_GE (conn_fd,0 ,"accept" )) + goto cleanup; + +ASSERT_TRUE (skel->bss->test_pass,"test_pass" ); + +cleanup: +if (conn_fd >=0 ) +close (conn_fd); +if (client_fd >=0 ) +close (client_fd); +bpf_link__destroy (reader_link); +bpf_tc_hook_destroy (&tc_hook); +if (server_fd >=0 ) +close (server_fd); +if (cgroup_fd >=0 ) +close (cgroup_fd); +netns_free (ns); +} +void test_skb_ext_cross_hook (void ) {struct test_xdp_meta *skel =NULL ;
@@ -1218,6 +1306,10 @@ void test_skb_ext_cross_hook(void)test_skb_ext_udp (skel,"tc_to_cgrp_ingress" ,READER_CGRP_SKB );if (test__start_subtest ("tc_to_sk_filter" ))test_skb_ext_udp (skel,"tc_to_sk_filter" ,READER_SK_FILTER ); +if (test__start_subtest ("tc_to_lsm" )) +test_skb_ext_tcp (skel,"tc_to_lsm" ,READER_LSM ); +if (test__start_subtest ("tc_to_skops" )) +test_skb_ext_tcp (skel,"tc_to_skops" ,READER_SKOPS );test_xdp_meta__destroy (skel); }
tools/testing/selftests/bpf/progs/test_xdp_meta.c +75 -0
81 lines not on this page · raw message
Signature · 1 line
2.43.0
PATCH v2 9/14 selftests/bpf: Test skb_ext read from kfree_skb tracepoint
In reply to Jakub SitnickiWrite skb_ext at cgroup/skb egress, send UDP to a closed loopback port so the packet is dropped, and read the extension back from a tp_btf/kfree_skb program.
--- .../bpf/prog_tests/xdp_context_test_run.c | 70 ++++++++++++++++++++++ tools/testing/selftests/bpf/progs/test_xdp_meta.c | 34 +++++++++++ 2 files changed, 104 insertions(+)
tools/testing/selftests/bpf/prog_tests/xdp_context_test_run.c +70 -0
@@ -1294,6 +1294,74 @@ static void test_skb_ext_tcp(struct test_xdp_meta *skel, const char *name,netns_free (ns); } +/* +* Test skb_ext survival until skb free: cgroup/skb egress -> kfree_skb. +* Send UDP to a closed port. The packet is dropped, triggering kfree_skb. +*/ +static void test_cgrp_egress_to_kfree_skb (struct test_xdp_meta *skel) +{ +struct sockaddr_in addr = { + .sin_family =AF_INET , + .sin_port =htons (4321 ), + .sin_addr.s_addr =htonl (INADDR_LOOPBACK ), + }; +struct bpf_link *cg_link =NULL ; +struct bpf_link *tp_link =NULL ; +struct netns_obj *ns =NULL ; +int cgroup_fd =-1 ; +char buf[1 ]; +int fd =-1 ; +int ret; + + cgroup_fd =test__join_cgroup ("/cgrp_to_kfree" ); +if (!ASSERT_GE (cgroup_fd,0 ,"join_cgroup" )) +return ; + + ns =netns_new ("cgrp_to_kfree" , true); +if (!ASSERT_OK_PTR (ns,"netns_new" )) + goto cleanup; + + skel->bss->test_pass = false; + + cg_link =bpf_program__attach_cgroup (skel->progs.cgrp_skb_ext_write, + cgroup_fd); +if (!ASSERT_OK_PTR (cg_link,"attach_cgroup" )) + goto cleanup; + + tp_link =bpf_program__attach_trace (skel->progs.tp_kfree_skb_ext_read); +if (!ASSERT_OK_PTR (tp_link,"attach_tp" )) + goto cleanup; + + fd =socket (AF_INET ,SOCK_DGRAM ,0 ); +if (!ASSERT_GE (fd,0 ,"socket" )) + goto cleanup; + + ret =connect (fd, (void *)&addr,sizeof (addr)); +if (!ASSERT_OK (ret,"connect" )) + goto cleanup; + + ret =send (fd, test_payload,TEST_PAYLOAD_LEN ,0 ); +if (!ASSERT_EQ (ret,TEST_PAYLOAD_LEN ,"send" )) + goto cleanup; + +/* Wait for ICMP error -- confirms the packet was freed */ + ret =recv (fd, buf,sizeof (buf),0 ); +if (!ASSERT_EQ (ret,-1 ,"recv" )) + goto cleanup; +ASSERT_EQ (errno,ECONNREFUSED ,"recv_econnrefused" ); + +ASSERT_TRUE (skel->bss->test_pass,"test_pass" ); + +cleanup: +if (fd >=0 ) +close (fd); +bpf_link__destroy (tp_link); +bpf_link__destroy (cg_link); +netns_free (ns); +if (cgroup_fd >=0 ) +close (cgroup_fd); +} +void test_skb_ext_cross_hook (void ) {struct test_xdp_meta *skel =NULL ;
@@ -1310,6 +1378,8 @@ void test_skb_ext_cross_hook(void)test_skb_ext_tcp (skel,"tc_to_lsm" ,READER_LSM );if (test__start_subtest ("tc_to_skops" ))test_skb_ext_tcp (skel,"tc_to_skops" ,READER_SKOPS ); +if (test__start_subtest ("cgrp_egress_to_kfree_skb" )) +test_cgrp_egress_to_kfree_skb (skel);test_xdp_meta__destroy (skel); }
tools/testing/selftests/bpf/progs/test_xdp_meta.c +34 -0
@@ -1112,4 +1112,38 @@ int sk_filter_skb_ext_read(struct __sk_buff *ctx)return ctx->len; } +/* Write skb_ext from cgroup/skb egress */ +SEC("cgroup_skb/egress") +int cgrp_skb_ext_write (struct __sk_buff *ctx) +{ +struct bpf_dynptr meta; + +if (!is_test_packet_tc (ctx)) +return 1 ; + +if (bpf_dynptr_from_skb_ext (ctx,0 ,BPF_SKB_EXT_F_CREATE , &meta)) +return 1 ; +bpf_dynptr_write (&meta,0 , (void *)meta_want,META_SIZE ,0 ); + +return 1 ; +} + +/* Read skb_ext from tp_btf/kfree_skb -- tests survival until skb free */ +SEC("tp_btf/kfree_skb") +int BPF_PROG (tp_kfree_skb_ext_read ,struct sk_buff *skb) +{ +__u8 meta_have[META_SIZE ]; +struct bpf_dynptr meta; + +if (bpf_dynptr_from_skb_ext ((struct __sk_buff *)skb,0 ,0 , &meta)) +return 0 ; +if (bpf_dynptr_read (meta_have,META_SIZE , &meta,0 ,0 )) +return 0 ; +if (!check_metadata (meta_have)) +return 0 ; + + test_pass = true; +return 0 ; +} + char _license[] SEC("license") = "GPL";
Signature · 1 line
2.43.0
PATCH v2 10/14 selftests/bpf: Test skb_ext read from netfilter hook
In reply to Jakub SitnickiAdd a TC -> netfilter cross-hook test for bpf_dynptr_from_skb_ext(). A TC ingress program writes skb_ext on loopback, and a netfilter program at NF_INET_LOCAL_IN reads it back.
--- .../bpf/prog_tests/xdp_context_test_run.c | 56 ++++++++++++++++++++++ tools/testing/selftests/bpf/progs/test_xdp_meta.c | 23 +++++++++ 2 files changed, 79 insertions(+)
tools/testing/selftests/bpf/prog_tests/xdp_context_test_run.c +56 -0
@@ -2,6 +2,7 @@#include <test_progs.h> #include <network_helpers.h> #include <linux/ipv6.h> +#include <linux/netfilter.h> #include <arpa/inet.h> #include "test_xdp_context_test_run.skel.h" #include "test_xdp_meta.skel.h"
@@ -1362,6 +1363,59 @@ static void test_cgrp_egress_to_kfree_skb(struct test_xdp_meta *skel)close (cgroup_fd); } +/* Test skb_ext survival across TC ingress -> netfilter hook */ +static void test_skb_ext_nf (struct test_xdp_meta *skel,const char *name) +{ +LIBBPF_OPTS (bpf_tc_hook, tc_hook, + .ifindex = 1 /* IFINDEX_LO */, + .attach_point = BPF_TC_INGRESS); + LIBBPF_OPTS(bpf_tc_opts, tc_opts, .handle = 1, .priority = 1); +LIBBPF_OPTS (bpf_netfilter_opts, nf_opts, + .pf = NFPROTO_IPV4, + .hooknum = NF_INET_LOCAL_IN, + .priority = 1); +struct bpf_link *reader_link =NULL ; +struct netns_obj *ns =NULL ; +int server_fd =-1 ; +int ret; + + ns =netns_new (name, true); +if (!ASSERT_OK_PTR (ns,"netns_new" )) +return ; + + server_fd =start_server (AF_INET ,SOCK_DGRAM ,"127.0.0.1" ,0 ,0 ); +if (!ASSERT_GE (server_fd,0 ,"start_server" )) + goto cleanup; + + skel->bss->test_pass = false; + + ret =bpf_tc_hook_create (&tc_hook); +if (!ASSERT_OK (ret,"bpf_tc_hook_create" )) + goto cleanup; + + tc_opts.prog_fd =bpf_program__fd (skel->progs.tc_skb_ext_write); + ret =bpf_tc_attach (&tc_hook, &tc_opts); +if (!ASSERT_OK (ret,"bpf_tc_attach" )) + goto cleanup; + + reader_link =bpf_program__attach_netfilter (skel->progs.nf_skb_ext_read, + &nf_opts); +if (!ASSERT_OK_PTR (reader_link,"attach_nf" )) + goto cleanup; + +if (send_loopback_udp (server_fd)) + goto cleanup; + +ASSERT_TRUE (skel->bss->test_pass,"test_pass" ); + +cleanup: +bpf_link__destroy (reader_link); +bpf_tc_hook_destroy (&tc_hook); +if (server_fd >=0 ) +close (server_fd); +netns_free (ns); +} +void test_skb_ext_cross_hook (void ) {struct test_xdp_meta *skel =NULL ;
@@ -1380,6 +1434,8 @@ void test_skb_ext_cross_hook(void)test_skb_ext_tcp (skel,"tc_to_skops" ,READER_SKOPS );if (test__start_subtest ("cgrp_egress_to_kfree_skb" ))test_cgrp_egress_to_kfree_skb (skel); +if (test__start_subtest ("tc_to_nf" )) +test_skb_ext_nf (skel,"tc_to_nf" );test_xdp_meta__destroy (skel); }
tools/testing/selftests/bpf/progs/test_xdp_meta.c +23 -0
@@ -1146,4 +1146,27 @@ int BPF_PROG(tp_kfree_skb_ext_read, struct sk_buff *skb)return 0 ; } +#define NF_ACCEPT 1 + +SEC("netfilter") +int nf_skb_ext_read (struct bpf_nf_ctx *ctx) +{ +struct __sk_buff *skb = (struct __sk_buff *)ctx->skb; +__u8 meta_have[META_SIZE ]; +struct bpf_dynptr meta; + +if (!skb) +return NF_ACCEPT ; + +if (bpf_dynptr_from_skb_ext (skb,0 ,0 , &meta)) +return NF_ACCEPT ; +if (bpf_dynptr_read (meta_have,META_SIZE , &meta,0 ,0 )) +return NF_ACCEPT ; +if (!check_metadata (meta_have)) +return NF_ACCEPT ; + + test_pass = true; +return NF_ACCEPT ; +} + char _license[] SEC("license") = "GPL";
Signature · 1 line
2.43.0
PATCH v2 11/14 selftests/bpf: Test skb_ext from LWT in, out, and xmit hooks
In reply to Jakub SitnickiAdd cross-hook tests for bpf_dynptr_from_skb_ext() covering all generic LWT program types. For lwt_in, a TC ingress program writes skb_ext on loopback and the LWT program reads it back. For lwt_out and lwt_xmit, the LWT programs write skb_ext on the output path and a TC ingress program reads it back after loopback.
--- .../bpf/prog_tests/xdp_context_test_run.c | 103 +++++++++++++++++++++ tools/testing/selftests/bpf/progs/test_xdp_meta.c | 45 +++++++++ 2 files changed, 148 insertions(+)
tools/testing/selftests/bpf/prog_tests/xdp_context_test_run.c +103 -0
@@ -1416,6 +1416,100 @@ static void test_skb_ext_nf(struct test_xdp_meta *skel, const char *name)netns_free (ns); } +#define LWT_EXT_PIN_PATH "/sys/fs/bpf/skb_ext_lwt" + +/* +* Test skb_ext across LWT hooks on loopback. +* +* @lwt_prog: BPF program to pin and attach via ip route encap +* @encap_dir: "in", "out", or "xmit" +* @writer: true if lwt_prog writes skb_ext (reader on TC ingress), +* false if lwt_prog reads skb_ext (writer on TC ingress) +*/ +static void test_skb_ext_lwt (struct test_xdp_meta *skel,const char *name, +struct bpf_program *lwt_prog, +const char *encap_dir,bool writer) +{ +LIBBPF_OPTS (bpf_tc_hook, tc_hook, + .ifindex = 1 /* IFINDEX_LO */, + .attach_point = BPF_TC_INGRESS); + LIBBPF_OPTS(bpf_tc_opts, tc_opts, .handle = 1, .priority = 1); +struct sockaddr_in addr = { + .sin_family =AF_INET , + }; +struct bpf_program *tc_prog; +char buf[TEST_PAYLOAD_LEN ]; +struct netns_obj *ns =NULL ; +bool pinned = false; +int server_fd =-1 ; +int fd =-1 ; +int port; +int ret; + +unlink (LWT_EXT_PIN_PATH ); + ret =bpf_program__pin (lwt_prog,LWT_EXT_PIN_PATH ); +if (!ASSERT_OK (ret,"pin lwt" )) +return ; + pinned = true; + + ns =netns_new (name, true); +if (!ASSERT_OK_PTR (ns,"netns_new" )) + goto cleanup_prehook; + +SYS (cleanup,"ip addr add 10.0.0.1/32 dev lo" ); +SYS (cleanup,"ip route replace table local local 10.0.0.1 " +"encap bpf %s pinned " LWT_EXT_PIN_PATH " dev lo" , + encap_dir); + + server_fd =start_server (AF_INET ,SOCK_DGRAM ,"10.0.0.1" ,0 ,0 ); +if (!ASSERT_GE (server_fd,0 ,"start_server" )) + goto cleanup_prehook; + + skel->bss->test_pass = false; + + ret =bpf_tc_hook_create (&tc_hook); +if (!ASSERT_OK (ret,"bpf_tc_hook_create" )) + goto cleanup_prehook; + +/* When LWT writes, TC ingress reads; when LWT reads, TC ingress writes */ + tc_prog = writer ? skel->progs.tc_skb_ext_read + : skel->progs.tc_skb_ext_write; + tc_opts.prog_fd =bpf_program__fd (tc_prog); + ret =bpf_tc_attach (&tc_hook, &tc_opts); +if (!ASSERT_OK (ret,"bpf_tc_attach" )) + goto cleanup; + + port =get_socket_local_port (server_fd); +if (!ASSERT_GE (port,0 ,"get_port" )) + goto cleanup; + + fd =socket (AF_INET ,SOCK_DGRAM ,0 ); +if (!ASSERT_GE (fd,0 ,"socket" )) + goto cleanup; + +inet_pton (AF_INET ,"10.0.0.1" , &addr.sin_addr); + addr.sin_port = port; + ret =sendto (fd, test_payload,TEST_PAYLOAD_LEN ,0 , + (void *)&addr,sizeof (addr)); +if (!ASSERT_EQ (ret,TEST_PAYLOAD_LEN ,"sendto" )) + goto cleanup; + ret =recvfrom (server_fd, buf,sizeof (buf),0 ,NULL ,NULL ); +ASSERT_EQ (ret,TEST_PAYLOAD_LEN ,"recvfrom" ); + +ASSERT_TRUE (skel->bss->test_pass,"test_pass" ); + +cleanup: +if (fd >=0 ) +close (fd); +bpf_tc_hook_destroy (&tc_hook); +cleanup_prehook: +if (server_fd >=0 ) +close (server_fd); +netns_free (ns); +if (pinned) +unlink (LWT_EXT_PIN_PATH ); +} +void test_skb_ext_cross_hook (void ) {struct test_xdp_meta *skel =NULL ;
@@ -1436,6 +1530,15 @@ void test_skb_ext_cross_hook(void)test_cgrp_egress_to_kfree_skb (skel);if (test__start_subtest ("tc_to_nf" ))test_skb_ext_nf (skel,"tc_to_nf" ); +if (test__start_subtest ("tc_to_lwt_in" )) +test_skb_ext_lwt (skel,"tc_to_lwt_in" , + skel->progs.lwt_in_skb_ext_read,"in" , false); +if (test__start_subtest ("lwt_out_to_tc" )) +test_skb_ext_lwt (skel,"lwt_out_to_tc" , + skel->progs.lwt_out_skb_ext_write,"out" , true); +if (test__start_subtest ("lwt_xmit_to_tc" )) +test_skb_ext_lwt (skel,"lwt_xmit_to_tc" , + skel->progs.lwt_xmit_skb_ext_write,"xmit" , true);test_xdp_meta__destroy (skel); }
tools/testing/selftests/bpf/progs/test_xdp_meta.c +45 -0
49 lines not on this page · raw message
Signature · 1 line
2.43.0
PATCH v2 12/14 selftests/bpf: Test skb_ext read from seg6local End.BPF hook
In reply to Jakub SitnickiTest bpf_dynptr_from_skb_ext() from lwt_seg6local context:
- TC writes skb_ext on the encapped packet leaving NS1,
- NS2 runs End.BPF for fd01::1 which reads it back,
- NS3 receives the packet and decapsulates it.
Note that End.BPF cannot deliver locally since seg6_lookup_nexthop rejects loopback routes, hence a three netns setup is necessary.
--- .../bpf/prog_tests/xdp_context_test_run.c | 170 +++++++++++++++++++++ tools/testing/selftests/bpf/progs/test_xdp_meta.c | 18 +++ 2 files changed, 188 insertions(+)
tools/testing/selftests/bpf/prog_tests/xdp_context_test_run.c +170 -0
@@ -1510,6 +1510,174 @@ static void test_skb_ext_lwt(struct test_xdp_meta *skel, const char *name,unlink (LWT_EXT_PIN_PATH ); } +#define SEG6_PIN_PATH "/sys/fs/bpf/skb_ext_seg6local" + +/* +* Test skb_ext survival across TC egress -> seg6local End.BPF hook. +* +* Topology: +* +* NS1 NS2 NS3 +* lo veth1 <-> veth2 veth3 <-> veth4 lo +* +* NS1 encaps fb01::2 with SRH (segments fd01::1,fd01::2) on output and +* writes skb_ext at TC egress on veth1. NS2 runs End.BPF for fd01::1, +* which reads skb_ext, then forwards to NS3 (seg6_lookup_nexthop +* rejects loopback routes with local_delivery=false, so End.BPF +* cannot deliver locally). NS3 has fd01::2 local, decapsulates, and +* delivers the inner UDP (dst=fb01::2) to a local socket for test +* synchronization. +* +* The TC program drops non-test packets, so NDP is bypassed with a +* static neighbor entry on the NS1->NS2 hop. +*/ +static void test_skb_ext_seg6local (struct test_xdp_meta *skel) +{ + LIBBPF_OPTS(bpf_tc_hook, tc_hook, .attach_point = BPF_TC_EGRESS); + LIBBPF_OPTS(bpf_tc_opts, tc_opts, .handle = 1, .priority = 1); +struct nstoken *nstoken =NULL ; +struct sockaddr_in6 dst = {}; +char buf[TEST_PAYLOAD_LEN ]; +bool pinned = false; +int client_fd =-1 ; +int server_fd =-1 ; +ssize_t bytes; +int ret; + +unlink (SEG6_PIN_PATH ); + ret =bpf_program__pin (skel->progs.seg6local_skb_ext_read, +SEG6_PIN_PATH ); +if (!ASSERT_OK (ret,"pin seg6local" )) +return ; + pinned = true; + + skel->bss->test_pass = false; + +SYS (cleanup,"ip netns add seg6_1" ); +SYS (cleanup,"ip netns add seg6_2" ); +SYS (cleanup,"ip netns add seg6_3" ); + +/* NS1 <-> NS2 veth pair; static NDP since TC drops NS/NA */ +SYS (cleanup,"ip -n seg6_1 link add veth1 type veth peer name veth2 netns seg6_2" ); +SYS (cleanup,"ip -n seg6_1 link set dev veth1 up" ); +SYS (cleanup,"ip -n seg6_2 link set dev veth2 address 02:00:00:00:00:02" ); +SYS (cleanup,"ip -n seg6_2 link set dev veth2 up" ); +SYS (cleanup,"ip -n seg6_1 -6 addr add fb00::12/16 dev veth1 scope link nodad" ); +SYS (cleanup,"ip -n seg6_2 -6 addr add fb00::21/16 dev veth2 scope link nodad" ); +SYS (cleanup,"ip -n seg6_1 -6 neigh add fb00::21 lladdr 02:00:00:00:00:02 " +"nud permanent dev veth1" ); + +/* NS2 <-> NS3 veth pair */ +SYS (cleanup,"ip -n seg6_2 link add veth3 type veth peer name veth4 netns seg6_3" ); +SYS (cleanup,"ip -n seg6_2 link set dev veth3 up" ); +SYS (cleanup,"ip -n seg6_3 link set dev veth4 up" ); +SYS (cleanup,"ip -n seg6_2 -6 addr add fb00::34/16 dev veth3 scope link nodad" ); +SYS (cleanup,"ip -n seg6_3 -6 addr add fb00::43/16 dev veth4 scope link nodad" ); + +/* NS1: source address + SRH encap on output + route for fd01::/16 */ +SYS (cleanup,"ip -n seg6_1 link set dev lo up" ); +SYS (cleanup,"ip -n seg6_1 -6 addr add fb01::1/128 dev lo nodad" ); +SYS (cleanup,"ip -n seg6_1 -6 route add fb01::2 encap seg6 mode encap " +"segs fd01::1,fd01::2 dev veth1 via fb00::21" ); +SYS (cleanup,"ip -n seg6_1 -6 route add fd01::/16 dev veth1 via fb00::21" ); + +/* NS2: seg6local End.BPF for fd01::1, then forward to NS3. +* Use open_netns so the pinned prog on bpffs is accessible. +*/ + nstoken =open_netns ("seg6_2" ); +if (!ASSERT_OK_PTR (nstoken,"open seg6_2" )) + goto cleanup; + +SYS (cleanup,"ip link set dev lo up" ); +SYS (cleanup,"sysctl -wq net.ipv6.conf.all.forwarding=1" ); +SYS (cleanup,"ip -6 route add fd01::2/128 dev veth3 via fb00::43" ); +SYS (cleanup,"ip -6 route add fd01::1 encap seg6local " +"action End.BPF endpoint pinned " SEG6_PIN_PATH " dev veth2" ); + +close_netns (nstoken); + nstoken =NULL ; + +/* NS3: decap point + UDP server. +* fd01::2 local triggers SRH decap (segments_left=0). +* fb01::2 local delivers the inner UDP to the socket. +*/ + nstoken =open_netns ("seg6_3" ); +if (!ASSERT_OK_PTR (nstoken,"open seg6_3" )) + goto cleanup; + +SYS (cleanup,"ip link set dev lo up" ); +SYS (cleanup,"sysctl -wq net.ipv6.conf.all.seg6_enabled=1" ); +SYS (cleanup,"sysctl -wq net.ipv6.conf.lo.seg6_enabled=1" ); +SYS (cleanup,"sysctl -wq net.ipv6.conf.veth4.seg6_enabled=1" ); +SYS (cleanup,"ip -6 addr add fd01::2/128 dev lo nodad" ); +SYS (cleanup,"ip -6 addr add fb01::2/128 dev lo nodad" ); + + server_fd =start_server (AF_INET6 ,SOCK_DGRAM ,"fb01::2" ,1234 ,0 ); +if (!ASSERT_GE (server_fd,0 ,"start_server" )) + goto cleanup; + +close_netns (nstoken); + nstoken =NULL ; + +/* NS1: write skb_ext at TC egress on veth1, then send. +* TC egress fires after seg6 encap, on the encapped packet. +*/ + nstoken =open_netns ("seg6_1" ); +if (!ASSERT_OK_PTR (nstoken,"open seg6_1" )) + goto cleanup; + + tc_hook.ifindex =if_nametoindex ("veth1" ); +if (!ASSERT_GT (tc_hook.ifindex,0 ,"ifindex veth1" )) + goto cleanup; + + ret =bpf_tc_hook_create (&tc_hook); +if (!ASSERT_OK (ret,"bpf_tc_hook_create" )) + goto cleanup; + + tc_opts.prog_fd =bpf_program__fd (skel->progs.tc_skb_ext_write); + ret =bpf_tc_attach (&tc_hook, &tc_opts); +if (!ASSERT_OK (ret,"bpf_tc_attach" )) + goto cleanup; + + client_fd =socket (AF_INET6 ,SOCK_DGRAM ,0 ); +if (!ASSERT_GE (client_fd,0 ,"socket" )) + goto cleanup; + + dst.sin6_family =AF_INET6 ; + dst.sin6_port =htons (1234 ); +inet_pton (AF_INET6 ,"fb01::2" , &dst.sin6_addr); + + bytes =sendto (client_fd, test_payload,TEST_PAYLOAD_LEN ,0 , + (void *)&dst,sizeof (dst)); + +close_netns (nstoken); + nstoken =NULL ; + +if (!ASSERT_EQ (bytes,TEST_PAYLOAD_LEN ,"sendto" )) + goto cleanup; + +/* Receive decapsulated packet -- synchronizes with seg6local */ + nstoken =open_netns ("seg6_3" ); +if (!ASSERT_OK_PTR (nstoken,"open seg6_3" )) + goto cleanup; + + bytes =recvfrom (server_fd, buf,sizeof (buf),0 ,NULL ,NULL ); +ASSERT_EQ (bytes,TEST_PAYLOAD_LEN ,"recvfrom" ); +ASSERT_TRUE (skel->bss->test_pass,"test_pass" ); + +cleanup: +close_netns (nstoken); +if (server_fd >=0 ) +close (server_fd); +if (client_fd >=0 ) +close (client_fd); +SYS_NOFAIL ("ip netns del seg6_3" ); +SYS_NOFAIL ("ip netns del seg6_2" ); +SYS_NOFAIL ("ip netns del seg6_1" ); +if (pinned) +unlink (SEG6_PIN_PATH ); +} +void test_skb_ext_cross_hook (void ) {struct test_xdp_meta *skel =NULL ;
@@ -1539,6 +1707,8 @@ void test_skb_ext_cross_hook(void)if (test__start_subtest ("lwt_xmit_to_tc" ))test_skb_ext_lwt (skel,"lwt_xmit_to_tc" , skel->progs.lwt_xmit_skb_ext_write,"xmit" , true); +if (test__start_subtest ("tc_to_seg6local" )) +test_skb_ext_seg6local (skel);test_xdp_meta__destroy (skel); }
tools/testing/selftests/bpf/progs/test_xdp_meta.c +18 -0
@@ -1214,4 +1214,22 @@ int lwt_xmit_skb_ext_write(struct __sk_buff *ctx)return BPF_OK ; } +/* Read skb_ext from seg6local End.BPF -- tests TC -> seg6local path */ +SEC("lwt_seg6local") +int seg6local_skb_ext_read (struct __sk_buff *ctx) +{ +__u8 meta_have[META_SIZE ]; +struct bpf_dynptr meta; + +if (bpf_dynptr_from_skb_ext (ctx,0 ,0 , &meta)) +return BPF_OK ; +if (bpf_dynptr_read (meta_have,META_SIZE , &meta,0 ,0 )) +return BPF_OK ; +if (!check_metadata (meta_have)) +return BPF_OK ; + + test_pass = true; +return BPF_OK ; +} + char _license[] SEC("license") = "GPL";
Signature · 1 line
2.43.0
PATCH v2 13/14 selftests/bpf: Test skb_ext read from sk_skb stream verdict hook
In reply to Jakub SitnickiTest bpf_dynptr_from_skb_ext() from sk_skb context. Write to skb_ext from TC on loopback; read from skb_ext from the sockmap verdict program.
--- .../selftests/bpf/prog_tests/socket_helpers.h | 1 + .../bpf/prog_tests/xdp_context_test_run.c | 80 ++++++++++++++++++++++ tools/testing/selftests/bpf/progs/test_xdp_meta.c | 18 +++++ 3 files changed, 99 insertions(+)
tools/testing/selftests/bpf/prog_tests/socket_helpers.h +1 -0
@@ -3,6 +3,7 @@#ifndef __SOCKET_HELPERS__#define __SOCKET_HELPERS__ +#include <error.h> #include <sys/un.h> #include <linux/vm_sockets.h>
tools/testing/selftests/bpf/prog_tests/xdp_context_test_run.c +80 -0
98 lines not on this page · raw message
tools/testing/selftests/bpf/progs/test_xdp_meta.c +18 -0
@@ -1232,4 +1232,22 @@ int seg6local_skb_ext_read(struct __sk_buff *ctx)return BPF_OK ; } +/* Read skb_ext from sk_skb stream verdict hook */ +SEC("sk_skb/stream_verdict") +int sk_skb_skb_ext_read (struct __sk_buff *ctx) +{ +__u8 meta_have[META_SIZE ]; +struct bpf_dynptr meta; + +if (bpf_dynptr_from_skb_ext (ctx,0 ,0 , &meta)) +return SK_PASS ; +if (bpf_dynptr_read (meta_have,META_SIZE , &meta,0 ,0 )) +return SK_PASS ; +if (!check_metadata (meta_have)) +return SK_PASS ; + + test_pass = true; +return SK_PASS ; +} + char _license[] SEC("license") = "GPL";
Signature · 1 line
2.43.0
PATCH v2 14/14 selftests/bpf: Use non-trivial test payload in xdp_context tests
In reply to Jakub SitnickiReplace the sequential test payload pattern (0x01..0x38) with higher-entropy values that don't alias common protocol header fields such as IP version/IHL or ethertype LSBs. This reduces the chance of false positives from stray packets.
--- tools/testing/selftests/bpf/prog_tests/xdp_context_test_run.c | 8 ++++---- tools/testing/selftests/bpf/progs/test_xdp_meta.c | 8 ++++---- 2 files changed, 8 insertions(+), 8 deletions(-)
tools/testing/selftests/bpf/prog_tests/xdp_context_test_run.c +4 -4
@@ -22,10 +22,10 @@#define TEST_PAYLOAD_LEN 32static const __u8 test_payload[TEST_PAYLOAD_LEN ] = { -0x01 ,0x02 ,0x03 ,0x04 ,0x05 ,0x06 ,0x07 ,0x08 , -0x11 ,0x12 ,0x13 ,0x14 ,0x15 ,0x16 ,0x17 ,0x18 , -0x21 ,0x22 ,0x23 ,0x24 ,0x25 ,0x26 ,0x27 ,0x28 , -0x31 ,0x32 ,0x33 ,0x34 ,0x35 ,0x36 ,0x37 ,0x38 , +0x49 ,0x20 ,0x63 ,0x72 ,0x6f ,0x73 ,0x73 ,0x65 , +0x64 ,0x20 ,0x68 ,0x6f ,0x6f ,0x6b ,0x73 ,0x20 , +0x26 ,0x20 ,0x6c ,0x69 ,0x76 ,0x65 ,0x64 ,0x20 , +0x74 ,0x6f ,0x20 ,0x74 ,0x65 ,0x6c ,0x6c ,0x21 , }; void test_xdp_context_error(int prog_fd, struct bpf_test_run_opts opts,
tools/testing/selftests/bpf/progs/test_xdp_meta.c +4 -4
@@ -24,10 +24,10 @@bool test_pass;static const __u8 meta_want[META_SIZE ] = { -0x01 ,0x02 ,0x03 ,0x04 ,0x05 ,0x06 ,0x07 ,0x08 , -0x11 ,0x12 ,0x13 ,0x14 ,0x15 ,0x16 ,0x17 ,0x18 , -0x21 ,0x22 ,0x23 ,0x24 ,0x25 ,0x26 ,0x27 ,0x28 , -0x31 ,0x32 ,0x33 ,0x34 ,0x35 ,0x36 ,0x37 ,0x38 , +0x49 ,0x20 ,0x63 ,0x72 ,0x6f ,0x73 ,0x73 ,0x65 , +0x64 ,0x20 ,0x68 ,0x6f ,0x6f ,0x6b ,0x73 ,0x20 , +0x26 ,0x20 ,0x6c ,0x69 ,0x76 ,0x65 ,0x64 ,0x20 , +0x74 ,0x6f ,0x20 ,0x74 ,0x65 ,0x6c ,0x6c ,0x21 , };static bool check_metadata (const char *file,int line,__u8 *meta_have)
Signature · 1 line
2.43.0
Quoted 3 lines · Jakub Sitnicki
That said, as things stand we have already established in v1 [3] that for our existing use case - attaching metadata to <1% of skbs - the
so you'll be using this bpf_skb_ext only on <1% of skb-s ? How about we add a bit in skb 'special_cleanup' or something. If set it will trigger a new tracepoint during kfree_skb/consume_skb. Then use bpf_rhashtable, populate when necessary, set bit, attach to that new tracepoint and delete from rhash where key==skb. bpf_rhash is specifically optimized for 8-byte keys.
I suspect it would be faster than this approach.
Overall this approach is fine from bpf perspective, but if it can be done with 1 bit + tracepoint approach that would be better.
Quoted 13 lines · Alexei Starovoitov
Quoted 3 lines · Jakub Sitnicki
That said, as things stand we have already established in v1 [3] that for our existing use case - attaching metadata to <1% of skbs - the
so you'll be using this
bpf_skb_extonly on <1% of skb-s ? How about we add a bit in skb 'special_cleanup' or something. If set it will trigger a new tracepoint during kfree_skb/consume_skb. Then usebpf_rhashtable, populate when necessary, set bit, attach to that new tracepoint and delete from rhash where key==skb.bpf_rhashis specifically optimized for 8-byte keys.
I suspect it would be faster than this approach.
Quoted 2 lines
Overall this approach is fine from bpf perspective, but if it can be done with 1 bit + tracepoint approach that would be better.
Thanks for taking a look.
Yes, our existing use case attaches metadata to only <1% of skbs. Even if we implemented all other use cases we have in mind, we would still only go up to ~5% of skbs by my best estimates.
So the gated-tracepoint, if we can call it that, makes much sense. Plus the idea of having a separate RHASH for each user is very appealing. No coordination between users needed, just like for BPF local storage.
I did some digging what it would take to make the gated-tracepoint idea wholesome:
1. kfree_skb/consume_skb cover only the normal free path. We would also need to hook up to GRO merge/recycle and TCP coallesce/collapse. IOW everywhere where we call skb_ext_reset/put today.
2. cloning - we would have to hook up to __copy_skb_header, so where we call __skb_ext_copy. Plus some handling of fast clones would be needed - perhaps a way to resolve &skb to its fclone twin address?
I think it deserves at least a prototype before we make a call.
Code-wise I'm thinking it might be easiest to take advantage of the fact that skb_ext already hook ups to all the right places where we free/clone skbs and add the new tracepoints there.
If we did it like that, we could then just gate on a bit from skb->active_extensions, and just handle activating the bpf_skb_ext in a special way, meaning it wouldn't result in allocating the skb_ext slab.
Let me give it a try and get back to you.
Quoted 35 lines · Jakub Sitnicki
Quoted 13 lines · Alexei Starovoitov
Quoted 3 lines · Jakub Sitnicki
That said, as things stand we have already established in v1 [3] that for our existing use case - attaching metadata to <1% of skbs - the
so you'll be using this
bpf_skb_extonly on <1% of skb-s ? How about we add a bit in skb 'special_cleanup' or something. If set it will trigger a new tracepoint during kfree_skb/consume_skb. Then usebpf_rhashtable, populate when necessary, set bit, attach to that new tracepoint and delete from rhash where key==skb.bpf_rhashis specifically optimized for 8-byte keys.
I suspect it would be faster than this approach.Quoted 2 lines
Overall this approach is fine from bpf perspective, but if it can be done with 1 bit + tracepoint approach that would be better.
Thanks for taking a look.
Yes, our existing use case attaches metadata to only <1% of skbs. Even if we implemented all other use cases we have in mind, we would still only go up to ~5% of skbs by my best estimates.
So the gated-tracepoint, if we can call it that, makes much sense. Plus the idea of having a separate RHASH for each user is very appealing. No coordination between users needed, just like for BPF local storage.
I did some digging what it would take to make the gated-tracepoint idea wholesome:
1. kfree_skb/consume_skb cover only the normal free path. We would also need to hook up to GRO merge/recycle and TCP coallesce/collapse. IOW everywhere where we call skb_ext_reset/put today.
Quoted 5 lines
2. cloning - we would have to hook up to
__copy_skb_header, so where we call__skb_ext_copy. Plus some handling of fast clones would be needed - perhaps a way to resolve &skb to its fclone twin address?I think it deserves at least a prototype before we make a call.
code is free. Pls produce patches and benchmark them.
Quoted 3 lines
Code-wise I'm thinking it might be easiest to take advantage of the fact that
skb_extalready hook ups to all the right places where we free/clone skbs and add the new tracepoints there.
fair enough.
Quoted 5 lines
If we did it like that, we could then just gate on a bit from
skb->active_extensions, and just handle activating thebpf_skb_extin a special way, meaning it wouldn't result in allocating theskb_extslab.Let me give it a try and get back to you.
Thanks!