08 Apr, 2022

2 commits

  • [ Upstream commit edc21dc909c6c133a2727f063eadd7907af51f94 ]

    When reworking btf__get_from_id() in commit a19f93cfafdf the error
    handling when calling bpf_btf_get_fd_by_id() changed. Before the rework
    if bpf_btf_get_fd_by_id() failed the error would not be propagated to
    callers of btf__get_from_id(), after the rework it is. This lead to a
    change in behavior in print_key_value() that now prints an error when
    trying to lookup keys in maps with no btf available.

    Fix this by following the way used in dumping maps to allow to look up
    keys in no-btf maps, by which it decides whether and where to get the
    btf info according to the btf value type.

    Fixes: a19f93cfafdf ("libbpf: Add internal helper to load BTF data by FD")
    Signed-off-by: Yinjun Zhang
    Signed-off-by: Simon Horman
    Signed-off-by: Andrii Nakryiko
    Reviewed-by: Niklas Söderlund
    Acked-by: Jiri Olsa
    Link: https://lore.kernel.org/bpf/1644249625-22479-1-git-send-email-yinjun.zhang@corigine.com
    Signed-off-by: Sasha Levin

    Yinjun Zhang
     
  • [ Upstream commit 0991f6a38f576aa9a5e34713e23c998a3310d4d0 ]

    After `bpftool gen skeleton`, the ${bpf_app}.skel.h will provide that
    ${bpf_app_name}__open helper to load bpf. If there is some error
    like ENOMEM, the ${bpf_app_name}__open will rollback(free) the allocated
    object, including `bpf_object_skeleton`.

    Since the ${bpf_app_name}__create_skeleton set the obj->skeleton first
    and not rollback it when error, it will cause double-free in
    ${bpf_app_name}__destory at ${bpf_app_name}__open. Therefore, we should
    set the obj->skeleton before return 0;

    Fixes: 5dc7a8b21144 ("bpftool, selftests/bpf: Embed object file inside skeleton")
    Signed-off-by: Wei Fu
    Signed-off-by: Andrii Nakryiko
    Link: https://lore.kernel.org/bpf/20220108084008.1053111-1-fuweid89@gmail.com
    Signed-off-by: Sasha Levin

    Wei Fu
     

09 Mar, 2022

1 commit

  • [ Upstream commit 1144ab9bdf3430e1b5b3f22741e5283841951add ]

    Fix one case where we don't do explicit clean up.

    Fixes: fbbb68de80a4 ("bpf: Add resolve_btfids tool to resolve BTF IDs in ELF object")
    Signed-off-by: Andrii Nakryiko
    Signed-off-by: Daniel Borkmann
    Link: https://lore.kernel.org/bpf/20211124002325.1737739-2-andrii@kernel.org
    Signed-off-by: Sasha Levin

    Andrii Nakryiko
     

09 Feb, 2022

1 commit

  • commit 7f3bdbc3f13146eb9d07de81ea71f551587a384b upstream.

    When building with 'make -s', there is some output from resolve_btfids:

    $ make -sj"$(nproc)" oldconfig prepare
    MKDIR .../tools/bpf/resolve_btfids/libbpf/
    MKDIR .../tools/bpf/resolve_btfids//libsubcmd
    LINK resolve_btfids

    Silent mode means that no information should be emitted about what is
    currently being done. Use the $(silent) variable from Makefile.include
    to avoid defining the msg macro so that there is no information printed.

    Fixes: fbbb68de80a4 ("bpf: Add resolve_btfids tool to resolve BTF IDs in ELF object")
    Signed-off-by: Nathan Chancellor
    Signed-off-by: Daniel Borkmann
    Link: https://lore.kernel.org/bpf/20220201212503.731732-1-nathan@kernel.org
    Signed-off-by: Greg Kroah-Hartman

    Nathan Chancellor
     

27 Jan, 2022

