netdev.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: "Björn Töpel" <bjorn@kernel.org>
To: Ciara Loftus <ciara.loftus@intel.com>
Cc: Netdev <netdev@vger.kernel.org>, bpf <bpf@vger.kernel.org>,
	"Karlsson, Magnus" <magnus.karlsson@intel.com>,
	Alexei Starovoitov <alexei.starovoitov@gmail.com>
Subject: Re: [PATCH v3 bpf 3/3] libbpf: only create rx and tx XDP rings when necessary
Date: Tue, 30 Mar 2021 19:25:29 +0200	[thread overview]
Message-ID: <CAJ+HfNicARR3ZoH38_ANx9t5cqFn9DEfvegjUSN019un5xcgnA@mail.gmail.com> (raw)
In-Reply-To: <20210330113419.4616-4-ciara.loftus@intel.com>

On Tue, 30 Mar 2021 at 14:05, Ciara Loftus <ciara.loftus@intel.com> wrote:
>
> Prior to this commit xsk_socket__create(_shared) always attempted to create
> the rx and tx rings for the socket. However this causes an issue when the
> socket being setup is that which shares the fd with the UMEM. If a
> previous call to this function failed with this socket after the rings were
> set up, a subsequent call would always fail because the rings are not torn
> down after the first call and when we try to set them up again we encounter
> an error because they already exist. Solve this by remembering whether the
> rings were set up by introducing a new flag to struct xsk_umem, and
> checking it before setting up the rings for sockets which share the fd
> with the UMEM.
>
> Fixes: 1cad07884239 ("libbpf: add support for using AF_XDP sockets")
>
> Signed-off-by: Ciara Loftus <ciara.loftus@intel.com>
> ---
>  tools/lib/bpf/xsk.c | 16 ++++++++++++++--
>  1 file changed, 14 insertions(+), 2 deletions(-)
>
> diff --git a/tools/lib/bpf/xsk.c b/tools/lib/bpf/xsk.c
> index d4991ddff05a..12110bba4cc0 100644
> --- a/tools/lib/bpf/xsk.c
> +++ b/tools/lib/bpf/xsk.c
> @@ -14,6 +14,7 @@
>  #include <unistd.h>
>  #include <arpa/inet.h>
>  #include <asm/barrier.h>
> +#include <linux/bitops.h>
>  #include <linux/compiler.h>
>  #include <linux/ethtool.h>
>  #include <linux/filter.h>
> @@ -46,6 +47,9 @@
>   #define PF_XDP AF_XDP
>  #endif
>
> +#define XDP_RX_RING_SETUP_DONE BIT(0)
> +#define XDP_TX_RING_SETUP_DONE BIT(1)
> +
>  enum xsk_prog {
>         XSK_PROG_FALLBACK,
>         XSK_PROG_REDIRECT_FLAGS,
> @@ -59,6 +63,7 @@ struct xsk_umem {
>         int fd;
>         int refcount;
>         struct list_head ctx_list;
> +       __u8 ring_setup_status;

Are we envisioning any more flags here? Otherwise, just a simple
bool/__u8 stating ring_setup_complete or ring_is_setup and just use
true/false and a simple check w/o bitwise and.


Björn

      reply	other threads:[~2021-03-30 17:26 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-03-30 11:34 [PATCH v3 bpf 0/3] AF_XDP Socket Creation Fixes Ciara Loftus
2021-03-30 11:34 ` [PATCH v3 bpf 1/3] libbpf: ensure umem pointer is non-NULL before dereferencing Ciara Loftus
2021-03-30 11:34 ` [PATCH v3 bpf 2/3] libbpf: restore umem state after socket create failure Ciara Loftus
2021-03-30 15:08   ` Alexei Starovoitov
2021-03-30 17:21     ` Björn Töpel
2021-03-30 11:34 ` [PATCH v3 bpf 3/3] libbpf: only create rx and tx XDP rings when necessary Ciara Loftus
2021-03-30 17:25   ` Björn Töpel [this message]

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=CAJ+HfNicARR3ZoH38_ANx9t5cqFn9DEfvegjUSN019un5xcgnA@mail.gmail.com \
    --to=bjorn@kernel.org \
    --cc=alexei.starovoitov@gmail.com \
    --cc=bpf@vger.kernel.org \
    --cc=ciara.loftus@intel.com \
    --cc=magnus.karlsson@intel.com \
    --cc=netdev@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).