28 Oct, 2020

1 commit

  • The memlock rlimit is a notorious source of failure for BPF programs. Most
    of the samples just set it to infinity, but a few used a lower limit. The
    problem with unconditionally setting a lower limit is that this will also
    override the limit if the system-wide setting is *higher* than the limit
    being set, which can lead to failures on systems that lock a lot of memory,
    but set 'ulimit -l' to unlimited before running a sample.

    One fix for this is to only conditionally set the limit if the current
    limit is lower, but it is simpler to just unify all the samples and have
    them all set the limit to infinity.

    Signed-off-by: Toke Høiland-Jørgensen
    Signed-off-by: Daniel Borkmann
    Acked-by: Andrii Nakryiko
    Acked-by: Jesper Dangaard Brouer
    Link: https://lore.kernel.org/bpf/20201026233623.91728-1-toke@redhat.com

    Toke Høiland-Jørgensen
     

12 Oct, 2020

1 commit

  • >From commit d7a18ea7e8b6 ("libbpf: Add generic bpf_program__attach()"),
    for some BPF programs, it is now possible to attach BPF programs
    with __attach() instead of explicitly calling __attach_().

    This commit refactors the __attach_tracepoint() with libbpf's generic
    __attach() method. In addition, this refactors the logic of setting
    the map FD to simplify the code. Also, the missing removal of
    bpf_load.o in Makefile has been fixed.

    Signed-off-by: Daniel T. Lee
    Signed-off-by: Alexei Starovoitov
    Acked-by: Andrii Nakryiko
    Link: https://lore.kernel.org/bpf/20201010181734.1109-3-danieltimlee@gmail.com

    Daniel T. Lee
     

04 Sep, 2020

