BPF List
 help / color / mirror / Atom feed
From: Anton Protopopov <aspsk@isovalent.com>
To: Alexei Starovoitov <alexei.starovoitov@gmail.com>
Cc: bpf <bpf@vger.kernel.org>
Subject: Re: [PATCH v3 bpf-next 4/7] libbpf: prog load: allow to use fd_array_cnt
Date: Tue, 3 Dec 2024 10:23:39 +0000	[thread overview]
Message-ID: <Z07cKx0pEIrk22ye@eis> (raw)
In-Reply-To: <CAADnVQJgYEiMbtPStOwGJLV4Dt1yj98Hy73-FEnDVh6a2be++w@mail.gmail.com>

On 24/12/02 06:34PM, Alexei Starovoitov wrote:
> On Fri, Nov 29, 2024 at 5:29 AM Anton Protopopov <aspsk@isovalent.com> wrote:
> >
> > Add new fd_array_cnt field to bpf_prog_load_opts
> > and pass it in bpf_attr, if set.
> >
> > Signed-off-by: Anton Protopopov <aspsk@isovalent.com>
> > ---
> >  tools/lib/bpf/bpf.c      | 5 +++--
> >  tools/lib/bpf/bpf.h      | 5 ++++-
> >  tools/lib/bpf/features.c | 2 +-
> >  3 files changed, 8 insertions(+), 4 deletions(-)
> >
> > diff --git a/tools/lib/bpf/bpf.c b/tools/lib/bpf/bpf.c
> > index becdfa701c75..0e7f59224936 100644
> > --- a/tools/lib/bpf/bpf.c
> > +++ b/tools/lib/bpf/bpf.c
> > @@ -105,7 +105,7 @@ int sys_bpf_prog_load(union bpf_attr *attr, unsigned int size, int attempts)
> >   */
> >  int probe_memcg_account(int token_fd)
> >  {
> > -       const size_t attr_sz = offsetofend(union bpf_attr, prog_token_fd);
> > +       const size_t attr_sz = offsetofend(union bpf_attr, fd_array_cnt);
> 
> Thankfully this function doesn't set fd_array_cnt below.
> Otherwise the detection of memcg would fail on older kernels.
> Let's avoid people mindlessly adding init of fd_array_cnt here by accident.
> Simply keep this line as-is.
> offsetofend(.., prog_token_fd) is fine.

Ok, thanks, reverted (as with the one you've mentioned below)

> >         struct bpf_insn insns[] = {
> >                 BPF_EMIT_CALL(BPF_FUNC_ktime_get_coarse_ns),
> >                 BPF_EXIT_INSN(),
> > @@ -238,7 +238,7 @@ int bpf_prog_load(enum bpf_prog_type prog_type,
> >                   const struct bpf_insn *insns, size_t insn_cnt,
> >                   struct bpf_prog_load_opts *opts)
> >  {
> > -       const size_t attr_sz = offsetofend(union bpf_attr, prog_token_fd);
> > +       const size_t attr_sz = offsetofend(union bpf_attr, fd_array_cnt);
> >         void *finfo = NULL, *linfo = NULL;
> >         const char *func_info, *line_info;
> >         __u32 log_size, log_level, attach_prog_fd, attach_btf_obj_fd;
> > @@ -311,6 +311,7 @@ int bpf_prog_load(enum bpf_prog_type prog_type,
> >         attr.line_info_cnt = OPTS_GET(opts, line_info_cnt, 0);
> >
> >         attr.fd_array = ptr_to_u64(OPTS_GET(opts, fd_array, NULL));
> > +       attr.fd_array_cnt = OPTS_GET(opts, fd_array_cnt, 0);
> >
> >         if (log_level) {
> >                 attr.log_buf = ptr_to_u64(log_buf);
> > diff --git a/tools/lib/bpf/bpf.h b/tools/lib/bpf/bpf.h
> > index a4a7b1ad1b63..435da95d2058 100644
> > --- a/tools/lib/bpf/bpf.h
> > +++ b/tools/lib/bpf/bpf.h
> > @@ -107,9 +107,12 @@ struct bpf_prog_load_opts {
> >          */
> >         __u32 log_true_size;
> >         __u32 token_fd;
> > +
> > +       /* if set, provides the length of fd_array */
> > +       __u32 fd_array_cnt;
> >         size_t :0;
> >  };
> > -#define bpf_prog_load_opts__last_field token_fd
> > +#define bpf_prog_load_opts__last_field fd_array_cnt
> >
> >  LIBBPF_API int bpf_prog_load(enum bpf_prog_type prog_type,
> >                              const char *prog_name, const char *license,
> > diff --git a/tools/lib/bpf/features.c b/tools/lib/bpf/features.c
> > index 760657f5224c..5afc9555d9ac 100644
> > --- a/tools/lib/bpf/features.c
> > +++ b/tools/lib/bpf/features.c
> > @@ -22,7 +22,7 @@ int probe_fd(int fd)
> >
> >  static int probe_kern_prog_name(int token_fd)
> >  {
> > -       const size_t attr_sz = offsetofend(union bpf_attr, prog_token_fd);
> > +       const size_t attr_sz = offsetofend(union bpf_attr, fd_array_cnt);
> 
> Same here. Don't change it.

  reply	other threads:[~2024-12-03 10:21 UTC|newest]

Thread overview: 14+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-11-29 13:28 [PATCH v3 bpf-next 0/7] Add fd_array_cnt attribute for BPF_PROG_LOAD Anton Protopopov
2024-11-29 13:28 ` [PATCH v3 bpf-next 1/7] bpf: add a __btf_get_by_fd helper Anton Protopopov
2024-11-29 13:28 ` [PATCH v3 bpf-next 2/7] bpf: move map/prog compatibility checks Anton Protopopov
2024-11-29 13:28 ` [PATCH v3 bpf-next 3/7] bpf: add fd_array_cnt attribute for prog_load Anton Protopopov
2024-12-03  2:26   ` Alexei Starovoitov
2024-12-03 10:31     ` Anton Protopopov
2024-11-29 13:28 ` [PATCH v3 bpf-next 4/7] libbpf: prog load: allow to use fd_array_cnt Anton Protopopov
2024-12-03  2:34   ` Alexei Starovoitov
2024-12-03 10:23     ` Anton Protopopov [this message]
2024-11-29 13:28 ` [PATCH v3 bpf-next 5/7] selftests/bpf: Add tests for fd_array_cnt Anton Protopopov
2024-12-03  2:37   ` Alexei Starovoitov
2024-12-03 10:25     ` Anton Protopopov
2024-11-29 13:28 ` [PATCH v3 bpf-next 6/7] bpf: fix potential error return Anton Protopopov
2024-11-29 13:28 ` [PATCH v3 bpf-next 7/7] selftest/bpf: replace magic constants by macros Anton Protopopov

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=Z07cKx0pEIrk22ye@eis \
    --to=aspsk@isovalent.com \
    --cc=alexei.starovoitov@gmail.com \
    --cc=bpf@vger.kernel.org \
    /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