Skip to content

bpf, lpm_trie: Allow sleepable BPF programs to use LPM tries

Vlad Poenaru bpf lkml sashiko-reviews stable 2 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. v2 Latest2 patches 4 repliesApplied 2/2
  2. v11 patch 3 repliesSuperseded

Changes in v2 from the cover letter

- Split into a 2-patch series.
- Patch 1 now also converts the trie_update_elem()/trie_delete_elem() walks from rcu_dereference() to rcu_dereference_protected(*p, 1), addressing review feedback that v1 only fixed the lookup path and left the same splat on the writer paths.
- New patch 2 adds the verifier whitelist entry so the fix is actually reachable for directly-referenced LPM tries.
- Retitled v1 ("Allow lookups from sleepable BPF programs").

Patches in v2 All 2 applied

#Subject and filesSizeRepliesApplied
1/2bpf, lpm_trie: Allow access from sleepable BPF programskernel/bpf/lpm_trie.c+4 -41 replyApplied
2/2bpf, lpm_trie: Allow sleepable programs to use LPM trie maps directlykernel/bpf/verifier.c+1 -03 repliesApplied

Reviews trailers per patch

All 2 patches have a Reviewed-by or Acked-by.

PatchEmil Tsalapatis
1/2R-b
2/2R-b

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

Read the v2 thread

Cover letter [PATCH bpf v2 0/2] bpf, lpm_trie: Allow sleepable BPF programs to use LPM tries

trie_lookup_elem() annotates its rcu_dereference_check() walks with only rcu_read_lock_bh_held(), so a sleepable BPF program that touches an LPM trie (e.g. a sleepable LSM hook calling bpf_map_lookup_elem()) trips a "suspicious RCU usage" lockdep splat on debug kernels: it holds only rcu_read_lock_trace(), which that annotation does not accept.

Patch 1 relaxes the rcu_dereference annotations in the trie walks so they no longer trip lockdep from the Tasks Trace context, including the trie_update_elem()/trie_delete_elem() writer walks (protected by trie->lock). Patch 2 adds BPF_MAP_TYPE_LPM_TRIE to the verifier's sleepable map whitelist so sleepable programs can reference an LPM trie directly, not just as the inner map of a map-of-maps. LPM trie nodes are reclaimed via bpf_mem_cache_free_rcu(), which chains a regular RCU grace period into a Tasks Trace grace period before freeing -- the same discipline BPF_MAP_TYPE_HASH relies on for sleepable access.

Changes since v1:
- Split into a 2-patch series.
- Patch 1 now also converts the trie_update_elem()/trie_delete_elem() walks from rcu_dereference() to rcu_dereference_protected(*p, 1), addressing review feedback that v1 only fixed the lookup path and left the same splat on the writer paths.
- New patch 2 adds the verifier whitelist entry so the fix is actually reachable for directly-referenced LPM tries.
- Retitled v1 ("Allow lookups from sleepable BPF programs").

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

Vlad Poenaru (2):
bpf, lpm_trie: Allow access from sleepable BPF programs bpf, lpm_trie: Allow sleepable programs to use LPM trie maps directly

 kernel/bpf/lpm_trie.c | 8 ++++----
 kernel/bpf/verifier.c | 1 +
 2 files changed, 5 insertions(+), 4 deletions(-)

--
2.53.0-Meta