BPF Archive on lore.kernel.org
 help / color / Atom feed
From: John Fastabend <john.fastabend@gmail.com>
To: Magnus Karlsson <magnus.karlsson@intel.com>,
	magnus.karlsson@intel.com, bjorn.topel@intel.com, ast@kernel.org,
	daniel@iogearbox.net, netdev@vger.kernel.org
Cc: jonathan.lemon@gmail.com, bpf@vger.kernel.org
Subject: RE: [PATCH bpf] libbpf: fix compatibility for kernels without need_wakeup
Date: Tue, 08 Oct 2019 12:28:41 -0700
Message-ID: <5d9ce369d6e5_17cc2aba94c845b415@john-XPS-13-9370.notmuch> (raw)
In-Reply-To: <1570530208-17720-1-git-send-email-magnus.karlsson@intel.com>

Magnus Karlsson wrote:
> When the need_wakeup flag was added to AF_XDP, the format of the
> XDP_MMAP_OFFSETS getsockopt was extended. Code was added to the kernel
> to take care of compatibility issues arrising from running
> applications using any of the two formats. However, libbpf was not
> extended to take care of the case when the application/libbpf uses the
> new format but the kernel only supports the old format. This patch
> adds support in libbpf for parsing the old format, before the
> need_wakeup flag was added, and emulating a set of static need_wakeup
> flags that will always work for the application.
> 
> Fixes: a4500432c2587cb2a ("libbpf: add support for need_wakeup flag in AF_XDP part")
> Reported-by: Eloy Degen <degeneloy@gmail.com>
> Signed-off-by: Magnus Karlsson <magnus.karlsson@intel.com>
> ---
>  tools/lib/bpf/xsk.c | 109 +++++++++++++++++++++++++++++++++++++---------------
>  1 file changed, 78 insertions(+), 31 deletions(-)
> 
> diff --git a/tools/lib/bpf/xsk.c b/tools/lib/bpf/xsk.c
> index a902838..46f9687 100644
> --- a/tools/lib/bpf/xsk.c
> +++ b/tools/lib/bpf/xsk.c
> @@ -44,6 +44,25 @@
>   #define PF_XDP AF_XDP
>  #endif
>  
> +#define is_mmap_offsets_v1(optlen) \
> +	((optlen) == sizeof(struct xdp_mmap_offsets_v1))
> +
> +#define get_prod_off(ring) \
> +	(is_mmap_offsets_v1(optlen) ? \
> +	 ((struct xdp_mmap_offsets_v1 *)&off)->ring.producer : \
> +	 off.ring.producer)
> +#define get_cons_off(ring) \
> +	(is_mmap_offsets_v1(optlen) ? \
> +	 ((struct xdp_mmap_offsets_v1 *)&off)->ring.consumer : \
> +	 off.ring.consumer)
> +#define get_desc_off(ring) \
> +	(is_mmap_offsets_v1(optlen) ? \
> +	 ((struct xdp_mmap_offsets_v1 *)&off)->ring.desc : off.ring.desc)
> +#define get_flags_off(ring) \
> +	(is_mmap_offsets_v1(optlen) ? \
> +	 ((struct xdp_mmap_offsets_v1 *)&off)->ring.consumer + sizeof(u32) : \
> +	 off.ring.flags)
> +
 
It seems the only thing added was flags right? If so seems we
only need the last one there, get_flags_off(). I think it would
be a bit cleaner to just use the macros where its actually
needed IMO.

Thanks,
John

  reply index

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-10-08 10:23 Magnus Karlsson
2019-10-08 19:28 ` John Fastabend [this message]
2019-10-09  7:31   ` Magnus Karlsson
2019-10-11 20:58     ` John Fastabend
2019-10-12 16:54       ` Alexei Starovoitov
2019-10-14  8:26         ` Magnus Karlsson
2019-10-16  3:42           ` Alexei Starovoitov

Reply instructions:

You may reply publically 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=5d9ce369d6e5_17cc2aba94c845b415@john-XPS-13-9370.notmuch \
    --to=john.fastabend@gmail.com \
    --cc=ast@kernel.org \
    --cc=bjorn.topel@intel.com \
    --cc=bpf@vger.kernel.org \
    --cc=daniel@iogearbox.net \
    --cc=jonathan.lemon@gmail.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

BPF Archive on lore.kernel.org

Archives are clonable:
	git clone --mirror https://lore.kernel.org/bpf/0 bpf/git/0.git

	# If you have public-inbox 1.1+ installed, you may
	# initialize and index your mirror using the following commands:
	public-inbox-init -V2 bpf bpf/ https://lore.kernel.org/bpf \
		bpf@vger.kernel.org
	public-inbox-index bpf

Example config snippet for mirrors

Newsgroup available over NNTP:
	nntp://nntp.lore.kernel.org/org.kernel.vger.bpf


AGPL code for this site: git clone https://public-inbox.org/public-inbox.git