30 Dec, 2020

2 commits

  • [ Upstream commit 092fde0f863b72b67c4d6dc03844f5658fc00a35 ]

    Fix a possible hang in xdpsock that can occur when using multiple
    threads. In this case, one or more of the threads might get stuck in
    the while-loop in tx_only after the user has signaled the main thread
    to stop execution. In this case, no more Tx packets will be sent, so a
    thread might get stuck in the aforementioned while-loop. Fix this by
    introducing a test inside the while-loop to check if the benchmark has
    been terminated. If so, return from the function.

    Fixes: cd9e72b6f210 ("samples/bpf: xdpsock: Add option to specify batch size")
    Signed-off-by: Magnus Karlsson
    Signed-off-by: Daniel Borkmann
    Link: https://lore.kernel.org/bpf/20201210163407.22066-1-magnus.karlsson@gmail.com
    Signed-off-by: Sasha Levin

    Magnus Karlsson
     
  • [ Upstream commit 0afe0a998c40085a6342e1aeb4c510cccba46caf ]

    Currently, lwt_len_hist's map lwt_len_hist_map is uses pinning, and the
    map isn't cleared on test end. This leds to reuse of that map for
    each test, which prevents the results of the test from being accurate.

    This commit fixes the problem by removing of pinned map from bpffs.
    Also, this commit add the executable permission to shell script
    files.

    Fixes: f74599f7c5309 ("bpf: Add tests and samples for LWT-BPF")
    Signed-off-by: Daniel T. Lee
    Signed-off-by: Andrii Nakryiko
    Link: https://lore.kernel.org/bpf/20201124090310.24374-7-danieltimlee@gmail.com
    Signed-off-by: Sasha Levin

    Daniel T. Lee
     

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
     

22 Oct, 2020

1 commit

  • Yaniv reported a compilation error after pulling latest libbpf:

    [...]
    ../libbpf/src/root/usr/include/bpf/bpf_helpers.h:99:10: error:
    unknown register name 'r0' in asm
    : "r0", "r1", "r2", "r3", "r4", "r5");
    [...]

    The issue got triggered given Yaniv was compiling tracing programs with native
    target (e.g. x86) instead of BPF target, hence no BTF generated vmlinux.h nor
    CO-RE used, and later llc with -march=bpf was invoked to compile from LLVM IR
    to BPF object file. Given that clang was expecting x86 inline asm and not BPF
    one the error complained that these regs don't exist on the former.

    Guard bpf_tail_call_static() with defined(__bpf__) where BPF inline asm is valid
    to use. BPF tracing programs on more modern kernels use BPF target anyway and
    thus the bpf_tail_call_static() function will be available for them. BPF inline
    asm is supported since clang 7 (clang
    Signed-off-by: Daniel Borkmann
    Acked-by: Andrii Nakryiko
    Acked-by: Yonghong Song
    Tested-by: Yaniv Agman
    Link: https://lore.kernel.org/bpf/CAMy7=ZUk08w5Gc2Z-EKi4JFtuUCaZYmE4yzhJjrExXpYKR4L8w@mail.gmail.com
    Link: https://lore.kernel.org/bpf/20201021203257.26223-1-daniel@iogearbox.net

    Daniel Borkmann
     

12 Oct, 2020

3 commits

  • Most of the samples were converted to use the new BTF-defined MAP as
    they moved to libbpf, but some of the samples were missing.

    Instead of using the previous BPF MAP definition, this commit refactors
    xdp_monitor and xdp_sample_pkts_kern MAP definition with the new
    BTF-defined MAP format.

    Also, this commit removes the max_entries attribute at PERF_EVENT_ARRAY
    map type. The libbpf's bpf_object__create_map() will automatically
    set max_entries to the maximum configured number of CPUs on the host.

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

    Daniel T. Lee
     
  • >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
     
  • To avoid confusion caused by the increasing fragmentation of the BPF
    Loader program, this commit would like to change to the libbpf loader
    instead of using the bpf_load.

    Thanks to libbpf's bpf_link interface, managing the tracepoint BPF
    program is much easier. bpf_program__attach_tracepoint manages the
    enable of tracepoint event and attach of BPF programs to it with a
    single interface bpf_link, so there is no need to manage event_fd and
    prog_fd separately.

    This commit refactors xdp_monitor with using this libbpf API, and the
    bpf_load is removed and migrated to libbpf.

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

    Daniel T. Lee
     

07 Oct, 2020

5 commits

  • Add an option to count the number of interrupts generated per second and
    total number of interrupts during the lifetime of the application for a
    given interface. This information is extracted from /proc/interrupts. Since
    there is no naming convention across drivers, the user must provide the
    string which is specific to their interface in the /proc/interrupts file on
    the command line.

    Usage:

    ./xdpsock ... -I

    eg. for queue 0 of i40e device eth0:

    ./xdpsock ... -I i40e-eth0-TxRx-0

    Signed-off-by: Ciara Loftus
    Signed-off-by: Alexei Starovoitov
    Link: https://lore.kernel.org/bpf/20201002133612.31536-3-ciara.loftus@intel.com

    Ciara Loftus
     
  • Categorise and record syscalls issued in the xdpsock sample app. The
    categories recorded are:

    rx_empty_polls: polls when the rx ring is empty
    fill_fail_polls: polls when failed to get addr from fill ring
    copy_tx_sendtos: sendtos issued for tx when copy mode enabled
    tx_wakeup_sendtos: sendtos issued when tx ring needs waking up
    opt_polls: polls issued since the '-p' flag is set

    Print the stats using '-a' on the xdpsock command line.

    Signed-off-by: Ciara Loftus
    Signed-off-by: Alexei Starovoitov
    Acked-by: Yonghong Song
    Link: https://lore.kernel.org/bpf/20201002133612.31536-2-ciara.loftus@intel.com

    Ciara Loftus
     
  • New statistics will be added in future commits. In preparation for this,
    let's split out the existing statistics into their own struct.

    Signed-off-by: Ciara Loftus
    Signed-off-by: Alexei Starovoitov
    Acked-by: Yonghong Song
    Link: https://lore.kernel.org/bpf/20201002133612.31536-1-ciara.loftus@intel.com

    Ciara Loftus
     
  • Compiling samples/bpf hits an error related to fallthrough marking.
    ...
    CC samples/bpf/hbm.o
    samples/bpf/hbm.c: In function ‘main’:
    samples/bpf/hbm.c:486:4: error: ‘fallthrough’ undeclared (first use in this function)
    fallthrough;
    ^~~~~~~~~~~

    The "fallthrough" is not defined under tools/include directory.
    Rather, it is "__fallthrough" is defined in linux/compiler.h.
    Including "linux/compiler.h" and using "__fallthrough" fixed the issue.

    Signed-off-by: Yonghong Song
    Signed-off-by: Alexei Starovoitov
    Link: https://lore.kernel.org/bpf/20201006043427.1891805-1-yhs@fb.com

    Yonghong Song
     
  • With latest llvm trunk, bpf programs under samples/bpf
    directory, if using CORE, may experience the following
    errors:

    LLVM ERROR: Cannot select: intrinsic %llvm.preserve.struct.access.index
    PLEASE submit a bug report to https://bugs.llvm.org/ and include the crash backtrace.
    Stack dump:
    0. Program arguments: llc -march=bpf -filetype=obj -o samples/bpf/test_probe_write_user_kern.o
    1. Running pass 'Function Pass Manager' on module ''.
    2. Running pass 'BPF DAG->DAG Pattern Instruction Selection' on function '@bpf_prog1'
    #0 0x000000000183c26c llvm::sys::PrintStackTrace(llvm::raw_ostream&, int)
    (/data/users/yhs/work/llvm-project/llvm/build.cur/install/bin/llc+0x183c26c)
    ...
    #7 0x00000000017c375e (/data/users/yhs/work/llvm-project/llvm/build.cur/install/bin/llc+0x17c375e)
    #8 0x00000000016a75c5 llvm::SelectionDAGISel::CannotYetSelect(llvm::SDNode*)
    (/data/users/yhs/work/llvm-project/llvm/build.cur/install/bin/llc+0x16a75c5)
    #9 0x00000000016ab4f8 llvm::SelectionDAGISel::SelectCodeCommon(llvm::SDNode*, unsigned char const*,
    unsigned int) (/data/users/yhs/work/llvm-project/llvm/build.cur/install/bin/llc+0x16ab4f8)
    ...
    Aborted (core dumped) | llc -march=bpf -filetype=obj -o samples/bpf/test_probe_write_user_kern.o

    The reason is due to llvm change https://reviews.llvm.org/D87153
    where the CORE relocation global generation is moved from the beginning
    of target dependent optimization (llc) to the beginning
    of target independent optimization (opt).

    Since samples/bpf programs did not use vmlinux.h and its clang compilation
    uses native architecture, we need to adjust arch triple at opt level
    to do CORE relocation global generation properly. Otherwise, the above
    error will appear.

    This patch fixed the issue by introduce opt and llvm-dis to compilation chain,
    which will do proper CORE relocation global generation as well as O2 level
    optimization. Tested with llvm10, llvm11 and trunk/llvm12.

    Signed-off-by: Yonghong Song
    Signed-off-by: Alexei Starovoitov
    Acked-by: Andrii Nakryiko
    Link: https://lore.kernel.org/bpf/20201006043427.1891742-1-yhs@fb.com

    Yonghong Song
     

