netdev.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Andrii Nakryiko <andrii.nakryiko@gmail.com>
To: Daniel Borkmann <daniel@iogearbox.net>
Cc: bpf@vger.kernel.org, netdev@vger.kernel.org,
	martin.lau@kernel.org,  razor@blackwall.org, ast@kernel.org,
	andrii@kernel.org,  john.fastabend@gmail.com
Subject: Re: [PATCH bpf-next 2/8] meta, bpf: Add bpf link support for meta device
Date: Wed, 27 Sep 2023 17:12:10 -0700	[thread overview]
Message-ID: <CAEf4BzbBArMVTHqiS0zmgnFr0rBm-ZAXFs9dkffa7-0Axw2XSA@mail.gmail.com> (raw)
In-Reply-To: <20230926055913.9859-3-daniel@iogearbox.net>

On Mon, Sep 25, 2023 at 10:59 PM Daniel Borkmann <daniel@iogearbox.net> wrote:
>
> This adds BPF link support for meta device (BPF_LINK_TYPE_META). Similar
> as with tcx or XDP, the BPF link for meta contains the device.
>
> The bpf_mprog API has been reused for its implementation. For details, see
> also commit e420bed0250 ("bpf: Add fd-based tcx multi-prog infra with link
> support").
>
> This is now the second user of bpf_mprog after tcx, and in meta case the
> implementation is also a bit more straight forward since it does not need
> to deal with miniq.
>
> The UAPI extensions for the BPF_LINK_CREATE command are similar as for tcx,
> that is, relative_{fd,id} and expected_revision.
>
> Signed-off-by: Daniel Borkmann <daniel@iogearbox.net>
> ---
>  drivers/net/meta.c             | 211 ++++++++++++++++++++++++++++++++-
>  include/net/meta.h             |   7 ++
>  include/uapi/linux/bpf.h       |  11 ++
>  kernel/bpf/syscall.c           |   2 +-
>  tools/include/uapi/linux/bpf.h |  11 ++
>  5 files changed, 240 insertions(+), 2 deletions(-)
>

[...]

> diff --git a/include/net/meta.h b/include/net/meta.h
> index 20fc61d05970..f1abe1d6d02d 100644
> --- a/include/net/meta.h
> +++ b/include/net/meta.h
> @@ -7,6 +7,7 @@
>
>  #ifdef CONFIG_META
>  int meta_prog_attach(const union bpf_attr *attr, struct bpf_prog *prog);
> +int meta_link_attach(const union bpf_attr *attr, struct bpf_prog *prog);
>  int meta_prog_detach(const union bpf_attr *attr, struct bpf_prog *prog);
>  int meta_prog_query(const union bpf_attr *attr, union bpf_attr __user *uattr);
>  #else
> @@ -16,6 +17,12 @@ static inline int meta_prog_attach(const union bpf_attr *attr,
>         return -EINVAL;
>  }
>
> +static inline int meta_link_attach(const union bpf_attr *attr,
> +                                  struct bpf_prog *prog)
> +{
> +       return -EINVAL;
> +}
> +
>  static inline int meta_prog_detach(const union bpf_attr *attr,
>                                    struct bpf_prog *prog)
>  {
> diff --git a/include/uapi/linux/bpf.h b/include/uapi/linux/bpf.h
> index 00a875720e84..fd069f285fbc 100644
> --- a/include/uapi/linux/bpf.h
> +++ b/include/uapi/linux/bpf.h
> @@ -1068,6 +1068,7 @@ enum bpf_link_type {
>         BPF_LINK_TYPE_NETFILTER = 10,
>         BPF_LINK_TYPE_TCX = 11,
>         BPF_LINK_TYPE_UPROBE_MULTI = 12,
> +       BPF_LINK_TYPE_META = 12,

it's not just some completely universal "meta" device, it's
specifically networking meta-device, is that right? so at least in
UAPI I think we should stay away from using super-generic "meta"
words, and do something like "net_meta" or "meta_net" or whatnot, but
indicate that this is networking stuff. WDYT?


>         MAX_BPF_LINK_TYPE,
>  };
>
> @@ -1653,6 +1654,13 @@ union bpf_attr {
>                                 __u32           flags;
>                                 __u32           pid;
>                         } uprobe_multi;
> +                       struct {
> +                               union {
> +                                       __u32   relative_fd;
> +                                       __u32   relative_id;
> +                               };
> +                               __u64           expected_revision;
> +                       } meta;
>                 };
>         } link_create;
>
> @@ -6564,6 +6572,9 @@ struct bpf_link_info {
>                         __u32 ifindex;
>                         __u32 attach_type;
>                 } tcx;
> +               struct {
> +                       __u32 ifindex;
> +               } meta;
>         };
>  } __attribute__((aligned(8)));
>
> diff --git a/kernel/bpf/syscall.c b/kernel/bpf/syscall.c
> index 51baf4355c39..b689da4de280 100644
> --- a/kernel/bpf/syscall.c
> +++ b/kernel/bpf/syscall.c
> @@ -4969,7 +4969,7 @@ static int link_create(union bpf_attr *attr, bpfptr_t uattr)
>                     attr->link_create.attach_type == BPF_TCX_EGRESS)
>                         ret = tcx_link_attach(attr, prog);
>                 else
> -                       ret = -EINVAL;
> +                       ret = meta_link_attach(attr, prog);
>                 break;
>         case BPF_PROG_TYPE_NETFILTER:
>                 ret = bpf_nf_link_attach(attr, prog);
> diff --git a/tools/include/uapi/linux/bpf.h b/tools/include/uapi/linux/bpf.h
> index 00a875720e84..fd069f285fbc 100644
> --- a/tools/include/uapi/linux/bpf.h
> +++ b/tools/include/uapi/linux/bpf.h
> @@ -1068,6 +1068,7 @@ enum bpf_link_type {
>         BPF_LINK_TYPE_NETFILTER = 10,
>         BPF_LINK_TYPE_TCX = 11,
>         BPF_LINK_TYPE_UPROBE_MULTI = 12,
> +       BPF_LINK_TYPE_META = 12,
>         MAX_BPF_LINK_TYPE,
>  };
>
> @@ -1653,6 +1654,13 @@ union bpf_attr {
>                                 __u32           flags;
>                                 __u32           pid;
>                         } uprobe_multi;
> +                       struct {
> +                               union {
> +                                       __u32   relative_fd;
> +                                       __u32   relative_id;
> +                               };
> +                               __u64           expected_revision;
> +                       } meta;
>                 };
>         } link_create;
>
> @@ -6564,6 +6572,9 @@ struct bpf_link_info {
>                         __u32 ifindex;
>                         __u32 attach_type;
>                 } tcx;
> +               struct {
> +                       __u32 ifindex;
> +               } meta;
>         };
>  } __attribute__((aligned(8)));
>
> --
> 2.34.1
>

  reply	other threads:[~2023-09-28  0:12 UTC|newest]