4 commits

  • commit 986dec18bbf41f50edc2e0aa4ac5ef8e0f64f328 upstream.

    Mixed indentation levels in the lists of options in bpftool's
    documentation produces some unexpected results. For the "bpftool" man
    page, it prints a warning:

    $ make -C bpftool.8
    GEN bpftool.8
    :26: (ERROR/3) Unexpected indentation.

    For other pages, there is no warning, but it results in a line break
    appearing in the option lists in the generated man pages.

    RST paragraphs should have a uniform indentation level. Let's fix it.

    Fixes: c07ba629df97 ("tools: bpftool: Update and synchronise option list in doc and help msg")
    Fixes: 8cc8c6357c8f ("tools: bpftool: Document and add bash completion for -L, -B options")
    Signed-off-by: Quentin Monnet
    Signed-off-by: Andrii Nakryiko
    Link: https://lore.kernel.org/bpf/20211110114632.24537-5-quentin@isovalent.com
    Signed-off-by: Greg Kroah-Hartman

    Quentin Monnet
     
  • commit 48f5aef4c458c19ab337eed8c95a6486cc014aa3 upstream.

    Bpftool's Makefile, and the Makefile for its documentation, both include
    scripts/utilities.mak, but they use none of the items defined in this
    file. Remove the includes.

    Fixes: 71bb428fe2c1 ("tools: bpf: add bpftool")
    Signed-off-by: Quentin Monnet
    Signed-off-by: Andrii Nakryiko
    Link: https://lore.kernel.org/bpf/20211110114632.24537-3-quentin@isovalent.com
    Signed-off-by: Greg Kroah-Hartman

    Quentin Monnet
     
  • [ Upstream commit 1a1a0b0364ad291bd8e509da104ac8b5b1afec5d ]

    The output of bpftool prog tracelog is currently buffered, which is
    inconvenient when piping the output into other commands. A simple
    tracelog | grep will typically not display anything. This patch fixes it
    by enabling line buffering on stdout for the whole bpftool binary.

    Fixes: 30da46b5dc3a ("tools: bpftool: add a command to dump the trace pipe")
    Signed-off-by: Quentin Monnet
    Signed-off-by: Paul Chaignon
    Signed-off-by: Andrii Nakryiko
    Acked-by: Yonghong Song
    Link: https://lore.kernel.org/bpf/20211220214528.GA11706@Mem
    Signed-off-by: Sasha Levin

    Paul Chaignon
     
  • [ Upstream commit ebbd7f64a3fbe9e0f235e39fc244ee9735e2a52a ]

    Following the extraction of prog_dump() from do_dump(), the struct btf
    allocated in prog_dump() is no longer freed on error; the struct
    bpf_prog_linfo is not freed at all. Make sure we release them before
    exiting the function.

    Fixes: ec2025095cf6 ("bpftool: Match several programs with same tag")
    Signed-off-by: Quentin Monnet
    Signed-off-by: Andrii Nakryiko
    Link: https://lore.kernel.org/bpf/20211110114632.24537-2-quentin@isovalent.com
    Signed-off-by: Sasha Levin

    Quentin Monnet
     

19 Nov, 2021

1 commit

  • [ Upstream commit e89ef634f81c9d90e1824ab183721f3b361472e6 ]

    Bpftool creates a new JSON object for writing program metadata in plain
    text mode, regardless of metadata being present or not. Then this writer
    is freed if any metadata has been found and printed, but it leaks
    otherwise. We cannot destroy the object unconditionally, because the
    destructor prints an undesirable line break. Instead, make sure the
    writer is created only after we have found program metadata to print.

    Found with valgrind.

    Fixes: aff52e685eb3 ("bpftool: Support dumping metadata")
    Signed-off-by: Quentin Monnet
    Signed-off-by: Andrii Nakryiko
    Link: https://lore.kernel.org/bpf/20211022094743.11052-1-quentin@isovalent.com
    Signed-off-by: Sasha Levin

    Quentin Monnet
     

01 Aug, 2021