01 Oct, 2020

1 commit


24 Sep, 2020

1 commit

  • Alexei Starovoitov says:

    ====================
    pull-request: bpf-next 2020-09-23

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

    We've added 95 non-merge commits during the last 22 day(s) which contain
    a total of 124 files changed, 4211 insertions(+), 2040 deletions(-).

    The main changes are:

    1) Full multi function support in libbpf, from Andrii.

    2) Refactoring of function argument checks, from Lorenz.

    3) Make bpf_tail_call compatible with functions (subprograms), from Maciej.

    4) Program metadata support, from YiFei.

    5) bpf iterator optimizations, from Yonghong.
    ====================

    Signed-off-by: David S. Miller

    David S. Miller
     

19 Sep, 2020

1 commit

  • s390 uses socketcall multiplexer instead of individual socket syscalls.
    Therefore, "kprobe/" SYSCALL(sys_connect) does not trigger and
    test_map_in_map fails. Fix by using "kprobe/__sys_connect" instead.

    Signed-off-by: Ilya Leoshkevich
    Signed-off-by: Daniel Borkmann
    Acked-by: Andrii Nakryiko
    Link: https://lore.kernel.org/bpf/20200915115519.3769807-1-iii@linux.ibm.com

    Ilya Leoshkevich
     

15 Sep, 2020

3 commits

  • Add a quiet option (-Q) that disables the statistics print outs of
    xdpsock. This is good to have when measuring 0% loss rate performance
    as it will be quite terrible if the application uses printfs.

    Signed-off-by: Magnus Karlsson
    Signed-off-by: Alexei Starovoitov
    Link: https://lore.kernel.org/bpf/1599726666-8431-4-git-send-email-magnus.karlsson@gmail.com

    Magnus Karlsson
     
  • Fix a possible deadlock in the l2fwd application in xdpsock that can
    occur when there is no space in the Tx ring. There are two ways to get
    the kernel to consume entries in the Tx ring: calling sendto() to make
    it send packets and freeing entries from the completion ring, as the
    kernel will not send a packet if there is no space for it to add a
    completion entry in the completion ring. The Tx loop in l2fwd only
    used to call sendto(). This patches adds cleaning the completion ring
    in that loop.

    Signed-off-by: Magnus Karlsson
    Signed-off-by: Alexei Starovoitov
    Link: https://lore.kernel.org/bpf/1599726666-8431-3-git-send-email-magnus.karlsson@gmail.com

    Magnus Karlsson
     
  • Fix the sending of a single packet (or small burst) in xdpsock when
    executing in copy mode. Currently, the l2fwd application in xdpsock
    only transmits the packets after a batch of them has been received,
    which might be confusing if you only send one packet and expect that
    it is returned pronto. Fix this by calling sendto() more often and add
    a comment in the code that states that this can be optimized if
    needed.

    Reported-by: Tirthendu Sarkar
    Signed-off-by: Magnus Karlsson
    Signed-off-by: Alexei Starovoitov
    Link: https://lore.kernel.org/bpf/1599726666-8431-2-git-send-email-magnus.karlsson@gmail.com

    Magnus Karlsson
     

