linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Roberto Sassu <roberto.sassu@huawei.com>
To: Andrii Nakryiko <andrii.nakryiko@gmail.com>,
	Joe Burton <jevburton.kernel@gmail.com>
Cc: Andrii Nakryiko <andrii@kernel.org>,
	Alexei Starovoitov <ast@kernel.org>,
	Daniel Borkmann <daniel@iogearbox.net>,
	Martin KaFai Lau <martin.lau@linux.dev>,
	Song Liu <song@kernel.org>, Yonghong Song <yhs@fb.com>,
	John Fastabend <john.fastabend@gmail.com>,
	KP Singh <kpsingh@kernel.org>,
	Stanislav Fomichev <sdf@google.com>, Hao Luo <haoluo@google.com>,
	Jiri Olsa <jolsa@kernel.org>, bpf <bpf@vger.kernel.org>,
	open list <linux-kernel@vger.kernel.org>,
	Joe Burton <jevburton@google.com>
Subject: RE: [PATCH v2 bpf-next] libbpf: Add bpf_obj_get_opts()
Date: Thu, 28 Jul 2022 07:58:44 +0000	[thread overview]
Message-ID: <03011a0506e8474db73c8c1fa9ec0786@huawei.com> (raw)
In-Reply-To: <CAEf4BzbWpQS6js5LfS80PkqwDwcLc+NgzfqqUTG-CkLP16shCg@mail.gmail.com>

> From: Andrii Nakryiko [mailto:andrii.nakryiko@gmail.com]
> Sent: Thursday, July 28, 2022 1:03 AM
> On Tue, Jul 19, 2022 at 12:40 PM Joe Burton <jevburton.kernel@gmail.com>
> wrote:
> >
> > From: Joe Burton <jevburton@google.com>
> >
> > Add an extensible variant of bpf_obj_get() capable of setting the
> > `file_flags` parameter.
> >
> > This parameter is needed to enable unprivileged access to BPF maps.
> > Without a method like this, users must manually make the syscall.
> >
> > Signed-off-by: Joe Burton <jevburton@google.com>
> > ---
> >  tools/lib/bpf/bpf.c      | 10 ++++++++++
> >  tools/lib/bpf/bpf.h      |  9 +++++++++
> >  tools/lib/bpf/libbpf.map |  1 +
> >  3 files changed, 20 insertions(+)
> >
> 
> I agree that bpf_obj_get_opts should be separate from bpf_get_fd_opts.
> Just because both currently have file_flags in them doesn't mean that
> they should/will always stay in sync. So two separate opts for two
> separate APIs makes sense to me.
> 
> So I'd accept this patch, but please see a few small things below and
> send v3. Thanks!

Should map_parse_fds() accept two opts, or just the flags
to be set on locally-defined variables?

Thanks

Roberto

