bpf: expand BPF arena kernel fault handling
Get series with b4
b4 am [email protected]Versions newest first · linked by author and title
- v2 Latest2 patches 0 repliesNew 1 of 2 applied
- v12 patches 4 repliesSuperseded
Changes in v2 from the cover letter
- Replace the global arena list with a latch rbtree.
- Restore the stack lookup fast path, checking the fault address before falling back to the tree lookup.
- Defer arena teardown with RCU work instead of synchronize_rcu().
- Add rate-limited deferred logging for faults outside the owning BPF program.
- Reuse bpf_testmod for the selftests instead of adding a module.
- Skip the selftests when the compiler lacks arena address-space casts.
- Correct the Fixes tag to reference the introduction of kernel arena accesses.
Patches in v2 1 of 2 applied
| # | Subject and files | Size | Replies | Applied |
|---|---|---|---|---|
| 1/2 | bpf: recover page faults across all arenaskernel/ | +91 | 0 replies | Applied |
| 2/2 | selftests/bpf: add arena fault recovery teststools/ tools/ tools/ +2 more | +207 | 0 replies |
Reviews trailers per patch
No Reviewed-by, Acked-by or Tested-by trailers for v2 yet.
Cover letter [PATCH bpf-next v2 0/2] bpf: expand BPF arena kernel fault handling
Currently, the BPF arena fault handler protects against a misbehaving BPF program passing an arena pointer to a kfunc then unmapping the backing pages, causing a kernel fault. However, it does not handle errors where the now unmapped arena address is instead accessed by a non-BPF path, or by a BPF program that has a different arena. The former case is already possible in sched-ext if a BPF program removes from the arena pages allocated from the genpool allocator.
Keep a list of all arenas in the system and attempt to match the kernel fault to all of them. If the fault does fall in an arena, handle it with the already established scratch page technique and retry the access.
Changes from v1 to v2:
- Replace the global arena list with a latch rbtree.
- Restore the stack lookup fast path, checking the fault address before falling back to the tree lookup.
- Defer arena teardown with RCU work instead of synchronize_rcu().
- Add rate-limited deferred logging for faults outside the owning BPF program.
- Reuse bpf_testmod for the selftests instead of adding a module.
- Skip the selftests when the compiler lacks arena address-space casts.
- Correct the Fixes tag to reference the introduction of kernel arena accesses.
Emil Tsalapatis (2):
bpf: recover page faults across all arenas selftests/bpf: add arena fault recovery tests
kernel/bpf/arena.c | 119 +++++++++++++----- .../selftests/bpf/prog_tests/arena_fault.c | 100 +++++++++++++++ .../testing/selftests/bpf/progs/arena_fault.c | 65 ++++++++++ .../selftests/bpf/progs/arena_fault_noarena.c | 17 +++ .../selftests/bpf/test_kmods/bpf_testmod.c | 22 ++++ .../bpf/test_kmods/bpf_testmod_kfunc.h | 3 + 6 files changed, 298 insertions(+), 28 deletions(-) create mode 100644 tools/testing/selftests/bpf/prog_tests/arena_fault.c create mode 100644 tools/testing/selftests/bpf/progs/arena_fault.c create mode 100644 tools/testing/selftests/bpf/progs/arena_fault_noarena.c
Signature · 1 line
2.52.0