1 commit

  • From commit 521095842027 ("libbpf: Deprecate notion of BPF program
    "title" in favor of "section name""), the term title has been replaced
    with section name in libbpf.

    Since the bpf_program__title() has been deprecated, this commit
    switches this function to bpf_program__section_name(). Due to
    this commit, the compilation warning issue has also been resolved.

    Fixes: 521095842027 ("libbpf: Deprecate notion of BPF program "title" in favor of "section name"")
    Signed-off-by: Daniel T. Lee
    Signed-off-by: Daniel Borkmann
    Link: https://lore.kernel.org/bpf/20200904063434.24963-1-danieltimlee@gmail.com

    Daniel T. Lee
     

16 Jul, 2020

2 commits

  • Extend xdp_redirect_cpu_{usr,kern}.c adding the possibility to load
    a XDP program on cpumap entries. The following options have been added:
    - mprog-name: cpumap entry program name
    - mprog-filename: cpumap entry program filename
    - redirect-device: output interface if the cpumap program performs a
    XDP_REDIRECT to an egress interface
    - redirect-map: bpf map used to perform XDP_REDIRECT to an egress
    interface
    - mprog-disable: disable loading XDP program on cpumap entries

    Add xdp_pass, xdp_drop, xdp_redirect stats accounting

    Co-developed-by: Jesper Dangaard Brouer
    Signed-off-by: Jesper Dangaard Brouer
    Signed-off-by: Lorenzo Bianconi
    Signed-off-by: Daniel Borkmann
    Link: https://lore.kernel.org/bpf/aa5a9a281b9dac425620fdabe82670ffb6bbdb92.1594734381.git.lorenzo@kernel.org

    Lorenzo Bianconi
     
  • Do not update xdp_redirect_cpu maps running while option loop but
    defer it after all available options have been parsed. This is a
    preliminary patch to pass the program name we want to attach to the
    map entries as a user option

    Signed-off-by: Lorenzo Bianconi
    Signed-off-by: Daniel Borkmann
    Acked-by: Jesper Dangaard Brouer
    Link: https://lore.kernel.org/bpf/95dc46286fd2c609042948e04bb7ae1f5b425538.1594734381.git.lorenzo@kernel.org

    Lorenzo Bianconi
     

16 Jun, 2020

1 commit

  • Memset on the pointer right after malloc can cause a NULL pointer
    deference if it failed to allocate memory. A simple fix is to
    replace malloc()/memset() pair with a simple call to calloc().

    Fixes: 0fca931a6f21 ("samples/bpf: program demonstrating access to xdp_rxq_info")
    Signed-off-by: Gaurav Singh
    Signed-off-by: Daniel Borkmann
    Acked-by: Jesper Dangaard Brouer
    Acked-by: John Fastabend

    Gaurav Singh
     

19 May, 2020

1 commit

  • Current method of checking pointer error is not user friendly.
    Especially the __must_check define makes this less intuitive.

    Since, libbpf has an API libbpf_get_error() which checks pointer error,
    this commit refactors existing pointer error check logic with libbpf.

    Signed-off-by: Daniel T. Lee
    Signed-off-by: Daniel Borkmann
    Acked-by: Yonghong Song
    Link: https://lore.kernel.org/bpf/20200516040608.1377876-2-danieltimlee@gmail.com

    Daniel T. Lee
     

15 May, 2020

1 commit

  • xdp_redirect_cpu is currently failing in bpf_prog_load_xattr()
    allocating cpu_map map if CONFIG_NR_CPUS is less than 64 since
    cpu_map_alloc() requires max_entries to be less than NR_CPUS.
    Set cpu_map max_entries according to NR_CPUS in xdp_redirect_cpu_kern.c
    and get currently running cpus in xdp_redirect_cpu_user.c

    Signed-off-by: Lorenzo Bianconi
    Signed-off-by: Alexei Starovoitov
    Acked-by: Yonghong Song
    Link: https://lore.kernel.org/bpf/374472755001c260158c4e4b22f193bdd3c56fb7.1589300442.git.lorenzo@kernel.org

    Lorenzo Bianconi
     

21 Jan, 2020

1 commit

  • Fix all files in samples/bpf to include libbpf header files with the bpf/
    prefix, to be consistent with external users of the library. Also ensure
    that all includes of exported libbpf header files (those that are exported
    on 'make install' of the library) use bracketed includes instead of quoted.

    To make sure no new files are introduced that doesn't include the bpf/
    prefix in its include, remove tools/lib/bpf from the include path entirely,
    and use tools/lib instead.

    Fixes: 6910d7d3867a ("selftests/bpf: Ensure bpf_helper_defs.h are taken from selftests dir")
    Signed-off-by: Toke Høiland-Jørgensen
    Signed-off-by: Alexei Starovoitov
    Acked-by: Jesper Dangaard Brouer
    Acked-by: Andrii Nakryiko
    Link: https://lore.kernel.org/bpf/157952560911.1683545.8795966751309534150.stgit@toke.dk

    Toke Høiland-Jørgensen
     

21 Dec, 2019

1 commit

  • When sample xdp_redirect_cpu was converted to use libbpf, the
    tracepoints used by this sample were not getting attached automatically
    like with bpf_load.c. The BPF-maps was still getting loaded, thus
    nobody notice that the tracepoints were not updating these maps.

    This fix doesn't use the new skeleton code, as this bug was introduced
    in v5.1 and stable might want to backport this. E.g. Red Hat QA uses
    this sample as part of their testing.

    Fixes: bbaf6029c49c ("samples/bpf: Convert XDP samples to libbpf usage")
    Signed-off-by: Jesper Dangaard Brouer
    Signed-off-by: Alexei Starovoitov
    Acked-by: Andrii Nakryiko
    Link: https://lore.kernel.org/bpf/157685877642.26195.2798780195186786841.stgit@firesoul

    Jesper Dangaard Brouer
     

16 Dec, 2019

1 commit

  • When attaching XDP programs, userspace can set flags to request the attach
    mode (generic/SKB mode, driver mode or hw offloaded mode). If no such flags
    are requested, the kernel will attempt to attach in driver mode, and then
    silently fall back to SKB mode if this fails.

    The silent fallback is a major source of user confusion, as users will try
    to load a program on a device without XDP support, and instead of an error
    they will get the silent fallback behaviour, not notice, and then wonder
    why performance is not what they were expecting.

    In an attempt to combat this, let's switch all the samples to default to
    explicitly requesting driver-mode attach. As part of this, ensure that all
    the userspace utilities have a switch to enable SKB mode. For those that
    have a switch to request driver mode, keep it but turn it into a no-op.

    Signed-off-by: Toke Høiland-Jørgensen
    Signed-off-by: Alexei Starovoitov
    Acked-by: Jesper Dangaard Brouer
    Acked-by: David Ahern
    Link: https://lore.kernel.org/bpf/20191216110742.364456-1-toke@redhat.com

    Toke Høiland-Jørgensen
     

22 Jun, 2019

1 commit


19 Jun, 2019

1 commit

  • Based on 1 normalized pattern(s):

    gplv2

    extracted by the scancode license scanner the SPDX license identifier

    GPL-2.0-only

    has been chosen to replace the boilerplate/reference in 58 file(s).

    Signed-off-by: Thomas Gleixner
    Reviewed-by: Enrico Weigelt
    Reviewed-by: Allison Randal
    Reviewed-by: Kate Stewart
    Cc: linux-spdx@vger.kernel.org
    Link: https://lkml.kernel.org/r/20190604081207.556988620@linutronix.de
    Signed-off-by: Greg Kroah-Hartman

    Thomas Gleixner
     

18 Jun, 2019

1 commit

  • Currently, header inclusion in each file is inconsistent.
    For example, "libbpf.h" header is included as multiple ways.

    #include "bpf/libbpf.h"
    #include "libbpf.h"

    Due to commit b552d33c80a9 ("samples/bpf: fix include path
    in Makefile"), $(srctree)/tools/lib/bpf/ path had been included
    during build, path "bpf/" in header isn't necessary anymore.

    This commit removes path "bpf/" in header inclusion.

    Signed-off-by: Daniel T. Lee
    Signed-off-by: Daniel Borkmann

    Daniel T. Lee
     

02 Feb, 2019

4 commits

  • Check the program id within the signal handler on polling xdp samples
    that were previously converted to libbpf usage. Avoid the situation of
    unloading the program that was not attached by sample that is exiting.
    Handle also the case where bpf_get_link_xdp_id didn't exit with an error
    but the xdp program was not found on an interface.

    Reported-by: Michal Papaj
    Reported-by: Jakub Spizewski
    Signed-off-by: Maciej Fijalkowski
    Reviewed-by: Jakub Kicinski
    Signed-off-by: Daniel Borkmann

    Maciej Fijalkowski
     
  • Make xdp samples consistent with iproute2 behavior and set the
    XDP_FLAGS_UPDATE_IF_NOEXIST by default when setting the xdp program on
    interface. Provide an option for user to force the program loading,
    which as a result will not include the mentioned flag in
    bpf_set_link_xdp_fd call.

    Signed-off-by: Maciej Fijalkowski
    Reviewed-by: Jakub Kicinski
    Acked-by: John Fastabend
    Signed-off-by: Daniel Borkmann

    Maciej Fijalkowski
     
  • Some of XDP samples that are attaching the bpf program to the interface
    via libbpf's bpf_set_link_xdp_fd are still using the bpf_load.c for
    loading and manipulating the ebpf program and maps. Convert them to do
    this through libbpf usage and remove bpf_load from the picture.

    While at it remove what looks like debug leftover in
    xdp_redirect_map_user.c

    In xdp_redirect_cpu, change the way that the program to be loaded onto
    interface is chosen - user now needs to pass the program's section name
    instead of the relative number. In case of typo print out the section
    names to choose from.

    Signed-off-by: Maciej Fijalkowski
    Reviewed-by: Jakub Kicinski
    Acked-by: Jesper Dangaard Brouer
    Signed-off-by: Daniel Borkmann

    Maciej Fijalkowski
     
  • The sample xdp_redirect_cpu is not using helper bpf_trace_printk.
    Thus it makes no sense that the --debug option us reading
    from /sys/kernel/debug/tracing/trace_pipe via read_trace_pipe.
    Simply remove it.

    Signed-off-by: Jesper Dangaard Brouer
    Acked-by: John Fastabend
    Signed-off-by: Daniel Borkmann

    Jesper Dangaard Brouer
     

17 Aug, 2018

1 commit

  • It is common XDP practice to unload/deattach the XDP bpf program,
    when the XDP sample program is Ctrl-C interrupted (SIGINT) or
    killed (SIGTERM).

    The samples/bpf programs xdp_redirect_cpu and xdp_rxq_info,
    forgot to trap signal SIGTERM (which is the default signal used
    by the kill command).

    This was discovered by Red Hat QA, which automated scripts depend
    on killing the XDP sample program after a timeout period.

    Fixes: fad3917e361b ("samples/bpf: add cpumap sample program xdp_redirect_cpu")
    Fixes: 0fca931a6f21 ("samples/bpf: program demonstrating access to xdp_rxq_info")
    Reported-by: Jean-Tsung Hsiao
    Signed-off-by: Jesper Dangaard Brouer
    Acked-by: Yonghong Song
    Signed-off-by: Daniel Borkmann

    Jesper Dangaard Brouer
     

14 Aug, 2018

1 commit

  • Daniel Borkmann says:

    ====================
    pull-request: bpf-next 2018-08-13

    The following pull-request contains BPF updates for your *net-next* tree.

    The main changes are:

    1) Add driver XDP support for veth. This can be used in conjunction with
    redirect of another XDP program e.g. sitting on NIC so the xdp_frame
    can be forwarded to the peer veth directly without modification,
    from Toshiaki.

    2) Add a new BPF map type REUSEPORT_SOCKARRAY and prog type SK_REUSEPORT
    in order to provide more control and visibility on where a SO_REUSEPORT
    sk should be located, and the latter enables to directly select a sk
    from the bpf map. This also enables map-in-map for application migration
    use cases, from Martin.

    3) Add a new BPF helper bpf_skb_ancestor_cgroup_id() that returns the id
    of cgroup v2 that is the ancestor of the cgroup associated with the
    skb at the ancestor_level, from Andrey.

    4) Implement BPF fs map pretty-print support based on BTF data for regular
    hash table and LRU map, from Yonghong.

    5) Decouple the ability to attach BTF for a map from the key and value
    pretty-printer in BPF fs, and enable further support of BTF for maps for
    percpu and LPM trie, from Daniel.

    6) Implement a better BPF sample of using XDP's CPU redirect feature for
    load balancing SKB processing to remote CPU. The sample implements the
    same XDP load balancing as Suricata does which is symmetric hash based
    on IP and L4 protocol, from Jesper.

    7) Revert adding NULL pointer check with WARN_ON_ONCE() in __xdp_return()'s
    critical path as it is ensured that the allocator is present, from Björn.
    ====================

    Signed-off-by: David S. Miller

    David S. Miller
     

10 Aug, 2018

2 commits

  • This implement XDP CPU redirection load-balancing across available
    CPUs, based on the hashing IP-pairs + L4-protocol. This equivalent to
    xdp-cpu-redirect feature in Suricata, which is inspired by the
    Suricata 'ippair' hashing code.

    An important property is that the hashing is flow symmetric, meaning
    that if the source and destination gets swapped then the selected CPU
    will remain the same. This is helps locality by placing both directions
    of a flows on the same CPU, in a forwarding/routing scenario.

    The hashing INITVAL (15485863 the 10^6th prime number) was fairly
    arbitrary choosen, but experiments with kernel tree pktgen scripts
    (pktgen_sample04_many_flows.sh +pktgen_sample05_flow_per_thread.sh)
    showed this improved the distribution.

    This patch also change the default loaded XDP program to be this
    load-balancer. As based on different user feedback, this seems to be
    the expected behavior of the sample xdp_redirect_cpu.

    Link: https://github.com/OISF/suricata/commit/796ec08dd7a63
    Signed-off-by: Jesper Dangaard Brouer
    Signed-off-by: Daniel Borkmann

    Jesper Dangaard Brouer
     
  • The teardown race in cpumap is really hard to reproduce. These changes
    makes it easier to reproduce, for QA.

    The --stress-mode now have a case of a very small queue size of 8, that helps
    to trigger teardown flush to encounter a full queue, which results in calling
    xdp_return_frame API, in a non-NAPI protect context.

    Also increase MAX_CPUS, as my QA department have larger machines than me.

    Tested-by: Jean-Tsung Hsiao
    Signed-off-by: Jesper Dangaard Brouer
    Signed-off-by: Daniel Borkmann

    Jesper Dangaard Brouer
     

