public inbox for bpf@vger.kernel.org
 help / color / mirror / Atom feed
* [PATCH v2 00/13] bpf: Add arena ASAN runtime and BPF library
@ 2026-01-27 18:15 Emil Tsalapatis
  2026-01-27 18:15 ` [PATCH v2 01/13] bpf: Add bpf_stream_print_stack stack dumping kfunc Emil Tsalapatis
                   ` (12 more replies)
  0 siblings, 13 replies; 32+ messages in thread
From: Emil Tsalapatis @ 2026-01-27 18:15 UTC (permalink / raw)
  To: bpf
  Cc: andrii, ast, daniel, eddyz87, emil, etsal, ihor.solodrai,
	martin.lau, memxor, puranjay, song, yonghong.song

Add a new subdirectory to tools/testing/selftests/bpf called libarena,
along with programs useful for writing arena-based BPF code. This
patchset adds the following:

1) libarena, a subdirectory where arena BPF code that is generally useful 
to BPF arena programs can be easily added and tested.

2) An ASAN runtime for BPF arena programs. BPF arenas allow for accessing 
memory after it has been freed or if it out of bounds, making it more 
difficult to triage bugs combined to regular BPF. Use LLVM's recently added 
support for address-space based sanitization to selectively sanitize just 
the arena accesses.

3) A set of memory allocators that can be reused by BPF programs to handle 
memory allocation/deletion. The allocators use the ASAN runtime to add 
address sanitization if requested.

The patch includes testing for the new allocators and ASAN features that
can be built from the top directory using "make libarena_test" and
"make libarena_test_asan". The generated binaries reside in libarena/.

The structure of this patch is:

1-2: Add BPF Streams kfunc for dumping the current program stack, and
allow BPF Streams kfuncs to be callable while holding a lock.

3-4: Minor changes to the /testing/selftests/bpf directory headers to
prepare for the introduction of libarena.

5-7: Add the base libarena directory and testing scaffolding, and
introduce the ASAN runtime.

8-9: Add a arena memory bump allocator along with testing. This
allocator is used for permanent allocations during program init.

10-11: Add a stack page-oriented allocator along with testing. This 
allocator is used for repeated large allocations to avoid constant
bpf_arena_{alloc,free}_pages calls.

12-13: Add a buddy allocator along with testing. The allocator acts as a
general allocator for arena-based BPF programs.

Signed-off-by: Emil Tsalapatis (Meta) <emil@etsalapatis.com>

