Skip to content

BPF Refcount followups 2: owner field

Dave Marchevsky bpf oe-kbuild-all 2 versions – New

Get series with b4
b4 am [email protected]

Versions newest first · linked by author and title

  1. v2 Latest6 patches 0 repliesNew 4 of 6 applied
  2. v16 patches 1 replySuperseded

Patches in v2 4 of 6 applied

#Subject and filesSizeRepliesApplied
1/6Revert "bpf: Disable bpf_refcount_acquire kfunc calls until race conditions are fixed"kernel/bpf/verifier.c tools/testing/selftests/bpf/prog_tests/refcounted_kptr.c+3 -40 replies
2/6bpf: Introduce internal definitions for UAPI-opaque bpf_{rb,list}_nodeinclude/linux/bpf.h kernel/bpf/helpers.c+23 -100 repliesApplied
3/6bpf: Add 'owner' field to bpf_{list,rb}_nodeinclude/linux/bpf.h include/uapi/linux/bpf.h kernel/bpf/helpers.c +1 more+68 -430 repliesApplied
4/6selftests/bpf: Add rbtree test exercising race which 'owner' field preventstools/testing/selftests/bpf/prog_tests/refcounted_kptr.c tools/testing/selftests/bpf/progs/refcounted_kptr.c+121 -10 repliesApplied
5/6selftests/bpf: Disable newly-added 'owner' field test until refcount re-enabledtools/testing/selftests/bpf/prog_tests/refcounted_kptr.c+0 -240 repliesApplied
6/6Revert "selftests/bpf: Disable newly-added 'owner' field test until refcount re-enabled"tools/testing/selftests/bpf/prog_tests/refcounted_kptr.c+24 -00 replies

Reviews trailers per patch

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

Read the v2 thread

Cover letter [PATCH v2 bpf-next 0/6] BPF Refcount followups 2: owner field

This series adds an 'owner' field to bpf_{list,rb}_node structs, to be used by the runtime to determine whether insertion or removal operations are valid in shared ownership scenarios. Both the races which the series fixes and the fix itself are inspired by Kumar's suggestions in [0].

Aside from insertion and removal having more reasons to fail, there are no user-facing changes as a result of this series.

* Patch 1 reverts disabling of bpf_refcount_acquire so that the fixed logic can be exercised by CI. It should _not_ be applied.
* Patch 2 adds internal definitions of bpf_{rb,list}_node so that their fields are easier to access.
* Patch 3 is the meat of the series - it adds 'owner' field and enforcement of correct owner to insertion and removal helpers.
* Patch 4 adds a test based on Kumar's examples.
* Patch 5 disables the test until bpf_refcount_acquire is re-enabled.
* Patch 6 reverts disabling of test added in this series logic can be exercised by CI. It should _not_ be applied.

[0]: https://lore.kernel.org/bpf/d7hyspcow5wtjcmw4fugdgyp3fwhljwuscp3xyut5qnwivyeru@ysdq543otzv2/

Changelog:

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

Patch 2 ("Introduce internal definitions for UAPI-opaque bpf_{rb,list}_node")
* Rename bpf_{rb,list}_node_internal -> bpf_{list,rb}_node_kern (Alexei)

Patch 3 ("bpf: Add 'owner' field to bpf_{list,rb}_node")
* WARN_ON_ONCE in __bpf_list_del when node has wrong owner. This shouldn't happen, but worth checking regardless (Alexei, offline convo)
* Continue previous patch's renaming changes

Dave Marchevsky (6):
[DONOTAPPLY] Revert "bpf: Disable bpf_refcount_acquire kfunc calls
until race conditions are fixed"
bpf: Introduce internal definitions for UAPI-opaque bpf_{rb,list}_node
bpf: Add 'owner' field to bpf_{list,rb}_node selftests/bpf: Add rbtree test exercising race which 'owner' field
prevents
selftests/bpf: Disable newly-added 'owner' field test until refcount
re-enabled
[DONOTAPPLY] Revert "selftests/bpf: Disable newly-added 'owner' field
test until refcount re-enabled"

 include/linux/bpf.h                           | 12 +++
 include/uapi/linux/bpf.h                      |  2 +
 kernel/bpf/helpers.c                          | 50 +++++++---
 kernel/bpf/verifier.c                         |  5 +-
 .../selftests/bpf/prog_tests/linked_list.c    | 78 +++++++--------
 .../bpf/prog_tests/refcounted_kptr.c          | 30 ++++++
 .../selftests/bpf/progs/refcounted_kptr.c     | 94 ++++++++++++++++++-
 7 files changed, 214 insertions(+), 57 deletions(-)
Signature · 1 line
2.34.1