From: sashiko-bot@kernel.org
To: "Emil Tsalapatis" <emil@etsalapatis.com>, bpf@vger.kernel.org
Subject: Re: [PATCH bpf 2/2] selftests/bpf: add arena fault recovery tests
Date: Wed, 28 Oct 2026 02:13:15 +0000 [thread overview]
Message-ID: <sashiko-outbox-187334@kernel.org> (raw)
In-Reply-To: <20261028015141.10710-3-emil@etsalapatis.com>
Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider:
- [Medium] selftests/bpf: unguarded arena dereference in arena_fault breaks no_alu32/bpf_gcc
--
commit 35e23b7a99b662f29a7ebcdbbc98176bb46d1150
Author: Emil Tsalapatis <emil@etsalapatis.com>
selftests/bpf: add arena fault recovery tests
This commit adds two BPF selftests and a supporting test kernel module to
verify arena page fault recovery when accessing an unbacked arena page from
a program with no arena or a program with a different arena map.
> diff --git a/tools/testing/selftests/bpf/progs/arena_fault.c b/tools/testing/selftests/bpf/progs/arena_fault.c
> new file mode 100644
> index 0000000000000..1967b128fdf69
> --- /dev/null
> +++ b/tools/testing/selftests/bpf/progs/arena_fault.c
> @@ -0,0 +1,55 @@
> +// SPDX-License-Identifier: GPL-2.0
> +
> +#define BPF_NO_KFUNC_PROTOTYPES
> +#include <vmlinux.h>
> +#include <bpf/bpf_helpers.h>
> +#include "bpf_arena_common.h"
> +#include "../test_kmods/bpf_test_arena_fault.h"
> +
> +struct {
> + __uint(type, BPF_MAP_TYPE_ARENA);
> + __uint(map_flags, BPF_F_MMAPABLE);
> + __uint(max_entries, 2);
> +} arena SEC(".maps");
> +
> +u64 __arena arena_pad;
> +volatile u64 observed;
> +
> +SEC("syscall")
> +int stash_and_free(void *ctx)
> +{
> + u64 __arena *val;
> +
> + val = bpf_arena_alloc_pages(&arena, NULL, 1, NUMA_NO_NODE, 0);
> + if (!val)
> + return 1;
> +
> + *val = 42;
> + bpf_test_arena_fault_stash((u64 *)val);
> + bpf_arena_free_pages(&arena, val, 1);
> + return 0;
> +}
> +
> +SEC("syscall")
> +int fault_stashed_wrong_arena(void *ctx)
> +{
> + u64 __arena *val;
> +
> + val = bpf_arena_alloc_pages(&arena, NULL, 1, NUMA_NO_NODE, 0);
> + if (!val)
> + return 1;
> +
> + *val = 1;
[Severity: Medium]
Will stash_and_free() and fault_stashed_wrong_arena() fail BPF verification
under test_progs-no_alu32 and test_progs-bpf_gcc when __BPF_FEATURE_ADDR_SPACE_CAST
is not defined?
In tools/testing/selftests/bpf/libarena/include/bpf_arena_common.h, __arena
only includes __attribute__((address_space(1))) when
__BPF_FEATURE_ADDR_SPACE_CAST is defined:
#if defined(__BPF_FEATURE_ADDR_SPACE_CAST) && !defined(BPF_ARENA_FORCE_ASM)
#define __arena __attribute__((address_space(1))) __attribute__((btf_type_tag("arena")))
...
#else
#define __arena __attribute__((btf_type_tag("arena")))
When tools/testing/selftests/bpf/Makefile builds test_progs-no_alu32 (with
-mcpu=v2) or test_progs-bpf_gcc, __BPF_FEATURE_ADDR_SPACE_CAST is not
defined. Without __attribute__((address_space(1))), the compiler does not
emit a BPF_ADDR_SPACE_CAST instruction before dereferencing val in
*val = 42 and *val = 1.
Because bpf_arena_alloc_pages() returns void * in kernel BTF,
check_kfunc_call() in kernel/bpf/verifier.c leaves R0 typed as SCALAR_VALUE
until BPF_ADDR_SPACE_CAST converts it to PTR_TO_ARENA in check_alu_op().
Without that cast, check_mem_access() rejects the stores to *val as invalid
scalar memory accesses, causing arena_fault__open_and_load() in
test_wrong_arena() and test_no_arena() in
tools/testing/selftests/bpf/prog_tests/arena_fault.c to fail instead of
skipping.
Should the arena pointer dereferences in progs/arena_fault.c be guarded by
#if defined(__BPF_FEATURE_ADDR_SPACE_CAST) (with the runner skipping when
unsupported), similar to other arena selftests?
--
Sashiko AI review · https://sashiko.dev/#/patchset/20261028015141.10710-1-emil@etsalapatis.com?part=2
prev parent reply other threads:[~2026-10-28 2:13 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-10-28 1:51 [PATCH bpf-next 0/2] bpf: expand BPF arena kernel fault handling Emil Tsalapatis
2026-10-28 1:51 ` [PATCH bpf 1/2] bpf: recover page faults across all arenas Emil Tsalapatis
2026-10-28 2:36 ` bot+bpf-ci
2026-10-28 1:51 ` [PATCH bpf 2/2] selftests/bpf: add arena fault recovery tests Emil Tsalapatis
2026-10-28 2:13 ` sashiko-bot [this message]
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=sashiko-outbox-187334@kernel.org \
--to=sashiko-bot@kernel.org \
--cc=bpf@vger.kernel.org \
--cc=emil@etsalapatis.com \
--cc=sashiko-reviews@lists.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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.