The Linux Kernel Mailing List
 help / color / mirror / Atom feed
* [PATCH] selftests/bpf: Remove duplicate copies of the arena spinlock qnodes
@ 2026-08-03  0:18 Changwoo Min
  2026-08-13  4:38 ` Kumar Kartikeya Dwivedi
  2026-08-17  9:05 ` Daniel Borkmann
  0 siblings, 2 replies; 6+ messages in thread
From: Changwoo Min @ 2026-08-03  0:18 UTC (permalink / raw)
  To: Alexei Starovoitov, Daniel Borkmann, Andrii Nakryiko,
	Eduard Zingerman, Kumar Kartikeya Dwivedi, Shuah Khan,
	Emil Tsalapatis
  Cc: Martin KaFai Lau, Song Liu, Yonghong Song, Jiri Olsa, bpf,
	sched-ext, linux-kselftest, linux-kernel, changwoo, kernel-dev

bpf_arena_spin_lock.h defines its 64KB qnodes array in the header, so
every translation unit including it emits a copy. __weak makes them all
resolve to one instance, but bpftool gen object merges only the symbols
and concatenates each input's .addr_space.1 bytes, leaving the surplus
copies unreferenced in the linked object.

libarena links ten such units, so nine copies were dead weight (bytes):

  object                             before       after
  -----------------------------------------------------
  .addr_space.1 in libarena.bpf.o    676200       86376
  libarena.skel.h                   2100123      892371
  libarena_asan.skel.h              2641124     1466477

Declare qnodes in the header and let each program define it once:
libarena in src/common.bpf.c, and the arena_spin_lock test beside the
lock it guards.

Tested with test_progs -t arena_spin_lock and -t libarena.

Signed-off-by: Changwoo Min <changwoo@igalia.com>
---
 .../selftests/bpf/libarena/include/bpf_arena_spin_lock.h   | 7 +------
 tools/testing/selftests/bpf/libarena/src/common.bpf.c      | 7 +++++++
 tools/testing/selftests/bpf/progs/arena_spin_lock.c        | 7 +++++++
 3 files changed, 15 insertions(+), 6 deletions(-)

