public inbox for bpf@vger.kernel.org
 help / color / mirror / Atom feed
From: Jiri Olsa <olsajiri@gmail.com>
To: Andrii Nakryiko <andrii.nakryiko@gmail.com>
Cc: Jiri Olsa <olsajiri@gmail.com>, Song Liu <song@kernel.org>,
	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>,
	Yafang Shao <laoar.shao@gmail.com>
Subject: Re: [PATCH bpf-next 3/6] bpf: Add link_info support for uprobe multi link
Date: Thu, 2 Nov 2023 15:58:17 +0100	[thread overview]
Message-ID: <ZUO5CRlYDB8N0dNk@krava> (raw)
In-Reply-To: <CAEf4BzZETCTyAqbBkfL2KvPo8T3ATXsRyj37f9kfVB2d7kj=sg@mail.gmail.com>

On Wed, Nov 01, 2023 at 03:21:42PM -0700, Andrii Nakryiko wrote:
> On Fri, Oct 27, 2023 at 7:30 AM Jiri Olsa <olsajiri@gmail.com> wrote:
> >
> > On Thu, Oct 26, 2023 at 10:55:35AM -0700, Song Liu wrote:
> > > On Wed, Oct 25, 2023 at 1:24 PM Jiri Olsa <jolsa@kernel.org> wrote:
> > > [...]
> 
> [...]
> 
> > >
> > > > +               if (upath_max > PATH_MAX)
> > > > +                       return -E2BIG;
> > >
> > > I don't think we need to fail here. How about we simply do
> > >
> > >    upath_max = min_ut(u32, upath_max, PATH_MAX);
> >
> > ok
> 
> +1, was going to say the same
> 
> >
> > >
> > > > +               buf = kmalloc(upath_max, GFP_KERNEL);
> > > > +               if (!buf)
> > > > +                       return -ENOMEM;
> > > > +               p = d_path(&umulti_link->path, buf, upath_max);
> > > > +               if (IS_ERR(p)) {
> > > > +                       kfree(buf);
> > > > +                       return -ENOSPC;
> > > > +               }
> > > > +               left = copy_to_user(upath, p, buf + upath_max - p);
> > > > +               kfree(buf);
> > > > +               if (left)
> > > > +                       return -EFAULT;
> > > > +       }
> > > > +
> > > > +       if (!uoffsets)
> > > > +               return 0;
> > > > +
> > > > +       if (ucount < umulti_link->cnt)
> > > > +               err = -ENOSPC;
> > > > +       else
> > > > +               ucount = umulti_link->cnt;
> > > > +
> > > > +       for (i = 0; i < ucount; i++) {
> > > > +               if (put_user(umulti_link->uprobes[i].offset, uoffsets + i))
> > > > +                       return -EFAULT;
> > > > +               if (uref_ctr_offsets &&
> > > > +                   put_user(umulti_link->uprobes[i].ref_ctr_offset, uref_ctr_offsets + i))
> > > > +                       return -EFAULT;
> > > > +               if (ucookies &&
> > > > +                   put_user(umulti_link->uprobes[i].cookie, ucookies + i))
> > > > +                       return -EFAULT;
> > >
> > > It feels expensive to put_user() 3x in a loop. Maybe we need a new struct
> > > with offset, ref_ctr_offset, and cookie?
> >
> > good idea, I think we could store offsets/uref_ctr_offsets/cookies
> > together both in kernel and user sapce and use just single put_user
> > call... will check
> >
> 
> hm... only offset is mandatory, and then we can have either cookie or
> ref_ctr_offset or both, so co-locating them in the same struct seems
> inconvenient and unnecessary

yes, using struct seems too complicated because of this

but during attach we could store offsets/ref_ctr_offsets/cookies
in separated arrays (instead of in bpf_uprobe) and just use single
copy_to_user call for each array in here

jirka

  reply	other threads:[~2023-11-02 14:58 UTC|newest]

Thread overview: 33+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-10-25 20:24 [PATCH bpf-next 0/6] bpf: Add link_info support for uprobe multi link Jiri Olsa
2023-10-25 20:24 ` [PATCH bpf-next 1/6] libbpf: Add st_type argument to elf_resolve_syms_offsets function Jiri Olsa
2023-10-26 16:29   ` Song Liu
2023-10-25 20:24 ` [PATCH bpf-next 2/6] bpf: Store ref_ctr_offsets values in bpf_uprobe array Jiri Olsa
2023-10-26 16:31   ` Song Liu
2023-10-27 13:56     ` Jiri Olsa
2023-10-27 14:23       ` Song Liu
2023-11-01 22:21         ` Andrii Nakryiko
2023-10-25 20:24 ` [PATCH bpf-next 3/6] bpf: Add link_info support for uprobe multi link Jiri Olsa
2023-10-26 11:57   ` Yafang Shao
2023-10-27 13:59     ` Jiri Olsa
2023-11-09  8:56       ` Jiri Olsa
2023-10-26 17:55   ` Song Liu
2023-10-27 14:29     ` Jiri Olsa
2023-11-01 22:21       ` Andrii Nakryiko
2023-11-02 14:58         ` Jiri Olsa [this message]
2023-11-02 16:21           ` Andrii Nakryiko
2023-10-30 10:18   ` Quentin Monnet
2023-10-30 21:17     ` Jiri Olsa
2023-11-01 22:21   ` Andrii Nakryiko
2023-11-02 14:43     ` Jiri Olsa
2023-11-02 16:19       ` Andrii Nakryiko
2023-10-25 20:24 ` [PATCH bpf-next 4/6] selftests/bpf: Use bpf_link__destroy in fill_link_info tests Jiri Olsa
2023-10-26 11:41   ` Yafang Shao
2023-10-26 18:00     ` Song Liu
2023-11-01 22:24   ` Andrii Nakryiko
2023-11-02 14:12     ` Jiri Olsa
2023-10-25 20:24 ` [PATCH bpf-next 5/6] selftests/bpf: Add link_info test for uprobe_multi link Jiri Olsa
2023-10-26 18:13   ` Song Liu
2023-11-01 22:27   ` Andrii Nakryiko
2023-10-25 20:24 ` [PATCH bpf-next 6/6] bpftool: Add support to display uprobe_multi links Jiri Olsa
2023-10-26 18:27   ` Song Liu
2023-10-30 10:17   ` Quentin Monnet

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=ZUO5CRlYDB8N0dNk@krava \
    --to=olsajiri@gmail.com \
    --cc=andrii.nakryiko@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=sdf@google.com \
    --cc=song@kernel.org \
    --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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox