Commit Graph

35 Commits

Author SHA1 Message Date
Jesper Dangaard Brouer
10626881f1 AF_XDP-interaction: Cleanups for af_xdp_user
Signed-off-by: Jesper Dangaard Brouer <brouer@redhat.com>
2021-11-03 21:43:11 +01:00
Jesper Dangaard Brouer
778b5e6cdf AF_XDP-interaction: info for using macro XSK_BTF_READ_INTO
The program segfaulted if using the XSK_BTF_READ_INTO macro
with field as a C-string e.g. "rx_ktime".

Add comments to highlight this happens.

Signed-off-by: Jesper Dangaard Brouer <brouer@redhat.com>
2021-11-03 21:06:55 +01:00
Jesper Dangaard Brouer
5080226836 AF_XDP-interaction: Use xsk_btf__read correctly
Signed-off-by: Jesper Dangaard Brouer <brouer@redhat.com>
2021-11-03 20:55:46 +01:00
Jesper Dangaard Brouer
d758f4f919 AF_XDP-interaction: Fix lib_xsk_extend entry->size bug
Signed-off-by: Jesper Dangaard Brouer <brouer@redhat.com>
2021-11-03 19:51:52 +01:00
Jesper Dangaard Brouer
3488e02d00 AF_XDP-interaction: Trying to use xsk_btf__read
This doesn't work with packet test.

Signed-off-by: Jesper Dangaard Brouer <brouer@redhat.com>
2021-11-03 19:21:16 +01:00
Jesper Dangaard Brouer
8bb3d3ce3d AF_XDP-interaction: steps towards using BTF id during pkt processing
Signed-off-by: Jesper Dangaard Brouer <brouer@redhat.com>
2021-11-03 18:14:17 +01:00
Jesper Dangaard Brouer
20a07fa297 AF_XDP-interaction: Adapt lib_xsk_extend while trying to use
Signed-off-by: Jesper Dangaard Brouer <brouer@redhat.com>
2021-11-03 15:27:09 +01:00
Ederson de Souza
34ef433573 Proposed: Helpers to access XDP hints based on BTF definitions
Based on:
 Subj: libbpf: Helpers to access XDP hints based on BTF definitions
  https://lore.kernel.org/all/20210803010331.39453-15-ederson.desouza@intel.com/
 From: Ederson de Souza <ederson.desouza@intel.com>

Ederson says:

 A new set of functions to help get the BTF definition of XDP hints
 structure and get the information based on it.

 `xsk_umem__btf_id` helps retrieve the BTF id of XDP metadata.
 `xsk_btf__init` sets up a context based on the BTF, including a hashmap,
 so that subsequent queries are faster.
 `xsk_btf__read` returns a pointer to the position in the XDP metadata
 containing a given field.
 `xsk_btf__has_field` checks the presence of a field in the BTF.
 `xsk_btf__free` frees up the context.

 Besides those, a macro `XSK_BTF_READ_INTO` acts as a convenient helper
 to read the field contents into a given variable.

 Note that currently, the hashmap used to speed-up offset location into
 the BTF doesn't use the field name as a string as key to the hashmap. It
 directly uses the pointer value instead, as it is expected that most of
 time, field names will be addressed by a shared constant string residing
 on read-only memory, thus saving some time. If this assumption is not
 entirely true, this optimisation needs to be rethought (or discarded
 altogether).

Signed-off-by: Jesper Dangaard Brouer <brouer@redhat.com>
2021-11-03 12:23:56 +01:00
Jesper Dangaard Brouer
bb5105e5ca AF_XDP-interaction: Makefile add hashmap to be compiled
Signed-off-by: Jesper Dangaard Brouer <brouer@redhat.com>
2021-11-03 11:34:58 +01:00
Jesper Dangaard Brouer
4cb152a3c7 AF_XDP-interaction: Using btf__resolve_size for struct members possible
Signed-off-by: Jesper Dangaard Brouer <brouer@redhat.com>
2021-11-03 11:07:47 +01:00
Andrii Nakryiko
e4168200de Import libbpf: resizable non-thread safe internal hashmap
This is a copy of the kernels/libbpf hashmap
 tools/lib/bpf/hashmap.{h,c}

The plan is to prototype an AF_XDP/xsk userspace API for accessing
BTF information, that should be moved to libbpf (or libxdp).  Thus,
this hashmap code will become avail if successful.

