mbox series

[bpf-next,0/6] BPF Refcount followups 2: owner field

Message ID 20230711175945.3298231-1-davemarchevsky@fb.com (mailing list archive)
Headers show
Series BPF Refcount followups 2: owner field | expand

Message

Dave Marchevsky July 11, 2023, 5:59 p.m. UTC
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/

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                          | 48 +++++++---
 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, 212 insertions(+), 57 deletions(-)