1 commit

  • Andrii Nakryiko says:

    ====================
    bpf-next 2021-07-30

    We've added 64 non-merge commits during the last 15 day(s) which contain
    a total of 83 files changed, 5027 insertions(+), 1808 deletions(-).

    The main changes are:

    1) BTF-guided binary data dumping libbpf API, from Alan.

    2) Internal factoring out of libbpf CO-RE relocation logic, from Alexei.

    3) Ambient BPF run context and cgroup storage cleanup, from Andrii.

    4) Few small API additions for libbpf 1.0 effort, from Evgeniy and Hengqi.

    5) bpf_program__attach_kprobe_opts() fixes in libbpf, from Jiri.

    6) bpf_{get,set}sockopt() support in BPF iterators, from Martin.

    7) BPF map pinning improvements in libbpf, from Martynas.

    8) Improved module BTF support in libbpf and bpftool, from Quentin.

    9) Bpftool cleanups and documentation improvements, from Quentin.

    10) Libbpf improvements for supporting CO-RE on old kernels, from Shuyi.

    11) Increased maximum cgroup storage size, from Stanislav.

    12) Small fixes and improvements to BPF tests and samples, from various folks.

    * https://git.kernel.org/pub/scm/linux/kernel/git/bpf/bpf-next: (64 commits)
    tools: bpftool: Complete metrics list in "bpftool prog profile" doc
    tools: bpftool: Document and add bash completion for -L, -B options
    selftests/bpf: Update bpftool's consistency script for checking options
    tools: bpftool: Update and synchronise option list in doc and help msg
    tools: bpftool: Complete and synchronise attach or map types
    selftests/bpf: Check consistency between bpftool source, doc, completion
    tools: bpftool: Slightly ease bash completion updates
    unix_bpf: Fix a potential deadlock in unix_dgram_bpf_recvmsg()
    libbpf: Add btf__load_vmlinux_btf/btf__load_module_btf
    tools: bpftool: Support dumping split BTF by id
    libbpf: Add split BTF support for btf__load_from_kernel_by_id()
    tools: Replace btf__get_from_id() with btf__load_from_kernel_by_id()
    tools: Free BTF objects at various locations
    libbpf: Rename btf__get_from_id() as btf__load_from_kernel_by_id()
    libbpf: Rename btf__load() as btf__load_into_kernel()
    libbpf: Return non-null error on failures in libbpf_find_prog_btf_id()
    bpf: Emit better log message if bpf_iter ctx arg btf_id == 0
    tools/resolve_btfids: Emit warnings and patch zero id for missing symbols
    bpf: Increase supported cgroup storage value size
    libbpf: Fix race when pinning maps in parallel
    ...
    ====================

    Link: https://lore.kernel.org/r/20210730225606.1897330-1-andrii@kernel.org
    Signed-off-by: Jakub Kicinski

    Jakub Kicinski
     

31 Jul, 2021

5 commits

  • Profiling programs with bpftool was extended some time ago to support
    two new metrics, namely itlb_misses and dtlb_misses (misses for the
    instruction/data translation lookaside buffer). Update the manual page
    and bash completion accordingly.

    Fixes: 450d060e8f75 ("bpftool: Add {i,d}tlb_misses support for bpftool profile")
    Signed-off-by: Quentin Monnet
    Signed-off-by: Andrii Nakryiko
    Link: https://lore.kernel.org/bpf/20210730215435.7095-8-quentin@isovalent.com

    Quentin Monnet
     
  • The -L|--use-loader option for using loader programs when loading, or
    when generating a skeleton, did not have any documentation or bash
    completion. Same thing goes for -B|--base-btf, used to pass a path to a
    base BTF object for split BTF such as BTF for kernel modules.

    This patch documents and adds bash completion for those options.

    Fixes: 75fa1777694c ("tools/bpftool: Add bpftool support for split BTF")
    Fixes: d510296d331a ("bpftool: Use syscall/loader program in "prog load" and "gen skeleton" command.")
    Signed-off-by: Quentin Monnet
    Signed-off-by: Andrii Nakryiko
    Link: https://lore.kernel.org/bpf/20210730215435.7095-7-quentin@isovalent.com

    Quentin Monnet
     
  • All bpftool commands support the options for JSON output and debug from
    libbpf. In addition, some commands support additional options
    corresponding to specific use cases.

    The list of options described in the man pages for the different
    commands are not always accurate. The messages for interactive help are
    mostly limited to HELP_SPEC_OPTIONS, and are even less representative of
    the actual set of options supported for the commands.

    Let's update the lists:

    - HELP_SPEC_OPTIONS is modified to contain the "default" options (JSON
    and debug), and to be extensible (no ending curly bracket).
    - All commands use HELP_SPEC_OPTIONS in their help message, and then
    complete the list with their specific options.
    - The lists of options in the man pages are updated.
    - The formatting of the list for bpftool.rst is adjusted to match
    formatting for the other man pages. This is for consistency, and also
    because it will be helpful in a future patch to automatically check
    that the files are synchronised.

    Signed-off-by: Quentin Monnet
    Signed-off-by: Andrii Nakryiko
    Link: https://lore.kernel.org/bpf/20210730215435.7095-5-quentin@isovalent.com

    Quentin Monnet
     
  • Update bpftool's list of attach type names to tell it about the latest
    attach types, or the "ringbuf" map. Also update the documentation, help
    messages, and bash completion when relevant.

    These missing items were reported by the newly added Python script used
    to help maintain consistency in bpftool.

    Signed-off-by: Quentin Monnet
    Signed-off-by: Andrii Nakryiko
    Link: https://lore.kernel.org/bpf/20210730215435.7095-4-quentin@isovalent.com

    Quentin Monnet
     
  • Bash completion for bpftool gets two minor improvements in this patch.

    Move the detection of attach types for "bpftool cgroup attach" outside
    of the "case/esac" bloc, where we cannot reuse our variable holding the
    list of supported attach types as a pattern list. After the change, we
    have only one list of cgroup attach types to update when new types are
    added, instead of the former two lists.

    Also rename the variables holding lists of names for program types, map
    types, and attach types, to make them more unique. This can make it
    slightly easier to point people to the relevant variables to update, but
    the main objective here is to help run a script to check that bash
    completion is up-to-date with bpftool's source code.

    Signed-off-by: Quentin Monnet
    Signed-off-by: Andrii Nakryiko
    Link: https://lore.kernel.org/bpf/20210730215435.7095-2-quentin@isovalent.com

    Quentin Monnet
     

30 Jul, 2021

4 commits

  • Split BTF objects are typically BTF objects for kernel modules, which
    are incrementally built on top of kernel BTF instead of redefining all
    kernel symbols they need. We can use bpftool with its -B command-line
    option to dump split BTF objects. It works well when the handle provided
    for the BTF object to dump is a "path" to the BTF object, typically
    under /sys/kernel/btf, because bpftool internally calls
    btf__parse_split() which can take a "base_btf" pointer and resolve the
    BTF reconstruction (although in that case, the "-B" option is
    unnecessary because bpftool performs autodetection).

    However, it did not work so far when passing the BTF object through its
    id, because bpftool would call btf__get_from_id() which did not provide
    a way to pass a "base_btf" pointer.

    In other words, the following works:

    # bpftool btf dump file /sys/kernel/btf/i2c_smbus -B /sys/kernel/btf/vmlinux

    But this was not possible:

    # bpftool btf dump id 6 -B /sys/kernel/btf/vmlinux

    The libbpf API has recently changed, and btf__get_from_id() has been
    deprecated in favour of btf__load_from_kernel_by_id() and its version
    with support for split BTF, btf__load_from_kernel_by_id_split(). Let's
    update bpftool to make it able to dump the BTF object in the second case
    as well.

    Signed-off-by: Quentin Monnet
    Signed-off-by: Andrii Nakryiko
    Acked-by: John Fastabend
    Link: https://lore.kernel.org/bpf/20210729162028.29512-9-quentin@isovalent.com

    Quentin Monnet
     
  • Replace the calls to function btf__get_from_id(), which we plan to
    deprecate before the library reaches v1.0, with calls to
    btf__load_from_kernel_by_id() in tools/ (bpftool, perf, selftests).
    Update the surrounding code accordingly (instead of passing a pointer to
    the btf struct, get it as a return value from the function).

    Signed-off-by: Quentin Monnet
    Signed-off-by: Andrii Nakryiko
    Acked-by: John Fastabend
    Link: https://lore.kernel.org/bpf/20210729162028.29512-6-quentin@isovalent.com

    Quentin Monnet
     
  • Make sure to call btf__free() (and not simply free(), which does not
    free all pointers stored in the struct) on pointers to struct btf
    objects retrieved at various locations.

    These were found while updating the calls to btf__get_from_id().

    Fixes: 999d82cbc044 ("tools/bpf: enhance test_btf file testing to test func info")
    Fixes: 254471e57a86 ("tools/bpf: bpftool: add support for func types")
    Fixes: 7b612e291a5a ("perf tools: Synthesize PERF_RECORD_* for loaded BPF programs")
    Fixes: d56354dc4909 ("perf tools: Save bpf_prog_info and BTF of new BPF programs")
    Fixes: 47c09d6a9f67 ("bpftool: Introduce "prog profile" command")
    Fixes: fa853c4b839e ("perf stat: Enable counting events for BPF programs")
    Signed-off-by: Quentin Monnet
    Signed-off-by: Andrii Nakryiko
    Link: https://lore.kernel.org/bpf/20210729162028.29512-5-quentin@isovalent.com

    Quentin Monnet
     
  • Kernel functions referenced by .BTF_ids may be changed from global to static
    and get inlined or get renamed/removed, and thus disappears from BTF.
    This causes kernel build failure when resolve_btfids do id patch for symbols
    in .BTF_ids in vmlinux. Update resolve_btfids to emit warning messages and
    patch zero id for missing symbols instead of aborting kernel build process.

    Suggested-by: Andrii Nakryiko
    Signed-off-by: Hengqi Chen
    Signed-off-by: Andrii Nakryiko
    Acked-by: Yonghong Song
    Link: https://lore.kernel.org/bpf/20210727132532.2473636-2-hengqi.chen@gmail.com

    Hengqi Chen
     

16 Jul, 2021

1 commit


08 Jul, 2021