v1->v2 (https://lore.kernel.org/bpf/20260122160131.2238331-1-etsal@meta.com/)

- Added missing format string argument (AI)
- Fix outdated selftests prog name check (AI)
- Fixed stack allocation check for segment creation (AI)
- Fix errors in non-ASAN bump allocator selftests (AI)
- Propagate error value from individual selftests in selftest.c
- Removed embedded metadata from bump allocator as it was needlessly
  complicating its behavior

Emil Tsalapatis (13):
  bpf: Add bpf_stream_print_stack stack dumping kfunc
  bpf: Allow BPF stream kfuncs while holding a lock
  selftests: bpf: Move bpf_arena_spin_lock.h to the top level
  selftests: bpf: Make WRITE_ONCE macro in bpf_atomic.h conditional
  selftests: bpf: Add basic libarena scaffolding
  selftests: bpf: Add arena ASAN runtime to libarena
  selftests: bpf: Add ASAN support for libarena selftests
  selftest: bpf: Add bump allocator for libarena
  selftests: bpf: Add libarena selftests for the bump allocator
  selftest: bpf: Add libarena stack allocator
  selftests: bpf: Add selftests for the libarena stack allocator
  selftests: bpf: Add buddy allocator for libarena
  selftests: bpf: Add selftests for the libarena buddy allocator

 kernel/bpf/helpers.c                          |   1 +
 kernel/bpf/stream.c                           |  13 +
 kernel/bpf/verifier.c                         |  13 +-
 tools/lib/bpf/bpf_helpers.h                   |   2 +
 tools/testing/selftests/bpf/.gitignore        |   2 +
 tools/testing/selftests/bpf/Makefile          |  24 +
 .../bpf/{progs => }/bpf_arena_spin_lock.h     |   4 +-
 tools/testing/selftests/bpf/bpf_atomic.h      |   2 +
 tools/testing/selftests/bpf/libarena/Makefile |  69 ++
 .../selftests/bpf/libarena/include/asan.h     | 133 +++
 .../selftests/bpf/libarena/include/buddy.h    |  62 ++
 .../selftests/bpf/libarena/include/bump.h     |  26 +
 .../selftests/bpf/libarena/include/common.h   | 118 +++
 .../selftests/bpf/libarena/include/stack.h    |  44 +
 .../selftests/bpf/libarena/include/userapi.h  |  23 +
 .../bpf/libarena/selftests/selftest.c         | 328 ++++++++
 .../bpf/libarena/selftests/selftest.h         |  17 +
 .../libarena/selftests/st_asan_buddy.bpf.c    | 238 ++++++
 .../bpf/libarena/selftests/st_asan_bump.bpf.c | 193 +++++
 .../bpf/libarena/selftests/st_asan_common.h   |  49 ++
 .../libarena/selftests/st_asan_stack.bpf.c    | 253 ++++++
 .../bpf/libarena/selftests/st_buddy.bpf.c     | 231 ++++++
 .../bpf/libarena/selftests/st_bump.bpf.c      | 281 +++++++
 .../selftests/bpf/libarena/src/asan.bpf.c     | 463 +++++++++++
 .../selftests/bpf/libarena/src/buddy.bpf.c    | 784 ++++++++++++++++++
 .../selftests/bpf/libarena/src/bump.bpf.c     | 196 +++++
 .../selftests/bpf/libarena/src/stack.bpf.c    | 338 ++++++++
 .../selftests/bpf/progs/arena_spin_lock.c     |   2 +-
 28 files changed, 3905 insertions(+), 4 deletions(-)
 rename tools/testing/selftests/bpf/{progs => }/bpf_arena_spin_lock.h (99%)
 create mode 100644 tools/testing/selftests/bpf/libarena/Makefile
 create mode 100644 tools/testing/selftests/bpf/libarena/include/asan.h
 create mode 100644 tools/testing/selftests/bpf/libarena/include/buddy.h
 create mode 100644 tools/testing/selftests/bpf/libarena/include/bump.h
 create mode 100644 tools/testing/selftests/bpf/libarena/include/common.h
 create mode 100644 tools/testing/selftests/bpf/libarena/include/stack.h
 create mode 100644 tools/testing/selftests/bpf/libarena/include/userapi.h
 create mode 100644 tools/testing/selftests/bpf/libarena/selftests/selftest.c
 create mode 100644 tools/testing/selftests/bpf/libarena/selftests/selftest.h
 create mode 100644 tools/testing/selftests/bpf/libarena/selftests/st_asan_buddy.bpf.c
 create mode 100644 tools/testing/selftests/bpf/libarena/selftests/st_asan_bump.bpf.c
 create mode 100644 tools/testing/selftests/bpf/libarena/selftests/st_asan_common.h
 create mode 100644 tools/testing/selftests/bpf/libarena/selftests/st_asan_stack.bpf.c
 create mode 100644 tools/testing/selftests/bpf/libarena/selftests/st_buddy.bpf.c
 create mode 100644 tools/testing/selftests/bpf/libarena/selftests/st_bump.bpf.c
 create mode 100644 tools/testing/selftests/bpf/libarena/src/asan.bpf.c
 create mode 100644 tools/testing/selftests/bpf/libarena/src/buddy.bpf.c
 create mode 100644 tools/testing/selftests/bpf/libarena/src/bump.bpf.c
 create mode 100644 tools/testing/selftests/bpf/libarena/src/stack.bpf.c

-- 
2.49.0


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

end of thread, other threads:[~2026-01-28  2:36 UTC | newest]

Thread overview: 32+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-01-27 18:15 [PATCH v2 00/13] bpf: Add arena ASAN runtime and BPF library Emil Tsalapatis
2026-01-27 18:15 ` [PATCH v2 01/13] bpf: Add bpf_stream_print_stack stack dumping kfunc Emil Tsalapatis
2026-01-27 19:17   ` Mykyta Yatsenko
2026-01-27 23:23     ` Emil Tsalapatis
2026-01-27 23:53   ` Kumar Kartikeya Dwivedi
2026-01-27 18:15 ` [PATCH v2 02/13] bpf: Allow BPF stream kfuncs while holding a lock Emil Tsalapatis
2026-01-28  0:01   ` Kumar Kartikeya Dwivedi
2026-01-27 18:15 ` [PATCH v2 03/13] selftests: bpf: Move bpf_arena_spin_lock.h to the top level Emil Tsalapatis
2026-01-28  0:13   ` Kumar Kartikeya Dwivedi
2026-01-27 18:16 ` [PATCH v2 04/13] selftests: bpf: Make WRITE_ONCE macro in bpf_atomic.h conditional Emil Tsalapatis
2026-01-27 19:26   ` Mykyta Yatsenko
2026-01-27 23:41     ` Emil Tsalapatis
2026-01-27 23:56       ` Kumar Kartikeya Dwivedi
2026-01-27 18:16 ` [PATCH v2 05/13] selftests: bpf: Add basic libarena scaffolding Emil Tsalapatis
2026-01-28  0:32   ` Alexei Starovoitov
2026-01-28  0:42   ` Kumar Kartikeya Dwivedi
2026-01-27 18:16 ` [PATCH v2 06/13] selftests: bpf: Add arena ASAN runtime to libarena Emil Tsalapatis
2026-01-28  2:27   ` Alexei Starovoitov
2026-01-27 18:16 ` [PATCH v2 07/13] selftests: bpf: Add ASAN support for libarena selftests Emil Tsalapatis
2026-01-27 18:38   ` bot+bpf-ci
2026-01-27 18:45     ` Emil Tsalapatis
2026-01-27 18:16 ` [PATCH v2 08/13] selftest: bpf: Add bump allocator for libarena Emil Tsalapatis
2026-01-28  2:36   ` Alexei Starovoitov
2026-01-27 18:16 ` [PATCH v2 09/13] selftests: bpf: Add libarena selftests for the bump allocator Emil Tsalapatis
2026-01-27 18:16 ` [PATCH v2 10/13] selftest: bpf: Add libarena stack allocator Emil Tsalapatis
2026-01-27 18:49   ` bot+bpf-ci
2026-01-27 18:16 ` [PATCH v2 11/13] selftests: bpf: Add selftests for the " Emil Tsalapatis
2026-01-28  2:35   ` Alexei Starovoitov
2026-01-27 18:16 ` [PATCH v2 12/13] selftests: bpf: Add buddy allocator for libarena Emil Tsalapatis
2026-01-27 18:49   ` bot+bpf-ci
2026-01-27 18:16 ` [PATCH v2 13/13] selftests: bpf: Add selftests for the libarena buddy allocator Emil Tsalapatis
2026-01-27 18:38   ` bot+bpf-ci

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox