All of lore.kernel.org
 help / color / mirror / Atom feed
From: "Daniel T. Lee" <danieltimlee@gmail.com>
To: Andrii Nakryiko <andrii.nakryiko@gmail.com>
Cc: "Daniel Borkmann" <daniel@iogearbox.net>,
	"Alexei Starovoitov" <ast@kernel.org>,
	"Andrii Nakryiko" <andrii@kernel.org>, brakmo <brakmo@fb.com>,
	"Jesper Dangaard Brouer" <brouer@redhat.com>,
	"Lorenzo Bianconi" <lorenzo@kernel.org>,
	"David Ahern" <dsa@cumulusnetworks.com>,
	"Yonghong Song" <yhs@fb.com>,
	"Toke Høiland-Jørgensen" <toke@redhat.com>,
	"Ira Weiny" <ira.weiny@intel.com>, "Thomas Graf" <tgraf@suug.ch>,
	"Jakub Kicinski" <kuba@kernel.org>,
	"Martin KaFai Lau" <kafai@fb.com>,
	"John Fastabend" <john.fastabend@gmail.com>,
	bpf <bpf@vger.kernel.org>, Networking <netdev@vger.kernel.org>,
	Xdp <xdp-newbies@vger.kernel.org>
Subject: Re: [PATCH bpf-next 4/9] samples: bpf: refactor task_fd_query program with libbpf
Date: Wed, 18 Nov 2020 12:19:17 +0900	[thread overview]
Message-ID: <CAEKGpzj-4X+OZNmjM+2ZJ+R_k=c_bNBTwiSfsXp2BQ4zV9YE5g@mail.gmail.com> (raw)
In-Reply-To: <CAEf4BzaQOfGOvGnzqGRoQmnysoWZrEo=ZBS4RreV3OfcKB3uQQ@mail.gmail.com>

On Wed, Nov 18, 2020 at 11:58 AM Andrii Nakryiko
<andrii.nakryiko@gmail.com> wrote:
>
> On Tue, Nov 17, 2020 at 6:57 AM Daniel T. Lee <danieltimlee@gmail.com> wrote:
> >
> > This commit refactors the existing kprobe program with libbpf bpf
> > loader. To attach bpf program, this uses generic bpf_program__attach()
> > approach rather than using bpf_load's load_bpf_file().
> >
> > To attach bpf to perf_event, instead of using previous ioctl method,
> > this commit uses bpf_program__attach_perf_event since it manages the
> > enable of perf_event and attach of BPF programs to it, which is much
> > more intuitive way to achieve.
> >
> > Also, explicit close(fd) has been removed since event will be closed
> > inside bpf_link__destroy() automatically.
> >
> > DEBUGFS macro from trace_helpers has been used to control uprobe events.
> > Furthermore, to prevent conflict of same named uprobe events, O_TRUNC
> > flag has been used to clear 'uprobe_events' interface.
> >
> > Signed-off-by: Daniel T. Lee <danieltimlee@gmail.com>
> > ---
> >  samples/bpf/Makefile             |   2 +-
> >  samples/bpf/task_fd_query_user.c | 101 ++++++++++++++++++++++---------
> >  2 files changed, 74 insertions(+), 29 deletions(-)
> >
>
> [...]
>
> >  static int test_debug_fs_uprobe(char *binary_path, long offset, bool is_return)
> >  {
> > +       char buf[256], event_alias[sizeof("test_1234567890")];
> >         const char *event_type = "uprobe";
> >         struct perf_event_attr attr = {};
> > -       char buf[256], event_alias[sizeof("test_1234567890")];
> >         __u64 probe_offset, probe_addr;
> >         __u32 len, prog_id, fd_type;
> > -       int err, res, kfd, efd;
> > +       int err = -1, res, kfd, efd;
> > +       struct bpf_link *link;
> >         ssize_t bytes;
> >
> > -       snprintf(buf, sizeof(buf), "/sys/kernel/debug/tracing/%s_events",
> > -                event_type);
> > -       kfd = open(buf, O_WRONLY | O_APPEND, 0);
> > +       snprintf(buf, sizeof(buf), DEBUGFS "%s_events", event_type);
> > +       kfd = open(buf, O_WRONLY | O_TRUNC, 0);
>
> O_TRUNC will also remove other events, created by users. Not a great
> experience. Let's leave the old behavior?
>

The reason why I used O_TRUNC is, it gets conflict error during tests.
I'm not sure if it is a bug of ftrace uprobes_events or not, but seems adding
same name of uprobe_events with another type seems not working.
(adding uretprobes after uprobes returns an error)

    samples/bpf # echo 'p:uprobes/test_500836 ./task_fd_query:0x3d80'
>> /sys/kernel/debug/tracing/uprobe_events
    samples/bpf # cat /sys/kernel/debug/tracing/uprobe_events
     p:uprobes/test_500836 ./task_fd_query:0x0000000000003d80
    samples/bpf# echo 'r:uprobes/test_500836 ./task_fd_query:0x3d80'
>> /sys/kernel/debug/tracing/uprobe_events
     bash: echo: write error: File exists

Since this gets error, I've just truncated on every open of this interface.

> >         CHECK_PERROR_RET(kfd < 0);
> >
> >         res = snprintf(event_alias, sizeof(event_alias), "test_%d", getpid());
> > @@ -240,8 +252,8 @@ static int test_debug_fs_uprobe(char *binary_path, long offset, bool is_return)
> >         close(kfd);
> >         kfd = -1;
> >
> > -       snprintf(buf, sizeof(buf), "/sys/kernel/debug/tracing/events/%ss/%s/id",
> > -                event_type, event_alias);
> > +       snprintf(buf, sizeof(buf), DEBUGFS "events/%ss/%s/id", event_type,
>
> I'd leave the string verbatim here (and above), I think it's better
> that way and easier to figure out what's written where. And then no
> need to expose DEBUGFS.
>

Sounds great. I'll keep the string path as it was.

> > +                event_alias);
> >         efd = open(buf, O_RDONLY, 0);
> >         CHECK_PERROR_RET(efd < 0);
> >
>
> [...]



-- 
Best,
Daniel T. Lee

  reply	other threads:[~2020-11-18  3:19 UTC|newest]

Thread overview: 32+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-11-17 14:56 [PATCH bpf-next 0/9] bpf: remove bpf_load loader completely Daniel T. Lee
2020-11-17 14:56 ` [PATCH bpf-next 1/9] selftests: bpf: move tracing helpers to trace_helper Daniel T. Lee
2020-11-18  1:19   ` Martin KaFai Lau
2020-11-18  2:44     ` Daniel T. Lee
2020-11-18  1:58   ` Andrii Nakryiko
2020-11-18  2:54     ` Daniel T. Lee
2020-11-18  3:04       ` Andrii Nakryiko
2020-11-17 14:56 ` [PATCH bpf-next 2/9] samples: bpf: refactor hbm program with libbpf Daniel T. Lee
2020-11-18  2:10   ` Martin KaFai Lau
2020-11-18  9:31     ` Daniel T. Lee
2020-11-17 14:56 ` [PATCH bpf-next 3/9] samples: bpf: refactor test_cgrp2_sock2 " Daniel T. Lee
2020-11-18  3:02   ` Andrii Nakryiko
2020-11-18  3:21     ` Daniel T. Lee
2020-11-18  5:58   ` Martin KaFai Lau
2020-11-18  9:03     ` Daniel T. Lee
2020-11-17 14:56 ` [PATCH bpf-next 4/9] samples: bpf: refactor task_fd_query " Daniel T. Lee
2020-11-18  2:58   ` Andrii Nakryiko
2020-11-18  3:19     ` Daniel T. Lee [this message]
2020-11-18  6:15   ` Martin KaFai Lau
2020-11-17 14:56 ` [PATCH bpf-next 5/9] samples: bpf: refactor ibumad " Daniel T. Lee
2020-11-18  2:52   ` Andrii Nakryiko
2020-11-18  3:05     ` Daniel T. Lee
2020-11-18  3:10       ` Andrii Nakryiko
2020-11-18  5:04         ` Daniel T. Lee
2020-11-17 14:56 ` [PATCH bpf-next 6/9] samples: bpf: refactor test_overhead " Daniel T. Lee
2020-11-18  2:45   ` Andrii Nakryiko
2020-11-17 14:56 ` [PATCH bpf-next 7/9] samples: bpf: fix lwt_len_hist reusing previous BPF map Daniel T. Lee
2020-11-17 14:56 ` [PATCH bpf-next 8/9] samples: bpf: remove unused trace_helper and bpf_load from Makefile Daniel T. Lee
2020-11-17 14:56 ` [PATCH bpf-next 9/9] samples: bpf: remove bpf_load loader completely Daniel T. Lee
2020-11-17 16:12   ` Jesper Dangaard Brouer
2020-11-18  2:48   ` Andrii Nakryiko
2020-11-18  2:57     ` Daniel T. Lee

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='CAEKGpzj-4X+OZNmjM+2ZJ+R_k=c_bNBTwiSfsXp2BQ4zV9YE5g@mail.gmail.com' \
    --to=danieltimlee@gmail.com \
    --cc=andrii.nakryiko@gmail.com \
    --cc=andrii@kernel.org \
    --cc=ast@kernel.org \
    --cc=bpf@vger.kernel.org \
    --cc=brakmo@fb.com \
    --cc=brouer@redhat.com \
    --cc=daniel@iogearbox.net \
    --cc=dsa@cumulusnetworks.com \
    --cc=ira.weiny@intel.com \
    --cc=john.fastabend@gmail.com \
    --cc=kafai@fb.com \
    --cc=kuba@kernel.org \
    --cc=lorenzo@kernel.org \
    --cc=netdev@vger.kernel.org \
    --cc=tgraf@suug.ch \
    --cc=toke@redhat.com \
    --cc=xdp-newbies@vger.kernel.org \
    --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.