All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH RFC v3 00/10] bpf: Avoid locks in bpf_timer and bpf_wq
@ 2026-01-07 17:49 Mykyta Yatsenko
  2026-01-07 17:49 ` [PATCH RFC v3 01/10] bpf: Refactor __bpf_async_set_callback() Mykyta Yatsenko
                   ` (9 more replies)
  0 siblings, 10 replies; 40+ messages in thread
From: Mykyta Yatsenko @ 2026-01-07 17:49 UTC (permalink / raw)
  To: bpf, ast, andrii, daniel, kafai, kernel-team, memxor, eddyz87
  Cc: Mykyta Yatsenko

This series reworks implementation of BPF timer and workqueue APIs.
The goal is to make both timers and wq non-blocking, enabling their use
in NMI context.
Today this code relies on a bpf_spin_lock embedded in the map element to
serialize:
 * init of the async object,
 * setting/changing the callback and bpf_prog
 * starting/cancelling the timer/work
 * tearing down when the map element is deleted or the map’s user ref is
 dropped

The basic design approach in this series:
 * Use irq_work to offload all blocking work from NMI
 * Introduce refcount to guarantee lifetime of the bpf_async_cb structs
 deferred to potentially multiple irq_work callbacks
 * Keep objects under RCU protection to make sure they are not freed
 while kfuncs/helpers access them (We can't use refcnt for this, as
 refcnt itself is part of the bpf_async_cb struct)

Signed-off-by: Mykyta Yatsenko <yatsenko@meta.com>
---
Changes in v3:
- Major rework
- Introduce mpmc_cell, allowing concurrent writes and reads
- Implement irq_work deferring
- Adding selftests
- Introduces bpf_timer_cancel_async kfunc
- Link to v2: https://lore.kernel.org/r/20251105-timer_nolock-v2-0-32698db08bfa@meta.com

Changes in v2:
- Move refcnt initialization and put (from cancel_and_free())
from patch 5 into the patch 4, so that patch 4 has more clear and full
implementation and use of refcnt
- Link to v1: https://lore.kernel.org/r/20251031-timer_nolock-v1-0-b064ae403bfb@meta.com

---
Mykyta Yatsenko (10):
      bpf: Refactor __bpf_async_set_callback()
      bpf: Factor out timer deletion helper
      bpf: Simplify bpf_timer_cancel()
      bpf: Add lock-free cell for NMI-safe async operations
      bpf: Enable bpf timer and workqueue use in NMI
      bpf: Add verifier support for bpf_timer argument in kfuncs
      bpf: Introduce bpf_timer_cancel_async() kfunc
      selftests/bpf: Refactor timer selftests
      selftests/bpf: Add stress test for timer async cancel
      selftests/bpf: Verify bpf_timer_cancel_async works

 kernel/bpf/Makefile                            |   2 +-
 kernel/bpf/helpers.c                           | 409 +++++++++++++++----------
 kernel/bpf/mpmc_cell.c                         |  62 ++++
 kernel/bpf/mpmc_cell.h                         | 112 +++++++
 kernel/bpf/verifier.c                          |  59 +++-
 tools/testing/selftests/bpf/prog_tests/timer.c |  92 +++++-
 tools/testing/selftests/bpf/progs/timer.c      |  37 ++-
 7 files changed, 588 insertions(+), 185 deletions(-)
---
base-commit: ea180ffbd27ce5abf2a06329fe1fc8d20dc9becf
change-id: 20251028-timer_nolock-457f5b9daace

Best regards,
-- 
Mykyta Yatsenko <yatsenko@meta.com>


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

end of thread, other threads:[~2026-01-15 18:52 UTC | newest]

Thread overview: 40+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-01-07 17:49 [PATCH RFC v3 00/10] bpf: Avoid locks in bpf_timer and bpf_wq Mykyta Yatsenko
2026-01-07 17:49 ` [PATCH RFC v3 01/10] bpf: Refactor __bpf_async_set_callback() Mykyta Yatsenko
2026-01-07 18:22   ` bot+bpf-ci
2026-01-09 22:18     ` Andrii Nakryiko
2026-01-13 13:58       ` Mykyta Yatsenko
2026-01-13 16:14       ` Mykyta Yatsenko
2026-01-09 22:18   ` Andrii Nakryiko
2026-01-12  6:47   ` Kumar Kartikeya Dwivedi
2026-01-12  8:12     ` Kumar Kartikeya Dwivedi
2026-01-07 17:49 ` [PATCH RFC v3 02/10] bpf: Factor out timer deletion helper Mykyta Yatsenko
2026-01-12  6:51   ` Kumar Kartikeya Dwivedi
2026-01-07 17:49 ` [PATCH RFC v3 03/10] bpf: Simplify bpf_timer_cancel() Mykyta Yatsenko
2026-01-07 18:22   ` bot+bpf-ci
2026-01-09 22:19     ` Andrii Nakryiko
2026-01-12  7:29       ` Kumar Kartikeya Dwivedi
2026-01-07 17:49 ` [PATCH RFC v3 04/10] bpf: Add lock-free cell for NMI-safe async operations Mykyta Yatsenko
2026-01-07 18:08   ` bot+bpf-ci
2026-01-07 18:30   ` Kumar Kartikeya Dwivedi
2026-01-07 19:05     ` Mykyta Yatsenko
2026-01-09  1:18       ` Andrii Nakryiko
2026-01-09 18:22         ` Mykyta Yatsenko
2026-01-09 18:47           ` Andrii Nakryiko
2026-01-09 23:51             ` Alexei Starovoitov
2026-01-10  0:03               ` Andrii Nakryiko
2026-01-09 22:19   ` Andrii Nakryiko
2026-01-07 17:49 ` [PATCH RFC v3 05/10] bpf: Enable bpf timer and workqueue use in NMI Mykyta Yatsenko
2026-01-07 18:22   ` bot+bpf-ci
2026-01-09 22:19   ` Andrii Nakryiko
2026-01-14 14:53     ` Mykyta Yatsenko
2026-01-15 18:39       ` Andrii Nakryiko
2026-01-15 18:52         ` Mykyta Yatsenko
2026-01-12  8:10   ` Kumar Kartikeya Dwivedi
2026-01-07 17:49 ` [PATCH RFC v3 06/10] bpf: Add verifier support for bpf_timer argument in kfuncs Mykyta Yatsenko
2026-01-09 22:19   ` Andrii Nakryiko
2026-01-07 17:49 ` [PATCH RFC v3 07/10] bpf: Introduce bpf_timer_cancel_async() kfunc Mykyta Yatsenko
2026-01-09 22:19   ` Andrii Nakryiko
2026-01-07 17:49 ` [PATCH RFC v3 08/10] selftests/bpf: Refactor timer selftests Mykyta Yatsenko
2026-01-07 17:49 ` [PATCH RFC v3 09/10] selftests/bpf: Add stress test for timer async cancel Mykyta Yatsenko
2026-01-07 17:49 ` [PATCH RFC v3 10/10] selftests/bpf: Verify bpf_timer_cancel_async works Mykyta Yatsenko
2026-01-09 22:19   ` Andrii Nakryiko

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.