From: Eduard Zingerman <eddyz87@gmail.com>
To: Martin KaFai Lau <martin.lau@linux.dev>, bpf@vger.kernel.org
Cc: Alexei Starovoitov <ast@kernel.org>,
Andrii Nakryiko <andrii@kernel.org>,
Daniel Borkmann <daniel@iogearbox.net>,
Yonghong Song <yonghong.song@linux.dev>,
Amery Hung <ameryhung@gmail.com>,
kernel-team@meta.com
Subject: Re: [PATCH v4 bpf-next 7/9] selftests/bpf: Add tailcall epilogue test
Date: Wed, 28 Aug 2024 23:16:27 -0700 [thread overview]
Message-ID: <5ef794cd921623dd8e0e6e350b6ad8ffd1aa7c26.camel@gmail.com> (raw)
In-Reply-To: <20240827194834.1423815-8-martin.lau@linux.dev>
On Tue, 2024-08-27 at 12:48 -0700, Martin KaFai Lau wrote:
> From: Martin KaFai Lau <martin.lau@kernel.org>
>
> This patch adds a gen_epilogue test to test a main prog
> using a bpf_tail_call.
>
> A non test_loader test is used. The tailcall target program,
> "test_epilogue_subprog", needs to be used in a struct_ops map
> before it can be loaded. Another struct_ops map is also needed
> to host the actual "test_epilogue_tailcall" struct_ops program
> that does the bpf_tail_call. The earlier test_loader patch
> will attach all struct_ops maps but the bpf_testmod.c does
> not support >1 attached struct_ops.
>
> The earlier patch used the test_loader which has already covered
> checking for the patched pro/epilogue instructions. This is done
> by the __xlated tag.
>
> This patch goes for the regular skel load and syscall test to do
> the tailcall test that can also allow to directly pass the
> the "struct st_ops_args *args" as ctx_in to the
> SEC("syscall") program.
>
> Signed-off-by: Martin KaFai Lau <martin.lau@kernel.org>
> ---
Acked-by: Eduard Zingerman <eddyz87@gmail.com>
[...]
> +static void test_tailcall(void)
> +{
> + LIBBPF_OPTS(bpf_test_run_opts, topts);
> + struct epilogue_tailcall *skel;
> + struct st_ops_args args;
> + int err, prog_fd;
> +
> + skel = epilogue_tailcall__open_and_load();
> + if (!ASSERT_OK_PTR(skel, "epilogue_tailcall__open_and_load"))
> + return;
> +
> + topts.ctx_in = &args;
> + topts.ctx_size_in = sizeof(args);
> +
> + skel->links.epilogue_tailcall =
> + bpf_map__attach_struct_ops(skel->maps.epilogue_tailcall);
> + if (!ASSERT_OK_PTR(skel->links.epilogue_tailcall, "attach_struct_ops"))
> + goto done;
> +
Nitpick:
Both test_epilogue_tailcall and test_epilogue_subprog would be
augmented with epilogue, and we know that tail call run as expected
because only test_epilogue_subprog does +1, right?
If above is true, could you please update the comment a bit, e.g.:
/* Both test_epilogue_tailcall and test_epilogue_subprog are
* augmented with epilogue. When syscall_epilogue_tailcall()
* is run test_epilogue_tailcall() is triggered,
* it executes a tail call and control is transferred to
* test_epilogue_subprog(). Only test_epilogue_subprog()
* does args->a += 1, thus final args.a value of 10001
* guarantees that tail call was executed as expected.
*/
(For some reason it took me a while to understand what happens in this test)
> + /* tailcall prog + gen_epilogue */
> + memset(&args, 0, sizeof(args));
> + prog_fd = bpf_program__fd(skel->progs.syscall_epilogue_tailcall);
> + err = bpf_prog_test_run_opts(prog_fd, &topts);
> + ASSERT_OK(err, "bpf_prog_test_run_opts");
> + ASSERT_EQ(args.a, 10001, "args.a");
> + ASSERT_EQ(topts.retval, 10001 * 2, "topts.retval");
> +
> +done:
> + epilogue_tailcall__destroy(skel);
> +}
[...]
next prev parent reply other threads:[~2024-08-29 6:16 UTC|newest]
Thread overview: 31+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-08-27 19:48 [PATCH v4 bpf-next 0/9] bpf: Add gen_epilogue to bpf_verifier_ops Martin KaFai Lau
2024-08-27 19:48 ` [PATCH v4 bpf-next 1/9] bpf: Move insn_buf[16] to bpf_verifier_env Martin KaFai Lau
2024-08-29 0:41 ` Eduard Zingerman
2024-08-29 1:46 ` Alexei Starovoitov
2024-08-29 15:20 ` Martin KaFai Lau
2024-08-29 15:26 ` Alexei Starovoitov
2024-08-29 15:33 ` Martin KaFai Lau
2024-08-27 19:48 ` [PATCH v4 bpf-next 3/9] bpf: Add gen_epilogue to bpf_verifier_ops Martin KaFai Lau
2024-08-29 2:26 ` Eduard Zingerman
2024-08-29 15:47 ` Martin KaFai Lau
2024-08-27 19:48 ` [PATCH v4 bpf-next 4/9] bpf: Export bpf_base_func_proto Martin KaFai Lau
2024-08-27 19:48 ` [PATCH v4 bpf-next 5/9] selftests/bpf: attach struct_ops maps before test prog runs Martin KaFai Lau
2024-08-27 19:48 ` [PATCH v4 bpf-next 6/9] selftests/bpf: Test gen_prologue and gen_epilogue Martin KaFai Lau
2024-08-29 7:27 ` Eduard Zingerman
2024-08-29 17:35 ` Martin KaFai Lau
2024-08-27 19:48 ` [PATCH v4 bpf-next 7/9] selftests/bpf: Add tailcall epilogue test Martin KaFai Lau
2024-08-29 6:16 ` Eduard Zingerman [this message]
2024-08-29 18:15 ` Martin KaFai Lau
2024-08-27 19:48 ` [PATCH v4 bpf-next 8/9] selftests/bpf: A pro/epilogue test when the main prog jumps back to the 1st insn Martin KaFai Lau
2024-08-29 6:21 ` Eduard Zingerman
2024-08-27 19:48 ` [PATCH v4 bpf-next 9/9] selftests/bpf: Test epilogue patching when the main prog has multiple BPF_EXIT Martin KaFai Lau
2024-08-28 0:58 ` Martin KaFai Lau
2024-08-29 6:28 ` Eduard Zingerman
2024-08-29 20:09 ` Martin KaFai Lau
2024-08-29 6:25 ` Eduard Zingerman
2024-08-27 19:52 ` [PATCH v4 bpf-next 2/9] bpf: Adjust BPF_JMP that jumps to the 1st insn of the prologue Martin KaFai Lau
2024-08-28 16:48 ` Alexei Starovoitov
2024-08-28 17:44 ` Martin KaFai Lau
2024-08-28 18:43 ` Alexei Starovoitov
2024-08-28 18:59 ` Martin KaFai Lau
[not found] ` <20240827194834.1423815-3-martin.lau@linux.dev>
2024-08-29 2:01 ` 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=5ef794cd921623dd8e0e6e350b6ad8ffd1aa7c26.camel@gmail.com \
--to=eddyz87@gmail.com \
--cc=ameryhung@gmail.com \
--cc=andrii@kernel.org \
--cc=ast@kernel.org \
--cc=bpf@vger.kernel.org \
--cc=daniel@iogearbox.net \
--cc=kernel-team@meta.com \
--cc=martin.lau@linux.dev \
--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