From: Anton Protopopov <aspsk@isovalent.com>
To: Andrii Nakryiko <andrii.nakryiko@gmail.com>
Cc: bpf@vger.kernel.org
Subject: Re: [PATCH v5 bpf-next 4/7] bpf: add fd_array_cnt attribute for prog_load
Date: Sat, 14 Dec 2024 05:12:05 +0000 [thread overview]
Message-ID: <Z10TpWbexd4JDGps@eis> (raw)
In-Reply-To: <CAEf4BzYqRyNCb5WB7JPA_N597LnpLm3e0ykPTP7m1eco_wyYpQ@mail.gmail.com>
On 24/12/13 02:18PM, Andrii Nakryiko wrote:
> On Fri, Dec 13, 2024 at 5:08 AM Anton Protopopov <aspsk@isovalent.com> wrote:
> >
> > The fd_array attribute of the BPF_PROG_LOAD syscall may contain a set
> > of file descriptors: maps or btfs. This field was introduced as a
> > sparse array. Introduce a new attribute, fd_array_cnt, which, if
> > present, indicates that the fd_array is a continuous array of the
> > corresponding length.
> >
> > If fd_array_cnt is non-zero, then every map in the fd_array will be
> > bound to the program, as if it was used by the program. This
> > functionality is similar to the BPF_PROG_BIND_MAP syscall, but such
> > maps can be used by the verifier during the program load.
> >
> > Signed-off-by: Anton Protopopov <aspsk@isovalent.com>
> > ---
> > include/uapi/linux/bpf.h | 10 ++++
> > kernel/bpf/syscall.c | 2 +-
> > kernel/bpf/verifier.c | 106 ++++++++++++++++++++++++++++-----
> > tools/include/uapi/linux/bpf.h | 10 ++++
> > 4 files changed, 112 insertions(+), 16 deletions(-)
> >
>
> [...]
>
> > int bpf_check(struct bpf_prog **prog, union bpf_attr *attr, bpfptr_t uattr, __u32 uattr_size)
> > {
> > u64 start_time = ktime_get_ns();
> > @@ -22881,7 +22954,6 @@ int bpf_check(struct bpf_prog **prog, union bpf_attr *attr, bpfptr_t uattr, __u3
> > env->insn_aux_data[i].orig_idx = i;
> > env->prog = *prog;
> > env->ops = bpf_verifier_ops[env->prog->type];
> > - env->fd_array = make_bpfptr(attr->fd_array, uattr.is_kernel);
> >
> > env->allow_ptr_leaks = bpf_allow_ptr_leaks(env->prog->aux->token);
> > env->allow_uninit_stack = bpf_allow_uninit_stack(env->prog->aux->token);
> > @@ -22904,6 +22976,10 @@ int bpf_check(struct bpf_prog **prog, union bpf_attr *attr, bpfptr_t uattr, __u3
> > if (ret)
> > goto err_unlock;
> >
> > + ret = process_fd_array(env, attr, uattr);
> > + if (ret)
> > + goto err_release_maps;
>
> I think this should be goto skip_full_check, so that we can finalize
> verifier log (you do log an error if fd_array FD is invalid, right?)
Right... Thanks for catching it!
> If this is the only issue, this can probably be just patched up while applying.
>
> > +
> > mark_verifier_state_clean(env);
> >
> > if (IS_ERR(btf_vmlinux)) {
> > diff --git a/tools/include/uapi/linux/bpf.h b/tools/include/uapi/linux/bpf.h
> > index 4162afc6b5d0..2acf9b336371 100644
> > --- a/tools/include/uapi/linux/bpf.h
> > +++ b/tools/include/uapi/linux/bpf.h
> > @@ -1573,6 +1573,16 @@ union bpf_attr {
> > * If provided, prog_flags should have BPF_F_TOKEN_FD flag set.
> > */
> > __s32 prog_token_fd;
> > + /* The fd_array_cnt can be used to pass the length of the
> > + * fd_array array. In this case all the [map] file descriptors
> > + * passed in this array will be bound to the program, even if
> > + * the maps are not referenced directly. The functionality is
> > + * similar to the BPF_PROG_BIND_MAP syscall, but maps can be
> > + * used by the verifier during the program load. If provided,
> > + * then the fd_array[0,...,fd_array_cnt-1] is expected to be
> > + * continuous.
> > + */
> > + __u32 fd_array_cnt;
> > };
> >
> > struct { /* anonymous struct used by BPF_OBJ_* commands */
> > --
> > 2.34.1
> >
> >
next prev parent reply other threads:[~2024-12-14 5:10 UTC|newest]
Thread overview: 12+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-12-13 13:09 [PATCH v5 bpf-next 0/7] Add fd_array_cnt attribute for BPF_PROG_LOAD Anton Protopopov
2024-12-13 13:09 ` [PATCH v5 bpf-next 1/7] bpf: add a __btf_get_by_fd helper Anton Protopopov
2024-12-13 13:09 ` [PATCH v5 bpf-next 2/7] bpf: move map/prog compatibility checks Anton Protopopov
2024-12-13 13:09 ` [PATCH v5 bpf-next 3/7] bpf: refactor check_pseudo_btf_id Anton Protopopov
2024-12-13 22:17 ` Andrii Nakryiko
2024-12-13 13:09 ` [PATCH v5 bpf-next 4/7] bpf: add fd_array_cnt attribute for prog_load Anton Protopopov
2024-12-13 22:18 ` Andrii Nakryiko
2024-12-14 5:12 ` Anton Protopopov [this message]
2024-12-13 13:09 ` [PATCH v5 bpf-next 5/7] libbpf: prog load: allow to use fd_array_cnt Anton Protopopov
2024-12-13 13:09 ` [PATCH v5 bpf-next 6/7] selftests/bpf: Add tests for fd_array_cnt Anton Protopopov
2024-12-13 13:09 ` [PATCH v5 bpf-next 7/7] selftest/bpf: replace magic constants by macros Anton Protopopov
2024-12-13 23:10 ` [PATCH v5 bpf-next 0/7] Add fd_array_cnt attribute for BPF_PROG_LOAD patchwork-bot+netdevbpf
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=Z10TpWbexd4JDGps@eis \
--to=aspsk@isovalent.com \
--cc=andrii.nakryiko@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;
as well as URLs for NNTP newsgroup(s).