2 commits

  • make[2]: *** No rule to make target 'install'. Stop.
    make[1]: *** [Makefile:122: runqslower_install] Error 2
    make: *** [Makefile:116: bpf_install] Error 2

    There is no rule for target 'install' in tools/bpf/runqslower/Makefile,
    and there is no need to install it, so just remove 'runqslower_install'.

    Fixes: 9c01546d26d2 ("tools/bpf: Add runqslower tool to tools/bpf")
    Signed-off-by: Wei Li
    Signed-off-by: Andrii Nakryiko
    Link: https://lore.kernel.org/bpf/20210628030409.3459095-1-liwei391@huawei.com

    Wei Li
     
  • Commit 2f064a59a11f ("sched: Change task_struct::state") renamed task->state
    to task->__state in task_struct. Fix runqslower to use the new name of the
    field.

    Fixes: 2f064a59a11f ("sched: Change task_struct::state")
    Signed-off-by: SanjayKumar Jeyakumar
    Signed-off-by: Andrii Nakryiko
    Acked-by: Yonghong Song
    Link: https://lore.kernel.org/bpf/20210707052914.21473-1-vjsanjay@gmail.com

    SanjayKumar Jeyakumar
     

06 Jul, 2021

1 commit

  • va_list 'ap' was opened but not closed by va_end() in error case. It should
    be closed by va_end() before the return.

    Fixes: aa52bcbe0e72 ("tools: bpftool: Fix json dump crash on powerpc")
    Signed-off-by: Gu Shengxian
    Signed-off-by: Daniel Borkmann
    Cc: Jiri Olsa
    Link: https://lore.kernel.org/bpf/20210706013543.671114-1-gushengxian507419@gmail.com

    Gu Shengxian
     

30 Jun, 2021

1 commit


18 Jun, 2021

2 commits

  • The vmlinux ".BTF_ids" ELF section is declared in btf_ids.h to hold a list
    of zero-filled BTF IDs, which is then patched at link-time with correct
    values by resolv_btfids. The section is flagged as "allocable" to preclude
    compression, but notably the section contents (BTF IDs) are untyped.

    When patching the BTF IDs, resolve_btfids writes in host-native endianness
    and relies on libelf for any required translation on reading and updating
    vmlinux. However, since the type of the .BTF_ids section content defaults
    to ELF_T_BYTE (i.e. unsigned char), no translation occurs. This results in
    incorrect patched values when cross-compiling to non-native endianness,
    and can manifest as kernel Oops and test failures which are difficult to
    troubleshoot [1].

    Explicitly set the type of patched data to ELF_T_WORD, the architecture-
    neutral ELF type corresponding to the u32 BTF IDs. This enables libelf to
    transparently perform any needed endian conversions.

    Fixes: fbbb68de80a4 ("bpf: Add resolve_btfids tool to resolve BTF IDs in ELF object")
    Signed-off-by: Tony Ambardar
    Signed-off-by: Daniel Borkmann
    Acked-by: Jiri Olsa
    Cc: Frank Eigler
    Cc: Mark Wielaard
    Cc: Jiri Olsa
    Cc: Yonghong Song
    Link: https://lore.kernel.org/bpf/CAPGftE_eY-Zdi3wBcgDfkz_iOr1KF10n=9mJHm1_a_PykcsoeA@mail.gmail.com [1]
    Link: https://lore.kernel.org/bpf/20210618061404.818569-1-Tony.Ambardar@gmail.com

    Tony Ambardar
     
  • Daniel Borkmann says:

    ====================
    pull-request: bpf-next 2021-06-17

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

    We've added 50 non-merge commits during the last 25 day(s) which contain
    a total of 148 files changed, 4779 insertions(+), 1248 deletions(-).

    The main changes are:

    1) BPF infrastructure to migrate TCP child sockets from a listener to another
    in the same reuseport group/map, from Kuniyuki Iwashima.

    2) Add a provably sound, faster and more precise algorithm for tnum_mul() as
    noted in https://arxiv.org/abs/2105.05398, from Harishankar Vishwanathan.

    3) Streamline error reporting changes in libbpf as planned out in the
    'libbpf: the road to v1.0' effort, from Andrii Nakryiko.

    4) Add broadcast support to xdp_redirect_map(), from Hangbin Liu.

    5) Extends bpf_map_lookup_and_delete_elem() functionality to 4 more map
    types, that is, {LRU_,PERCPU_,LRU_PERCPU_,}HASH, from Denis Salopek.

    6) Support new LLVM relocations in libbpf to make them more linker friendly,
    also add a doc to describe the BPF backend relocations, from Yonghong Song.

    7) Silence long standing KUBSAN complaints on register-based shifts in
    interpreter, from Daniel Borkmann and Eric Biggers.

    8) Add dummy PT_REGS macros in libbpf to fail BPF program compilation when
    target arch cannot be determined, from Lorenz Bauer.

    9) Extend AF_XDP to support large umems with 1M+ pages, from Magnus Karlsson.

    10) Fix two minor libbpf tc BPF API issues, from Kumar Kartikeya Dwivedi.

    11) Move libbpf BPF_SEQ_PRINTF/BPF_SNPRINTF macros that can be used by BPF
    programs to bpf_helpers.h header, from Florent Revest.
    ====================

    Signed-off-by: David S. Miller

    David S. Miller
     

