Skip to content

Allow struct_ops maps with a large number of programs

Kui-Feng Lee bpf netdev 4 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. v4 Latest3 patches 1 replyApplied 3/3
  2. v33 patches 2 repliesSuperseded
  3. v23 patches 14 repliesSuperseded
Earlier versions · 1
VersionPostedPatchesRepliesStatus
v12 patches2 repliesSuperseded

Patches in v4 All 3 applied

#Subject and filesSizeRepliesApplied
1/3bpf, net: validate struct_ops when updating value.kernel/bpf/bpf_struct_ops.c net/ipv4/tcp_cong.c+7 -100 repliesApplied
2/3bpf: struct_ops supports more than one page for trampolines.include/linux/bpf.h kernel/bpf/bpf_struct_ops.c net/bpf/bpf_dummy_struct_ops.c+97 -471 replyApplied
3/3selftests/bpf: Test struct_ops maps with a large number of program links.tools/testing/selftests/bpf/bpf_testmod/bpf_testmod.h tools/testing/selftests/bpf/prog_tests/test_struct_ops_multi_pages.c tools/testing/selftests/bpf/progs/struct_ops_multi_pages.c+176 -00 repliesApplied

Reviews trailers per patch

No Reviewed-by, Acked-by or Tested-by trailers for v4 yet.

Read the v4 thread

Cover letter [PATCH bpf-next v4 0/3] Allow struct_ops maps with a large number of programs

The BPF struct_ops previously only allowed for one page to be used for the trampolines of all links in a map. However, we have recently run out of space due to the large number of BPF program links. By allocating additional pages when we exhaust an existing page, we can accommodate more links in a single map.

The variable st_map->image has been changed to st_map->image_pages, and its type has been changed to an array of pointers to buffers of PAGE_SIZE. Additional pages are allocated when all existing pages are exhausted.

The test case loads a struct_ops maps having 40 programs. Their trampolines takes about 6.6k+ bytes over 1.5 pages on x86.

---
Major differences from v3:

- Refactor buffer allocations to bpf_struct_ops_tramp_buf_alloc() and bpf_struct_ops_tramp_buf_free().

Major differences from v2:

- Move image buffer allocation to bpf_struct_ops_prepare_trampoline().

Major differences from v1:

- Always free pages if failing to update.

- Allocate 8 pages at most.

v3: https://lore.kernel.org/all/[email protected]/
v2: https://lore.kernel.org/all/[email protected]/
v1: https://lore.kernel.org/all/[email protected]/

Kui-Feng Lee (3):
bpf, net: validate struct_ops when updating value.
bpf: struct_ops supports more than one page for trampolines. selftests/bpf: Test struct_ops maps with a large number of program
links.

 include/linux/bpf.h                           |   4 +-
 kernel/bpf/bpf_struct_ops.c                   | 139 ++++++++++++------
 net/bpf/bpf_dummy_struct_ops.c                |  12 +-
 net/ipv4/tcp_cong.c                           |   6 +-
 .../selftests/bpf/bpf_testmod/bpf_testmod.h   |  44 ++++++
 .../prog_tests/test_struct_ops_multi_pages.c  |  30 ++++
 .../bpf/progs/struct_ops_multi_pages.c        | 102 +++++++++++++
 7 files changed, 280 insertions(+), 57 deletions(-)
 create mode 100644 tools/testing/selftests/bpf/prog_tests/test_struct_ops_multi_pages.c
 create mode 100644 tools/testing/selftests/bpf/progs/struct_ops_multi_pages.c
Signature · 1 line
2.34.1