Commit abd0c0f
Martin KaFai Lau
Merge branch 'make-tc-bpf-helpers-preserve-skb-metadata'
Jakub Sitnicki says:
====================
Make TC BPF helpers preserve skb metadata
Changes in v4:
- Fix copy-paste bug in check_metadata() test helper (AI review)
- Add "out of scope" section (at the bottom)
- Link to v3: https://lore.kernel.org/r/[email protected]
Changes in v3:
- Use the already existing BPF_STREAM_STDERR const in tests (Martin)
- Unclone skb head on bpf_dynptr_write to skb metadata (patch 3) (Martin)
- Swap order of patches 1 & 2 to refer to skb_postpush_data_move() in docs
- Mention in skb_data_move() docs how to move just the metadata
- Note in pskb_expand_head() docs to move metadata after skb_push() (Jakub)
- Link to v2: https://lore.kernel.org/r/[email protected]
Changes in v2:
- Tweak WARN_ON_ONCE check in skb_data_move() (patch 2)
- Convert all tests to verify skb metadata in BPF (patches 9-10)
- Add test coverage for modified BPF helpers (patches 12-15)
- Link to RFCv1: https://lore.kernel.org/r/[email protected]
This patch set continues our work [1] to allow BPF programs and user-space
applications to attach multiple bytes of metadata to packets via the
XDP/skb metadata area.
The focus of this patch set it to ensure that skb metadata remains intact
when packets pass through a chain of TC BPF programs that call helpers
which operate on skb head.
Currently, several helpers that either adjust the skb->data pointer or
reallocate skb->head do not preserve metadata at its expected location,
that is immediately in front of the MAC header. These are:
- bpf_skb_adjust_room
- bpf_skb_change_head
- bpf_skb_change_proto
- bpf_skb_change_tail
- bpf_skb_vlan_pop
- bpf_skb_vlan_push
In TC BPF context, metadata must be moved whenever skb->data changes to
keep the skb->data_meta pointer valid. I don't see any way around
it. Creative ideas how to avoid that would be very welcome.
With that in mind, we can patch the helpers in at least two different ways:
1. Integrate metadata move into header move
Replace the existing memmove, which follows skb_push/pull, with a helper
that moves both headers and metadata in a single call. This avoids an
extra memmove but reduces transparency.
skb_pull(skb, len);
- memmove(skb->data, skb->data - len, n);
+ skb_postpull_data_move(skb, len, n);
skb->mac_header += len;
skb_push(skb, len)
- memmove(skb->data, skb->data + len, n);
+ skb_postpush_data_move(skb, len, n);
skb->mac_header -= len;
2. Move metadata separately
Add a dedicated metadata move after the header move. This is more
explicit but costs an additional memmove.
skb_pull(skb, len);
memmove(skb->data, skb->data - len, n);
+ skb_metadata_postpull_move(skb, len);
skb->mac_header += len;
skb_push(skb, len)
+ skb_metadata_postpush_move(skb, len);
memmove(skb->data, skb->data + len, n);
skb->mac_header -= len;
This patch set implements option (1), expecting that "you can have just one
memmove" will be the most obvious feedback, while readability is a,
somewhat subjective, matter of taste, which I don't claim to have ;-)
The structure of the patch set is as follows:
- patches 1-4 prepare ground for safe-proofing the BPF helpers
- patches 5-9 modify the BPF helpers to preserve skb metadata
- patches 10-11 prepare ground for metadata tests with BPF helper calls
- patches 12-16 adapt and expand tests to cover the made changes
Out of scope for this series:
- safe-proofing tunnel & tagging devices - VLAN, GRE, ...
(next in line, in development preview at [2])
- metadata access after packet foward
(to do after Rx path - once metadata reliably reaches sk_filter)
Thanks,
-jkbs
[1] https://lore.kernel.org/all/20250814-skb-metadata-thru-dynptr-v7-0-8a39e636e0fb@cloudflare.com/
[2] https://github.com/jsitnicki/linux/commits/skb-meta/safeproof-netdevs/
====================
Link: https://patch.msgid.link/[email protected]
Signed-off-by: Martin KaFai Lau <[email protected]>File tree
8 files changed
+475
-183
lines changed- include/linux
- kernel/bpf
- net/core
- tools/testing/selftests/bpf
- prog_tests
- progs
8 files changed
+475
-183
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1781 | 1781 | | |
1782 | 1782 | | |
1783 | 1783 | | |
| 1784 | + | |
| 1785 | + | |
1784 | 1786 | | |
1785 | 1787 | | |
1786 | 1788 | | |
| |||
1817 | 1819 | | |
1818 | 1820 | | |
1819 | 1821 | | |
| 1822 | + | |
| 1823 | + | |
| 1824 | + | |
| 1825 | + | |
| 1826 | + | |
| 1827 | + | |
| 1828 | + | |
1820 | 1829 | | |
1821 | 1830 | | |
1822 | 1831 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
355 | 355 | | |
356 | 356 | | |
357 | 357 | | |
| 358 | + | |
358 | 359 | | |
359 | 360 | | |
360 | | - | |
| 361 | + | |
361 | 362 | | |
362 | 363 | | |
363 | 364 | | |
364 | 365 | | |
365 | 366 | | |
366 | 367 | | |
367 | | - | |
| 368 | + | |
368 | 369 | | |
369 | 370 | | |
370 | 371 | | |
| |||
731 | 732 | | |
732 | 733 | | |
733 | 734 | | |
734 | | - | |
735 | | - | |
736 | 735 | | |
737 | | - | |
| 736 | + | |
738 | 737 | | |
739 | 738 | | |
740 | 739 | | |
741 | 740 | | |
742 | 741 | | |
743 | | - | |
744 | 742 | | |
745 | | - | |
| 743 | + | |
| 744 | + | |
746 | 745 | | |
747 | 746 | | |
748 | 747 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
4564 | 4564 | | |
4565 | 4565 | | |
4566 | 4566 | | |
| 4567 | + | |
| 4568 | + | |
| 4569 | + | |
| 4570 | + | |
| 4571 | + | |
| 4572 | + | |
| 4573 | + | |
| 4574 | + | |
| 4575 | + | |
| 4576 | + | |
| 4577 | + | |
| 4578 | + | |
| 4579 | + | |
| 4580 | + | |
| 4581 | + | |
| 4582 | + | |
| 4583 | + | |
| 4584 | + | |
| 4585 | + | |
| 4586 | + | |
| 4587 | + | |
| 4588 | + | |
| 4589 | + | |
| 4590 | + | |
| 4591 | + | |
| 4592 | + | |
| 4593 | + | |
| 4594 | + | |
| 4595 | + | |
| 4596 | + | |
| 4597 | + | |
| 4598 | + | |
| 4599 | + | |
| 4600 | + | |
| 4601 | + | |
| 4602 | + | |
| 4603 | + | |
| 4604 | + | |
| 4605 | + | |
| 4606 | + | |
| 4607 | + | |
| 4608 | + | |
| 4609 | + | |
| 4610 | + | |
| 4611 | + | |
| 4612 | + | |
| 4613 | + | |
| 4614 | + | |
| 4615 | + | |
| 4616 | + | |
| 4617 | + | |
| 4618 | + | |
| 4619 | + | |
| 4620 | + | |
| 4621 | + | |
| 4622 | + | |
| 4623 | + | |
| 4624 | + | |
| 4625 | + | |
| 4626 | + | |
| 4627 | + | |
| 4628 | + | |
| 4629 | + | |
| 4630 | + | |
| 4631 | + | |
| 4632 | + | |
| 4633 | + | |
| 4634 | + | |
| 4635 | + | |
| 4636 | + | |
| 4637 | + | |
| 4638 | + | |
| 4639 | + | |
| 4640 | + | |
| 4641 | + | |
4567 | 4642 | | |
4568 | 4643 | | |
4569 | 4644 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1842 | 1842 | | |
1843 | 1843 | | |
1844 | 1844 | | |
1845 | | - | |
1846 | | - | |
1847 | | - | |
1848 | | - | |
| 1845 | + | |
| 1846 | + | |
1849 | 1847 | | |
1850 | 1848 | | |
1851 | 1849 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
3253 | 3253 | | |
3254 | 3254 | | |
3255 | 3255 | | |
3256 | | - | |
| 3256 | + | |
3257 | 3257 | | |
3258 | 3258 | | |
3259 | 3259 | | |
3260 | | - | |
| 3260 | + | |
3261 | 3261 | | |
3262 | 3262 | | |
3263 | 3263 | | |
| |||
3281 | 3281 | | |
3282 | 3282 | | |
3283 | 3283 | | |
3284 | | - | |
| 3284 | + | |
3285 | 3285 | | |
3286 | 3286 | | |
3287 | 3287 | | |
| |||
3326 | 3326 | | |
3327 | 3327 | | |
3328 | 3328 | | |
| 3329 | + | |
3329 | 3330 | | |
3330 | 3331 | | |
3331 | 3332 | | |
3332 | | - | |
| 3333 | + | |
3333 | 3334 | | |
3334 | 3335 | | |
3335 | 3336 | | |
| |||
3489 | 3490 | | |
3490 | 3491 | | |
3491 | 3492 | | |
| 3493 | + | |
3492 | 3494 | | |
3493 | 3495 | | |
3494 | 3496 | | |
| |||
3499 | 3501 | | |
3500 | 3502 | | |
3501 | 3503 | | |
3502 | | - | |
| 3504 | + | |
3503 | 3505 | | |
3504 | 3506 | | |
3505 | 3507 | | |
| |||
3873 | 3875 | | |
3874 | 3876 | | |
3875 | 3877 | | |
| 3878 | + | |
3876 | 3879 | | |
3877 | 3880 | | |
3878 | 3881 | | |
| |||
3882 | 3885 | | |
3883 | 3886 | | |
3884 | 3887 | | |
3885 | | - | |
| 3888 | + | |
3886 | 3889 | | |
3887 | 3890 | | |
3888 | 3891 | | |
| |||
3894 | 3897 | | |
3895 | 3898 | | |
3896 | 3899 | | |
| 3900 | + | |
3897 | 3901 | | |
3898 | 3902 | | |
3899 | 3903 | | |
| |||
12102 | 12106 | | |
12103 | 12107 | | |
12104 | 12108 | | |
| 12109 | + | |
| 12110 | + | |
| 12111 | + | |
| 12112 | + | |
| 12113 | + | |
| 12114 | + | |
| 12115 | + | |
| 12116 | + | |
| 12117 | + | |
| 12118 | + | |
| 12119 | + | |
| 12120 | + | |
12105 | 12121 | | |
12106 | 12122 | | |
12107 | 12123 | | |
| |||
12129 | 12145 | | |
12130 | 12146 | | |
12131 | 12147 | | |
12132 | | - | |
12133 | | - | |
12134 | | - | |
12135 | 12148 | | |
12136 | 12149 | | |
12137 | 12150 | | |
| |||
12149 | 12162 | | |
12150 | 12163 | | |
12151 | 12164 | | |
12152 | | - | |
12153 | | - | |
12154 | | - | |
12155 | 12165 | | |
12156 | 12166 | | |
12157 | 12167 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
2234 | 2234 | | |
2235 | 2235 | | |
2236 | 2236 | | |
| 2237 | + | |
| 2238 | + | |
| 2239 | + | |
| 2240 | + | |
2237 | 2241 | | |
2238 | 2242 | | |
2239 | 2243 | | |
| |||
2305 | 2309 | | |
2306 | 2310 | | |
2307 | 2311 | | |
2308 | | - | |
2309 | | - | |
2310 | 2312 | | |
2311 | 2313 | | |
2312 | 2314 | | |
| |||
0 commit comments