Thread overview: 22+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-09-26  5:59 [PATCH bpf-next 0/8] Add bpf programmable device Daniel Borkmann
2023-09-26  5:59 ` [PATCH bpf-next 1/8] meta, bpf: Add bpf programmable meta device Daniel Borkmann
2023-09-26 21:26   ` Stanislav Fomichev
2023-09-28  9:16   ` Toke Høiland-Jørgensen
2023-09-28 12:01     ` Willem de Bruijn
2023-09-28 21:14     ` Daniel Borkmann
2023-09-29 19:25       ` Alexei Starovoitov
2023-10-13 11:26   ` Florian Kauer
2023-09-26  5:59 ` [PATCH bpf-next 2/8] meta, bpf: Add bpf link support for " Daniel Borkmann
2023-09-28  0:12   ` Andrii Nakryiko [this message]
2023-09-26  5:59 ` [PATCH bpf-next 3/8] tools: Sync if_link uapi header Daniel Borkmann
2023-09-26  5:59 ` [PATCH bpf-next 4/8] libbpf: Add link-based API for meta Daniel Borkmann
2023-09-26 11:19   ` Quentin Monnet
2023-09-28  0:12   ` Andrii Nakryiko
2023-09-28 21:30     ` Daniel Borkmann
2023-09-26  5:59 ` [PATCH bpf-next 5/8] bpftool: Implement link show support " Daniel Borkmann
2023-09-26 11:19   ` Quentin Monnet
2023-09-26  5:59 ` [PATCH bpf-next 6/8] bpftool: Extend net dump with meta progs Daniel Borkmann
2023-09-26 11:19   ` Quentin Monnet
2023-09-26  5:59 ` [PATCH bpf-next 7/8] selftests/bpf: Add netlink helper library Daniel Borkmann
2023-09-26 21:35   ` Stanislav Fomichev
2023-09-26  5:59 ` [PATCH bpf-next 8/8] selftests/bpf: Add selftests for meta Daniel Borkmann

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=CAEf4BzbBArMVTHqiS0zmgnFr0rBm-ZAXFs9dkffa7-0Axw2XSA@mail.gmail.com \
    --to=andrii.nakryiko@gmail.com \
    --cc=andrii@kernel.org \
    --cc=ast@kernel.org \
    --cc=bpf@vger.kernel.org \
    --cc=daniel@iogearbox.net \
    --cc=john.fastabend@gmail.com \
    --cc=martin.lau@kernel.org \
    --cc=netdev@vger.kernel.org \
    --cc=razor@blackwall.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).