All of lore.kernel.org
 help / color / mirror / Atom feed
From: Martin KaFai Lau <martin.lau@linux.dev>
To: bpf@vger.kernel.org
Cc: 'Alexei Starovoitov ' <ast@kernel.org>,
	'Andrii Nakryiko ' <andrii@kernel.org>,
	'Daniel Borkmann ' <daniel@iogearbox.net>,
	'Song Liu ' <songliubraving@meta.com>,
	kernel-team@meta.com
Subject: [PATCH bpf-next 0/9] bpf: Avoid unnecessary deadlock detection and failure in task storage
Date: Tue, 25 Oct 2022 11:45:15 -0700	[thread overview]
Message-ID: <20221025184524.3526117-1-martin.lau@linux.dev> (raw)

From: Martin KaFai Lau <martin.lau@kernel.org>

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

-- 
2.30.2


             reply	other threads:[~2022-10-25 18:46 UTC|newest]

Thread overview: 11+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-10-25 18:45 Martin KaFai Lau [this message]
2022-10-25 18:45 ` [PATCH bpf-next 1/9] bpf: Remove prog->active check for bpf_lsm and bpf_iter Martin KaFai Lau
2022-10-25 18:45 ` [PATCH bpf-next 2/9] bpf: Append _recur naming to the bpf_task_storage helper proto Martin KaFai Lau
2022-10-25 18:45 ` [PATCH bpf-next 3/9] bpf: Refactor the core bpf_task_storage_get logic into a new function Martin KaFai Lau
2022-10-25 18:45 ` [PATCH bpf-next 4/9] bpf: Avoid taking spinlock in bpf_task_storage_get if potential deadlock is detected Martin KaFai Lau
2022-10-25 18:45 ` [PATCH bpf-next 5/9] bpf: Add new bpf_task_storage_get proto with no deadlock detection Martin KaFai Lau
2022-10-25 18:45 ` [PATCH bpf-next 6/9] bpf: bpf_task_storage_delete_recur does lookup first before the deadlock check Martin KaFai Lau
2022-10-25 18:45 ` [PATCH bpf-next 7/9] bpf: Add new bpf_task_storage_delete proto with no deadlock detection Martin KaFai Lau
2022-10-25 18:45 ` [PATCH bpf-next 8/9] selftests/bpf: Ensure no task storage failure for bpf_lsm.s prog due to " Martin KaFai Lau
2022-10-25 18:45 ` [PATCH bpf-next 9/9] selftests/bpf: Tracing prog can still do lookup under busy lock Martin KaFai Lau
2022-10-26  6:20 ` [PATCH bpf-next 0/9] bpf: Avoid unnecessary deadlock detection and failure in task storage patchwork-bot+netdevbpf

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20221025184524.3526117-1-martin.lau@linux.dev \
    --to=martin.lau@linux.dev \
    --cc=andrii@kernel.org \
    --cc=ast@kernel.org \
    --cc=bpf@vger.kernel.org \
    --cc=daniel@iogearbox.net \
    --cc=kernel-team@meta.com \
    --cc=songliubraving@meta.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.