public inbox for bpf@vger.kernel.org
 help / color / mirror / Atom feed
From: "Emil Tsalapatis" <emil@etsalapatis.com>
To: "Kumar Kartikeya Dwivedi" <memxor@gmail.com>,
	"Emil Tsalapatis" <emil@etsalapatis.com>
Cc: <bpf@vger.kernel.org>, <ast@kernel.org>, <andrii@kernel.org>,
	<daniel@iogearbox.net>, <eddyz87@gmail.com>, <song@kernel.org>
Subject: Re: [PATCH bpf-next v7 4/9] selftests/bpf: Move READ_ONCE/WRITE_ONCE macros to bpf_experimental.h
Date: Fri, 17 Apr 2026 12:38:57 -0400	[thread overview]
Message-ID: <DHVKTIVB9DWW.BU3DZBYQKM6Z@etsalapatis.com> (raw)
In-Reply-To: <CAP01T77P96yW4Fpfw2PDEvbZ1yGMMyrSEa3+k_NnN7X6tS6EsA@mail.gmail.com>

On Fri Apr 17, 2026 at 12:21 PM EDT, Kumar Kartikeya Dwivedi wrote:
> On Fri, 17 Apr 2026 at 17:06, Emil Tsalapatis <emil@etsalapatis.com> wrote:
>>
>> On Sun Apr 12, 2026 at 3:33 PM EDT, Kumar Kartikeya Dwivedi wrote:
>> > On Sun, 12 Apr 2026 at 19:45, Emil Tsalapatis <emil@etsalapatis.com> wrote:
>> >>
>> >> The WRITE_ONCE macro is identically defined both in bpf_atomic.h
>> >> and in bpf_arena_common.h. Deduplicate the definitions by moving
>> >> the macro to the commonly used bpf_experimental.h header. Also
>> >> move the READ_ONCE macro to the same file for uniformity.
>> >>
>> >
>> > The right header for these is bpf_atomic.h, not bpf_experimental.h. We
>> > want volatile loads to be shipped with bpf_atomic.h and all other
>> > atomic primitives.
>> > https://lore.kernel.org/bpf/CAP01T754eOs2DCjMmkK=CppEwfk5EX84tc70ZqS0_OxTfgxE=w@mail.gmail.com
>>
>> bpf_experimental.h is included in bpf_atomic.h, so there's no possible
>> breakage there. A bunch of arena-related code like bpf_arena_list.h
>> also uses WRITE_ONCE but doesn't include bpf_atomic.h, so we'd have to
>> manually add an extra headers for no reason. Even if we do that,
>> bpf_atomic.h includes vmlinux.h and so any header like bpf_arena_list.h
>> I mentioned that requires WRITE_ONCE won't be importable by userspace.
>>
>> Besides, WRITE_ONCE/READ_ONCE are ultimately compiler shorthands even if
>> they are used most heavily in atomics and don't stick out in
>> bpf_experimental.h.
>>
>
> It's a sad situation indeed. It just feels odd not to provide the
> equivalent of relaxed loads in the header encapsulating all atomic
> access primitives.

I agree it's not the best, my first attempt was to move the definitions to
bpf_atomic.h but that ended up being so much extra adjustments that it
felt silly to do just for this macro.

> bpf_experimental.h is a kitchen sink header for everything we need to
> include that doesn't get its own definition somewhere.

Maybe that is the problem? bpf_experimental.h has outgrown its original
purpose, it it worth splitting into multiple headers to avoid carrying
around all the compat scaffolding just to get access to a couple
definitions? For example, cast_kern/cast_user and the hardcoded address
cast bytecode are useless to most programs (and most arena programs
since they require LLVM >= 19), but they are still included everywhere.

> I think trying to be consistent and deliberating on having topical
> headers for a library you want to export is a good exercise to have
> right now, while we're at it.

>
> It might be cleaner in the end to just place ifndef around all of the
> macro definitions in bpf_atomic.h. That's probably good hygiene too,
> since I presume the naming is universal and programs themselves may
> have their own versions, etc.
>