15 May, 2018

1 commit


03 Feb, 2018

1 commit


18 Oct, 2017

1 commit

  • This sample program show how to use cpumap and the associated
    tracepoints.

    It provides command line stats, which shows how the XDP-RX process,
    cpumap-enqueue and cpumap kthread dequeue is cooperating on a per CPU
    basis. It also utilize the xdp_exception and xdp_redirect_err
    transpoints to allow users quickly to identify setup issues.

    One issue with ixgbe driver is that the driver reset the link when
    loading XDP. This reset the procfs smp_affinity settings. Thus,
    after loading the program, these must be reconfigured. The easiest
    workaround it to reduce the RX-queue to e.g. two via:

    # ethtool --set-channels ixgbe1 combined 2

    And then add CPUs above 0 and 1, like:

    # xdp_redirect_cpu --dev ixgbe1 --prog 2 --cpu 2 --cpu 3 --cpu 4

    Another issue with ixgbe is that the page recycle mechanism is tied to
    the RX-ring size. And the default setting of 512 elements is too
    small. This is the same issue with regular devmap XDP_REDIRECT.
    To overcome this I've been using 1024 rx-ring size:

    # ethtool -G ixgbe1 rx 1024 tx 1024

    V3:
    - whitespace cleanups
    - bpf tracepoint cannot access top part of struct

    V4:
    - report on kthread sched events, according to tracepoint change
    - report average bulk enqueue size

    V5:
    - bpf_map_lookup_elem on cpumap not allowed from bpf_prog
    use separate map to mark CPUs not available

    V6:
    - correct kthread sched summary output

    V7:
    - Added a --stress-mode for concurrently changing underlying cpumap

    Signed-off-by: Jesper Dangaard Brouer
    Signed-off-by: David S. Miller

    Jesper Dangaard Brouer