All of lore.kernel.org
 help / color / mirror / Atom feed
From: Jiri Olsa <olsajiri@gmail.com>
To: Yafang Shao <laoar.shao@gmail.com>
Cc: Alexei Starovoitov <ast@kernel.org>,
	Daniel Borkmann <daniel@iogearbox.net>,
	Andrii Nakryiko <andrii@kernel.org>,
	bpf@vger.kernel.org, Martin KaFai Lau <kafai@fb.com>,
	Song Liu <songliubraving@fb.com>, Yonghong Song <yhs@fb.com>,
	John Fastabend <john.fastabend@gmail.com>,
	KP Singh <kpsingh@chromium.org>,
	Stanislav Fomichev <sdf@google.com>, Hao Luo <haoluo@google.com>,
	Quentin Monnet <quentin@isovalent.com>
Subject: Re: [PATCH bpf-next 1/8] bpf: Add cookie to perf_event bpf_link_info records
Date: Fri, 19 Jan 2024 09:03:18 +0100	[thread overview]
Message-ID: <Zaosxtg3Ko7ttJz1@krava> (raw)
In-Reply-To: <CALOAHbDnUaGtTAnrJthHV_U1Oz6c+2MeE7LQ6aqeW6y5cKt=OQ@mail.gmail.com>

On Thu, Jan 18, 2024 at 08:24:58PM +0800, Yafang Shao wrote:
> On Thu, Jan 18, 2024 at 5:54 PM Jiri Olsa <jolsa@kernel.org> wrote:
> >
> > At the moment we don't store cookie for perf_event probes,
> > while we do that for the rest of the probes.
> >
> > Adding cookie fields to struct bpf_link_info perf event
> > probe records:
> >
> >   perf_event.uprobe
> >   perf_event.kprobe
> >   perf_event.tracepoint
> >   perf_event.perf_event
> >
> > And the code to store that in bpf_link_info struct.
> >
> > Signed-off-by: Jiri Olsa <jolsa@kernel.org>
> > ---
> >  include/uapi/linux/bpf.h       | 4 ++++
> >  kernel/bpf/syscall.c           | 4 ++++
> >  tools/include/uapi/linux/bpf.h | 4 ++++
> >  3 files changed, 12 insertions(+)
> >
> > diff --git a/include/uapi/linux/bpf.h b/include/uapi/linux/bpf.h
> > index a00f8a5623e1..b823d367a83c 100644
> > --- a/include/uapi/linux/bpf.h
> > +++ b/include/uapi/linux/bpf.h
> > @@ -6582,6 +6582,7 @@ struct bpf_link_info {
> >                                         __aligned_u64 file_name; /* in/out */
> >                                         __u32 name_len;
> >                                         __u32 offset; /* offset from file_name */
> > +                                       __u64 cookie;
> >                                 } uprobe; /* BPF_PERF_EVENT_UPROBE, BPF_PERF_EVENT_URETPROBE */
> >                                 struct {
> >                                         __aligned_u64 func_name; /* in/out */
> > @@ -6589,14 +6590,17 @@ struct bpf_link_info {
> >                                         __u32 offset; /* offset from func_name */
> >                                         __u64 addr;
> >                                         __u64 missed;
> > +                                       __u64 cookie;
> >                                 } kprobe; /* BPF_PERF_EVENT_KPROBE, BPF_PERF_EVENT_KRETPROBE */
> >                                 struct {
> >                                         __aligned_u64 tp_name;   /* in/out */
> >                                         __u32 name_len;
> 
> It might be beneficial to include an alignment pad '__u32 :32;' here,
> following the pattern used in other instances within this file.

good cactch, thanks

jirka

> 
> > +                                       __u64 cookie;
> >                                 } tracepoint; /* BPF_PERF_EVENT_TRACEPOINT */
> >                                 struct {
> >                                         __u64 config;
> >                                         __u32 type;
> 
> Same here.
> 
> > +                                       __u64 cookie;
> >                                 } event; /* BPF_PERF_EVENT_EVENT */
> >                         };
> >                 } perf_event;
> > diff --git a/kernel/bpf/syscall.c b/kernel/bpf/syscall.c
> > index a1f18681721c..13193aaafb64 100644
> > --- a/kernel/bpf/syscall.c
> > +++ b/kernel/bpf/syscall.c
> > @@ -3501,6 +3501,7 @@ static int bpf_perf_link_fill_kprobe(const struct perf_event *event,
> >         if (!kallsyms_show_value(current_cred()))
> >                 addr = 0;
> >         info->perf_event.kprobe.addr = addr;
> > +       info->perf_event.kprobe.cookie = event->bpf_cookie;
> >         return 0;
> >  }
> >  #endif
> > @@ -3526,6 +3527,7 @@ static int bpf_perf_link_fill_uprobe(const struct perf_event *event,
> >         else
> >                 info->perf_event.type = BPF_PERF_EVENT_UPROBE;
> >         info->perf_event.uprobe.offset = offset;
> > +       info->perf_event.uprobe.cookie = event->bpf_cookie;
> >         return 0;
> >  }
> >  #endif
> > @@ -3553,6 +3555,7 @@ static int bpf_perf_link_fill_tracepoint(const struct perf_event *event,
> >         uname = u64_to_user_ptr(info->perf_event.tracepoint.tp_name);
> >         ulen = info->perf_event.tracepoint.name_len;
> >         info->perf_event.type = BPF_PERF_EVENT_TRACEPOINT;
> > +       info->perf_event.tracepoint.cookie = event->bpf_cookie;
> >         return bpf_perf_link_fill_common(event, uname, ulen, NULL, NULL, NULL, NULL);
> >  }
> >
> > @@ -3561,6 +3564,7 @@ static int bpf_perf_link_fill_perf_event(const struct perf_event *event,
> >  {
> >         info->perf_event.event.type = event->attr.type;
> >         info->perf_event.event.config = event->attr.config;
> > +       info->perf_event.event.cookie = event->bpf_cookie;
> >         info->perf_event.type = BPF_PERF_EVENT_EVENT;
> >         return 0;
> >  }
> > diff --git a/tools/include/uapi/linux/bpf.h b/tools/include/uapi/linux/bpf.h
> > index a00f8a5623e1..b823d367a83c 100644
> > --- a/tools/include/uapi/linux/bpf.h
> > +++ b/tools/include/uapi/linux/bpf.h
> > @@ -6582,6 +6582,7 @@ struct bpf_link_info {
> >                                         __aligned_u64 file_name; /* in/out */
> >                                         __u32 name_len;
> >                                         __u32 offset; /* offset from file_name */
> > +                                       __u64 cookie;
> >                                 } uprobe; /* BPF_PERF_EVENT_UPROBE, BPF_PERF_EVENT_URETPROBE */
> >                                 struct {
> >                                         __aligned_u64 func_name; /* in/out */
> > @@ -6589,14 +6590,17 @@ struct bpf_link_info {
> >                                         __u32 offset; /* offset from func_name */
> >                                         __u64 addr;
> >                                         __u64 missed;
> > +                                       __u64 cookie;
> >                                 } kprobe; /* BPF_PERF_EVENT_KPROBE, BPF_PERF_EVENT_KRETPROBE */
> >                                 struct {
> >                                         __aligned_u64 tp_name;   /* in/out */
> >                                         __u32 name_len;
> > +                                       __u64 cookie;
> >                                 } tracepoint; /* BPF_PERF_EVENT_TRACEPOINT */
> >                                 struct {
> >                                         __u64 config;
> >                                         __u32 type;
> > +                                       __u64 cookie;
> >                                 } event; /* BPF_PERF_EVENT_EVENT */
> >                         };
> >                 } perf_event;
> > --
> > 2.43.0
> >
> 
> 
> -- 
> Regards
> Yafang

  reply	other threads:[~2024-01-19  8:03 UTC|newest]

