public inbox for bpf@vger.kernel.org
 help / color / mirror / Atom feed
From: Eduard Zingerman <eddyz87@gmail.com>
To: Martin KaFai Lau <martin.lau@linux.dev>
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, bpf@vger.kernel.org
Subject: Re: [RFC PATCH bpf-next 3/6] selftests/test: test gen_prologue and gen_epilogue
Date: Thu, 15 Aug 2024 17:23:20 -0700	[thread overview]
Message-ID: <92f724366153f2fbd7d9e92b6ba6f82408970dd7.camel@gmail.com> (raw)
In-Reply-To: <0625a342-887c-4c27-a7a7-9f0eadc31b9d@linux.dev>

On Thu, 2024-08-15 at 16:41 -0700, Martin KaFai Lau wrote:

[...]

> >      SEC("struct_ops/test_epilogue")
> >      __naked int test_epilogue(void)
> >      {
> >      	asm volatile (
> >      	"r0 = 0;"
> 
> I also want to test a struct_ops prog making kfunc call, e.g. the 
> BPF_PROG(test_epilogue_kfunc) in this patch. I have never tried this in asm, so 
> a n00b question. Do you know if there is an example how to call kfunc?

Here is an example:
progs/verifier_ref_tracking.c, specifically take a look at
acquire_release_user_key_reference(). The main trick is to have
__kfunc_btf_root() with dummy calls, so that there are BTF signatures
for kfuncs included in the object file.

> >      	"exit;"
> >      	::: __clobber_all);
> >      }
> >      
> >      SEC(".struct_ops.link")
> >      struct bpf_testmod_st_ops st_ops = {
> >      	.test_epilogue = (void *)test_epilogue,
> >      };
> > 
> > (Complete example is in the attachment).
> > test_loader based tests can also trigger program execution via __retval() macro.
> > The only (minor) shortcoming that I see, is that test_loader would
> > load/unload st_ops map multiple times because of the following
> > interaction:
> > - test_loader assumes that each bpf program defines a test;
> > - test_loader re-creates all maps before each test;
> > - libbpf struct_ops autocreate logic marks all programs referenced
> >    from struct_ops map as autoloaded.
> 
> If I understand correctly, there are redundant works but still work?

Yes.

> Potentially the test_loader can check all the loaded struct_ops progs of a 
> st_ops map at once which is an optimization.

Yes, I should look into this.

> Re: __retval(), the struct_ops progs is triggered by a SEC("syscall") prog. 
> Before calling this syscall prog, the st_ops map needs to be attached first. I 
> think the attach part is missing also? or there is a way?

I think libbpf handles the attachment automatically, I'll double check and reply.


  reply	other threads:[~2024-08-16  0:23 UTC|newest]

Thread overview: 19+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-08-13 18:49 [RFC PATCH bpf-next 0/6] bpf: Add gen_epilogue and allow kfunc call in pro/epilogue Martin KaFai Lau
2024-08-13 18:49 ` [RFC PATCH bpf-next 1/6] bpf: Add gen_epilogue to bpf_verifier_ops Martin KaFai Lau
2024-08-14 20:56   ` Eduard Zingerman
2024-08-15 22:14     ` Martin KaFai Lau
2024-08-17 22:25   ` Amery Hung
2024-08-13 18:49 ` [RFC PATCH bpf-next 2/6] bpf: Export bpf_base_func_proto Martin KaFai Lau
2024-08-13 18:49 ` [RFC PATCH bpf-next 3/6] selftests/test: test gen_prologue and gen_epilogue Martin KaFai Lau
2024-08-14 20:48   ` Eduard Zingerman
2024-08-15 23:41     ` Martin KaFai Lau
2024-08-16  0:23       ` Eduard Zingerman [this message]
2024-08-16  1:50         ` Eduard Zingerman
2024-08-16 17:27           ` Martin KaFai Lau
2024-08-16 20:27             ` Eduard Zingerman
2024-08-19 22:30               ` Martin KaFai Lau
2024-08-13 18:49 ` [RFC PATCH bpf-next 4/6] bpf: Add module parameter to " Martin KaFai Lau
2024-08-13 18:49 ` [RFC PATCH bpf-next 5/6] bpf: Allow pro/epilogue to call kfunc Martin KaFai Lau
2024-08-14 22:17   ` Eduard Zingerman
2024-08-15 23:47     ` Martin KaFai Lau
2024-08-13 18:49 ` [RFC PATCH bpf-next 6/6] selftests/bpf: Add kfunc call test in gen_prologue and gen_epilogue Martin KaFai Lau

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=92f724366153f2fbd7d9e92b6ba6f82408970dd7.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