Skip to content

bpf: Support bpf_rcu_head in hash and LRU hash maps

Puranjay Mohan bpf 1 version In review

Get series with b4
b4 am [email protected]

Versions newest first

  1. v1 Latest2 patches 1 replyIn review

Patches in v1 No applies recorded yet

#Subject and filesSizeRepliesApplied
1/2bpf: Support bpf_rcu_head in hash and LRU hash mapsinclude/linux/bpf.h kernel/bpf/hashtab.c kernel/bpf/helpers.c +1 more+214 -261 reply
2/2selftests/bpf: Add bpf_call_rcu tests for hash and LRU hash mapstools/testing/selftests/bpf/prog_tests/call_rcu.c tools/testing/selftests/bpf/progs/call_rcu.c+526 -20 replies

Reviews trailers per patch

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

Read the v1 thread

Cover letter [PATCH bpf-next 0/2] bpf: Support bpf_rcu_head in hash and LRU hash maps

bpf_call_rcu() currently only takes a bpf_rcu_head in an array, because an array element is never freed while the map is alive. Hash elements are recycled, and an RCU callback cannot be cancelled, so a delete racing a queued callback would hand the element back to the allocator underneath it.

This keeps the element alive until the callback has run. The map claims the head before releasing an element; if a callback is queued or running, the element is unlinked but not returned to the allocator, and the callback returns it through a new map_release_elem(). Patch 1 also covers the two places a hash recycles an element without freeing it: the per-CPU spare a preallocated htab uses on update, and LRU eviction.

Patch 2 adds tests for the delete, replace, recycle and eviction paths. Each was checked against a kernel with the corresponding hunk reverted.

Puranjay Mohan (2):
bpf: Support bpf_rcu_head in hash and LRU hash maps selftests/bpf: Add bpf_call_rcu tests for hash and LRU hash maps

 include/linux/bpf.h                           |   5 +
 kernel/bpf/hashtab.c                          | 104 ++++++-
 kernel/bpf/helpers.c                          | 117 +++++++-
 kernel/bpf/syscall.c                          |  14 +-
 .../selftests/bpf/prog_tests/call_rcu.c       | 254 +++++++++++++++-
 tools/testing/selftests/bpf/progs/call_rcu.c  | 274 ++++++++++++++++++
 6 files changed, 740 insertions(+), 28 deletions(-)

base-commit: 4f3a5eae895b9995e93425a75235d8f1f3268caa

Signature · 1 line
2.53.0-Meta