Skip to content

Add support for kptrs in more BPF maps

Kumar Kartikeya Dwivedi bpf 3 versions – In review

Get series with b4
b4 am [email protected]

Versions newest first · linked by author and title

  1. v3 Latest3 patches 6 repliesIn review
  2. v27 patches 1 replySuperseded 4 of 7 applied
  3. v17 patches 1 replySuperseded

Changes in v3 from the cover letter

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

* Fix a use-after-free bug in local storage patch
* Fix selftest for aarch64 (don't use fentry/fmod_ret)
* Wait for RCU Tasks Trace GP along with RCU GP in selftest

Patches in v3 No applies recorded yet

#Subject and filesSizeRepliesApplied
1/3bpf: Support kptrs in percpu hashmap and percpu LRU hashmapkernel/bpf/hashtab.c kernel/bpf/syscall.c+39 -220 replies
2/3bpf: Support kptrs in local storage mapsinclude/linux/bpf_local_storage.h kernel/bpf/bpf_local_storage.c kernel/bpf/syscall.c +1 more+63 -96 replies
3/3selftests/bpf: Add more tests for kptrs in mapstools/testing/selftests/bpf/prog_tests/map_kptr.c tools/testing/selftests/bpf/progs/map_kptr.c tools/testing/selftests/bpf/progs/rcu_tasks_trace_gp.c+451 -650 replies

Reviews trailers per patch

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

Read the v3 thread

Cover letter [PATCH bpf-next v3 0/3] Add support for kptrs in more BPF maps

This set adds support for kptrs in percpu hashmaps, percpu LRU hashmaps, and local storage maps (covering sk, cgrp, task, inode).

Tests are expanded to test more existing maps at runtime and also test the code path for the local storage maps (which is shared by all implementations).

A question for reviewers is what the position of the BPF runtime should be on dealing with reference cycles that can be created by BPF programs at runtime using this additional support. For instance, one can store the kptr of the task in its own task local storage, creating a cycle which prevents destruction of task local storage. Cycles can be formed using arbitrarily long kptr ownership chains. Therefore, just preventing storage of such kptrs in some maps is not a sufficient solution, and is more likely to hurt usability.

There is precedence in existing runtimes which promise memory safety, like Rust, where reference cycles and memory leaks are permitted. However, traditionally the safety guarantees of BPF have been stronger. Thus, more discussion and thought is invited on this topic to ensure we cover all usage aspects.

Changelog:
----------
v2 -> v3
v2: https://lore.kernel.org/bpf/[email protected]/

* Fix a use-after-free bug in local storage patch
* Fix selftest for aarch64 (don't use fentry/fmod_ret)
* Wait for RCU Tasks Trace GP along with RCU GP in selftest

v1 -> v2
v1: https://lore.kernel.org/bpf/[email protected]

* Simplify selftests, fix a couple of bugs

Kumar Kartikeya Dwivedi (3):
bpf: Support kptrs in percpu hashmap and percpu LRU hashmap
bpf: Support kptrs in local storage maps selftests/bpf: Add more tests for kptrs in maps

 include/linux/bpf_local_storage.h             |   6 +
 kernel/bpf/bpf_local_storage.c                |  48 ++-
 kernel/bpf/hashtab.c                          |  59 +--
 kernel/bpf/syscall.c                          |   8 +-
 kernel/bpf/verifier.c                         |  12 +-
 .../selftests/bpf/prog_tests/map_kptr.c       | 136 +++++--
 tools/testing/selftests/bpf/progs/map_kptr.c  | 344 +++++++++++++++---
 .../selftests/bpf/progs/rcu_tasks_trace_gp.c  |  36 ++
 8 files changed, 553 insertions(+), 96 deletions(-)
 create mode 100644 tools/testing/selftests/bpf/progs/rcu_tasks_trace_gp.c

base-commit: 68bfd65fb98d16239d14719a47cc1582510001de

Signature · 1 line
2.39.2