> Maybe others have better opinions. I would have suggested namespacing
> everything with arena_, but then they work on non-arena just as well,
> so that doesn't make too much sense.
>
>
>>
>> >
>> >> Signed-off-by: Emil Tsalapatis <emil@etsalapatis.com>
>> >> Acked-by: Song Liu <song@kernel.org>
>> >> ---
>> >> [...]
>>


  reply	other threads:[~2026-04-17 16:39 UTC|newest]

Thread overview: 34+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-04-12 17:45 [PATCH bpf-next v7 0/9] Introduce arena library and runtime Emil Tsalapatis
2026-04-12 17:45 ` [PATCH bpf-next v7 1/9] bpf: Allow instructions with arena source and non-arena dest registers Emil Tsalapatis
2026-04-12 19:54   ` Alexei Starovoitov
2026-04-12 17:45 ` [PATCH bpf-next v7 2/9] selftests/bpf: Add tests for non-arena/arena operations Emil Tsalapatis
2026-04-12 17:45 ` [PATCH bpf-next v7 3/9] selftests/bpf: Move bpf_arena_spin_lock.h to the top level Emil Tsalapatis
2026-04-12 19:31   ` Kumar Kartikeya Dwivedi
2026-04-17 16:07     ` Emil Tsalapatis
2026-04-12 17:45 ` [PATCH bpf-next v7 4/9] selftests/bpf: Move READ_ONCE/WRITE_ONCE macros to bpf_experimental.h Emil Tsalapatis
2026-04-12 19:33   ` Kumar Kartikeya Dwivedi
2026-04-17 16:06     ` Emil Tsalapatis
2026-04-17 16:21       ` Kumar Kartikeya Dwivedi
2026-04-17 16:38         ` Emil Tsalapatis [this message]
2026-04-12 17:45 ` [PATCH bpf-next v7 5/9] selftests/bpf: Add basic libarena scaffolding Emil Tsalapatis
2026-04-12 18:28   ` bot+bpf-ci
2026-04-12 18:31     ` Emil Tsalapatis
2026-04-12 17:45 ` [PATCH bpf-next v7 6/9] selftests/bpf: Add arena ASAN runtime to libarena Emil Tsalapatis
2026-04-12 18:28   ` bot+bpf-ci
2026-04-12 18:34     ` Emil Tsalapatis
2026-04-12 17:45 ` [PATCH bpf-next v7 7/9] selftests/bpf: Add ASAN support for libarena selftests Emil Tsalapatis
2026-04-12 17:45 ` [PATCH bpf-next v7 8/9] selftests/bpf: Add buddy allocator for libarena Emil Tsalapatis
2026-04-12 17:45 ` [PATCH bpf-next v7 9/9] selftests/bpf: Add selftests for libarena buddy allocator Emil Tsalapatis
2026-04-12 19:22 ` [PATCH bpf-next v7 0/9] Introduce arena library and runtime Kumar Kartikeya Dwivedi
2026-04-17 14:43   ` Emil Tsalapatis
2026-04-17 16:15     ` Kumar Kartikeya Dwivedi
2026-04-17 16:33       ` Emil Tsalapatis
2026-04-17 17:06         ` Alexei Starovoitov
2026-04-17 18:03           ` Emil Tsalapatis
2026-04-17 18:21             ` Alexei Starovoitov
2026-04-12 20:00 ` patchwork-bot+netdevbpf
2026-04-16 20:23 ` Matt Bobrowski
2026-04-16 20:31   ` Matt Bobrowski
2026-04-16 20:43     ` Song Liu
2026-04-17  5:59       ` Matt Bobrowski
2026-04-17 14:36         ` Emil Tsalapatis

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=DHVKTIVB9DWW.BU3DZBYQKM6Z@etsalapatis.com \
    --to=emil@etsalapatis.com \
    --cc=andrii@kernel.org \
    --cc=ast@kernel.org \
    --cc=bpf@vger.kernel.org \
    --cc=daniel@iogearbox.net \
    --cc=eddyz87@gmail.com \
    --cc=memxor@gmail.com \
    --cc=song@kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox