All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH bpf-next v4 0/8] bpf: Introduce deferred task context execution
@ 2025-09-15 20:18 Mykyta Yatsenko
  2025-09-15 20:18 ` [PATCH bpf-next v4 1/8] bpf: refactor special field-type detection Mykyta Yatsenko
                   ` (8 more replies)
  0 siblings, 9 replies; 17+ messages in thread
From: Mykyta Yatsenko @ 2025-09-15 20:18 UTC (permalink / raw)
  To: bpf, ast, andrii, daniel, kafai, kernel-team, eddyz87, memxor
  Cc: Mykyta Yatsenko

From: Mykyta Yatsenko <yatsenko@meta.com>

This patch introduces a new mechanism for BPF programs to schedule
deferred execution in the context of a specific task using the kernel’s
task_work infrastructure.

The new bpf_task_work interface enables BPF use cases that
require sleepable subprogram execution within task context, for example,
scheduling sleepable function from the context that does not
allow sleepable, such as NMI.

Introduced kfuncs bpf_task_work_schedule_signal() and
bpf_task_work_schedule_resume() for scheduling BPF callbacks correspond
to different modes used by task_work (TWA_SIGNAL or TWA_RESUME).

The implementation manages scheduling state via metadata objects (struct
bpf_task_work_context). Pointers to bpf_task_work_context are stored
in BPF map values. State transitions are handled via an atomic
state machine (bpf_task_work_state) to ensure correctness under
concurrent usage and deletion, lifetime is guarded by refcounting and
RCU Tasks Trace.
Kfuncs call task_work_add() indirectly via irq_work to avoid locking in
potentially NMI context.

Changelog:
---
v3 -> v4
v3: https://lore.kernel.org/all/20250905164508.1489482-1-mykyta.yatsenko5@gmail.com/
 * Modify async callback return value processing in verifier, to allow
non-zero return values.
 * Change return type of the callback from void to int, as verifier
expects scalar value.
 * Switched to void* for bpf_map API kfunc arguments to avoid casts.
 * Addressing numerous nits and small improvements.

v2 -> v3
v2: https://lore.kernel.org/all/20250815192156.272445-1-mykyta.yatsenko5@gmail.com/
 * Introduce ref counting
 * Add patches with minor verifier and btf.c refactorings to avoid code
duplication
 * Rework initiation of the task work scheduling to handle race with map
usercnt dropping to zero

Mykyta Yatsenko (8):
  bpf: refactor special field-type detection
  bpf: extract generic helper from process_timer_func()
  bpf: htab: extract helper for freeing special structs
  bpf: verifier: permit non-zero returns from async callbacks
  bpf: bpf task work plumbing
  bpf: extract map key pointer calculation
  bpf: task work scheduling kfuncs
  selftests/bpf: BPF task work scheduling tests

 include/linux/bpf.h                           |  11 +
 include/uapi/linux/bpf.h                      |   4 +
 kernel/bpf/arraymap.c                         |   8 +-
 kernel/bpf/btf.c                              |  63 ++-
 kernel/bpf/hashtab.c                          |  43 +-
 kernel/bpf/helpers.c                          | 378 +++++++++++++++++-
 kernel/bpf/syscall.c                          |  16 +-
 kernel/bpf/verifier.c                         | 160 +++++++-
 tools/include/uapi/linux/bpf.h                |   4 +
 .../selftests/bpf/prog_tests/test_task_work.c | 149 +++++++
 tools/testing/selftests/bpf/progs/task_work.c | 107 +++++
 .../selftests/bpf/progs/task_work_fail.c      |  96 +++++
 12 files changed, 941 insertions(+), 98 deletions(-)
 create mode 100644 tools/testing/selftests/bpf/prog_tests/test_task_work.c
 create mode 100644 tools/testing/selftests/bpf/progs/task_work.c
 create mode 100644 tools/testing/selftests/bpf/progs/task_work_fail.c

-- 
2.51.0


^ permalink raw reply	[flat|nested] 17+ messages in thread

end of thread, other threads:[~2025-09-16 20:09 UTC | newest]

Thread overview: 17+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-09-15 20:18 [PATCH bpf-next v4 0/8] bpf: Introduce deferred task context execution Mykyta Yatsenko
2025-09-15 20:18 ` [PATCH bpf-next v4 1/8] bpf: refactor special field-type detection Mykyta Yatsenko
2025-09-15 20:18 ` [PATCH bpf-next v4 2/8] bpf: extract generic helper from process_timer_func() Mykyta Yatsenko
2025-09-15 21:19   ` Eduard Zingerman
2025-09-16 11:43     ` Mykyta Yatsenko
2025-09-15 20:18 ` [PATCH bpf-next v4 3/8] bpf: htab: extract helper for freeing special structs Mykyta Yatsenko
2025-09-15 20:18 ` [PATCH bpf-next v4 4/8] bpf: verifier: permit non-zero returns from async callbacks Mykyta Yatsenko
2025-09-15 21:24   ` Eduard Zingerman
2025-09-15 20:18 ` [PATCH bpf-next v4 5/8] bpf: bpf task work plumbing Mykyta Yatsenko
2025-09-15 21:40   ` Eduard Zingerman
2025-09-15 20:18 ` [PATCH bpf-next v4 6/8] bpf: extract map key pointer calculation Mykyta Yatsenko
2025-09-15 20:18 ` [PATCH bpf-next v4 7/8] bpf: task work scheduling kfuncs Mykyta Yatsenko
2025-09-15 21:52   ` Eduard Zingerman
2025-09-16 20:08   ` Kumar Kartikeya Dwivedi
2025-09-15 20:18 ` [PATCH bpf-next v4 8/8] selftests/bpf: BPF task work scheduling tests Mykyta Yatsenko
2025-09-15 22:08   ` Eduard Zingerman
2025-09-16  7:36 ` [syzbot ci] Re: bpf: Introduce deferred task context execution syzbot ci

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.