All of lore.kernel.org
 help / color / mirror / Atom feed
From: Yonghong Song <yonghong.song@linux.dev>
To: Puranjay Mohan <puranjay@kernel.org>,
	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>,
	Kumar Kartikeya Dwivedi <memxor@gmail.com>,
	bpf@vger.kernel.org
Subject: Re: [PATCH bpf-next v5 4/4] selftests/bpf: Add tests for arena fault reporting
Date: Tue, 2 Sep 2025 09:22:25 -0700	[thread overview]
Message-ID: <edfbf4a2-392d-422e-aab3-288161a80dbd@linux.dev> (raw)
In-Reply-To: <20250901193730.43543-5-puranjay@kernel.org>



On 9/1/25 12:37 PM, 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.
>
> The added bpf programs need to access the user_vm_start in struct
> bpf_arena, this is done by casting &arena to struct bpf_arena *, but
> barrier_var() is used on this ptr before accessing ptr->user_vm_start;
> to stop GCC from issuing an out-of-bound access due to the cast from
> smaller map struct to larger "struct bpf_arena"
>
> Signed-off-by: Puranjay Mohan <puranjay@kernel.org>

LGTM with one nit below.

Acked-by: Yonghong Song <yonghong.song@linux.dev>

> ---
>   .../testing/selftests/bpf/prog_tests/stream.c | 34 ++++++++++-
>   tools/testing/selftests/bpf/progs/stream.c    | 61 +++++++++++++++++++
>   2 files changed, 94 insertions(+), 1 deletion(-)
>
> diff --git a/tools/testing/selftests/bpf/prog_tests/stream.c b/tools/testing/selftests/bpf/prog_tests/stream.c
> index 9d0e5d93edee7..b2a85364e3c4f 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)
> @@ -63,6 +79,7 @@ void test_stream_errors(void)
>   	struct stream *skel;
>   	int ret, prog_fd;
>   	char buf[1024];
> +	char fault_addr[64] = {0};

Looks like the above '= {0}' is not necessary as the only usage
is below:

+			sprintf(fault_addr, "0x%lx", skel->bss->fault_addr);
+			ret = match_regex(fault_addr, buf);

>   
>   	skel = stream__open_and_load();
>   	if (!ASSERT_OK_PTR(skel, "stream__open_and_load"))
> @@ -85,6 +102,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");
> @@ -92,8 +117,15 @@ void test_stream_errors(void)
>   		buf[ret] = '\0';
>   
>   		ret = match_regex(stream_error_arr[i].errstr, buf);
> -		if (!ASSERT_TRUE(ret == 1, "regex match"))
> +		if (ret && (i == 2 || i == 3)) {
> +			sprintf(fault_addr, "0x%lx", skel->bss->fault_addr);
> +			ret = match_regex(fault_addr, buf);
> +		}
> +		if (!ASSERT_TRUE(ret == 1, "regex match")) {
>   			fprintf(stderr, "Output from stream:\n%s\n", buf);
> +			if (i == 2 || i == 3)
> +				fprintf(stderr, "Fault Addr: 0x%lx\n", skel->bss->fault_addr);
> +		}
>   	}
>   
>   	stream__destroy(skel);
>
[...]


  reply	other threads:[~2025-09-02 16:22 UTC|newest]

Thread overview: 13+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-09-01 19:37 [PATCH bpf-next v5 0/4] bpf: report arena faults to BPF streams Puranjay Mohan
2025-09-01 19:37 ` [PATCH bpf-next v5 1/4] bpf: arm64: simplify exception table handling Puranjay Mohan
2025-09-01 19:37 ` [PATCH bpf-next v5 2/4] bpf: core: introduce main_prog_aux for stream access Puranjay Mohan
2025-09-02  2:25   ` Alexei Starovoitov
2025-09-02  2:32     ` Kumar Kartikeya Dwivedi
2025-09-01 19:37 ` [PATCH bpf-next v5 3/4] bpf: Report arena faults to BPF stderr Puranjay Mohan
2025-09-02 12:42   ` kernel test robot
2025-09-03  0:01   ` Eduard Zingerman
2025-09-01 19:37 ` [PATCH bpf-next v5 4/4] selftests/bpf: Add tests for arena fault reporting Puranjay Mohan
2025-09-02 16:22   ` Yonghong Song [this message]
2025-09-02 22:21   ` Eduard Zingerman
2025-09-05 14:00     ` Puranjay Mohan
2025-09-05 18:38       ` 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=edfbf4a2-392d-422e-aab3-288161a80dbd@linux.dev \
    --to=yonghong.song@linux.dev \
    --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=memxor@gmail.com \
    --cc=puranjay@kernel.org \
    --cc=sdf@fomichev.me \
    --cc=song@kernel.org \
    --cc=will@kernel.org \
    --cc=xukuohai@huaweicloud.com \
    /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.