All of lore.kernel.org
 help / color / mirror / Atom feed
From: "Toke Høiland-Jørgensen" <toke@redhat.com>
To: Andrii Nakryiko <andrii@kernel.org>,
	bpf@vger.kernel.org, ast@kernel.org, daniel@iogearbox.net
Cc: andrii@kernel.org, kernel-team@fb.com
Subject: Re: [PATCH bpf-next 1/4] libbpf: streamline low-level XDP APIs
Date: Thu, 20 Jan 2022 13:00:21 +0100	[thread overview]
Message-ID: <87tudy7h2i.fsf@toke.dk> (raw)
In-Reply-To: <20220120061422.2710637-2-andrii@kernel.org>

Andrii Nakryiko <andrii@kernel.org> writes:

> Introduce 4 new netlink-based XDP APIs for attaching, detaching, and
> querying XDP programs:
>   - bpf_xdp_attach;
>   - bpf_xdp_detach;
>   - bpf_xdp_query;
>   - bpf_xdp_query_id.
>
> These APIs replace bpf_set_link_xdp_fd, bpf_set_link_xdp_fd_opts,
> bpf_get_link_xdp_id, and bpf_get_link_xdp_info APIs ([0]). The latter
> don't follow a consistent naming pattern and some of them use
> non-extensible approaches (e.g., struct xdp_link_info which can't be
> modified without breaking libbpf ABI).
>
> The approach I took with these low-level XDP APIs is similar to what we
> did with low-level TC APIs. There is a nice duality of bpf_tc_attach vs
> bpf_xdp_attach, and so on. I left bpf_xdp_attach() to support detaching
> when -1 is specified for prog_fd for generality and convenience, but
> bpf_xdp_detach() is preferred due to clearer naming and associated
> semantics. Both bpf_xdp_attach() and bpf_xdp_detach() accept the same
> opts struct allowing to specify expected old_prog_fd.
>
> While doing the refactoring, I noticed that old APIs require users to
> specify opts with old_fd == -1 to declare "don't care about already
> attached XDP prog fd" condition. Otherwise, FD 0 is assumed, which is
> essentially never an intended behavior. So I made this behavior
> consistent with other kernel and libbpf APIs, in which zero FD means "no
> FD". This seems to be more in line with the latest thinking in BPF land
> and should cause less user confusion, hopefully.
>
> For querying, I left two APIs, both more generic bpf_xdp_query()
> allowing to query multiple IDs and attach mode, but also
> a specialization of it, bpf_xdp_query_id(), which returns only requested
> prog_id. Uses of prog_id returning bpf_get_link_xdp_id() were so
> prevalent across selftests and samples, that it seemed a very common use
> case and using bpf_xdp_query() for doing it felt very cumbersome with
> a highly branches if/else chain based on flags and attach mode.
>
> Old APIs are scheduled for deprecation in libbpf 0.8 release.
>
>   [0] Closes: https://github.com/libbpf/libbpf/issues/309
>
> Signed-off-by: Andrii Nakryiko <andrii@kernel.org>

Acked-by: Toke Høiland-Jørgensen <toke@redhat.com>


  reply	other threads:[~2022-01-20 12:00 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-01-20  6:14 [PATCH bpf-next 0/4] libbpf: streamline netlink-based XDP APIs Andrii Nakryiko
2022-01-20  6:14 ` [PATCH bpf-next 1/4] libbpf: streamline low-level " Andrii Nakryiko
2022-01-20 12:00   ` Toke Høiland-Jørgensen [this message]
2022-01-20  6:14 ` [PATCH bpf-next 2/4] bpftool: use new API for attaching XDP program Andrii Nakryiko
2022-01-20  6:14 ` [PATCH bpf-next 3/4] selftests/bpf: switch to new libbpf XDP APIs Andrii Nakryiko
2022-01-20  6:14 ` [PATCH bpf-next 4/4] samples/bpf: adapt samples/bpf to bpf_xdp_xxx() APIs Andrii Nakryiko

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=87tudy7h2i.fsf@toke.dk \
    --to=toke@redhat.com \
    --cc=andrii@kernel.org \
    --cc=ast@kernel.org \
    --cc=bpf@vger.kernel.org \
    --cc=daniel@iogearbox.net \
    --cc=kernel-team@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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.