diff --git a/tools/testing/selftests/bpf/libarena/include/bpf_arena_spin_lock.h b/tools/testing/selftests/bpf/libarena/include/bpf_arena_spin_lock.h
index ae6b72d15bb6..71d9db610263 100644
--- a/tools/testing/selftests/bpf/libarena/include/bpf_arena_spin_lock.h
+++ b/tools/testing/selftests/bpf/libarena/include/bpf_arena_spin_lock.h
@@ -103,12 +103,7 @@ struct arena_qnode {
 #define _Q_LOCKED_VAL		(1U << _Q_LOCKED_OFFSET)
 #define _Q_PENDING_VAL		(1U << _Q_PENDING_OFFSET)
 
-/*
- * The qnodes are marked __weak so we can define them in the header
- * while still ensuring all compilation units use the same struct
- * instance.
- */
-struct arena_qnode __weak __arena __hidden qnodes[_Q_MAX_CPUS][_Q_MAX_NODES];
+extern struct arena_qnode __arena __hidden qnodes[_Q_MAX_CPUS][_Q_MAX_NODES];
 
 static inline u32 encode_tail(int cpu, int idx)
 {
diff --git a/tools/testing/selftests/bpf/libarena/src/common.bpf.c b/tools/testing/selftests/bpf/libarena/src/common.bpf.c
index 50be57213dfb..06481f2a2892 100644
--- a/tools/testing/selftests/bpf/libarena/src/common.bpf.c
+++ b/tools/testing/selftests/bpf/libarena/src/common.bpf.c
@@ -8,6 +8,13 @@ const volatile u32 zero = 0;
 
 struct buddy __arena buddy;
 
+/*
+ * Storage for the queue nodes declared by bpf_arena_spin_lock.h. Each program
+ * linking the arena spinlock provides exactly one definition, so that the array
+ * is emitted once rather than once per translation unit.
+ */
+struct arena_qnode __arena __hidden qnodes[_Q_MAX_CPUS][_Q_MAX_NODES];
+
 int arena_fls(__u64 word)
 {
 	if (!word)
diff --git a/tools/testing/selftests/bpf/progs/arena_spin_lock.c b/tools/testing/selftests/bpf/progs/arena_spin_lock.c
index cf7cda79c16c..92e75ec3844c 100644
--- a/tools/testing/selftests/bpf/progs/arena_spin_lock.c
+++ b/tools/testing/selftests/bpf/progs/arena_spin_lock.c
@@ -23,6 +23,13 @@ int cs_count;
 #if defined(ENABLE_ATOMICS_TESTS) && defined(__BPF_FEATURE_ADDR_SPACE_CAST)
 arena_spinlock_t __arena lock;
 int test_skip = 1;
+
+/*
+ * Storage for the queue nodes declared by bpf_arena_spin_lock.h. Each program
+ * linking the arena spinlock provides exactly one definition; libarena's lives
+ * in libarena/src/common.bpf.c.
+ */
+struct arena_qnode __arena __hidden qnodes[_Q_MAX_CPUS][_Q_MAX_NODES];
 #else
 int test_skip = 2;
 #endif
-- 
2.55.0


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

* Re: [PATCH] selftests/bpf: Remove duplicate copies of the arena spinlock qnodes
  2026-08-03  0:18 [PATCH] selftests/bpf: Remove duplicate copies of the arena spinlock qnodes Changwoo Min
@ 2026-08-13  4:38 ` Kumar Kartikeya Dwivedi
  2026-08-17  9:05 ` Daniel Borkmann
  1 sibling, 0 replies; 6+ messages in thread
From: Kumar Kartikeya Dwivedi @ 2026-08-13  4:38 UTC (permalink / raw)
  To: Changwoo Min, Alexei Starovoitov, Daniel Borkmann,
	Andrii Nakryiko, Eduard Zingerman, Shuah Khan, Emil Tsalapatis
  Cc: Martin KaFai Lau, Song Liu, Yonghong Song, Jiri Olsa, bpf,
	sched-ext, linux-kselftest, linux-kernel, kernel-dev

On Mon Aug 3, 2026 at 2:18 AM CEST, Changwoo Min wrote:
> bpf_arena_spin_lock.h defines its 64KB qnodes array in the header, so
> every translation unit including it emits a copy. __weak makes them all
> resolve to one instance, but bpftool gen object merges only the symbols
> and concatenates each input's .addr_space.1 bytes, leaving the surplus
> copies unreferenced in the linked object.
>
> libarena links ten such units, so nine copies were dead weight (bytes):
>
>   object                             before       after
>   -----------------------------------------------------
>   .addr_space.1 in libarena.bpf.o    676200       86376
>   libarena.skel.h                   2100123      892371
>   libarena_asan.skel.h              2641124     1466477
>
> Declare qnodes in the header and let each program define it once:
> libarena in src/common.bpf.c, and the arena_spin_lock test beside the
> lock it guards.
>
> Tested with test_progs -t arena_spin_lock and -t libarena.
>
> Signed-off-by: Changwoo Min <changwoo@igalia.com>
> ---

This seems ok to me. I don't have better ideas. Emil, any thoughts?

>  .../selftests/bpf/libarena/include/bpf_arena_spin_lock.h   | 7 +------
>  tools/testing/selftests/bpf/libarena/src/common.bpf.c      | 7 +++++++
>  tools/testing/selftests/bpf/progs/arena_spin_lock.c        | 7 +++++++
>  3 files changed, 15 insertions(+), 6 deletions(-)
>
> diff --git a/tools/testing/selftests/bpf/libarena/include/bpf_arena_spin_lock.h b/tools/testing/selftests/bpf/libarena/include/bpf_arena_spin_lock.h
> index ae6b72d15bb6..71d9db610263 100644
> --- a/tools/testing/selftests/bpf/libarena/include/bpf_arena_spin_lock.h
> +++ b/tools/testing/selftests/bpf/libarena/include/bpf_arena_spin_lock.h
> @@ -103,12 +103,7 @@ struct arena_qnode {
>  #define _Q_LOCKED_VAL		(1U << _Q_LOCKED_OFFSET)
>  #define _Q_PENDING_VAL		(1U << _Q_PENDING_OFFSET)
>
> -/*
> - * The qnodes are marked __weak so we can define them in the header
> - * while still ensuring all compilation units use the same struct
> - * instance.
> - */
> -struct arena_qnode __weak __arena __hidden qnodes[_Q_MAX_CPUS][_Q_MAX_NODES];
> +extern struct arena_qnode __arena __hidden qnodes[_Q_MAX_CPUS][_Q_MAX_NODES];
>
>  static inline u32 encode_tail(int cpu, int idx)
>  {
> diff --git a/tools/testing/selftests/bpf/libarena/src/common.bpf.c b/tools/testing/selftests/bpf/libarena/src/common.bpf.c
> index 50be57213dfb..06481f2a2892 100644
> --- a/tools/testing/selftests/bpf/libarena/src/common.bpf.c
> +++ b/tools/testing/selftests/bpf/libarena/src/common.bpf.c
> @@ -8,6 +8,13 @@ const volatile u32 zero = 0;
>
>  struct buddy __arena buddy;
>
> +/*
> + * Storage for the queue nodes declared by bpf_arena_spin_lock.h. Each program
> + * linking the arena spinlock provides exactly one definition, so that the array
> + * is emitted once rather than once per translation unit.
> + */
> +struct arena_qnode __arena __hidden qnodes[_Q_MAX_CPUS][_Q_MAX_NODES];
> +
>  int arena_fls(__u64 word)
>  {
>  	if (!word)
> diff --git a/tools/testing/selftests/bpf/progs/arena_spin_lock.c b/tools/testing/selftests/bpf/progs/arena_spin_lock.c
> index cf7cda79c16c..92e75ec3844c 100644
> --- a/tools/testing/selftests/bpf/progs/arena_spin_lock.c
> +++ b/tools/testing/selftests/bpf/progs/arena_spin_lock.c
> @@ -23,6 +23,13 @@ int cs_count;
>  #if defined(ENABLE_ATOMICS_TESTS) && defined(__BPF_FEATURE_ADDR_SPACE_CAST)
>  arena_spinlock_t __arena lock;
>  int test_skip = 1;
> +
> +/*
> + * Storage for the queue nodes declared by bpf_arena_spin_lock.h. Each program
> + * linking the arena spinlock provides exactly one definition; libarena's lives
> + * in libarena/src/common.bpf.c.
> + */
> +struct arena_qnode __arena __hidden qnodes[_Q_MAX_CPUS][_Q_MAX_NODES];
>  #else
>  int test_skip = 2;
>  #endif


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

* Re: [PATCH] selftests/bpf: Remove duplicate copies of the arena spinlock qnodes
  2026-08-03  0:18 [PATCH] selftests/bpf: Remove duplicate copies of the arena spinlock qnodes Changwoo Min
  2026-08-13  4:38 ` Kumar Kartikeya Dwivedi
@ 2026-08-17  9:05 ` Daniel Borkmann
  2026-08-17 16:00   ` Changwoo Min
  1 sibling, 1 reply; 6+ messages in thread
From: Daniel Borkmann @ 2026-08-17  9:05 UTC (permalink / raw)
  To: Changwoo Min, Alexei Starovoitov, Andrii Nakryiko,
	Eduard Zingerman, Kumar Kartikeya Dwivedi, Shuah Khan,
	Emil Tsalapatis
  Cc: Martin KaFai Lau, Song Liu, Yonghong Song, Jiri Olsa, bpf,
	sched-ext, linux-kselftest, linux-kernel, kernel-dev

On 8/3/26 2:18 AM, Changwoo Min wrote:
> bpf_arena_spin_lock.h defines its 64KB qnodes array in the header, so
> every translation unit including it emits a copy. __weak makes them all
> resolve to one instance, but bpftool gen object merges only the symbols
> and concatenates each input's .addr_space.1 bytes, leaving the surplus
> copies unreferenced in the linked object.
> 
> libarena links ten such units, so nine copies were dead weight (bytes):
> 
>    object                             before       after
>    -----------------------------------------------------
>    .addr_space.1 in libarena.bpf.o    676200       86376
>    libarena.skel.h                   2100123      892371
>    libarena_asan.skel.h              2641124     1466477
> 
> Declare qnodes in the header and let each program define it once:
> libarena in src/common.bpf.c, and the arena_spin_lock test beside the
> lock it guards.
> 
> Tested with test_progs -t arena_spin_lock and -t libarena.
> 
> Signed-off-by: Changwoo Min <changwoo@igalia.com>
This doesn't apply cleanly, could you respin against latest bpf-next?

Thanks,
Daniel

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

* Re: [PATCH] selftests/bpf: Remove duplicate copies of the arena spinlock qnodes
  2026-08-17  9:05 ` Daniel Borkmann
@ 2026-08-17 16:00   ` Changwoo Min
  2026-08-17 17:14     ` Emil Tsalapatis
  0 siblings, 1 reply; 6+ messages in thread
From: Changwoo Min @ 2026-08-17 16:00 UTC (permalink / raw)
  To: Daniel Borkmann, Alexei Starovoitov, Andrii Nakryiko,
	Eduard Zingerman, Kumar Kartikeya Dwivedi, Shuah Khan,
	Emil Tsalapatis
  Cc: Martin KaFai Lau, Song Liu, Yonghong Song, Jiri Olsa, bpf,
	sched-ext, linux-kselftest, linux-kernel, kernel-dev

Hi Daniel,

On 8/17/26 6:05 PM, Daniel Borkmann wrote:
> On 8/3/26 2:18 AM, Changwoo Min wrote:
>> bpf_arena_spin_lock.h defines its 64KB qnodes array in the header, so
>> every translation unit including it emits a copy. __weak makes them all
>> resolve to one instance, but bpftool gen object merges only the symbols
>> and concatenates each input's .addr_space.1 bytes, leaving the surplus
>> copies unreferenced in the linked object.
>>
>> libarena links ten such units, so nine copies were dead weight (bytes):
>>
>>    object                             before       after
>>    -----------------------------------------------------
>>    .addr_space.1 in libarena.bpf.o    676200       86376
>>    libarena.skel.h                   2100123      892371
>>    libarena_asan.skel.h              2641124     1466477
>>
>> Declare qnodes in the header and let each program define it once:
>> libarena in src/common.bpf.c, and the arena_spin_lock test beside the
>> lock it guards.
>>
>> Tested with test_progs -t arena_spin_lock and -t libarena.
>>
>> Signed-off-by: Changwoo Min <changwoo@igalia.com>
> This doesn't apply cleanly, could you respin against latest bpf-next?

Sure. I will send the v2 rebased on the HEAD of the the bpf-next tree soon.

Regards.
Changwoo Min

> 
> Thanks,
> Daniel
> 


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

* Re: [PATCH] selftests/bpf: Remove duplicate copies of the arena spinlock qnodes
  2026-08-17 16:00   ` Changwoo Min
@ 2026-08-17 17:14     ` Emil Tsalapatis
  2026-08-17 18:05       ` Kumar Kartikeya Dwivedi
  0 siblings, 1 reply; 6+ messages in thread
From: Emil Tsalapatis @ 2026-08-17 17:14 UTC (permalink / raw)
  To: Changwoo Min
  Cc: Daniel Borkmann, Alexei Starovoitov, Andrii Nakryiko,
	Eduard Zingerman, Kumar Kartikeya Dwivedi, Shuah Khan,
	Emil Tsalapatis, Martin KaFai Lau, Song Liu, Yonghong Song,
	Jiri Olsa, bpf, sched-ext, linux-kselftest, linux-kernel,
	kernel-dev

On Mon, Aug 17, 2026 at 9:02 AM Changwoo Min <changwoo@igalia.com> wrote:
>
> >
> Hi Daniel,
>
> On 8/17/26 6:05 PM, Daniel Borkmann wrote:
> > On 8/3/26 2:18 AM, Changwoo Min wrote:
> >> bpf_arena_spin_lock.h defines its 64KB qnodes array in the header, so
> >> every translation unit including it emits a copy. __weak makes them all
> >> resolve to one instance, but bpftool gen object merges only the symbols
> >> and concatenates each input's .addr_space.1 bytes, leaving the surplus
> >> copies unreferenced in the linked object.
> >>
> >> libarena links ten such units, so nine copies were dead weight (bytes):
> >>
> >>    object                             before       after
> >>    -----------------------------------------------------
> >>    .addr_space.1 in libarena.bpf.o    676200       86376
> >>    libarena.skel.h                   2100123      892371
> >>    libarena_asan.skel.h              2641124     1466477
> >>
> >> Declare qnodes in the header and let each program define it once:
> >> libarena in src/common.bpf.c, and the arena_spin_lock test beside the
> >> lock it guards.
> >>
> >> Tested with test_progs -t arena_spin_lock and -t libarena.
> >>
> >> Signed-off-by: Changwoo Min <changwoo@igalia.com>

Hi Changwoo,

Sorry for the late reply, for the next version feel free to add:

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

> > This doesn't apply cleanly, could you respin against latest bpf-next?
>
> Sure. I will send the v2 rebased on the HEAD of the the bpf-next tree soon.
>
> Regards.
> Changwoo Min
>
> >
> > Thanks,
> > Daniel
> >
>
>

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

* Re: [PATCH] selftests/bpf: Remove duplicate copies of the arena spinlock qnodes
  2026-08-17 17:14     ` Emil Tsalapatis
@ 2026-08-17 18:05       ` Kumar Kartikeya Dwivedi
  0 siblings, 0 replies; 6+ messages in thread
From: Kumar Kartikeya Dwivedi @ 2026-08-17 18:05 UTC (permalink / raw)
  To: Emil Tsalapatis, Changwoo Min
  Cc: Daniel Borkmann, Alexei Starovoitov, Andrii Nakryiko,
	Eduard Zingerman, Shuah Khan, Emil Tsalapatis, Martin KaFai Lau,
	Song Liu, Yonghong Song, Jiri Olsa, bpf, sched-ext,
	linux-kselftest, linux-kernel, kernel-dev

On Mon Aug 17, 2026 at 7:14 PM CEST, Emil Tsalapatis wrote:
> On Mon, Aug 17, 2026 at 9:02 AM Changwoo Min <changwoo@igalia.com> wrote:
>>
>> >
>> Hi Daniel,
>>
>> On 8/17/26 6:05 PM, Daniel Borkmann wrote:
>> > On 8/3/26 2:18 AM, Changwoo Min wrote:
>> >> bpf_arena_spin_lock.h defines its 64KB qnodes array in the header, so
>> >> every translation unit including it emits a copy. __weak makes them all
>> >> resolve to one instance, but bpftool gen object merges only the symbols
>> >> and concatenates each input's .addr_space.1 bytes, leaving the surplus
>> >> copies unreferenced in the linked object.
>> >>
>> >> libarena links ten such units, so nine copies were dead weight (bytes):
>> >>
>> >>    object                             before       after
>> >>    -----------------------------------------------------
>> >>    .addr_space.1 in libarena.bpf.o    676200       86376
>> >>    libarena.skel.h                   2100123      892371
>> >>    libarena_asan.skel.h              2641124     1466477
>> >>
>> >> Declare qnodes in the header and let each program define it once:
>> >> libarena in src/common.bpf.c, and the arena_spin_lock test beside the
>> >> lock it guards.
>> >>
>> >> Tested with test_progs -t arena_spin_lock and -t libarena.
>> >>
>> >> Signed-off-by: Changwoo Min <changwoo@igalia.com>
>
> Hi Changwoo,
>
> Sorry for the late reply, for the next version feel free to add:
>
> Reviewed-by: Emil Tsalapatis <emil@etsalapatis.com>
>

Added the tag to v2 and applied, thanks.

>> > This doesn't apply cleanly, could you respin against latest bpf-next?
>>
>> Sure. I will send the v2 rebased on the HEAD of the the bpf-next tree soon.
>>
>> Regards.
>> Changwoo Min
>>
>> >
>> > Thanks,
>> > Daniel
>> >
>>
>>


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

end of thread, other threads:[~2026-08-17 18:05 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-08-03  0:18 [PATCH] selftests/bpf: Remove duplicate copies of the arena spinlock qnodes Changwoo Min
2026-08-13  4:38 ` Kumar Kartikeya Dwivedi
2026-08-17  9:05 ` Daniel Borkmann
2026-08-17 16:00   ` Changwoo Min
2026-08-17 17:14     ` Emil Tsalapatis
2026-08-17 18:05       ` Kumar Kartikeya Dwivedi

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