12 Jun, 2021

1 commit

  • Fix to return a negative error code from the error handling
    case instead of 0, as done elsewhere in this function.

    Fixes: 668da745af3c2 ("tools: bpftool: add support for quotations ...")
    Reported-by: Hulk Robot
    Signed-off-by: Zhihao Cheng
    Signed-off-by: Andrii Nakryiko
    Reviewed-by: Quentin Monnet
    Link: https://lore.kernel.org/bpf/20210609115916.2186872-1-chengzhihao1@huawei.com

    Zhihao Cheng
     

09 Jun, 2021

1 commit

  • When the bootstrap and final bpftool have different architectures, we
    need to build two distinct disasm.o objects. Add a recipe for the
    bootstrap disasm.o.

    After commit d510296d331a ("bpftool: Use syscall/loader program in
    "prog load" and "gen skeleton" command.") cross-building bpftool didn't
    work anymore, because the bootstrap bpftool was linked using objects
    from different architectures:

    $ make O=/tmp/bpftool ARCH=arm64 CROSS_COMPILE=aarch64-linux-gnu- -C tools/bpf/bpftool/ V=1
    [...]
    aarch64-linux-gnu-gcc ... -c -MMD -o /tmp/bpftool/disasm.o /home/z/src/linux/kernel/bpf/disasm.c
    gcc ... -c -MMD -o /tmp/bpftool//bootstrap/main.o main.c
    gcc ... -o /tmp/bpftool//bootstrap/bpftool /tmp/bpftool//bootstrap/main.o ... /tmp/bpftool/disasm.o
    /usr/bin/ld: /tmp/bpftool/disasm.o: Relocations in generic ELF (EM: 183)
    /usr/bin/ld: /tmp/bpftool/disasm.o: Relocations in generic ELF (EM: 183)
    /usr/bin/ld: /tmp/bpftool/disasm.o: Relocations in generic ELF (EM: 183)
    /usr/bin/ld: /tmp/bpftool/disasm.o: error adding symbols: file in wrong format
    collect2: error: ld returned 1 exit status
    [...]

    The final bpftool was built for e.g. arm64, while the bootstrap bpftool,
    executed on the host, was built for x86. The problem here was that disasm.o
    linked into the bootstrap bpftool was arm64 rather than x86. With the fix
    we build two disasm.o, one for the target bpftool in arm64, and one for
    the bootstrap bpftool in x86.

    Fixes: d510296d331a ("bpftool: Use syscall/loader program in "prog load" and "gen skeleton" command.")
    Signed-off-by: Jean-Philippe Brucker
    Signed-off-by: Andrii Nakryiko
    Signed-off-by: Daniel Borkmann
    Acked-by: Andrii Nakryiko
    Link: https://lore.kernel.org/bpf/20210603170515.1854642-1-jean-philippe@linaro.org

    Jean-Philippe Brucker
     

28 May, 2021

1 commit


26 May, 2021

1 commit

  • Follow libbpf's error handling conventions and pass through errors and errno
    properly. Skeleton code always returned NULL on errors (not ERR_PTR(err)), so
    there are no backwards compatibility concerns. But now we also set errno
    properly, so it's possible to distinguish different reasons for failure, if
    necessary.

    Signed-off-by: Andrii Nakryiko
    Signed-off-by: Alexei Starovoitov
    Acked-by: John Fastabend
    Acked-by: Toke Høiland-Jørgensen
    Link: https://lore.kernel.org/bpf/20210525035935.1461796-6-andrii@kernel.org

    Andrii Nakryiko
     

25 May, 2021

1 commit

  • The help information was not added at the time when the function got added.
    Fix this and add the missing information to its cli, documentation and bash
    completion.

    Fixes: db94cc0b4805 ("bpftool: Add support for BPF_CGROUP_INET_SOCK_RELEASE")
    Signed-off-by: Liu Jian
    Signed-off-by: Daniel Borkmann
    Reviewed-by: Quentin Monnet
    Link: https://lore.kernel.org/bpf/20210525014139.323859-1-liujian56@huawei.com

    Liu Jian
     

19 May, 2021

1 commit

  • Add -L flag to bpftool to use libbpf gen_trace facility and syscall/loader program
    for skeleton generation and program loading.

    "bpftool gen skeleton -L" command will generate a "light skeleton" or "loader skeleton"
    that is similar to existing skeleton, but has one major difference:
    $ bpftool gen skeleton lsm.o > lsm.skel.h
    $ bpftool gen skeleton -L lsm.o > lsm.lskel.h
    $ diff lsm.skel.h lsm.lskel.h
    @@ -5,34 +4,34 @@
    #define __LSM_SKEL_H__

    #include
    -#include
    +#include

    The light skeleton does not use majority of libbpf infrastructure.
    It doesn't need libelf. It doesn't parse .o file.
    It only needs few sys_bpf wrappers. All of them are in bpf/bpf.h file.
    In future libbpf/bpf.c can be inlined into bpf.h, so not even libbpf.a would be
    needed to work with light skeleton.

    "bpftool prog load -L file.o" command is introduced for debugging of syscall/loader
    program generation. Just like the same command without -L it will try to load
    the programs from file.o into the kernel. It won't even try to pin them.

    "bpftool prog load -L -d file.o" command will provide additional debug messages
    on how syscall/loader program was generated.
    Also the execution of syscall/loader program will use bpf_trace_printk() for
    each step of loading BTF, creating maps, and loading programs.
    The user can do "cat /.../trace_pipe" for further debug.

    An example of fexit_sleep.lskel.h generated from progs/fexit_sleep.c:
    struct fexit_sleep {
    struct bpf_loader_ctx ctx;
    struct {
    struct bpf_map_desc bss;
    } maps;
    struct {
    struct bpf_prog_desc nanosleep_fentry;
    struct bpf_prog_desc nanosleep_fexit;
    } progs;
    struct {
    int nanosleep_fentry_fd;
    int nanosleep_fexit_fd;
    } links;
    struct fexit_sleep__bss {
    int pid;
    int fentry_cnt;
    int fexit_cnt;
    } *bss;
    };

    Signed-off-by: Alexei Starovoitov
    Signed-off-by: Daniel Borkmann
    Acked-by: Andrii Nakryiko
    Link: https://lore.kernel.org/bpf/20210514003623.28033-18-alexei.starovoitov@gmail.com

    Alexei Starovoitov
     

12 May, 2021

3 commits

  • As discussed in [0], stop emitting static variables in BPF skeletons to avoid
    issues with name-conflicting static variables across multiple
    statically-linked BPF object files.

    Users using static variables to pass data between BPF programs and user-space
    should do a trivial one-time switch according to the following simple rules:
    - read-only `static volatile const` variables should be converted to
    `volatile const`;
    - read/write `static volatile` variables should just drop `static volatile`
    modifiers to become global variables/symbols. To better handle older Clang
    versions, such newly converted global variables should be explicitly
    initialized with a specific value or `= 0`/`= {}`, whichever is
    appropriate.

    [0] https://lore.kernel.org/bpf/CAEf4BzZo7_r-hsNvJt3w3kyrmmBJj7ghGY8+k4nvKF0KLjma=w@mail.gmail.com/T/#m664d4b0d6b31ac8b2669360e0fc2d6962e9f5ec1

    Signed-off-by: Andrii Nakryiko
    Signed-off-by: Alexei Starovoitov
    Link: https://lore.kernel.org/bpf/20210507054119.270888-5-andrii@kernel.org

    Andrii Nakryiko
     
  • For better future extensibility add per-file linker options. Currently
    the set of available options is empty. This changes bpf_linker__add_file()
    API, but it's not a breaking change as bpf_linker APIs hasn't been released
    yet.

    Signed-off-by: Andrii Nakryiko
    Signed-off-by: Alexei Starovoitov
    Link: https://lore.kernel.org/bpf/20210507054119.270888-3-andrii@kernel.org

    Andrii Nakryiko
     
  • Similarly to .rodata, strip any const/volatile/restrict modifiers when
    generating BPF skeleton. They are not helpful and actually just get in the way.

    Signed-off-by: Andrii Nakryiko
    Signed-off-by: Alexei Starovoitov
    Acked-by: Yonghong Song
    Link: https://lore.kernel.org/bpf/20210507054119.270888-2-andrii@kernel.org

    Andrii Nakryiko
     

24 Apr, 2021

2 commits

  • Dump succinct information for each member of DATASEC: its kinds and name. This
    is extremely helpful to see at a quick glance what is inside each DATASEC of
    a given BTF. Without this, one has to jump around BTF data to just find out
    the name of a VAR or FUNC. DATASEC's var_secinfo member is special in that
    regard because it doesn't itself contain the name of the member, delegating
    that to the referenced VAR and FUNC kinds. Other kinds, like
    STRUCT/UNION/FUNC/ENUM, encode member names directly and thus are clearly
    identifiable in BTF dump.

    The new output looks like this:

    [35] DATASEC '.bss' size=0 vlen=6
    type_id=8 offset=0 size=4 (VAR 'input_bss1')
    type_id=13 offset=0 size=4 (VAR 'input_bss_weak')
    type_id=16 offset=0 size=4 (VAR 'output_bss1')
    type_id=17 offset=0 size=4 (VAR 'output_data1')
    type_id=18 offset=0 size=4 (VAR 'output_rodata1')
    type_id=20 offset=0 size=8 (VAR 'output_sink1')
    [36] DATASEC '.data' size=0 vlen=2
    type_id=9 offset=0 size=4 (VAR 'input_data1')
    type_id=14 offset=0 size=4 (VAR 'input_data_weak')
    [37] DATASEC '.kconfig' size=0 vlen=2
    type_id=25 offset=0 size=4 (VAR 'LINUX_KERNEL_VERSION')
    type_id=28 offset=0 size=1 (VAR 'CONFIG_BPF_SYSCALL')
    [38] DATASEC '.ksyms' size=0 vlen=1
    type_id=30 offset=0 size=1 (VAR 'bpf_link_fops')
    [39] DATASEC '.rodata' size=0 vlen=2
    type_id=12 offset=0 size=4 (VAR 'input_rodata1')
    type_id=15 offset=0 size=4 (VAR 'input_rodata_weak')
    [40] DATASEC 'license' size=0 vlen=1
    type_id=24 offset=0 size=4 (VAR 'LICENSE')

    Signed-off-by: Andrii Nakryiko
    Signed-off-by: Alexei Starovoitov
    Acked-by: Yonghong Song
    Link: https://lore.kernel.org/bpf/20210423181348.1801389-3-andrii@kernel.org

    Andrii Nakryiko
     
  • Add dumping of "extern" linkage for BTF VAR kind. Also shorten
    "global-allocated" to "global" to be in line with FUNC's "global".

    Signed-off-by: Andrii Nakryiko
    Signed-off-by: Alexei Starovoitov
    Acked-by: Yonghong Song
    Link: https://lore.kernel.org/bpf/20210423181348.1801389-2-andrii@kernel.org

    Andrii Nakryiko
     

16 Apr, 2021

1 commit

  • With clang compiler:
    make -j60 LLVM=1 LLVM_IAS=1 nlmsg_len nlmsg_len is "unsigned int".
    The macro NLMSG_OK is defined as below in uapi/linux/netlink.h.
    #define NLMSG_OK(nlh,len) ((len) >= (int)sizeof(struct nlmsghdr) && \
    (nlh)->nlmsg_len >= sizeof(struct nlmsghdr) && \
    (nlh)->nlmsg_len
    Signed-off-by: Alexei Starovoitov
    Acked-by: Andrii Nakryiko
    Link: https://lore.kernel.org/bpf/20210413153435.3029635-1-yhs@fb.com

    Yonghong Song
     

02 Apr, 2021

1 commit

  • Reusing BPF_SK_SKB_STREAM_VERDICT is possible but its name is
    confusing and more importantly we still want to distinguish them
    from user-space. So we can just reuse the stream verdict code but
    introduce a new type of eBPF program, skb_verdict. Users are not
    allowed to attach stream_verdict and skb_verdict programs to the
    same map.

    Signed-off-by: Cong Wang
    Signed-off-by: Alexei Starovoitov
    Acked-by: John Fastabend
    Link: https://lore.kernel.org/bpf/20210331023237.41094-10-xiyou.wangcong@gmail.com

    Cong Wang
     

01 Apr, 2021

1 commit

  • * make eprintf static, used only in main.c
    * initialize ret in eprintf
    * remove unused *tmp

    v3:
    * remove another err (Song Liu)

    v2:
    * remove unused 'int err = -1'

    Signed-off-by: Stanislav Fomichev
    Signed-off-by: Andrii Nakryiko
    Acked-by: Song Liu
    Link: https://lore.kernel.org/bpf/20210329223143.3659983-1-sdf@google.com

    Stanislav Fomichev