05 Sep, 2020

1 commit

  • We got slightly different patches removing a double word
    in a comment in net/ipv4/raw.c - picked the version from net.

    Simple conflict in drivers/net/ethernet/ibm/ibmvnic.c. Use cached
    values instead of VNIC login response buffer (following what
    commit 507ebe6444a4 ("ibmvnic: Fix use-after-free of VNIC login
    response buffer") did).

    Signed-off-by: Jakub Kicinski

    Jakub Kicinski
     

04 Sep, 2020

2 commits

  • This commit adds xsk_fwd test file to .gitignore which is newly added
    to samples/bpf.

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

    Daniel T. Lee
     
  • 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
     

01 Sep, 2020

3 commits

  • The txpush program in the xdpsock sample application is supposed
    to send out all packets in the umem in a round-robin fashion.
    The problem is that it only cycled through the first BATCH_SIZE
    worth of packets. Fixed this so that it cycles through all buffers
    in the umem as intended.

    Fixes: 248c7f9c0e21 ("samples/bpf: convert xdpsock to use libbpf for AF_XDP access")
    Signed-off-by: Weqaar Janjua
    Signed-off-by: Daniel Borkmann
    Acked-by: Björn Töpel
    Link: https://lore.kernel.org/bpf/20200828161717.42705-1-weqaar.a.janjua@intel.com

    Weqaar Janjua
     
  • Optimize the throughput performance of the l2fwd sub-app in the
    xdpsock sample application by removing a duplicate syscall and
    increasing the size of the fill ring.

    The latter needs some further explanation. We recommend that you set
    the fill ring size >= HW RX ring size + AF_XDP RX ring size. Make sure
    you fill up the fill ring with buffers at regular intervals, and you
    will with this setting avoid allocation failures in the driver. These
    are usually quite expensive since drivers have not been written to
    assume that allocation failures are common. For regular sockets,
    kernel allocated memory is used that only runs out in OOM situations
    that should be rare.

    These two performance optimizations together lead to a 6% percent
    improvement for the l2fwd app on my machine.

    Signed-off-by: Magnus Karlsson
    Signed-off-by: Daniel Borkmann
    Link: https://lore.kernel.org/bpf/1598619065-1944-1-git-send-email-magnus.karlsson@intel.com

    Magnus Karlsson
     
  • This sample code illustrates the packet forwarding between multiple
    AF_XDP sockets in multi-threading environment. All the threads and
    sockets are sharing a common buffer pool, with each socket having
    its own private buffer cache. The sockets are created with the
    xsk_socket__create_shared() function, which allows multiple AF_XDP
    sockets to share the same UMEM object.

    Example 1: Single thread handling two sockets. Packets received
    from socket A (on top of interface IFA, queue QA) are forwarded
    to socket B (on top of interface IFB, queue QB) and vice-versa.
    The thread is affinitized to CPU core C:

    ./xsk_fwd -i IFA -q QA -i IFB -q QB -c C

    Example 2: Two threads, each handling two sockets. Packets from
    socket A are sent to socket B (by thread X), packets
    from socket B are sent to socket A (by thread X); packets from
    socket C are sent to socket D (by thread Y), packets from socket
    D are sent to socket C (by thread Y). The two threads are bound
    to CPU cores CX and CY:

    ./xdp_fwd -i IFA -q QA -i IFB -q QB -i IFC -q QC -i IFD -q QD -c CX -c CY

    Signed-off-by: Cristian Dumitrescu
    Signed-off-by: Daniel Borkmann
    Acked-by: Björn Töpel
    Link: https://lore.kernel.org/bpf/1598603189-32145-15-git-send-email-magnus.karlsson@intel.com

    Cristian Dumitrescu
     

25 Aug, 2020

3 commits

  • For the problem of increasing fragmentation of the bpf loader programs,
    instead of using bpf_loader.o, which is used in samples/bpf, this
    commit refactors the existing tracepoint tracing programs with libbbpf
    bpf loader.

    - Adding a tracepoint event and attaching a bpf program to it was done
    through bpf_program_attach().
    - Instead of using the existing BPF MAP definition, MAP definition
    has been refactored with the new BTF-defined MAP format.

    Signed-off-by: Daniel T. Lee
    Signed-off-by: Alexei Starovoitov
    Link: https://lore.kernel.org/bpf/20200823085334.9413-4-danieltimlee@gmail.com

    Daniel T. Lee
     
  • For the problem of increasing fragmentation of the bpf loader programs,
    instead of using bpf_loader.o, which is used in samples/bpf, this
    commit refactors the existing kprobe tracing programs with libbbpf
    bpf loader.

    - For kprobe events pointing to system calls, the SYSCALL() macro in
    trace_common.h was used.
    - Adding a kprobe event and attaching a bpf program to it was done
    through bpf_program_attach().
    - Instead of using the existing BPF MAP definition, MAP definition
    has been refactored with the new BTF-defined MAP format.

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

    Daniel T. Lee
     
  • Since commit cc7f641d637b ("samples: bpf: Refactor BPF map performance
    test with libbpf") has ommited the removal of bpf_load.o from Makefile,
    this commit removes the bpf_load.o rule for targets where bpf_load.o is
    not used.

    Fixes: cc7f641d637b ("samples: bpf: Refactor BPF map performance test with libbpf")
    Signed-off-by: Daniel T. Lee
    Signed-off-by: Alexei Starovoitov
    Link: https://lore.kernel.org/bpf/20200823085334.9413-2-danieltimlee@gmail.com

    Daniel T. Lee
     

24 Aug, 2020

1 commit

  • Replace the existing /* fall through */ comments and its variants with
    the new pseudo-keyword macro fallthrough[1]. Also, remove unnecessary
    fall-through markings when it is the case.

    [1] https://www.kernel.org/doc/html/v5.7/process/deprecated.html?highlight=fallthrough#implicit-switch-case-fall-through

    Signed-off-by: Gustavo A. R. Silva

    Gustavo A. R. Silva
     

19 Aug, 2020

1 commit

  • >From commit f1394b798814 ("block: mark blk_account_io_completion
    static") symbol blk_account_io_completion() has been marked as static,
    which makes it no longer possible to attach kprobe to this event.
    Currently, there are broken samples due to this reason.

    As a solution to this, attach kprobe events to blk_account_io_done()
    to modify them to perform the same behavior as before.

    Signed-off-by: Daniel T. Lee
    Signed-off-by: Alexei Starovoitov
    Acked-by: Yonghong Song
    Link: https://lore.kernel.org/bpf/20200818051641.21724-1-danieltimlee@gmail.com

    Daniel T. Lee
     

22 Jul, 2020

1 commit

  • A handful of samples and selftests fail to build on s390, because
    after commit 0ebeea8ca8a4 ("bpf: Restrict bpf_probe_read{, str}()
    only to archs where they work") bpf_probe_read is not available
    anymore.

    Fix by using bpf_probe_read_kernel.

    Signed-off-by: Ilya Leoshkevich
    Signed-off-by: Alexei Starovoitov
    Link: https://lore.kernel.org/bpf/20200720114806.88823-1-iii@linux.ibm.com

    Ilya Leoshkevich
     

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
     

14 Jul, 2020

1 commit

  • Introduce the --extra-stats (or simply -x) flag to the xdpsock application
    which prints additional statistics alongside the regular rx and tx
    counters. The new statistics printed report error conditions eg. rx ring
    full, invalid descriptors, etc.

    Signed-off-by: Ciara Loftus
    Signed-off-by: Alexei Starovoitov
    Link: https://lore.kernel.org/bpf/20200708072835.4427-3-ciara.loftus@intel.com

    Ciara Loftus
     

11 Jul, 2020

1 commit

  • The `BPF_LOG_BUF_SIZE`'s value is `UINT32_MAX >> 8`, so define an array
    with it on stack caused an overflow.

    Signed-off-by: Wenbo Zhang
    Signed-off-by: Daniel Borkmann
    Acked-by: Andrii Nakryiko
    Link: https://lore.kernel.org/bpf/20200710092035.28919-1-ethercflow@gmail.com

    Wenbo Zhang
     

08 Jul, 2020

3 commits

  • Previously, in order to set the numa_node attribute at the time of map
    creation using "libbpf", it was necessary to call bpf_create_map_node()
    directly (bpf_load approach), instead of calling bpf_object_load()
    that handles everything on its own, including map creation. And because
    of this problem, this sample had problems with refactoring from bpf_load
    to libbbpf.

    However, by commit 1bdb6c9a1c43 ("libbpf: Add a bunch of attribute
    getters/setters for map definitions") added the numa_node attribute and
    allowed it to be set in the map.

    By using libbpf instead of bpf_load, the inner map definition has
    been explicitly declared with BTF-defined format. Also, the element of
    ARRAY_OF_MAPS was also statically specified using the BTF format. And
    for this reason some logic in fixup_map() was not needed and changed
    or removed.

    Signed-off-by: Daniel T. Lee
    Signed-off-by: Daniel Borkmann
    Acked-by: Andrii Nakryiko
    Link: https://lore.kernel.org/bpf/20200707184855.30968-4-danieltimlee@gmail.com

    Daniel T. Lee
     
  • From commit 646f02ffdd49 ("libbpf: Add BTF-defined map-in-map
    support"), a way to define internal map in BTF-defined map has been
    added.

    Instead of using previous 'inner_map_idx' definition, the structure to
    be used for the inner map can be directly defined using array directive.

    __array(values, struct inner_map)

    This commit refactors map in map test program with libbpf by explicitly
    defining inner map with BTF-defined format.

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

    Daniel T. Lee
     
  • Currently, BPF programs with kprobe/sys_connect does not work properly.

    Commit 34745aed515c ("samples/bpf: fix kprobe attachment issue on x64")
    This commit modifies the bpf_load behavior of kprobe events in the x64
    architecture. If the current kprobe event target starts with "sys_*",
    add the prefix "__x64_" to the front of the event.

    Appending "__x64_" prefix with kprobe/sys_* event was appropriate as a
    solution to most of the problems caused by the commit below.

    commit d5a00528b58c ("syscalls/core, syscalls/x86: Rename struct
    pt_regs-based sys_*() to __x64_sys_*()")

    However, there is a problem with the sys_connect kprobe event that does
    not work properly. For __sys_connect event, parameters can be fetched
    normally, but for __x64_sys_connect, parameters cannot be fetched.

    ffffffff818d3520 :
    ffffffff818d3520: e8 fb df 32 00 callq 0xffffffff81c01520

    ffffffff818d3525: 48 8b 57 60 movq 96(%rdi), %rdx
    ffffffff818d3529: 48 8b 77 68 movq 104(%rdi), %rsi
    ffffffff818d352d: 48 8b 7f 70 movq 112(%rdi), %rdi
    ffffffff818d3531: e8 1a ff ff ff callq 0xffffffff818d3450

    ffffffff818d3536: 48 98 cltq
    ffffffff818d3538: c3 retq
    ffffffff818d3539: 0f 1f 80 00 00 00 00 nopl (%rax)

    As the assembly code for __x64_sys_connect shows, parameters should be
    fetched and set into rdi, rsi, rdx registers prior to calling
    __sys_connect.

    Because of this problem, this commit fixes the sys_connect event by
    first getting the value of the rdi register and then the value of the
    rdi, rsi, and rdx register through an offset based on that value.

    Fixes: 34745aed515c ("samples/bpf: fix kprobe attachment issue on x64")
    Signed-off-by: Daniel T. Lee
    Signed-off-by: Daniel Borkmann
    Acked-by: Andrii Nakryiko
    Link: https://lore.kernel.org/bpf/20200707184855.30968-2-danieltimlee@gmail.com

    Daniel T. Lee
     

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

2 commits

  • Because the previous two commit replaced the bpf_load implementation of
    the user program with libbpf, the corresponding kernel program's MAP
    definition can be replaced with new BTF-defined map syntax.

    This commit only updates the samples which uses libbpf API for loading
    bpf program not with bpf_load.

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

    Daniel T. Lee
     
  • This commit adds tracex7 test file (testfile.img) to .gitignore which
    comes from test_override_return.sh.

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

    Daniel T. Lee