> > diff --git a/tools/lib/bpf/bpf.c b/tools/lib/bpf/bpf.c
> > index 5eb0df90eb2b..5acb0e8bd13c 100644
> > --- a/tools/lib/bpf/bpf.c
> > +++ b/tools/lib/bpf/bpf.c
> > @@ -578,12 +578,22 @@ int bpf_obj_pin(int fd, const char *pathname)
> >  }
> >
> >  int bpf_obj_get(const char *pathname)
> > +{
> > +       LIBBPF_OPTS(bpf_obj_get_opts, opts);
> 
> if you were doing it this way, here should be an empty line. But
> really you can/should just pass NULL instead of opts in this case.
> 
> > +       return bpf_obj_get_opts(pathname, &opts);
> > +}
> > +
> > +int bpf_obj_get_opts(const char *pathname, const struct bpf_obj_get_opts
> *opts)
> >  {
> >         union bpf_attr attr;
> >         int fd;
> >
> > +       if (!OPTS_VALID(opts, bpf_obj_get_opts))
> > +               return libbpf_err(-EINVAL);
> > +
> >         memset(&attr, 0, sizeof(attr));
> >         attr.pathname = ptr_to_u64((void *)pathname);
> > +       attr.file_flags = OPTS_GET(opts, file_flags, 0);
> >
> >         fd = sys_bpf_fd(BPF_OBJ_GET, &attr, sizeof(attr));
> >         return libbpf_err_errno(fd);
> > diff --git a/tools/lib/bpf/bpf.h b/tools/lib/bpf/bpf.h
> > index 88a7cc4bd76f..f31b493b5f9a 100644
> > --- a/tools/lib/bpf/bpf.h
> > +++ b/tools/lib/bpf/bpf.h
> > @@ -270,8 +270,17 @@ LIBBPF_API int bpf_map_update_batch(int fd, const
> void *keys, const void *values
> >                                     __u32 *count,
> >                                     const struct bpf_map_batch_opts *opts);
> >
> > +struct bpf_obj_get_opts {
> > +       size_t sz; /* size of this struct for forward/backward compatibility */
> > +
> > +       __u32 file_flags;
> 
> please add size_t :0; to avoid non-zero-initialized padding  (we do it
> in a lot of other opts structs)
> 
> 
> > +};
> > +#define bpf_obj_get_opts__last_field file_flags
> > +
> >  LIBBPF_API int bpf_obj_pin(int fd, const char *pathname);
> >  LIBBPF_API int bpf_obj_get(const char *pathname);
> > +LIBBPF_API int bpf_obj_get_opts(const char *pathname,
> > +                               const struct bpf_obj_get_opts *opts);
> >
> >  struct bpf_prog_attach_opts {
> >         size_t sz; /* size of this struct for forward/backward compatibility */
> > diff --git a/tools/lib/bpf/libbpf.map b/tools/lib/bpf/libbpf.map
> > index 0625adb9e888..119e6e1ea7f1 100644
> > --- a/tools/lib/bpf/libbpf.map
> > +++ b/tools/lib/bpf/libbpf.map
> > @@ -355,6 +355,7 @@ LIBBPF_0.8.0 {
> >
> >  LIBBPF_1.0.0 {
> >         global:
> > +               bpf_obj_get_opts;
> >                 bpf_prog_query_opts;
> >                 bpf_program__attach_ksyscall;
> >                 btf__add_enum64;
> > --
> > 2.37.0.170.g444d1eabd0-goog
> >

  reply	other threads:[~2022-07-28  7:58 UTC|newest]

Thread overview: 18+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-07-19 19:40 [PATCH v2 bpf-next] libbpf: Add bpf_obj_get_opts() Joe Burton
2022-07-19 20:40 ` Stanislav Fomichev
2022-07-20  8:02   ` Roberto Sassu
2022-07-20 15:56     ` Stanislav Fomichev
2022-07-20 22:30       ` Roberto Sassu
2022-07-20 22:38         ` Stanislav Fomichev
2022-07-20 22:44           ` Roberto Sassu
2022-07-20 22:48             ` Stanislav Fomichev
2022-07-20 23:02               ` Roberto Sassu
2022-07-20 23:08                 ` Stanislav Fomichev
2022-07-20 23:12                   ` Roberto Sassu
2022-07-20 23:14                     ` Stanislav Fomichev
2022-07-20 23:17                       ` Roberto Sassu
2022-07-20 23:26                         ` Stanislav Fomichev
2022-07-27 23:02 ` Andrii Nakryiko
2022-07-28  7:58   ` Roberto Sassu [this message]
2022-07-29 18:55     ` Andrii Nakryiko
2022-07-29 20:20   ` Joe Burton

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=03011a0506e8474db73c8c1fa9ec0786@huawei.com \
    --to=roberto.sassu@huawei.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=jevburton.kernel@gmail.com \
    --cc=jevburton@google.com \
    --cc=john.fastabend@gmail.com \
    --cc=jolsa@kernel.org \
    --cc=kpsingh@kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=martin.lau@linux.dev \
    --cc=sdf@google.com \
    --cc=song@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 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).