bpf.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Andrii Nakryiko <andrii.nakryiko@gmail.com>
To: Jiri Olsa <jolsa@redhat.com>
Cc: Florent Revest <revest@chromium.org>,
	Jiri Olsa <jolsa@kernel.org>, Alexei Starovoitov <ast@kernel.org>,
	Daniel Borkmann <daniel@iogearbox.net>,
	Networking <netdev@vger.kernel.org>, bpf <bpf@vger.kernel.org>,
	Yonghong Song <yhs@fb.com>, Martin KaFai Lau <kafai@fb.com>,
	David Miller <davem@redhat.com>,
	John Fastabend <john.fastabend@gmail.com>,
	Jesper Dangaard Brouer <hawk@kernel.org>,
	Wenbo Zhang <ethercflow@gmail.com>,
	KP Singh <kpsingh@chromium.org>, Andrii Nakryiko <andriin@fb.com>,
	bgregg@netflix.com, Al Viro <viro@zeniv.linux.org.uk>
Subject: Re: [PATCH 2/3] bpf: Add d_path helper
Date: Sun, 5 Apr 2020 19:49:17 -0700	[thread overview]
Message-ID: <CAEf4BzZziVPm_WDvu8XmZWcvzY-M3_V3niYv3=AZ_=k+WzAr=A@mail.gmail.com> (raw)
In-Reply-To: <20200403090158.GE2784502@krava>

On Fri, Apr 3, 2020 at 2:03 AM Jiri Olsa <jolsa@redhat.com> wrote:
>
> On Thu, Apr 02, 2020 at 04:02:55PM +0200, Florent Revest wrote:
> > On Wed, 2020-04-01 at 13:09 +0200, Jiri Olsa wrote:
> > > + * int bpf_d_path(struct path *path, char *buf, u32 sz)
> > > + * Description
> > > + *         Return full path for given 'struct path' object, which
> > > + *         needs to be the kernel BTF 'path' object. The path is
> > > + *         returned in buffer provided 'buf' of size 'sz'.
> > > + *
> > > + * Return
> > > + *         length of returned string on success, or a negative
> > > + *         error in case of failure
> > > + *
> >
> > You might want to add that d_path is ambiguous since it can add
> > " (deleted)" at the end of your path and you don't know whether this is
> > actually part of the file path or not. :)
>
> right
>
> >
> > > +BPF_CALL_3(bpf_d_path, struct path *, path, char *, buf, u32, sz)
> > > +{
> > > +   char *p = d_path(path, buf, sz - 1);
> >
> > I am curious why you'd use sz - 1 here? In my experience, d_path's
> > output is 0 limited so you shouldn't need to keep an extra byte for
> > that (if that was the intention here).
> >
> > > +   int len;
> > > +
> > > +   if (IS_ERR(p)) {
> > > +           len = PTR_ERR(p);
> > > +   } else {
> > > +           len = strlen(p);
> > > +           if (len && p != buf) {
> > > +                   memmove(buf, p, len);
> >
> > Have you considered returning the offset within buf instead and let the
> > BPF program do pointer arithmetics to find the beginning of the string?
>
> we could do that.. I was following some other user of d_path,
> which I can't find at the moment ;-) I'll check

This would make it hard to support variable-length data encoding and
sending it over perf_buffer, because it would prevent back-to-back
"stitching" of multiple strings compactly in output buffer. So I think
current approach is preferable.

>
> >
> > > +                   buf[len] = 0;
> >
> > If my previous comment about sz - 1 is true, then this wouldn't be
> > necessary, you could just use memmove with len + 1.
>
> hum, you might be right, I'll check on this
>
> thanks,
> jirka
>
> >
> > > +           }
> > > +   }
> > > +
> > > +   return len;
> > > +}
> >
>

  reply	other threads:[~2020-04-06  2:49 UTC|newest]

Thread overview: 20+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-04-01 11:09 [RFC 0/3] bpf: Add d_path helper Jiri Olsa
2020-04-01 11:09 ` [PATCH 1/3] bpf: Add support to check if BTF object is nested in another object Jiri Olsa
2020-04-07  1:16   ` Alexei Starovoitov
2020-04-07  9:37     ` Jiri Olsa
2020-04-01 11:09 ` [PATCH 2/3] bpf: Add d_path helper Jiri Olsa
2020-04-02 14:02   ` Florent Revest
2020-04-03  9:01     ` Jiri Olsa
2020-04-06  2:49       ` Andrii Nakryiko [this message]
2020-04-01 11:09 ` [PATCH 3/3] selftests/bpf: Add test for " Jiri Olsa
2020-04-02 14:03 ` [RFC 0/3] bpf: Add " Florent Revest
2020-04-03  8:55   ` Jiri Olsa
2020-04-02 14:21 ` Al Viro
2020-04-03  9:08   ` Jiri Olsa
2020-04-06  3:16     ` Al Viro
2020-04-06  9:09       ` Jiri Olsa
2020-04-06 12:47         ` Al Viro
2020-04-07  1:10         ` Alexei Starovoitov
2020-04-07  8:53           ` Jiri Olsa
2020-04-07  9:27           ` KP Singh
2020-04-07  9:45             ` 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='CAEf4BzZziVPm_WDvu8XmZWcvzY-M3_V3niYv3=AZ_=k+WzAr=A@mail.gmail.com' \
    --to=andrii.nakryiko@gmail.com \
    --cc=andriin@fb.com \
    --cc=ast@kernel.org \
    --cc=bgregg@netflix.com \
    --cc=bpf@vger.kernel.org \
    --cc=daniel@iogearbox.net \
    --cc=davem@redhat.com \
    --cc=ethercflow@gmail.com \
    --cc=hawk@kernel.org \
    --cc=john.fastabend@gmail.com \
    --cc=jolsa@kernel.org \
    --cc=jolsa@redhat.com \
    --cc=kafai@fb.com \
    --cc=kpsingh@chromium.org \
    --cc=netdev@vger.kernel.org \
    --cc=revest@chromium.org \
    --cc=viro@zeniv.linux.org.uk \
    --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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).