Re: [PATCH bpf-next 3/7] bpf: Add support for kprobe multi session cookie

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On Mon, Apr 22, 2024 at 10:48:25AM -0700, Alexei Starovoitov wrote:
> On Mon, Apr 22, 2024 at 5:13 AM Jiri Olsa <jolsa@xxxxxxxxxx> wrote:
> >
> > Adding support for cookie within the session of kprobe multi
> > entry and return program.
> >
> > The session cookie is u64 value and can be retrieved be new
> > kfunc bpf_session_cookie, which returns pointer to the cookie
> > value. The bpf program can use the pointer to store (on entry)
> > and load (on return) the value.
> >
> > The cookie value is implemented via fprobe feature that allows
> > to share values between entry and return ftrace fprobe callbacks.
> >
> > Signed-off-by: Jiri Olsa <jolsa@xxxxxxxxxx>
> > ---
> >  kernel/bpf/verifier.c    |  7 +++++++
> >  kernel/trace/bpf_trace.c | 19 ++++++++++++++++---
> >  2 files changed, 23 insertions(+), 3 deletions(-)
> >
> > diff --git a/kernel/bpf/verifier.c b/kernel/bpf/verifier.c
> > index 68cfd6fc6ad4..baaca451aebc 100644
> > --- a/kernel/bpf/verifier.c
> > +++ b/kernel/bpf/verifier.c
> > @@ -10987,6 +10987,7 @@ enum special_kfunc_type {
> >         KF_bpf_percpu_obj_drop_impl,
> >         KF_bpf_throw,
> >         KF_bpf_iter_css_task_new,
> > +       KF_bpf_session_cookie,
> >  };
> >
> >  BTF_SET_START(special_kfunc_set)
> > @@ -11013,6 +11014,7 @@ BTF_ID(func, bpf_throw)
> >  #ifdef CONFIG_CGROUPS
> >  BTF_ID(func, bpf_iter_css_task_new)
> >  #endif
> > +BTF_ID(func, bpf_session_cookie)
> >  BTF_SET_END(special_kfunc_set)
> >
> >  BTF_ID_LIST(special_kfunc_list)
> > @@ -11043,6 +11045,7 @@ BTF_ID(func, bpf_iter_css_task_new)
> >  #else
> >  BTF_ID_UNUSED
> >  #endif
> > +BTF_ID(func, bpf_session_cookie)
> >
> >  static bool is_kfunc_ret_null(struct bpf_kfunc_call_arg_meta *meta)
> >  {
> > @@ -12409,6 +12412,10 @@ static int check_kfunc_call(struct bpf_verifier_env *env, struct bpf_insn *insn,
> >                                  * because packet slices are not refcounted (see
> >                                  * dynptr_type_refcounted)
> >                                  */
> > +                       } else if (meta.func_id == special_kfunc_list[KF_bpf_session_cookie]) {
> > +                               mark_reg_known_zero(env, regs, BPF_REG_0);
> > +                               regs[BPF_REG_0].type = PTR_TO_MEM;
> > +                               regs[BPF_REG_0].mem_size = sizeof(u64);
> 
> Are you sure you need this?
> 
> } else if (!__btf_type_is_struct(ptr_type)) {
> 
> block should have handled it automatically.

yes, but only as read-only memory and we need the bpf program to be able to write
to it

I'll double check that, but AFAICS we can't set r0_size/!r0_rdonly before we reach
that if block, because bpf_session_cookie has no arguments

jirka

> 
> > +__bpf_kfunc __u64 *bpf_session_cookie(void)
> > +{
> 
> ...




[Index of Archives]     [Linux Samsung SoC]     [Linux Rockchip SoC]     [Linux Actions SoC]     [Linux for Synopsys ARC Processors]     [Linux NFS]     [Linux NILFS]     [Linux USB Devel]     [Video for Linux]     [Linux Audio Users]     [Yosemite News]     [Linux Kernel]     [Linux SCSI]


  Powered by Linux