Skip to content

Add skb + xdp dynptrs

Joanne Koong bpf netdev oe-kbuild-all 13 versions – Applied

Status from this message: This series was applied to bpf/bpf-next.git (master)

Get series with b4
b4 am [email protected]

Versions newest first · linked by author and title

  1. v13 Latest10 patches 37 repliesApplied 10/10
  2. v1210 patches 0 repliesSuperseded
  3. v1110 patches 2 repliesSuperseded
Earlier versions · 10
VersionPostedPatchesRepliesStatus
v109 patches6 repliesSuperseded
v95 patches38 repliesSuperseded
v85 patches2 repliesSuperseded
v73 patches3 repliesSuperseded
v63 patches5 repliesSuperseded
v53 patches2 repliesSuperseded
v43 patches36 repliesSuperseded
v33 patches1 replySuperseded
v23 patches0 repliesSuperseded
v13 patches48 repliesSuperseded

Changes in v13 from the cover letter

* Fix missing { } for case statement

Patches in v13 All 10 applied

#Subject and filesSizeRepliesApplied
1/10bpf: Support "sk_buff" and "xdp_buff" as valid kfunc arg typeskernel/bpf/btf.c+4 -00 repliesApplied
2/10bpf: Refactor process_dynptr_funcinclude/linux/bpf_verifier.h kernel/bpf/verifier.c+31 -340 repliesApplied
3/10bpf: Allow initializing dynptrs in kfuncskernel/bpf/verifier.c+22 -453 repliesApplied
4/10bpf: Define no-ops for externally called bpf dynptr functionsinclude/linux/bpf.h+45 -300 repliesApplied
5/10bpf: Refactor verifier dynptr into get_dynptr_arg_regkernel/bpf/verifier.c+50 -300 repliesApplied
6/10bpf: Add __uninit kfunc annotationDocumentation/bpf/kfuncs.rst kernel/bpf/verifier.c+33 -20 repliesApplied
7/10bpf: Add skb dynptrsinclude/linux/bpf.h include/linux/filter.h include/uapi/linux/bpf.h +5 more+261 -190 repliesApplied
8/10bpf: Add xdp dynptrsinclude/linux/bpf.h include/linux/filter.h include/uapi/linux/bpf.h +4 more+76 -60 repliesApplied
9/10bpf: Add bpf_dynptr_slice and bpf_dynptr_slice_rdwrinclude/linux/filter.h include/uapi/linux/bpf.h kernel/bpf/helpers.c +3 more+288 -720 repliesApplied
10/10selftests/bpf: tests for using dynptrs to parse skb and xdp bufferstools/testing/selftests/bpf/bpf_kfuncs.h tools/testing/selftests/bpf/prog_tests/cls_redirect.c tools/testing/selftests/bpf/prog_tests/dynptr.c +11 more+2520 -2310 repliesApplied

Reviews trailers per patch

1 of 10 patches has a Reviewed-by or Acked-by.

PatchAndrii Nakryiko
1/10
2/10
3/10
4/10
5/10
6/10
7/10
8/10
9/10
10/10A-b

Trailers given in replies are filled; those carried in the patches from earlier versions are outlined with dashes.

Read the v13 thread

Cover letter [PATCH v13 bpf-next 00/10] Add skb + xdp dynptrs

This patchset is the 2nd in the dynptr series. The 1st can be found here [0].

This patchset adds skb and xdp type dynptrs, which have two main benefits for packet parsing:
* allowing operations on sizes that are not statically known at compile-time (eg variable-sized accesses).
* more ergonomic and less brittle iteration through data (eg does not need manual if checking for being within bounds of data_end)

When comparing the differences in runtime for packet parsing without dynptrs vs. with dynptrs, there is no noticeable difference. Patch 9 contains more details as well as examples of how to use skb and xdp dynptrs.

[0] https://lore.kernel.org/bpf/[email protected]/

--
Changelog:

v12 = https://lore.kernel.org/bpf/[email protected]/
v12 -> v13:
* Fix missing { } for case statement

v11 = https://lore.kernel.org/bpf/[email protected]/
v11 -> v12:
* Change constant mem size checking to use "__szk" kfunc annotation for slices
* Use autoloading for success selftests

v10 = https://lore.kernel.org/bpf/[email protected]/
v10 -> v11:
* Reject bpf_dynptr_slice_rdwr() for non-writable progs at load time instead of runtime
* Add additional patch (__uninit kfunc annotation)
* Expand on documentation
* Add bpf_dynptr_write() calls for persisting writes in tests

v9 = https://lore.kernel.org/bpf/[email protected]/
v9 -> v10:
* Add bpf_dynptr_slice and bpf_dynptr_slice_rdwr interface
* Add some more tests
* Split up patchset into more parts to make it easier to review

v8 = https://lore.kernel.org/bpf/[email protected]/
v8 -> v9:
* Fix dynptr_get_type() to check non-stack dynptrs

v7 = https://lore.kernel.org/bpf/[email protected]/
v7 -> v8:
* Change helpers to kfuncs
* Add 2 new patches (1/5 and 2/5)

