From: Eduard Zingerman <eddyz87@gmail.com>
To: Emil Tsalapatis <emil@etsalapatis.com>, bpf@vger.kernel.org
Cc: ast@kernel.org, daniel@iogearbox.net, john.fastabend@gmail.com,
memxor@gmail.com, andrii@kernel.org, yonghong.song@linux.dev
Subject: Re: [PATCH v2 3/4] libbpf: offset global arena data into the arena if possible
Date: Fri, 21 Nov 2025 19:17:45 -0800 [thread overview]
Message-ID: <ef19d394a7b4993a4f42fc063a9e33bf174f7035.camel@gmail.com> (raw)
In-Reply-To: <20251118030058.162967-4-emil@etsalapatis.com>
On Mon, 2025-11-17 at 22:00 -0500, Emil Tsalapatis wrote:
> Currently, libbpf places global arena data at the very beginning of
> the arena mapping. Stray NULL dereferences into the arena then find
> valid data and lead to silent corruption instead of causing an arena
> page fault. The data is placed in the mapping at load time, preventing
> us from reserving the region using bpf_arena_reserve_pages().
>
> Adjust the arena logic to attempt placing the data from an offset within
> the arena (currently 16 pages in) instead of the very beginning. If
> placing the data at an offset would lead to an allocation failure due
> to global data being as large as the entire arena, progressively reduce
> the offset down to 0 until placement succeeds.
>
> Adjust existing arena tests in the same commit to account for the new
> global data offset. New tests that explicitly consider the new feature
> are introduced in the next patch.
>
> Signed-off-by: Emil Tsalapatis <emil@etsalapatis.com>
> ---
[...]
> @@ -3006,6 +3011,17 @@ static int init_arena_map_data(struct bpf_object *obj, struct bpf_map *map,
> memcpy(obj->arena_data, data, data_sz);
> obj->arena_data_sz = data_sz;
>
> + /*
> + * find the largest offset for global arena variables
> + * where they still fit in the arena
> + */
> + for (off_pages = max_off_pages; off_pages > 0; off_pages >>= 1) {
> + if (off_pages * page_sz + data_alloc_sz <= mmap_sz)
> + break;
> + }
> +
> + obj->arena_data_off = off_pages * page_sz;
> +
> /* make bpf_map__init_value() work for ARENA maps */
> map->mmaped = obj->arena_data;
>
Please correct me if I'm wrong about the goals of this change:
a. Avoid allocating global data at NULL address
b. Reserve some space to use by upcoming arena-KASAN functionality.
For (b) wouldn't it be simpler to implicitly increase the arena map
size by an amount needed for KASAN functionality? Then there would be
no need to guess the necessary data offset.
For (a), is there a way to move an address of first valid mmaped page
(from BPF perspective) w/o physically allocating the first page?
[...]
next prev parent reply other threads:[~2025-11-22 3:17 UTC|newest]
Thread overview: 14+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-11-18 3:00 [PATCH v2 0/4] libbpf: move arena variables out of the zero page Emil Tsalapatis
2025-11-18 3:00 ` [PATCH v2 1/4] selftests/bpf: explicitly account for globals in verifier_arena_large Emil Tsalapatis
2025-11-22 1:44 ` Eduard Zingerman
2025-11-18 3:00 ` [PATCH v2 2/4] libbpf: add stub for offset-related skeleton padding Emil Tsalapatis
2025-11-18 3:00 ` [PATCH v2 3/4] libbpf: offset global arena data into the arena if possible Emil Tsalapatis
2025-11-22 3:17 ` Eduard Zingerman [this message]
2025-12-01 18:34 ` Emil Tsalapatis
2025-12-01 22:35 ` Eduard Zingerman
2025-12-03 16:07 ` Emil Tsalapatis
2025-11-25 22:11 ` Andrii Nakryiko
2025-12-01 20:41 ` Emil Tsalapatis
2025-12-01 22:45 ` Andrii Nakryiko
2025-12-03 16:13 ` Emil Tsalapatis
2025-11-18 3:00 ` [PATCH v2 4/4] selftests/bpf: add tests for the arena offset of globals 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=ef19d394a7b4993a4f42fc063a9e33bf174f7035.camel@gmail.com \
--to=eddyz87@gmail.com \
--cc=andrii@kernel.org \
--cc=ast@kernel.org \
--cc=bpf@vger.kernel.org \
--cc=daniel@iogearbox.net \
--cc=emil@etsalapatis.com \
--cc=john.fastabend@gmail.com \
--cc=memxor@gmail.com \
--cc=yonghong.song@linux.dev \
/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