BPF List
 help / color / mirror / Atom feed
* [PATCH bpf-next v2 0/4] selftests/bpf: libarena: compatibility fixups
@ 2026-10-27 19:24 Emil Tsalapatis
  2026-10-27 19:24 ` [PATCH bpf-next v2 1/4] libarena: remove in-code licenses Emil Tsalapatis
                   ` (4 more replies)
  0 siblings, 5 replies; 6+ messages in thread
From: Emil Tsalapatis @ 2026-10-27 19:24 UTC (permalink / raw)
  To: bpf; +Cc: ast, andrii, eddyz87, memxor, daniel, Emil Tsalapatis

This patchset fixes several issues found while integrating with large
BPF codebases.

Patch 1 fixes a mismatch between the in-code licenses for some files
that do not actually correspond to the licenses at the top of the file.
Remove the in-code license sections, since libarena is distributed only
as source code anyway.

Patches 2-3 add an explicit allocator growth call. Some allocator
users prefer to explicitly expand the arena instead of implicitly
letting the allocator do so when required to satisfy an alloc. The
change is non-functional for existing users.

Patch 4 changes the type of the volatile zero variable used for loop
convergence to __u32. This is available from <linux/types.h>, while u32
needs to be typedef'ed in for userspace programs.

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

v1 -> v2 (https://lore.kernel.org/bpf/20261027162916.10996-1-emil@etsalapatis.com/)
- Add a "Dual BSD/GPL" license section to the benchmark consumer so
  libarena-malloc and libarena-calloc remain loadable (Sashiko bot).
- Rename buddy_grow()'s size argument to nr_chunks and use a size_t
  loop index to make the chunk-count API explicit (Sashiko bot).



Emil Tsalapatis (4):
  libarena: remove in-code licenses
  selftests/bpf: libarena: make allocator growth on alloc failure
    optional
  selftests/bpf: libarena: add explicit buddy_grow() call
  selftests/bpf: libarena: Make zero variable type __u32 instead of u32

 .../bpf/libarena/benchs/bench_malloc.bpf.c    |  2 +
 .../bpf/libarena/include/libarena/buddy.h     |  2 +
 .../bpf/libarena/include/libarena/common.h    |  2 +-
 .../selftests/bpf/libarena/src/asan.bpf.c     |  2 -
 .../selftests/bpf/libarena/src/buddy.bpf.c    | 48 +++++++++++++++++--
 .../selftests/bpf/libarena/src/common.bpf.c   |  4 +-
 6 files changed, 50 insertions(+), 10 deletions(-)

-- 
2.52.0


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

* [PATCH bpf-next v2 1/4] libarena: remove in-code licenses
  2026-10-27 19:24 [PATCH bpf-next v2 0/4] selftests/bpf: libarena: compatibility fixups Emil Tsalapatis
@ 2026-10-27 19:24 ` Emil Tsalapatis
  2026-10-27 19:24 ` [PATCH bpf-next v2 2/4] selftests/bpf: libarena: make allocator growth on alloc failure optional Emil Tsalapatis
                   ` (3 subsequent siblings)
  4 siblings, 0 replies; 6+ messages in thread
From: Emil Tsalapatis @ 2026-10-27 19:24 UTC (permalink / raw)
  To: bpf; +Cc: ast, andrii, eddyz87, memxor, daniel, Emil Tsalapatis

The libarena code currently specifies a license section in multiple
locations. These sections are a) inaccurate, since the license is
actually Dual BSD/GPL, not pure GPL, and b) superfluous, since the
files already have the license on them and libarena is distributed
as a source. Remove the license strings: The code that includes the
the libarena sources should be the one with the license section.

Signed-off-by: Emil Tsalapatis <emil@etsalapatis.com>
---
 tools/testing/selftests/bpf/libarena/benchs/bench_malloc.bpf.c | 2 ++
 tools/testing/selftests/bpf/libarena/src/asan.bpf.c            | 2 --
 tools/testing/selftests/bpf/libarena/src/buddy.bpf.c           | 2 --
 tools/testing/selftests/bpf/libarena/src/common.bpf.c          | 2 --
 4 files changed, 2 insertions(+), 6 deletions(-)

diff --git a/tools/testing/selftests/bpf/libarena/benchs/bench_malloc.bpf.c b/tools/testing/selftests/bpf/libarena/benchs/bench_malloc.bpf.c
index e06397dc9a40..636178f1fa6a 100644
--- a/tools/testing/selftests/bpf/libarena/benchs/bench_malloc.bpf.c
+++ b/tools/testing/selftests/bpf/libarena/benchs/bench_malloc.bpf.c
@@ -49,3 +49,5 @@ int bench_calloc(void)
 	__sync_add_and_fetch(&bench_hits, i);
 	return 0;
 }
+
+char _license[] SEC("license") = "Dual BSD/GPL";
diff --git a/tools/testing/selftests/bpf/libarena/src/asan.bpf.c b/tools/testing/selftests/bpf/libarena/src/asan.bpf.c
index de656b69d13a..8a0f06110606 100644
--- a/tools/testing/selftests/bpf/libarena/src/asan.bpf.c
+++ b/tools/testing/selftests/bpf/libarena/src/asan.bpf.c
@@ -532,5 +532,3 @@ __weak __noasan int asan_init(struct asan_init_args *args)
 #pragma clang attribute pop
 
 #endif /* BPF_ARENA_ASAN */
-
-__weak char _license[] SEC("license") = "GPL";
diff --git a/tools/testing/selftests/bpf/libarena/src/buddy.bpf.c b/tools/testing/selftests/bpf/libarena/src/buddy.bpf.c
index 2490ab1396de..552ce87875e3 100644
--- a/tools/testing/selftests/bpf/libarena/src/buddy.bpf.c
+++ b/tools/testing/selftests/bpf/libarena/src/buddy.bpf.c
@@ -899,5 +899,3 @@ __weak int buddy_free(struct buddy __arena *buddy, void __arena *addr)
 
 	return ret;
 }
-
-__weak char _license[] SEC("license") = "GPL";
diff --git a/tools/testing/selftests/bpf/libarena/src/common.bpf.c b/tools/testing/selftests/bpf/libarena/src/common.bpf.c
index d1af60b81838..d859bd538c52 100644
--- a/tools/testing/selftests/bpf/libarena/src/common.bpf.c
+++ b/tools/testing/selftests/bpf/libarena/src/common.bpf.c
@@ -85,5 +85,3 @@ __weak void arena_free(void __arena *ptr)
 {
 	buddy_free(&buddy, ptr);
 }
-
-char _license[] SEC("license") = "GPL";
-- 
2.52.0


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

* [PATCH bpf-next v2 2/4] selftests/bpf: libarena: make allocator growth on alloc failure optional
  2026-10-27 19:24 [PATCH bpf-next v2 0/4] selftests/bpf: libarena: compatibility fixups Emil Tsalapatis
  2026-10-27 19:24 ` [PATCH bpf-next v2 1/4] libarena: remove in-code licenses Emil Tsalapatis
@ 2026-10-27 19:24 ` Emil Tsalapatis
  2026-10-27 19:24 ` [PATCH bpf-next v2 3/4] selftests/bpf: libarena: add explicit buddy_grow() call Emil Tsalapatis
                   ` (2 subsequent siblings)
  4 siblings, 0 replies; 6+ messages in thread
From: Emil Tsalapatis @ 2026-10-27 19:24 UTC (permalink / raw)
  To: bpf; +Cc: ast, andrii, eddyz87, memxor, daniel, Emil Tsalapatis

The buddy allocator currently always grows when an allocation fails due
to a lack of allocated arena pages. This behavior assumes that the user
sizes the arena to be as large as the maximum allocation size, but that
is not always the case.

Add a nogrow allocation option for users that want to explicitly control
the total mapped size of the arena. With this API, an allocation request
that cannot be serviced from currently mapped arena pages fails instead
of triggering bpf_arena_alloc_pages(). The user instead explicitly maps
additional memory into the arena with a separate buddy_grow() call.

Signed-off-by: Emil Tsalapatis <emil@etsalapatis.com>
---
 .../bpf/libarena/include/libarena/buddy.h     |  1 +
 .../selftests/bpf/libarena/src/buddy.bpf.c    | 20 +++++++++++++++++--
 2 files changed, 19 insertions(+), 2 deletions(-)

diff --git a/tools/testing/selftests/bpf/libarena/include/libarena/buddy.h b/tools/testing/selftests/bpf/libarena/include/libarena/buddy.h
index 528c69a1f38e..958450fc5f9d 100644
--- a/tools/testing/selftests/bpf/libarena/include/libarena/buddy.h
+++ b/tools/testing/selftests/bpf/libarena/include/libarena/buddy.h
@@ -77,5 +77,6 @@ int buddy_init(struct buddy __arena *buddy);
 int buddy_destroy(struct buddy __arena *buddy);
 int buddy_free(struct buddy __arena *buddy, void __arena *free);
 void __arena *buddy_alloc(struct buddy __arena *buddy, size_t size);
+void __arena *buddy_alloc_nogrow(struct buddy __arena *buddy, size_t size);
 
 #endif /* __BPF__  */
diff --git a/tools/testing/selftests/bpf/libarena/src/buddy.bpf.c b/tools/testing/selftests/bpf/libarena/src/buddy.bpf.c
index 552ce87875e3..ed359d4af1f4 100644
--- a/tools/testing/selftests/bpf/libarena/src/buddy.bpf.c
+++ b/tools/testing/selftests/bpf/libarena/src/buddy.bpf.c
@@ -747,8 +747,9 @@ static u64 buddy_alloc_from_new_chunk(struct buddy __arena *buddy, struct buddy_
 
 	return (u64)address;
 }
-__weak
-void __arena *buddy_alloc(struct buddy __arena *buddy, size_t size)
+
+static __always_inline
+void __arena *buddy_alloc_maygrow(struct buddy __arena *buddy, size_t size, bool grow)
 {
 	void __arena *address = NULL;
 	struct buddy_chunk __arena *chunk;
@@ -772,6 +773,9 @@ void __arena *buddy_alloc(struct buddy __arena *buddy, size_t size)
 	if (address)
 		goto done;
 
+	if (!grow)
+		return NULL;
+
 	/* Get a new chunk. */
 	chunk = buddy_chunk_get(buddy);
 	if (chunk)
@@ -796,6 +800,18 @@ void __arena *buddy_alloc(struct buddy __arena *buddy, size_t size)
 	return address;
 }
 
+__weak
+void __arena *buddy_alloc(struct buddy __arena *buddy, size_t size)
+{
+	return buddy_alloc_maygrow(buddy, size, true);
+}
+
+__weak
+void __arena *buddy_alloc_nogrow(struct buddy __arena *buddy, size_t size)
+{
+	return buddy_alloc_maygrow(buddy, size, false);
+}
+
 static __always_inline int buddy_free_unlocked(struct buddy __arena *buddy, u64 addr)
 {
 	struct buddy_header __arena *header, *buddy_header;
-- 
2.52.0


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

* [PATCH bpf-next v2 3/4] selftests/bpf: libarena: add explicit buddy_grow() call
  2026-10-27 19:24 [PATCH bpf-next v2 0/4] selftests/bpf: libarena: compatibility fixups Emil Tsalapatis
  2026-10-27 19:24 ` [PATCH bpf-next v2 1/4] libarena: remove in-code licenses Emil Tsalapatis
  2026-10-27 19:24 ` [PATCH bpf-next v2 2/4] selftests/bpf: libarena: make allocator growth on alloc failure optional Emil Tsalapatis
@ 2026-10-27 19:24 ` Emil Tsalapatis
  2026-10-27 19:24 ` [PATCH bpf-next v2 4/4] selftests/bpf: libarena: Make zero variable type __u32 instead of u32 Emil Tsalapatis
  2026-10-28 18:50 ` [PATCH bpf-next v2 0/4] selftests/bpf: libarena: compatibility fixups patchwork-bot+netdevbpf
  4 siblings, 0 replies; 6+ messages in thread
From: Emil Tsalapatis @ 2026-10-27 19:24 UTC (permalink / raw)
  To: bpf; +Cc: ast, andrii, eddyz87, memxor, daniel, Emil Tsalapatis

Add an API call for explicitly growing the arena through
page allocation. Useful for programs that do not do so
implicitly through buddy_alloc().

Signed-off-by: Emil Tsalapatis <emil@etsalapatis.com>
---
 .../bpf/libarena/include/libarena/buddy.h     |  1 +
 .../selftests/bpf/libarena/src/buddy.bpf.c    | 26 +++++++++++++++++++
 2 files changed, 27 insertions(+)

diff --git a/tools/testing/selftests/bpf/libarena/include/libarena/buddy.h b/tools/testing/selftests/bpf/libarena/include/libarena/buddy.h
index 958450fc5f9d..90674ac077df 100644
--- a/tools/testing/selftests/bpf/libarena/include/libarena/buddy.h
+++ b/tools/testing/selftests/bpf/libarena/include/libarena/buddy.h
@@ -78,5 +78,6 @@ int buddy_destroy(struct buddy __arena *buddy);
 int buddy_free(struct buddy __arena *buddy, void __arena *free);
 void __arena *buddy_alloc(struct buddy __arena *buddy, size_t size);
 void __arena *buddy_alloc_nogrow(struct buddy __arena *buddy, size_t size);
+int buddy_grow(struct buddy __arena *buddy, size_t nr_chunks);
 
 #endif /* __BPF__  */
diff --git a/tools/testing/selftests/bpf/libarena/src/buddy.bpf.c b/tools/testing/selftests/bpf/libarena/src/buddy.bpf.c
index ed359d4af1f4..d12c8924a0ad 100644
--- a/tools/testing/selftests/bpf/libarena/src/buddy.bpf.c
+++ b/tools/testing/selftests/bpf/libarena/src/buddy.bpf.c
@@ -812,6 +812,32 @@ void __arena *buddy_alloc_nogrow(struct buddy __arena *buddy, size_t size)
 	return buddy_alloc_maygrow(buddy, size, false);
 }
 
+__weak
+int buddy_grow(struct buddy __arena *buddy, size_t nr_chunks)
+{
+	struct buddy_chunk __arena *chunk;
+	unsigned long flags;
+	size_t chunk_index;
+
+	for (chunk_index = zero; chunk_index < nr_chunks && can_loop; chunk_index++) {
+		chunk = buddy_chunk_get(buddy);
+		if (!chunk)
+			return -ENOMEM;
+
+		if (buddy_lock(buddy, flags)) {
+			bpf_arena_free_pages(&arena, chunk, BUDDY_CHUNK_PAGES);
+			return -ENOMEM;
+		}
+
+		chunk->next = buddy->first_chunk;
+		buddy->first_chunk = chunk;
+
+		buddy_unlock(buddy, flags);
+	}
+
+	return 0;
+}
+
 static __always_inline int buddy_free_unlocked(struct buddy __arena *buddy, u64 addr)
 {
 	struct buddy_header __arena *header, *buddy_header;
-- 
2.52.0


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

* [PATCH bpf-next v2 4/4] selftests/bpf: libarena: Make zero variable type __u32 instead of u32
  2026-10-27 19:24 [PATCH bpf-next v2 0/4] selftests/bpf: libarena: compatibility fixups Emil Tsalapatis
                   ` (2 preceding siblings ...)
  2026-10-27 19:24 ` [PATCH bpf-next v2 3/4] selftests/bpf: libarena: add explicit buddy_grow() call Emil Tsalapatis
@ 2026-10-27 19:24 ` Emil Tsalapatis
  2026-10-28 18:50 ` [PATCH bpf-next v2 0/4] selftests/bpf: libarena: compatibility fixups patchwork-bot+netdevbpf
  4 siblings, 0 replies; 6+ messages in thread
From: Emil Tsalapatis @ 2026-10-27 19:24 UTC (permalink / raw)
  To: bpf; +Cc: ast, andrii, eddyz87, memxor, daniel, Emil Tsalapatis

Change the zero variable used for loop convergence to the user-visible
__u32 type to avoid missing type issues when including the skeleton
in userspace.

Signed-off-by: Emil Tsalapatis <emil@etsalapatis.com>
---
 tools/testing/selftests/bpf/libarena/include/libarena/common.h | 2 +-
 tools/testing/selftests/bpf/libarena/src/common.bpf.c          | 2 +-
 2 files changed, 2 insertions(+), 2 deletions(-)

diff --git a/tools/testing/selftests/bpf/libarena/include/libarena/common.h b/tools/testing/selftests/bpf/libarena/include/libarena/common.h
index a6220355a697..940e82cc2928 100644
--- a/tools/testing/selftests/bpf/libarena/include/libarena/common.h
+++ b/tools/testing/selftests/bpf/libarena/include/libarena/common.h
@@ -43,7 +43,7 @@ struct {
  * imprecise. To force the variable to be imprecise, initialize it with
  * the opaque volatile variable 0 instead of the constant 0.
  */
-volatile u32 zero __weak;
+volatile __u32 zero __weak;
 extern volatile u64 asan_violated;
 
 int arena_fls(__u64 word);
diff --git a/tools/testing/selftests/bpf/libarena/src/common.bpf.c b/tools/testing/selftests/bpf/libarena/src/common.bpf.c
index d859bd538c52..c3c5326d8ca2 100644
--- a/tools/testing/selftests/bpf/libarena/src/common.bpf.c
+++ b/tools/testing/selftests/bpf/libarena/src/common.bpf.c
@@ -7,7 +7,7 @@
 #include <libarena/buddy.h>
 
 struct buddy __arena buddy;
-volatile u32 zero = 0;
+volatile __u32 zero = 0;
 
 /*
  * Storage for the queue nodes declared by bpf_arena_spin_lock.h. Each program
-- 
2.52.0


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

* Re: [PATCH bpf-next v2 0/4] selftests/bpf: libarena: compatibility fixups
  2026-10-27 19:24 [PATCH bpf-next v2 0/4] selftests/bpf: libarena: compatibility fixups Emil Tsalapatis
                   ` (3 preceding siblings ...)
  2026-10-27 19:24 ` [PATCH bpf-next v2 4/4] selftests/bpf: libarena: Make zero variable type __u32 instead of u32 Emil Tsalapatis
@ 2026-10-28 18:50 ` patchwork-bot+netdevbpf
  4 siblings, 0 replies; 6+ messages in thread
From: patchwork-bot+netdevbpf @ 2026-10-28 18:50 UTC (permalink / raw)
  To: Emil Tsalapatis; +Cc: bpf, ast, andrii, eddyz87, memxor, daniel

Hello:

This series was applied to bpf/bpf-next.git (master)
by Andrii Nakryiko <andrii@kernel.org>:

On Tue, 27 Oct 2026 19:24:09 +0000 you wrote:
> This patchset fixes several issues found while integrating with large
> BPF codebases.
> 
> Patch 1 fixes a mismatch between the in-code licenses for some files
> that do not actually correspond to the licenses at the top of the file.
> Remove the in-code license sections, since libarena is distributed only
> as source code anyway.
> 
> [...]

Here is the summary with links:
  - [bpf-next,v2,1/4] libarena: remove in-code licenses
    https://git.kernel.org/bpf/bpf-next/c/6e7f37fc8623
  - [bpf-next,v2,2/4] selftests/bpf: libarena: make allocator growth on alloc failure optional
    https://git.kernel.org/bpf/bpf-next/c/8e192d828784
  - [bpf-next,v2,3/4] selftests/bpf: libarena: add explicit buddy_grow() call
    https://git.kernel.org/bpf/bpf-next/c/1d9c7ff6e163
  - [bpf-next,v2,4/4] selftests/bpf: libarena: Make zero variable type __u32 instead of u32
    https://git.kernel.org/bpf/bpf-next/c/c2bc2eebaa83

You are awesome, thank you!
-- 
Deet-doot-dot, I am a bot.
https://korg.docs.kernel.org/patchwork/pwbot.html



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

end of thread, other threads:[~2026-10-28 18:50 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-10-27 19:24 [PATCH bpf-next v2 0/4] selftests/bpf: libarena: compatibility fixups Emil Tsalapatis
2026-10-27 19:24 ` [PATCH bpf-next v2 1/4] libarena: remove in-code licenses Emil Tsalapatis
2026-10-27 19:24 ` [PATCH bpf-next v2 2/4] selftests/bpf: libarena: make allocator growth on alloc failure optional Emil Tsalapatis
2026-10-27 19:24 ` [PATCH bpf-next v2 3/4] selftests/bpf: libarena: add explicit buddy_grow() call Emil Tsalapatis
2026-10-27 19:24 ` [PATCH bpf-next v2 4/4] selftests/bpf: libarena: Make zero variable type __u32 instead of u32 Emil Tsalapatis
2026-10-28 18:50 ` [PATCH bpf-next v2 0/4] selftests/bpf: libarena: compatibility fixups patchwork-bot+netdevbpf

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