From: Leon Hwang <leon.hwang@linux.dev>
To: Emil Tsalapatis <emil@etsalapatis.com>, bpf@vger.kernel.org
Cc: 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>,
Kumar Kartikeya Dwivedi <memxor@gmail.com>,
Song Liu <song@kernel.org>,
Yonghong Song <yonghong.song@linux.dev>,
Jiri Olsa <jolsa@kernel.org>,
John Fastabend <john.fastabend@gmail.com>,
Quentin Monnet <qmo@kernel.org>, Shuah Khan <shuah@kernel.org>,
linux-kernel@vger.kernel.org, linux-kselftest@vger.kernel.org,
kernel-patches-bot@fb.com
Subject: Re: [PATCH bpf-next v10 7/9] selftests/bpf: Test direct reading/writing read-only percpu_array map
Date: Mon, 20 Jul 2026 13:03:35 +0800 [thread overview]
Message-ID: <6abd493f-e1d1-42f6-87b5-c4d3b176ad1c@linux.dev> (raw)
In-Reply-To: <DK17OV4181RP.1LRGDA6VBB364@etsalapatis.com>
On 18/7/26 06:49, Emil Tsalapatis wrote:
> On Wed Jul 15, 2026 at 11:32 AM EDT, Leon Hwang wrote:
>> Verify these two cases:
>>
>> 1. Direct reading the data of read-only percpu data's percpu_array map
>> is allowed.
>> 2. Direct writing the data of read-only percpu data's percpu_array map
>> is disallowed.
>>
>> Assisted-by: Codex:gpt-5.5-xhigh
>> Signed-off-by: Leon Hwang <leon.hwang@linux.dev>
>> ---
>> .../bpf/prog_tests/global_data_init.c | 83 +++++++++++++++++++
>> 1 file changed, 83 insertions(+)
>>
>> diff --git a/tools/testing/selftests/bpf/prog_tests/global_data_init.c b/tools/testing/selftests/bpf/prog_tests/global_data_init.c
>> index f7a56e3fdbce..d4405646847a 100644
>> --- a/tools/testing/selftests/bpf/prog_tests/global_data_init.c
>> +++ b/tools/testing/selftests/bpf/prog_tests/global_data_init.c
>> @@ -199,6 +199,85 @@ static void test_global_percpu_data_lskel(void)
>> test_global_percpu_data_lskel__destroy(lskel);
>> }
>>
>> +static int create_rdonly_percpu_array(void)
>> +{
>> + LIBBPF_OPTS(bpf_map_create_opts, map_opts,
>> + .map_flags = BPF_F_RDONLY_PROG,
>> + );
>> + int key = 0, map_fd, err;
>> + __u64 value = 0;
>> +
>> + map_fd = bpf_map_create(BPF_MAP_TYPE_PERCPU_ARRAY, "percpu_ro_map", sizeof(int),
>> + sizeof(__u64), 1, &map_opts);
>> + if (!ASSERT_GE(map_fd, 0, "bpf_map_create"))
>> + return -1;
>> +
>> + err = bpf_map_update_elem(map_fd, &key, &value, BPF_F_ALL_CPUS);
>> + if (!ASSERT_OK(err, "bpf_map_update_elem"))
>> + goto out;
>> +
>> + err = bpf_map_freeze(map_fd);
>> + if (!ASSERT_OK(err, "bpf_map_freeze"))
>> + goto out;
>> +
>> + return map_fd;
>> +
>> +out:
>> + close(map_fd);
>> + return -1;
>> +}
>> +
>> +static void test_global_percpu_data_rdonly_direct_read(void)
>> +{
>> + struct bpf_insn insns[] = {
>> + BPF_LD_MAP_VALUE(BPF_REG_1, 0, 0),
>> + BPF_LDX_MEM(BPF_DW, BPF_REG_0, BPF_REG_1, 0),
>> + BPF_EXIT_INSN(),
>> + };
>
> Why hardcode this as inline assembly? Can we do a syscall example in the
> progs/? That way there will also be a concrete example of how we're
> using the feature in practice.
We are unable to implement it with a syscall example, because libbpf
does not support creating a rdonly internal map for global percpu data.
We have no '.ropercpu' section support in libbpf.
Will add comment to explain the reason of hardcoded insns.
Thanks,
Leon
> [...]
next prev parent reply other threads:[~2026-07-20 5:03 UTC|newest]
Thread overview: 28+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-07-15 15:32 [PATCH bpf-next v10 0/9] bpf: Introduce global percpu data Leon Hwang
2026-07-15 15:32 ` [PATCH bpf-next v10 1/9] bpf: Drop duplicate blank lines in verifier Leon Hwang
2026-07-17 5:08 ` Emil Tsalapatis
2026-07-17 5:28 ` Leon Hwang
2026-07-15 15:32 ` [PATCH bpf-next v10 2/9] bpf: Introduce global percpu data Leon Hwang
2026-07-17 6:25 ` Emil Tsalapatis
2026-07-20 4:59 ` Leon Hwang
2026-07-20 22:55 ` Emil Tsalapatis
2026-07-15 15:32 ` [PATCH bpf-next v10 3/9] libbpf: Probe percpu data feature Leon Hwang
2026-07-17 21:52 ` Emil Tsalapatis
2026-07-15 15:32 ` [PATCH bpf-next v10 4/9] libbpf: Add support for global percpu data Leon Hwang
2026-07-17 21:39 ` Emil Tsalapatis
2026-07-20 4:59 ` Leon Hwang
2026-07-15 15:32 ` [PATCH bpf-next v10 5/9] bpftool: Generate skeleton " Leon Hwang
2026-07-17 21:52 ` Emil Tsalapatis
2026-07-20 5:00 ` Leon Hwang
2026-07-15 15:32 ` [PATCH bpf-next v10 6/9] selftests/bpf: Add tests to verify " Leon Hwang
2026-07-15 16:11 ` bot+bpf-ci
2026-07-16 5:30 ` Leon Hwang
2026-07-17 22:47 ` Emil Tsalapatis
2026-07-20 5:02 ` Leon Hwang
2026-07-15 15:32 ` [PATCH bpf-next v10 7/9] selftests/bpf: Test direct reading/writing read-only percpu_array map Leon Hwang
2026-07-17 22:49 ` Emil Tsalapatis
2026-07-20 5:03 ` Leon Hwang [this message]
2026-07-15 15:32 ` [PATCH bpf-next v10 8/9] selftests/bpf: Test verifier log for global percpu data Leon Hwang
2026-07-17 22:50 ` Emil Tsalapatis
2026-07-15 15:32 ` [PATCH bpf-next v10 9/9] selftests/bpf: Verify bpf_iter " Leon Hwang
2026-07-17 23:11 ` 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=6abd493f-e1d1-42f6-87b5-c4d3b176ad1c@linux.dev \
--to=leon.hwang@linux.dev \
--cc=andrii@kernel.org \
--cc=ast@kernel.org \
--cc=bpf@vger.kernel.org \
--cc=daniel@iogearbox.net \
--cc=eddyz87@gmail.com \
--cc=emil@etsalapatis.com \
--cc=john.fastabend@gmail.com \
--cc=jolsa@kernel.org \
--cc=kernel-patches-bot@fb.com \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-kselftest@vger.kernel.org \
--cc=martin.lau@linux.dev \
--cc=memxor@gmail.com \
--cc=qmo@kernel.org \
--cc=shuah@kernel.org \
--cc=song@kernel.org \
--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