Netdev Archive on lore.kernel.org help / color / mirror / Atom feed
From: Yonghong Song <yhs@fb.com> To: Johan Almbladh <johan.almbladh@anyfinetworks.com> Cc: Alexei Starovoitov <ast@kernel.org>, Daniel Borkmann <daniel@iogearbox.net>, Andrii Nakryiko <andrii@kernel.org>, Martin KaFai Lau <kafai@fb.com>, Song Liu <songliubraving@fb.com>, John Fastabend <john.fastabend@gmail.com>, KP Singh <kpsingh@kernel.org>, Tony Ambardar <Tony.Ambardar@gmail.com>, Networking <netdev@vger.kernel.org>, bpf <bpf@vger.kernel.org> Subject: Re: [PATCH 06/14] bpf/tests: Add more BPF_LSH/RSH/ARSH tests for ALU64 Date: Thu, 29 Jul 2021 08:39:25 -0700 [thread overview] Message-ID: <12ed8726-41c6-b173-b30a-1bd625a12718@fb.com> (raw) In-Reply-To: <CAM1=_QQJ+uYXuU_nOVb3djW-G8wJs4Azz36pXk8mO3vQBuVouQ@mail.gmail.com> On 7/29/21 5:34 AM, Johan Almbladh wrote: > On Thu, Jul 29, 2021 at 1:30 AM Yonghong Song <yhs@fb.com> wrote: >>> @@ -4139,6 +4139,106 @@ static struct bpf_test tests[] = { >>> { }, >>> { { 0, 0x80000000 } }, >>> }, >>> + { >>> + "ALU64_LSH_X: Shift < 32, low word", >>> + .u.insns_int = { >>> + BPF_LD_IMM64(R0, 0x0123456789abcdefLL), >>> + BPF_ALU32_IMM(BPF_MOV, R1, 12), >>> + BPF_ALU64_REG(BPF_LSH, R0, R1), >>> + BPF_EXIT_INSN(), >>> + }, >>> + INTERNAL, >>> + { }, >>> + { { 0, 0xbcdef000 } } >> >> In bpf_test struct, the result is defined as __u32 >> struct { >> int data_size; >> __u32 result; >> } test[MAX_SUBTESTS]; >> >> But the above result 0xbcdef000 does not really capture the bpf program >> return value, which should be 0x3456789abcdef000. >> Can we change "result" type to __u64 so the result truly captures the >> program return value? > > This was also my though at first, but I don't think that is possible. > As I understand it, the eBPF functions have the prototype int > func(struct *ctx). While the context pointer will have a different > size on 32-bit and 64-bit architectures, the return value will always > be 32 bits on most, or all, platforms. Thanks for explanation. Yes, all BPF_PROG_RUN variables have bpf program return type u32, so you are right, we cannot really check prog return value against a 64bit R0. > >> We have several other similar cases for the rest of this patch. > > I have used two ways to check the full 64-bit result in such cases. > > 1) Load the expected result as a 64-bit value in a register. Then jump > conditionally if the result matches this value or not. The jump > destinations each set a distinct value in R0, which is finally > examined as the result. > > 2) Run the test twice. The first one returns the low 32-bits of R0. > The second adds a 32-bit right shift to return the high 32 bits. > > When I first wrote the tests I tried to use as few complex > instructions not under test as possible, in order to test each > instruction in isolation. Since the 32-bit right shift is a much > simpler operation than conditional jumps, at least in the 32-bit MIPS > JIT, I chose method (2) for most of the tests. Existing tests seem to > use method (1), so in some cases I used that instead when adding more > tests of the same operation. The motivation for the simple one-by-one > tests is mainly convenience and better diagnostics during JIT > development. Both methods (1) and (2) are equally valid of course. it is totally okay to use (2). Your tests are fine in that regard. > > By the way, thanks a lot for the review, Yonghong! You are welcome! > > Johan >
next prev parent reply other threads:[~2021-07-29 15:39 UTC|newest] Thread overview: 43+ messages / expand[flat|nested] mbox.gz Atom feed top 2021-07-28 17:04 [PATCH 00/14] bpf/tests: Extend the eBPF test suite Johan Almbladh 2021-07-28 17:04 ` [PATCH 01/14] bpf/tests: Add BPF_JMP32 test cases Johan Almbladh 2021-07-28 22:31 ` Yonghong Song 2021-07-29 21:30 ` Johan Almbladh 2021-07-28 17:04 ` [PATCH 02/14] bpf/tests: Add BPF_MOV tests for zero and sign extension Johan Almbladh 2021-07-28 22:36 ` Yonghong Song 2021-07-28 17:04 ` [PATCH 03/14] bpf/tests: Fix typos in test case descriptions Johan Almbladh 2021-07-28 22:43 ` Yonghong Song 2021-07-28 17:04 ` [PATCH 04/14] bpf/tests: Add more tests of ALU32 and ALU64 bitwise operations Johan Almbladh 2021-07-28 22:53 ` Yonghong Song 2021-07-28 17:04 ` [PATCH 05/14] bpf/tests: Add more ALU32 tests for BPF_LSH/RSH/ARSH Johan Almbladh 2021-07-28 22:57 ` Yonghong Song 2021-07-28 17:04 ` [PATCH 06/14] bpf/tests: Add more BPF_LSH/RSH/ARSH tests for ALU64 Johan Almbladh 2021-07-28 23:30 ` Yonghong Song 2021-07-29 12:34 ` Johan Almbladh 2021-07-29 15:39 ` Yonghong Song [this message] 2021-07-28 17:04 ` [PATCH 07/14] bpf/tests: Add more ALU64 BPF_MUL tests Johan Almbladh 2021-07-28 23:32 ` Yonghong Song 2021-07-29 21:21 ` Johan Almbladh 2021-07-28 17:04 ` [PATCH 08/14] bpf/tests: Add tests for ALU operations implemented with function calls Johan Almbladh 2021-07-28 23:52 ` Yonghong Song 2021-07-29 21:17 ` Johan Almbladh 2021-07-29 22:54 ` Yonghong Song 2021-07-28 17:04 ` [PATCH 09/14] bpf/tests: Add word-order tests for load/store of double words Johan Almbladh 2021-07-28 23:54 ` Yonghong Song 2021-07-28 17:04 ` [PATCH 10/14] bpf/tests: Add branch conversion JIT test Johan Almbladh 2021-07-28 23:58 ` Yonghong Song 2021-07-29 12:45 ` Johan Almbladh 2021-07-29 15:46 ` Yonghong Song 2021-07-29 0:55 ` Yonghong Song 2021-07-29 13:24 ` Johan Almbladh 2021-07-29 15:50 ` Yonghong Song 2021-07-28 17:04 ` [PATCH 11/14] bpf/tests: Add test for 32-bit context pointer argument passing Johan Almbladh 2021-07-29 0:09 ` Yonghong Song 2021-07-29 13:29 ` Johan Almbladh 2021-07-29 15:50 ` Yonghong Song 2021-07-28 17:05 ` [PATCH 12/14] bpf/tests: Add tests for atomic operations Johan Almbladh 2021-07-29 0:36 ` Yonghong Song 2021-07-28 17:05 ` [PATCH 13/14] bpf/tests: Add tests for BPF_CMPXCHG Johan Almbladh 2021-07-29 0:45 ` Yonghong Song 2021-07-28 17:05 ` [PATCH 14/14] bpf/tests: Add tail call test suite Johan Almbladh 2021-07-29 2:56 ` Yonghong Song 2021-07-29 20:44 ` Johan Almbladh
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=12ed8726-41c6-b173-b30a-1bd625a12718@fb.com \ --to=yhs@fb.com \ --cc=Tony.Ambardar@gmail.com \ --cc=andrii@kernel.org \ --cc=ast@kernel.org \ --cc=bpf@vger.kernel.org \ --cc=daniel@iogearbox.net \ --cc=johan.almbladh@anyfinetworks.com \ --cc=john.fastabend@gmail.com \ --cc=kafai@fb.com \ --cc=kpsingh@kernel.org \ --cc=netdev@vger.kernel.org \ --cc=songliubraving@fb.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: linkBe 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).