Skip to content

Enable RCU semantics for task kptrs

David Vernet bpf lkml 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 Latest3 patches 0 repliesApplied 3/3
  2. v13 patches 3 repliesSuperseded

Changes in v2 from the cover letter

- Remove testcases validating nested trust inheritance. The first version used 'struct task_struct __rcu *parent', but because that field has the __rcu tag it functions differently on gcc and llvm and causes gcc selftests to fail. Alexei is reworking nested trust, anyways so let's leave it off for now (Alexei).

Patches in v2 All 3 applied

#Subject and filesSizeRepliesApplied
1/3bpf: Make struct task_struct an RCU-safe typekernel/bpf/helpers.c kernel/bpf/verifier.c tools/testing/selftests/bpf/prog_tests/task_kfunc.c +3 more+108 -160 repliesApplied
2/3bpf: Remove now-defunct task kfuncskernel/bpf/helpers.c tools/testing/selftests/bpf/prog_tests/task_kfunc.c tools/testing/selftests/bpf/progs/rcu_read_lock.c +3 more+14 -1620 repliesApplied
3/3bpf,docs: Update documentation to reflect new task kfuncsDocumentation/bpf/kfuncs.rst+43 -60 repliesApplied

Reviews trailers per patch

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

Read the v2 thread

Cover letter [PATCH bpf-next v2 0/3] Enable RCU semantics for task kptrs

In commit 22df776a9a86 ("tasks: Extract rcu_users out of union"), the 'refcount_t rcu_users' field was extracted out of a union with the 'struct rcu_head rcu' field. This allows us to use the field for refcounting struct task_struct with RCU protection, as the RCU callback no longer flips rcu_users to be nonzero after the callback is scheduled.

This patch set leverages this to do a few things:

1. Marks struct task_struct as RCU safe in the verifier, allowing referenced kptr tasks stored in maps to be accessed in an RCU read region without acquiring a reference (with just a NULL check).
2. Makes bpf_task_acquire() a KF_ACQUIRE | KF_RCU | KF_RET_NULL kfunc.
3. Removes bpf_task_kptr_get() and bpf_task_acquire_not_zero(), as they're now redundant with the above two changes.
4. Updates selftests and documentation accordingly.

---
Changelog:
v1: https://lore.kernel.org/all/[email protected]/
v1 -> v2:
- Remove testcases validating nested trust inheritance. The first version used 'struct task_struct __rcu *parent', but because that field has the __rcu tag it functions differently on gcc and llvm and causes gcc selftests to fail. Alexei is reworking nested trust, anyways so let's leave it off for now (Alexei).

David Vernet (3):
bpf: Make struct task_struct an RCU-safe type
bpf: Remove now-defunct task kfuncs
bpf,docs: Update documentation to reflect new task kfuncs

 Documentation/bpf/kfuncs.rst                  |  49 ++++++-
 kernel/bpf/helpers.c                          |  78 +---------
 kernel/bpf/verifier.c                         |   1 +
 .../selftests/bpf/prog_tests/task_kfunc.c     |   3 +-
 .../selftests/bpf/progs/rcu_read_lock.c       |   9 +-
 .../selftests/bpf/progs/task_kfunc_common.h   |   6 +-
 .../selftests/bpf/progs/task_kfunc_failure.c  | 135 ++++++++----------
 .../selftests/bpf/progs/task_kfunc_success.c  |  48 +++++--
 8 files changed, 155 insertions(+), 174 deletions(-)
Signature · 1 line
2.39.0