From: Kumar Kartikeya Dwivedi <memxor@gmail.com>
To: puranjay@kernel.org
Cc: Yonghong Song <yonghong.song@linux.dev>,
Alexei Starovoitov <ast@kernel.org>,
Daniel Borkmann <daniel@iogearbox.net>,
Andrii Nakryiko <andrii@kernel.org>,
Martin KaFai Lau <martin.lau@linux.dev>,
Eduard Zingerman <eddyz87@gmail.com>, Song Liu <song@kernel.org>,
John Fastabend <john.fastabend@gmail.com>,
KP Singh <kpsingh@kernel.org>,
Stanislav Fomichev <sdf@fomichev.me>,
Hao Luo <haoluo@google.com>, Jiri Olsa <jolsa@kernel.org>,
Xu Kuohai <xukuohai@huaweicloud.com>,
Catalin Marinas <catalin.marinas@arm.com>,
Will Deacon <will@kernel.org>,
bpf@vger.kernel.org
Subject: Re: [PATCH bpf-next 3/3] selftests/bpf: Add tests for arena fault reporting
Date: Thu, 7 Aug 2025 17:25:06 +0200 [thread overview]
Message-ID: <CAP01T75_WiqLmJE7x==wagJTMfg2BoZkv6otexA6FGm-=UFXew@mail.gmail.com> (raw)
In-Reply-To: <mb61ph5yjgt77.fsf@kernel.org>
On Thu, 7 Aug 2025 at 15:25, <puranjay@kernel.org> wrote:
>
> Yonghong Song <yonghong.song@linux.dev> writes:
>
> > On 8/6/25 1:58 AM, Puranjay Mohan wrote:
> >> Add selftests for testing the reporting of arena page faults through BPF
> >> streams. Two new bpf programs are added that read and write to an
> >> unmapped arena address and the fault reporting is verified in the
> >> userspace through streams.
> >>
> >> Signed-off-by: Puranjay Mohan <puranjay@kernel.org>
> >> ---
> >> .../testing/selftests/bpf/prog_tests/stream.c | 24 ++++++++++++
> >> tools/testing/selftests/bpf/progs/stream.c | 37 +++++++++++++++++++
> >> 2 files changed, 61 insertions(+)
> >>
> >> diff --git a/tools/testing/selftests/bpf/prog_tests/stream.c b/tools/testing/selftests/bpf/prog_tests/stream.c
> >> index d9f0185dca61b..4bdde56de35b1 100644
> >> --- a/tools/testing/selftests/bpf/prog_tests/stream.c
> >> +++ b/tools/testing/selftests/bpf/prog_tests/stream.c
> >> @@ -41,6 +41,22 @@ struct {
> >> "([a-zA-Z_][a-zA-Z0-9_]*\\+0x[0-9a-fA-F]+/0x[0-9a-fA-F]+\n"
> >> "|[ \t]+[^\n]+\n)*",
> >> },
> >> + {
> >> + offsetof(struct stream, progs.stream_arena_read_fault),
> >> + "ERROR: Arena READ access at unmapped address 0x.*\n"
> >> + "CPU: [0-9]+ UID: 0 PID: [0-9]+ Comm: .*\n"
> >> + "Call trace:\n"
> >> + "([a-zA-Z_][a-zA-Z0-9_]*\\+0x[0-9a-fA-F]+/0x[0-9a-fA-F]+\n"
> >> + "|[ \t]+[^\n]+\n)*",
> >> + },
> >> + {
> >> + offsetof(struct stream, progs.stream_arena_write_fault),
> >> + "ERROR: Arena WRITE access at unmapped address 0x.*\n"
> >> + "CPU: [0-9]+ UID: 0 PID: [0-9]+ Comm: .*\n"
> >> + "Call trace:\n"
> >> + "([a-zA-Z_][a-zA-Z0-9_]*\\+0x[0-9a-fA-F]+/0x[0-9a-fA-F]+\n"
> >> + "|[ \t]+[^\n]+\n)*",
> >> + },
> >> };
> >>
> >> static int match_regex(const char *pattern, const char *string)
> >> @@ -85,6 +101,14 @@ void test_stream_errors(void)
> >> continue;
> >> }
> >> #endif
> >> +#if !defined(__x86_64__) && !defined(__aarch64__)
> >> + ASSERT_TRUE(1, "Arena fault reporting unsupported, skip.");
> >> + if (i == 2 || i == 3) {
> >> + ret = bpf_prog_stream_read(prog_fd, 2, buf, sizeof(buf), &ropts);
> >> + ASSERT_EQ(ret, 0, "stream read");
> >> + continue;
> >> + }
> >> +#endif
> >>
> >> ret = bpf_prog_stream_read(prog_fd, BPF_STREAM_STDERR, buf, sizeof(buf), &ropts);
> >> ASSERT_GT(ret, 0, "stream read");
> >> diff --git a/tools/testing/selftests/bpf/progs/stream.c b/tools/testing/selftests/bpf/progs/stream.c
> >> index 35790897dc879..58ebff60cd96a 100644
> >> --- a/tools/testing/selftests/bpf/progs/stream.c
> >> +++ b/tools/testing/selftests/bpf/progs/stream.c
> >> @@ -1,10 +1,15 @@
> >> // SPDX-License-Identifier: GPL-2.0
> >> /* Copyright (c) 2025 Meta Platforms, Inc. and affiliates. */
> >> +#define BPF_NO_KFUNC_PROTOTYPES
> >
> > Do we have to defineBPF_NO_KFUNC_PROTOTYPES in the above? Without the above, we do not need
> > below extern bpf_res_spin_lock and bpf_res_spin_unlock.
> >
>
> If we don't define BPF_NO_KFUNC_PROTOTYPES then there are build failures
> for bpf_arena_alloc/free_pages() because the prototypes in vmlinux.h
> lack __arena attribute.
I would address this by dropping the alloc/free.
Instead to work around "addr_space_cast insn in program without arena error",
insert a dummy store "ptr = &arena" in the program, where ptr is a
global void *.
>
> >> +
> >> + page = bpf_arena_alloc_pages(&arena, NULL, 1, NUMA_NO_NODE, 0);
> >> + bpf_arena_free_pages(&arena, page, 1);
> >> +
>
> Thanks,
> Puranjay
next prev parent reply other threads:[~2025-08-07 15:25 UTC|newest]
Thread overview: 13+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-08-06 8:58 [PATCH bpf-next 0/3] bpf: Report arena faults to BPF streams Puranjay Mohan
2025-08-06 8:58 ` [PATCH bpf-next 1/3] bpf: arm64: simplify exception table handling Puranjay Mohan
2025-08-06 22:58 ` Yonghong Song
2025-08-06 8:58 ` [PATCH bpf-next 2/3] bpf: Report arena faults to BPF stderr Puranjay Mohan
2025-08-06 23:57 ` Yonghong Song
2025-08-07 13:22 ` puranjay
2025-08-06 8:58 ` [PATCH bpf-next 3/3] selftests/bpf: Add tests for arena fault reporting Puranjay Mohan
2025-08-07 0:04 ` Yonghong Song
2025-08-07 13:25 ` puranjay
2025-08-07 15:25 ` Kumar Kartikeya Dwivedi [this message]
2025-08-11 10:35 ` Puranjay Mohan
2025-08-11 20:31 ` Kumar Kartikeya Dwivedi
2025-08-11 17:14 ` Eduard Zingerman
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='CAP01T75_WiqLmJE7x==wagJTMfg2BoZkv6otexA6FGm-=UFXew@mail.gmail.com' \
--to=memxor@gmail.com \
--cc=andrii@kernel.org \
--cc=ast@kernel.org \
--cc=bpf@vger.kernel.org \
--cc=catalin.marinas@arm.com \
--cc=daniel@iogearbox.net \
--cc=eddyz87@gmail.com \
--cc=haoluo@google.com \
--cc=john.fastabend@gmail.com \
--cc=jolsa@kernel.org \
--cc=kpsingh@kernel.org \
--cc=martin.lau@linux.dev \
--cc=puranjay@kernel.org \
--cc=sdf@fomichev.me \
--cc=song@kernel.org \
--cc=will@kernel.org \
--cc=xukuohai@huaweicloud.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;
as well as URLs for NNTP newsgroup(s).