Original kernel commit 553db8ba73df ("libbpf: add resizable non-thread
safe internal hashmap") (Author: Andrii Nakryiko). Thus, giving Andrii
author credit in this git commit.

Andrii Nakryiko said:

    libbpf: add resizable non-thread safe internal hashmap

    There is a need for fast point lookups inside libbpf for multiple use
    cases (e.g., name resolution for BTF-to-C conversion, by-name lookups in
    BTF for upcoming BPF CO-RE relocation support, etc). This patch
    implements simple resizable non-thread safe hashmap using single linked
    list chains.

    Four different insert strategies are supported:
     - HASHMAP_ADD - only add key/value if key doesn't exist yet;
     - HASHMAP_SET - add key/value pair if key doesn't exist yet; otherwise,
       update value;
     - HASHMAP_UPDATE - update value, if key already exists; otherwise, do
       nothing and return -ENOENT;
     - HASHMAP_APPEND - always add key/value pair, even if key already exists.
       This turns hashmap into a multimap by allowing multiple values to be
       associated with the same key. Most useful read API for such hashmap is
       hashmap__for_each_key_entry() iteration. If hashmap__find() is still
       used, it will return last inserted key/value entry (first in a bucket
       chain).

    For HASHMAP_SET and HASHMAP_UPDATE, old key/value pair is returned, so
    that calling code can handle proper memory management, if necessary.

Signed-off-by: Jesper Dangaard Brouer <brouer@redhat.com>
2021-11-03 11:01:36 +01:00
Jesper Dangaard Brouer
1a02d53b5f XDP-interaction: BTF try walking struct BTF members
Signed-off-by: Jesper Dangaard Brouer <brouer@redhat.com>
2021-11-02 16:37:24 +01:00
Jesper Dangaard Brouer
2778646e37 XDP-interaction: Playing with BTF APIs
Signed-off-by: Jesper Dangaard Brouer <brouer@redhat.com>
2021-11-02 14:52:40 +01:00
Jesper Dangaard Brouer
49c33e775f XDP-interaction: Require loading custom BPF program
Don't allow loading the default xsk BPF-prog if not specifying
any BPF-prog.  We have a need for our own BPf-prog.

Signed-off-by: Jesper Dangaard Brouer <brouer@redhat.com>
2021-11-02 14:34:43 +01:00
Jesper Dangaard Brouer
5245641946 AF_XDP-interaction: Improve comments explaning attributes
Signed-off-by: Jesper Dangaard Brouer <brouer@redhat.com>
2021-11-02 13:58:39 +01:00
Jesper Dangaard Brouer
c905867f29 AF_XDP-interaction: Make the two meta data types different sizes
On purpose to make it more difficult for userspace side.

Signed-off-by: Jesper Dangaard Brouer <brouer@redhat.com>
2021-11-02 12:40:49 +01:00
Jesper Dangaard Brouer
555aec82a7 AF_XDP-interaction: Two meta data structs
Signed-off-by: Jesper Dangaard Brouer <brouer@redhat.com>
2021-11-02 10:46:11 +01:00
Jesper Dangaard Brouer
69c0f60008 AF_XDP-interaction: Make BPF-prog BTF aware
Signed-off-by: Jesper Dangaard Brouer <brouer@redhat.com>
2021-10-29 17:54:09 +02:00
Jesper Dangaard Brouer
858778aa83 AF_XDP-interaction: crude extraction of metadata area
Signed-off-by: Jesper Dangaard Brouer <brouer@redhat.com>
2021-10-29 16:06:42 +02:00
Jesper Dangaard Brouer
1bc02a7470 AF_XDP-interaction: Add --pktinfo option that print info on pkt
To verify the contents of the incomming packets add a
function print_pkt_info() that decode part of the packet
headers and print IP-header src+dst (both IPv4 and IPv6).

Signed-off-by: Jesper Dangaard Brouer <brouer@redhat.com>
2021-10-29 14:53:33 +02:00
Jesper Dangaard Brouer
54d51b06b4 AF_XDP-interaction: Have XDP-prog with something into meta area
Signed-off-by: Jesper Dangaard Brouer <brouer@redhat.com>
2021-10-28 18:45:41 +02:00
Jesper Dangaard Brouer
5df5332f23 AF_XDP-interaction: config AF_XDP frame_headroom
The default frame_headroom seems to be zero as
define XSK_UMEM__DEFAULT_FRAME_HEADROOM is zero.

This patch does explicit xsk_umem_config setup.
Comment taken from kernel/samples/bpf/xdpsock_user.c.

Signed-off-by: Jesper Dangaard Brouer <brouer@redhat.com>
2021-10-28 18:20:56 +02:00
Jesper Dangaard Brouer
359cc27c72 AF_XDP-interaction: use bpf_xdp_adjust_meta
This only works in skb-mode, other modes fail the bpf_xdp_adjust_meta
call and result in XDP_ABORTED.  This only occurred on mlx5.

Signed-off-by: Jesper Dangaard Brouer <brouer@redhat.com>
2021-10-28 17:42:23 +02:00
Jesper Dangaard Brouer
9ef9104c61 AF_XDP-interaction: Fix strncpy warning in common_user_bpf_xdp.c
Signed-off-by: Jesper Dangaard Brouer <brouer@redhat.com>
2021-10-28 14:20:14 +02:00
Jesper Dangaard Brouer
6f0a1e3f01 AF_XDP-interaction: Use bpf_program__section_name
BPF program title (bpf_program__title) is getting deprecated
in libbpf use bpf_program__section_name() instead.

Signed-off-by: Jesper Dangaard Brouer <brouer@redhat.com>
2021-10-28 13:35:12 +02:00
Jesper Dangaard Brouer
9e8218556c AF_XDP-interaction: Use new .maps section for BTF aware map definitions
In-practice only 'xdp_stats_map' definition gets associated BTF,
as it uses the proper '__type' construct.

The AF_XDP map BPF_MAP_TYPE_XSKMAP doesn't know about BTF yet.

Signed-off-by: Jesper Dangaard Brouer <brouer@redhat.com>
2021-10-28 13:17:33 +02:00
Jesper Dangaard Brouer
3e65f68cdb AF_XDP-interaction: Make af_xdp_user default load af_xdp_kern.o
When not loading an XDP-prog the XSK library bits will load a
default XDP-prog.

In our use-case we always want to load our XDP-prog, which is
stored in af_xdp_kern.o.

Signed-off-by: Jesper Dangaard Brouer <brouer@redhat.com>
2021-10-27 18:21:07 +02:00
Jesper Dangaard Brouer
0dc1b0eab5 AF_XDP-interaction: Started on newer .maps SEC usage but stopped
Something in fishy as it seems this BPF-object is not getting used.

Use old maps SEC defines until figuring out what is wrong,
but keep new dot-maps defines.

Signed-off-by: Jesper Dangaard Brouer <brouer@redhat.com>
2021-10-26 17:00:48 +02:00
Jesper Dangaard Brouer
d4d325ddfc Introduce USER_TARGETS_OBJS_DEPS for extra dependencies
This USER_TARGETS_OBJS_DEPS allows makefiles to define
dependencies for USER_TARGETS_OBJS targets.

Signed-off-by: Jesper Dangaard Brouer <brouer@redhat.com>
2021-10-26 16:02:25 +02:00
Jesper Dangaard Brouer
5d10995545 AF_XDP-interaction: Use USER_TARGETS_OBJS for common_* objects
Signed-off-by: Jesper Dangaard Brouer <brouer@redhat.com>
2021-10-26 15:31:33 +02:00
Jesper Dangaard Brouer
27b0efe3e2 AF_XDP-interaction: Add common_defines.h from XDP-tutorial
Signed-off-by: Jesper Dangaard Brouer <brouer@redhat.com>
2021-10-26 15:29:02 +02:00
Jesper Dangaard Brouer
e6c2d60cbf AF_XDP-interaction: Add common_user_bpf_xdp.c+h from XDP-tutorial
As example (advanced03-AF_XDP) we copied from XDP-tutorial depend on these.

Signed-off-by: Jesper Dangaard Brouer <brouer@redhat.com>
2021-10-26 15:23:55 +02:00
Jesper Dangaard Brouer
118bb615b3 AF_XDP-interaction: Add common_params.c+h from XDP-tutorial
Signed-off-by: Jesper Dangaard Brouer <brouer@redhat.com>
2021-10-26 15:17:39 +02:00
Jesper Dangaard Brouer
7c7c1a9039 AF_XDP-interaction: Add Makefile
Signed-off-by: Jesper Dangaard Brouer <brouer@redhat.com>
2021-10-15 18:26:24 +02:00
Eelco Chaudron
68743eb1d3 AF_XDP-interaction: Import AF_XDP example from XDP-tutorial
https://github.com/xdp-project/xdp-tutorial/blob/master/advanced03-AF_XDP/

Give Eelco Chaudron credit as code Author.

Signed-off-by: Jesper Dangaard Brouer <brouer@redhat.com>
2021-10-15 18:23:42 +02:00