From: Leon Hwang <leon.hwang@linux.dev>
To: Alexei Starovoitov <alexei.starovoitov@gmail.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 v6 11/12] selftests/bpf: Add test to verify xlated insns for global percpu data
Date: Tue, 16 Jun 2026 12:18:54 +0800 [thread overview]
Message-ID: <d9eaffaa-6bbd-4af1-97cd-e5e37917c526@linux.dev> (raw)
In-Reply-To: <DJ9XY0Y2D2R8.16S9E0QFFMLQS@gmail.com>
On 16/6/26 05:29, Alexei Starovoitov wrote:
> On Mon Jun 15, 2026 at 8:26 AM PDT, Leon Hwang wrote:
[...]
>> + ASSERT_EQ(ld_imm64_xlated[0].code, ld_imm64_raw[0].code, "ld_imm64 opcode");
>> + ASSERT_TRUE(ld_imm64_xlated[0].dst_reg == ld_imm64_raw[0].dst_reg, "ld_imm64 dst_reg");
>> + /*
>> + * The xlated instruction has the map ID in imm and the offset
>> + * in the next instruction's imm. The raw instruction just has
>> + * the offset in its imm.
>> + */
>> + ASSERT_EQ(ld_imm64_xlated[1].imm, ld_imm64_to_u64(ld_imm64_raw), "ld_imm64 off");
>> +
>> + mov64_percpu_reg = BPF_MOV64_PERCPU_REG(ld_imm64_raw[0].dst_reg, ld_imm64_raw[0].dst_reg);
>> + ASSERT_MEMEQ(&insns[idx + 2], &mov64_percpu_reg, insn_sz, "mov64_percpu_reg");
>
> If the point of the test was to check that percpu_array_map_direct_value_meta()
> computes 'off' correctly then it failed to achieve that goal.
It was to check the 'off' and the mov64_percpu_reg insn.
To avoid relying on the insns loaded from ELF obj, use raw insns to
check the 'off' with a percpu_array map:
struct bpf_insn raw_insns[] = {
BPF_LD_MAP_VALUE(BPF_REG_1, 0, 0),
BPF_LDX_MEM(BPF_W, BPF_REG_0, BPF_REG_1, 0),
BPF_EXIT_INSN(),
};
skel = test_global_percpu_data__open_and_load();
exp_off = offsetof(struct test_global_percpu_data__percpu,
struct_data.nums[6]);
raw_insns[0].imm = bpf_map__fd(skel->maps.percpu);
raw_insns[1].imm = exp_off;
prog_fd = bpf_prog_load(...);
err = get_xlated_program(prog_fd, &insns, &cnt);
idx = find_percpu_ld_imm64(insns, cnt);
ASSERT_EQ(insns[idx + 1].imm, exp_off, "exp_off");
Would this achieve that goal?
> It checks that map ID is correct which is a pointless test.
> Either make it a real test or drop this patch.
>
No map ID check here.
Thanks,
Leon
next prev parent reply other threads:[~2026-06-16 4:19 UTC|newest]
Thread overview: 21+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-06-15 15:26 [PATCH bpf-next v6 00/12] bpf: Introduce global percpu data Leon Hwang
2026-06-15 15:26 ` [PATCH bpf-next v6 01/12] bpf: Drop duplicate blank lines in verifier Leon Hwang
2026-06-15 15:26 ` [PATCH bpf-next v6 02/12] bpf: Disallow interpreter fallback for user BPF_ADDR_SPACE_CAST insn Leon Hwang
2026-06-15 15:26 ` [PATCH bpf-next v6 03/12] bpf: Disallow interpreter fallback for BPF_ADDR_PERCPU insn Leon Hwang
2026-06-15 15:26 ` [PATCH bpf-next v6 04/12] bpf: Introduce global percpu data Leon Hwang
2026-06-15 15:26 ` [PATCH bpf-next v6 05/12] libbpf: Probe percpu data feature Leon Hwang
2026-06-15 15:26 ` [PATCH bpf-next v6 06/12] libbpf: Add support for global percpu data Leon Hwang
2026-06-15 15:41 ` sashiko-bot
2026-06-16 4:17 ` Leon Hwang
2026-06-15 15:26 ` [PATCH bpf-next v6 07/12] bpftool: Generate skeleton " Leon Hwang
2026-06-15 15:26 ` [PATCH bpf-next v6 08/12] selftests/bpf: Add tests to verify " Leon Hwang
2026-06-15 15:26 ` [PATCH bpf-next v6 09/12] selftests/bpf: Add test to verify accessing rdonly percpu_array Leon Hwang
2026-06-15 15:26 ` [PATCH bpf-next v6 10/12] selftests/bpf: Add tests to verify verifier log for global percpu data Leon Hwang
2026-06-15 15:40 ` sashiko-bot
2026-06-16 4:18 ` Leon Hwang
2026-06-15 15:26 ` [PATCH bpf-next v6 11/12] selftests/bpf: Add test to verify xlated insns " Leon Hwang
2026-06-15 21:29 ` Alexei Starovoitov
2026-06-16 4:18 ` Leon Hwang [this message]
2026-06-16 4:23 ` Alexei Starovoitov
2026-06-16 4:33 ` Leon Hwang
2026-06-15 15:26 ` [PATCH bpf-next v6 12/12] selftests/bpf: Add test to verify bpf_iter " Leon Hwang
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=d9eaffaa-6bbd-4af1-97cd-e5e37917c526@linux.dev \
--to=leon.hwang@linux.dev \
--cc=alexei.starovoitov@gmail.com \
--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=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