v6 = https://lore.kernel.org/bpf/[email protected]/
v6 -> v7
* Change bpf_dynptr_data() to return read-only data slices if the skb prog is read-only (Martin)
* Add test "skb_invalid_write" to test that writes to rd-only data slices are rejected

v5 = https://lore.kernel.org/bpf/[email protected]/
v5 -> v6
* Address kernel test robot errors by static inlining

v4 = https://lore.kernel.org/bpf/[email protected]/
v4 -> v5
* Address kernel test robot errors for configs w/out CONFIG_NET set
* For data slices, return PTR_TO_MEM instead of PTR_TO_PACKET (Kumar)
* Split selftests into subtests (Andrii)
* Remove insn patching. Use rdonly and rdwr protos for dynptr skb construction (Andrii)
* bpf_dynptr_data() returns NULL for rd-only dynptrs. There will be a separate bpf_dynptr_data_rdonly() added later (Andrii and Kumar)

v3 = https://lore.kernel.org/bpf/[email protected]/
v3 -> v4
* Forgot to commit --amend the kernel test robot error fixups

v2 = https://lore.kernel.org/bpf/[email protected]/
v2 -> v3
* Fix kernel test robot build test errors

v1 = https://lore.kernel.org/bpf/[email protected]/
v1 -> v2
* Return data slices to rd-only skb dynptrs (Martin)
* bpf_dynptr_write allows writes to frags for skb dynptrs, but always invalidates associated data slices (Martin)
* Use switch casing instead of ifs (Andrii)
* Use 0xFD for experimental kind number in the selftest (Zvi)
* Put selftest conversions w/ dynptrs into new files (Alexei)
* Add new selftest "test_cls_redirect_dynptr.c"

Joanne Koong (10):
bpf: Support "sk_buff" and "xdp_buff" as valid kfunc arg types
bpf: Refactor process_dynptr_func
bpf: Allow initializing dynptrs in kfuncs
bpf: Define no-ops for externally called bpf dynptr functions
bpf: Refactor verifier dynptr into get_dynptr_arg_reg
bpf: Add __uninit kfunc annotation
bpf: Add skb dynptrs
bpf: Add xdp dynptrs
bpf: Add bpf_dynptr_slice and bpf_dynptr_slice_rdwr selftests/bpf: tests for using dynptrs to parse skb and xdp buffers

 Documentation/bpf/kfuncs.rst                  |  17 +
 include/linux/bpf.h                           |  95 +-
 include/linux/bpf_verifier.h                  |   3 -
 include/linux/filter.h                        |  46 +
 include/uapi/linux/bpf.h                      |  18 +-
 kernel/bpf/btf.c                              |  22 +
 kernel/bpf/helpers.c                          | 221 +++-
 kernel/bpf/verifier.c                         | 415 ++++++--
 net/core/filter.c                             | 108 +-
 tools/include/uapi/linux/bpf.h                |  18 +-
 tools/testing/selftests/bpf/bpf_kfuncs.h      |  38 +
 .../selftests/bpf/prog_tests/cls_redirect.c   |  25 +
 .../testing/selftests/bpf/prog_tests/dynptr.c |  74 +-
 .../selftests/bpf/prog_tests/l4lb_all.c       |   2 +
 .../bpf/prog_tests/parse_tcp_hdr_opt.c        |  93 ++
 .../selftests/bpf/prog_tests/xdp_attach.c     |  11 +-
 .../testing/selftests/bpf/progs/dynptr_fail.c | 287 ++++-
 .../selftests/bpf/progs/dynptr_success.c      |  55 +-
 .../bpf/progs/test_cls_redirect_dynptr.c      | 980 ++++++++++++++++++
 .../bpf/progs/test_l4lb_noinline_dynptr.c     | 487 +++++++++
 .../bpf/progs/test_parse_tcp_hdr_opt.c        | 119 +++
 .../bpf/progs/test_parse_tcp_hdr_opt_dynptr.c | 114 ++
 .../selftests/bpf/progs/test_xdp_dynptr.c     | 257 +++++
 .../selftests/bpf/test_tcp_hdr_options.h      |   1 +
 24 files changed, 3320 insertions(+), 186 deletions(-)
 create mode 100644 tools/testing/selftests/bpf/bpf_kfuncs.h
 create mode 100644 tools/testing/selftests/bpf/prog_tests/parse_tcp_hdr_opt.c
 create mode 100644 tools/testing/selftests/bpf/progs/test_cls_redirect_dynptr.c
 create mode 100644 tools/testing/selftests/bpf/progs/test_l4lb_noinline_dynptr.c
 create mode 100644 tools/testing/selftests/bpf/progs/test_parse_tcp_hdr_opt.c
 create mode 100644 tools/testing/selftests/bpf/progs/test_parse_tcp_hdr_opt_dynptr.c
 create mode 100644 tools/testing/selftests/bpf/progs/test_xdp_dynptr.c
Signature · 1 line
2.34.1