From: Jiri Olsa <jolsa@kernel.org>
To: Alexei Starovoitov <ast@kernel.org>,
Daniel Borkmann <daniel@iogearbox.net>
Cc: bpf@vger.kernel.org, Andrii Nakryiko <andrii@kernel.org>,
Eduard Zingerman <eddyz87@gmail.com>,
Kumar Kartikeya Dwivedi <memxor@gmail.com>,
linux-mm@kvack.org, Andrew Morton <akpm@linux-foundation.org>,
"Liam R. Howlett" <liam@infradead.org>,
Lorenzo Stoakes <ljs@kernel.org>,
linux-kselftest@vger.kernel.org, Shuah Khan <shuah@kernel.org>,
John Fastabend <john.fastabend@gmail.com>
Subject: [RFC bpf-next 8/9] selftests/bpf: Add faultable user page writes test
Date: Wed, 21 Oct 2026 21:57:57 +0200 [thread overview]
Message-ID: <20261021195759.119421-9-jolsa@kernel.org> (raw)
In-Reply-To: <20261021195759.119421-1-jolsa@kernel.org>
Exercise fault-enabled writes into an allocated user page
and verify the written data.
Assisted-by: Codex:GPT-6
Signed-off-by: Jiri Olsa <jolsa@kernel.org>
---
.../selftests/bpf/prog_tests/user_page.c | 25 +++++++++++++++++++
tools/testing/selftests/bpf/progs/user_page.c | 7 ++++++
2 files changed, 32 insertions(+)
diff --git a/tools/testing/selftests/bpf/prog_tests/user_page.c b/tools/testing/selftests/bpf/prog_tests/user_page.c
index 1b5dff2c8ff6..74ce52d726ec 100644
--- a/tools/testing/selftests/bpf/prog_tests/user_page.c
+++ b/tools/testing/selftests/bpf/prog_tests/user_page.c
@@ -11,6 +11,7 @@ enum {
USER_PAGE_ALLOC = 1,
USER_PAGE_EXEC = 2,
USER_PAGE_EXEC_ONLY = 3,
+ USER_PAGE_WRITE = 4,
};
static noinline void user_page_trigger(void)
@@ -186,6 +187,28 @@ static void test_partial_exec(struct user_page *skel)
munmap((void *)addr, page_size * 3);
}
+static void test_faultable_write(struct user_page *skel)
+{
+ static const char expected[] = "fault-enabled BPF write";
+ long page_size = sysconf(_SC_PAGESIZE);
+ long addr = -1;
+
+ if (!alloc_user_pages(skel, 1, &addr))
+ return;
+
+ skel->bss->user_addr = addr;
+ skel->bss->action = USER_PAGE_WRITE;
+ user_page_trigger();
+ if (!ASSERT_EQ(skel->bss->write_ret, 0, "write_ret"))
+ goto out;
+
+ ASSERT_EQ(memcmp((void *)addr, expected, sizeof(expected)), 0, "written_data");
+
+out:
+ if (addr >= 0)
+ munmap((void *)addr, page_size);
+}
+
void test_user_page(void)
{
struct user_page *skel;
@@ -208,6 +231,8 @@ void test_user_page(void)
test_execute_user_page(skel);
if (test__start_subtest("partial_exec"))
test_partial_exec(skel);
+ if (test__start_subtest("faultable_write"))
+ test_faultable_write(skel);
out:
user_page__destroy(skel);
diff --git a/tools/testing/selftests/bpf/progs/user_page.c b/tools/testing/selftests/bpf/progs/user_page.c
index 38f6fcb89bc6..a855b0b46350 100644
--- a/tools/testing/selftests/bpf/progs/user_page.c
+++ b/tools/testing/selftests/bpf/progs/user_page.c
@@ -11,6 +11,7 @@ char _license[] SEC("license") = "GPL";
#define USER_PAGE_ALLOC 1
#define USER_PAGE_EXEC 2
#define USER_PAGE_EXEC_ONLY 3
+#define USER_PAGE_WRITE 4
int monitored_pid;
int action;
@@ -19,6 +20,8 @@ long exec_addr;
unsigned long nr_pages;
int write_ret;
int exec_ret;
+
+static const char data[] = "fault-enabled BPF write";
static const unsigned char insns[] = {
0xf3, 0x0f, 0x1e, 0xfa, /* endbr64 */
0xb8, 42, 0, 0, 0, 0xc3, /* mov $42, %eax; ret */
@@ -43,6 +46,10 @@ int user_page_test(struct pt_regs *ctx)
case USER_PAGE_EXEC_ONLY:
exec_ret = bpf_user_page_exec(exec_addr);
break;
+ case USER_PAGE_WRITE:
+ write_ret = bpf_probe_write_user_faultable((void *)user_addr, data,
+ sizeof(data));
+ break;
}
return 0;
--
2.54.0
next prev parent reply other threads:[~2026-10-21 19:59 UTC|newest]
Thread overview: 19+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-10-21 19:57 [RFC bpf-next 0/9] bpf: Add support to allocate user page Jiri Olsa
2026-10-21 19:57 ` [RFC bpf-next 1/9] bpf: Add __srcptr kfunc argument suffix Jiri Olsa
2026-10-21 19:57 ` [RFC bpf-next 2/9] bpf: Add uprobe faultable user copy kfunc Jiri Olsa
2026-10-21 20:30 ` bot+bpf-ci
2026-10-21 19:57 ` [RFC bpf-next 3/9] mm: Expose locked mprotect operation Jiri Olsa
2026-10-21 20:30 ` bot+bpf-ci
2026-10-22 10:25 ` Lorenzo Stoakes (ARM)
2026-10-22 19:39 ` Jiri Olsa
2026-10-21 19:57 ` [RFC bpf-next 4/9] bpf: Add kfuncs to allocate and seal user pages Jiri Olsa
2026-10-21 20:41 ` bot+bpf-ci
2026-10-21 19:57 ` [RFC bpf-next 5/9] selftests/bpf: Add __srcptr kfunc arguments test Jiri Olsa
2026-10-21 19:57 ` [RFC bpf-next 6/9] selftests/bpf: Add user page allocation test Jiri Olsa
2026-10-21 19:57 ` [RFC bpf-next 7/9] selftests/bpf: Add uprobe user page exec test Jiri Olsa
2026-10-21 19:57 ` Jiri Olsa [this message]
2026-10-21 19:57 ` [RFC bpf-next 9/9] selftests/bpf: Add user page failures test Jiri Olsa
2026-10-21 20:30 ` bot+bpf-ci
2026-10-21 21:53 ` [RFC bpf-next 0/9] bpf: Add support to allocate user page Alexei Starovoitov
2026-10-22 10:01 ` Jiri Olsa
2026-10-22 10:27 ` Lorenzo Stoakes (ARM)
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=20261021195759.119421-9-jolsa@kernel.org \
--to=jolsa@kernel.org \
--cc=akpm@linux-foundation.org \
--cc=andrii@kernel.org \
--cc=ast@kernel.org \
--cc=bpf@vger.kernel.org \
--cc=daniel@iogearbox.net \
--cc=eddyz87@gmail.com \
--cc=john.fastabend@gmail.com \
--cc=liam@infradead.org \
--cc=linux-kselftest@vger.kernel.org \
--cc=linux-mm@kvack.org \
--cc=ljs@kernel.org \
--cc=memxor@gmail.com \
--cc=shuah@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