Skip to content

bpf: Avoid unnecessary deadlock detection and failure in task storage

Martin KaFai Lau bpf 1 version 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

  1. v1 Latest9 patches 0 repliesApplied 9/9

Patches in v1 All 9 applied

#Subject and filesSizeRepliesApplied
1/9bpf: Remove prog->active check for bpf_lsm and bpf_iterarch/arm64/net/bpf_jit_comp.c arch/x86/net/bpf_jit_comp.c include/linux/bpf.h +3 more+98 -540 repliesApplied
2/9bpf: Append _recur naming to the bpf_task_storage helper protoinclude/linux/bpf.h kernel/bpf/bpf_task_storage.c kernel/trace/bpf_trace.c+10 -100 repliesApplied
3/9bpf: Refactor the core bpf_task_storage_get logic into a new functionkernel/bpf/bpf_task_storage.c+26 -180 repliesApplied
4/9bpf: Avoid taking spinlock in bpf_task_storage_get if potential deadlock is detectedkernel/bpf/bpf_local_storage.c kernel/bpf/bpf_task_storage.c+9 -70 repliesApplied
5/9bpf: Add new bpf_task_storage_get proto with no deadlock detectioninclude/linux/bpf.h kernel/bpf/bpf_task_storage.c kernel/trace/bpf_trace.c+33 -10 repliesApplied
6/9bpf: bpf_task_storage_delete_recur does lookup first before the deadlock checkkernel/bpf/bpf_task_storage.c+11 -70 repliesApplied
7/9bpf: Add new bpf_task_storage_delete proto with no deadlock detectioninclude/linux/bpf.h kernel/bpf/bpf_task_storage.c kernel/trace/bpf_trace.c+32 -10 repliesApplied
8/9selftests/bpf: Ensure no task storage failure for bpf_lsm.s prog due to deadlock detectiontools/testing/selftests/bpf/prog_tests/task_local_storage.c tools/testing/selftests/bpf/progs/task_storage_nodeadlock.c+145 -00 repliesApplied
9/9selftests/bpf: Tracing prog can still do lookup under busy locktools/testing/selftests/bpf/prog_tests/task_local_storage.c tools/testing/selftests/bpf/progs/task_ls_recursion.c+86 -50 repliesApplied

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/9] bpf: Avoid unnecessary deadlock detection and failure in task storage

From: Martin KaFai Lau <[email protected]>

The commit bc235cdb423a ("bpf: Prevent deadlock from recursive bpf_task_storage_[get|delete]") added deadlock detection to avoid a tracing program from recurring
on the bpf_task_storage_{get,delete}() helpers. These helpers acquire
a spin lock and it will lead to deadlock.

It is unnecessary for the bpf_lsm and bpf_iter programs which do not recur. The situation is the same as the existing bpf_pid_task_storage_{lookup,delete}_elem() which are used in the syscall and they also do not have deadlock detection.

This set is to add new bpf_task_storage_{get,delete}() helper proto without the deadlock detection. The set also removes the prog->active check from the bpf_lsm and bpf_iter program. Please see the individual patch for details.

Martin KaFai Lau (9):
bpf: Remove prog->active check for bpf_lsm and bpf_iter
bpf: Append _recur naming to the bpf_task_storage helper proto
bpf: Refactor the core bpf_task_storage_get logic into a new function
bpf: Avoid taking spinlock in bpf_task_storage_get if potential
deadlock is detected
bpf: Add new bpf_task_storage_get proto with no deadlock detection
bpf: bpf_task_storage_delete_recur does lookup first before the
deadlock check
bpf: Add new bpf_task_storage_delete proto with no deadlock detection selftests/bpf: Ensure no task storage failure for bpf_lsm.s prog due
to deadlock detection
selftests/bpf: Tracing prog can still do lookup under busy lock

 arch/arm64/net/bpf_jit_comp.c                 |   9 +-
 arch/x86/net/bpf_jit_comp.c                   |  19 +--
 include/linux/bpf.h                           |  26 ++--
 include/linux/bpf_verifier.h                  |  15 +-
 kernel/bpf/bpf_local_storage.c                |   1 +
 kernel/bpf/bpf_task_storage.c                 | 119 +++++++++++---
 kernel/bpf/syscall.c                          |   5 +-
 kernel/bpf/trampoline.c                       |  80 ++++++++--
 kernel/trace/bpf_trace.c                      |   5 +
 .../bpf/prog_tests/task_local_storage.c       | 146 +++++++++++++++++-
 .../selftests/bpf/progs/task_ls_recursion.c   |  43 +++++-
 .../bpf/progs/task_storage_nodeadlock.c       |  47 ++++++
 12 files changed, 431 insertions(+), 84 deletions(-)
 create mode 100644 tools/testing/selftests/bpf/progs/task_storage_nodeadlock.c
Signature · 1 line
2.30.2