Thread overview: 19+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-01-18  9:54 [PATCH bpf-next 0/8] bpf: Add cookies retrieval for perf/kprobe multi links Jiri Olsa
2024-01-18  9:54 ` [PATCH bpf-next 1/8] bpf: Add cookie to perf_event bpf_link_info records Jiri Olsa
2024-01-18 12:24   ` Yafang Shao
2024-01-19  8:03     ` Jiri Olsa [this message]
2024-01-18  9:54 ` [PATCH bpf-next 2/8] bpf: Store cookies in kprobe_multi bpf_link_info data Jiri Olsa
2024-01-18 13:21   ` Yafang Shao
2024-01-18  9:54 ` [PATCH bpf-next 3/8] bpftool: Fix wrong free call in do_show_link Jiri Olsa
2024-01-18 12:29   ` Yafang Shao
2024-01-18 17:51     ` Quentin Monnet
2024-01-18  9:54 ` [PATCH bpf-next 4/8] selftests/bpf: Add cookies check for kprobe_multi fill_link_info test Jiri Olsa
2024-01-18  9:54 ` [PATCH bpf-next 5/8] selftests/bpf: Add cookies check for perf_event " Jiri Olsa
2024-01-18  9:54 ` [PATCH bpf-next 6/8] selftests/bpf: Add fill_link_info test for perf event Jiri Olsa
2024-01-18  9:54 ` [PATCH bpf-next 7/8] bpftool: Display cookie for perf event link probes Jiri Olsa
2024-01-18 17:51   ` Quentin Monnet
2024-01-18  9:54 ` [PATCH bpf-next 8/8] bpftool: Display cookie for kprobe multi link Jiri Olsa
2024-01-18 17:51   ` Quentin Monnet
2024-01-19  8:03     ` Jiri Olsa
2024-01-18 12:42 ` [PATCH bpf-next 0/8] bpf: Add cookies retrieval for perf/kprobe multi links Yafang Shao
2024-01-19  8:03   ` Jiri Olsa

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=Zaosxtg3Ko7ttJz1@krava \
    --to=olsajiri@gmail.com \
    --cc=andrii@kernel.org \
    --cc=ast@kernel.org \
    --cc=bpf@vger.kernel.org \
    --cc=daniel@iogearbox.net \
    --cc=haoluo@google.com \
    --cc=john.fastabend@gmail.com \
    --cc=kafai@fb.com \
    --cc=kpsingh@chromium.org \
    --cc=laoar.shao@gmail.com \
    --cc=quentin@isovalent.com \
    --cc=sdf@google.com \
    --cc=songliubraving@fb.com \
    --cc=yhs@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: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.