Commit Graph

27 Commits

Author SHA1 Message Date
Viktor Malik fd762d8319
tools/resolve_btfids: Fix comparison of distinct pointer types warning in resolve_btfids
JIRA: https://issues.redhat.com/browse/RHEL-30774

commit 13c9b702e6cb8e406d5fa6b2dca422fa42d2f13e
Author: Liwei Song <liwei.song.lsong@gmail.com>
Date:   Mon Jul 22 16:32:59 2024 +0800

    tools/resolve_btfids: Fix comparison of distinct pointer types warning in resolve_btfids
    
    Add a type cast for set8->pairs to fix below compile warning:
    
    main.c: In function 'sets_patch':
    main.c:699:50: warning: comparison of distinct pointer types lacks a cast
      699 |        BUILD_BUG_ON(set8->pairs != &set8->pairs[0].id);
          |                                 ^~
    
    Fixes: 9707ac4fe2f5 ("tools/resolve_btfids: Refactor set sorting with types from btf_ids.h")
    Signed-off-by: Liwei Song <liwei.song.lsong@gmail.com>
    Signed-off-by: Daniel Borkmann <daniel@iogearbox.net>
    Acked-by: Jiri Olsa <jolsa@kernel.org>
    Link: https://lore.kernel.org/bpf/20240722083305.4009723-1-liwei.song.lsong@gmail.com

Signed-off-by: Viktor Malik <vmalik@redhat.com>
2024-11-26 15:55:19 +01:00
Viktor Malik 4cfd2998cf
resolve_btfids: Handle presence of .BTF.base section
JIRA: https://issues.redhat.com/browse/RHEL-30774

commit 6ba77385f386053cea2a1cad33717de74a26db4e
Author: Alan Maguire <alan.maguire@oracle.com>
Date:   Thu Jun 13 10:50:11 2024 +0100

    resolve_btfids: Handle presence of .BTF.base section
    
    Now that btf_parse_elf() handles .BTF.base section presence,
    we need to ensure that resolve_btfids uses .BTF.base when present
    rather than the vmlinux base BTF passed in via the -B option.
    Detect .BTF.base section presence and unset the base BTF path
    to ensure that BTF ELF parsing will do the right thing.
    
    Signed-off-by: Alan Maguire <alan.maguire@oracle.com>
    Signed-off-by: Andrii Nakryiko <andrii@kernel.org>
    Reviewed-by: Eduard Zingerman <eddyz87@gmail.com>
    Link: https://lore.kernel.org/bpf/20240613095014.357981-7-alan.maguire@oracle.com

Signed-off-by: Viktor Malik <vmalik@redhat.com>
2024-11-26 14:40:09 +01:00
Viktor Malik bbeeed9724
bpf: Fix potential integer overflow in resolve_btfids
JIRA: https://issues.redhat.com/browse/RHEL-30773

commit 44382b3ed6b2787710c8ade06c0e97f5970a47c8
Author: Friedrich Vock <friedrich.vock@gmx.de>
Date:   Tue May 14 09:09:31 2024 +0200

    bpf: Fix potential integer overflow in resolve_btfids
    
    err is a 32-bit integer, but elf_update returns an off_t, which is 64-bit
    at least on 64-bit platforms. If symbols_patch is called on a binary between
    2-4GB in size, the result will be negative when cast to a 32-bit integer,
    which the code assumes means an error occurred. This can wrongly trigger
    build failures when building very large kernel images.
    
    Fixes: fbbb68de80 ("bpf: Add resolve_btfids tool to resolve BTF IDs in ELF object")
    Signed-off-by: Friedrich Vock <friedrich.vock@gmx.de>
    Signed-off-by: Daniel Borkmann <daniel@iogearbox.net>
    Acked-by: Daniel Borkmann <daniel@iogearbox.net>
    Link: https://lore.kernel.org/bpf/20240514070931.199694-1-friedrich.vock@gmx.de

Signed-off-by: Viktor Malik <vmalik@redhat.com>
2024-11-13 09:39:19 +01:00
Viktor Malik 1d404c1b0c
tools/resolve_btfids: Fix cross-compilation to non-host endianness
JIRA: https://issues.redhat.com/browse/RHEL-16042

commit 903fad4394666bc23975c93fb58f137ce64b5192
Author: Viktor Malik <vmalik@redhat.com>
Date:   Tue Feb 6 13:46:10 2024 +0100

    tools/resolve_btfids: Fix cross-compilation to non-host endianness

    The .BTF_ids section is pre-filled with zeroed BTF ID entries during the
    build and afterwards patched by resolve_btfids with correct values.
    Since resolve_btfids always writes in host-native endianness, it relies
    on libelf to do the translation when the target ELF is cross-compiled to
    a different endianness (this was introduced in commit 61e8aeda93
    ("bpf: Fix libelf endian handling in resolv_btfids")).

    Unfortunately, the translation will corrupt the flags fields of SET8
    entries because these were written during vmlinux compilation and are in
    the correct endianness already. This will lead to numerous selftests
    failures such as:

        $ sudo ./test_verifier 502 502
        #502/p sleepable fentry accept FAIL
        Failed to load prog 'Invalid argument'!
        bpf_fentry_test1 is not sleepable
        verification time 34 usec
        stack depth 0
        processed 0 insns (limit 1000000) max_states_per_insn 0 total_states 0 peak_states 0 mark_read 0
        Summary: 0 PASSED, 0 SKIPPED, 1 FAILED

    Since it's not possible to instruct libelf to translate just certain
    values, let's manually bswap the flags (both global and entry flags) in
    resolve_btfids when needed, so that libelf then translates everything
    correctly.

    Fixes: ef2c6f370a63 ("tools/resolve_btfids: Add support for 8-byte BTF sets")
    Signed-off-by: Viktor Malik <vmalik@redhat.com>
    Signed-off-by: Andrii Nakryiko <andrii@kernel.org>
    Link: https://lore.kernel.org/bpf/7b6bff690919555574ce0f13d2a5996cacf7bf69.1707223196.git.vmalik@redhat.com

Signed-off-by: Viktor Malik <vmalik@redhat.com>
2024-03-05 09:22:49 +01:00
Viktor Malik e170981a75
tools/resolve_btfids: Refactor set sorting with types from btf_ids.h
JIRA: https://issues.redhat.com/browse/RHEL-16042

commit 9707ac4fe2f5bac6406d2403f8b8a64d7b3d8e43
Author: Viktor Malik <vmalik@redhat.com>
Date:   Tue Feb 6 13:46:09 2024 +0100

    tools/resolve_btfids: Refactor set sorting with types from btf_ids.h

    Instead of using magic offsets to access BTF ID set data, leverage types
    from btf_ids.h (btf_id_set and btf_id_set8) which define the actual
    layout of the data. Thanks to this change, set sorting should also
    continue working if the layout changes.

    This requires to sync the definition of 'struct btf_id_set8' from
    include/linux/btf_ids.h to tools/include/linux/btf_ids.h. We don't sync
    the rest of the file at the moment, b/c that would require to also sync
    multiple dependent headers and we don't need any other defs from
    btf_ids.h.

    Signed-off-by: Viktor Malik <vmalik@redhat.com>
    Signed-off-by: Andrii Nakryiko <andrii@kernel.org>
    Acked-by: Daniel Xu <dxu@dxuuu.xyz>
    Link: https://lore.kernel.org/bpf/ff7f062ddf6a00815fda3087957c4ce667f50532.1707223196.git.vmalik@redhat.com

Signed-off-by: Viktor Malik <vmalik@redhat.com>
2024-03-05 09:22:46 +01:00
Jan Stancek de7da32ded Merge: ALSA - update drivers for 9.3
MR: https://gitlab.com/redhat/centos-stream/src/kernel/centos-stream-9/-/merge_requests/2615

This is a backport of ALSA changes up to 6.4-rc6 kernel for RHEL 9.3.

Bugzilla: https://bugzilla.redhat.com/2179848

This upstream patchset updates the ALSA driver code:

- ALSA core
- ALSA HDA
- ALSA USB
- ALSA PCI
- ALSA SoC (mainly SOF including SoundWire drivers)
- Soundwire bus
- dt-bindings for qcom (Qualcomm) and fsl (Freescale) for automotive boards, NVidia seems handed in !2355

The other components are touched to get things in sync with the current upstream:

Some touched drivers are for hardware platforms which are not used in RHEL. The purpose to merge those upstream commits is to keep the future code sync more easy.

Kernel module renames:

- snd-soc-sst-broadwell -> snd-soc-bdw-rt286
- snd-soc-sst-haswell -> snd-soc-hsw-rt5640

Note: The Elf -> ELF patch touches many subsystems. I can remove it on demand.

ARK configuration changes: https://gitlab.com/cki-project/kernel-ark/-/merge_requests/2500 and https://gitlab.com/cki-project/kernel-ark/-/merge_requests/2520

Signed-off-by: Jaroslav Kysela <jkysela@redhat.com>

Approved-by: Adrien Thierry <athierry@redhat.com>
Approved-by: Antoine Tenart <atenart@redhat.com>
Approved-by: Tony Camuso <tcamuso@redhat.com>
Approved-by: David Arcari <darcari@redhat.com>
Approved-by: Wander Lairson Costa <wander@redhat.com>
Approved-by: Jocelyn Falempe <jfalempe@redhat.com>
Approved-by: Eric Chanudet <echanude@redhat.com>
Approved-by: Julia Denham <jdenham@redhat.com>

Signed-off-by: Jan Stancek <jstancek@redhat.com>
2023-07-04 11:15:01 +02:00
Jaroslav Kysela c2ecc3ca46 ELF: fix all "Elf" typos
Bugzilla: https://bugzilla.redhat.com/2179848

commit 70e79866ab36feaaed8ef26dacfbcbac6a0631c9
Author: Alexey Dobriyan <adobriyan@gmail.com>
Date: Tue Feb 28 15:14:17 2023 +0300

    ELF: fix all "Elf" typos

    ELF is acronym and therefore should be spelled in all caps.

    I left one exception at Documentation/arm/nwfpe/nwfpe.rst which looks like
    being written in the first person.

    Link: https://lkml.kernel.org/r/Y/3wGWQviIOkyLJW@p183
    Signed-off-by: Alexey Dobriyan <adobriyan@gmail.com>
    Signed-off-by: Andrew Morton <akpm@linux-foundation.org>

Signed-off-by: Jaroslav Kysela <jkysela@redhat.com>
2023-06-21 16:22:19 +02:00
Viktor Malik 5372d33604 tools/resolve_btfids: Install subcmd headers
Bugzilla: https://bugzilla.redhat.com/2178930

commit af03299d8536d62b49c7f3cb929349eb2d66bcd5
Author: Ian Rogers <irogers@google.com>
Date:   Mon Jan 23 22:43:23 2023 -0800

    tools/resolve_btfids: Install subcmd headers
    
    Previously tools/lib/subcmd was added to the include path, switch to
    installing the headers and then including from that directory. This
    avoids dependencies on headers internal to tools/lib/subcmd. Add the
    missing subcmd directory to the affected #include.
    
    Signed-off-by: Ian Rogers <irogers@google.com>
    Signed-off-by: Daniel Borkmann <daniel@iogearbox.net>
    Acked-by: Jiri Olsa <jolsa@kernel.org>
    Link: https://lore.kernel.org/bpf/20230124064324.672022-1-irogers@google.com

Signed-off-by: Viktor Malik <vmalik@redhat.com>
2023-06-14 10:44:33 +02:00
Artem Savkov a8d0196eca tools/resolve_btfids: Add support for 8-byte BTF sets
Bugzilla: https://bugzilla.redhat.com/2137876

commit ef2c6f370a637e6f84c813f31fe0ebb4ced2ed69
Author: Kumar Kartikeya Dwivedi <memxor@gmail.com>
Date:   Thu Jul 21 15:42:34 2022 +0200

    tools/resolve_btfids: Add support for 8-byte BTF sets
    
    A flag is a 4-byte symbol that may follow a BTF ID in a set8. This is
    used in the kernel to tag kfuncs in BTF sets with certain flags. Add
    support to adjust the sorting code so that it passes size as 8 bytes
    for 8-byte BTF sets.
    
    Cc: Jiri Olsa <jolsa@kernel.org>
    Signed-off-by: Kumar Kartikeya Dwivedi <memxor@gmail.com>
    Acked-by: Jiri Olsa <jolsa@kernel.org>
    Link: https://lore.kernel.org/r/20220721134245.2450-3-memxor@gmail.com
    Signed-off-by: Alexei Starovoitov <ast@kernel.org>

Signed-off-by: Artem Savkov <asavkov@redhat.com>
2023-01-05 15:46:42 +01:00
Artem Savkov 868e1941b2 tools/resolve_btf_ids: Close ELF file on error
Bugzilla: https://bugzilla.redhat.com/2069046

Upstream Status: git://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git

commit 1144ab9bdf3430e1b5b3f22741e5283841951add
Author: Andrii Nakryiko <andrii@kernel.org>
Date:   Tue Nov 23 16:23:13 2021 -0800

    tools/resolve_btf_ids: Close ELF file on error

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

    Fixes: fbbb68de80 ("bpf: Add resolve_btfids tool to resolve BTF IDs in ELF object")
    Signed-off-by: Andrii Nakryiko <andrii@kernel.org>
    Signed-off-by: Daniel Borkmann <daniel@iogearbox.net>
    Link: https://lore.kernel.org/bpf/20211124002325.1737739-2-andrii@kernel.org

Signed-off-by: Artem Savkov <asavkov@redhat.com>
2022-08-24 12:53:40 +02:00
Yauheni Kaliuta da768f8a97 tools/resolve_btfids: Switch to new btf__type_cnt API
Bugzilla: http://bugzilla.redhat.com/2069045

commit 2d8f09fafc6351d77f724c208c8168d2512d5478
Author: Hengqi Chen <hengqi.chen@gmail.com>
Date:   Fri Oct 22 21:06:21 2021 +0800

    tools/resolve_btfids: Switch to new btf__type_cnt API
    
    Replace the call to btf__get_nr_types with new API btf__type_cnt.
    The old API will be deprecated in libbpf v0.7+. No functionality
    change.
    
    Signed-off-by: Hengqi Chen <hengqi.chen@gmail.com>
    Signed-off-by: Andrii Nakryiko <andrii@kernel.org>
    Link: https://lore.kernel.org/bpf/20211022130623.1548429-4-hengqi.chen@gmail.com

Signed-off-by: Yauheni Kaliuta <ykaliuta@redhat.com>
2022-06-03 17:23:55 +03:00
Yauheni Kaliuta 9650902646 tools/resolve_btfids: Skip unresolved symbol warning for empty BTF sets
Bugzilla: http://bugzilla.redhat.com/2069045

commit 3345193f6f3cc24791c245d4ba2c38502f1cf684
Author: Kumar Kartikeya Dwivedi <memxor@gmail.com>
Date:   Mon Nov 22 20:17:42 2021 +0530

    tools/resolve_btfids: Skip unresolved symbol warning for empty BTF sets
    
    resolve_btfids prints a warning when it finds an unresolved symbol,
    (id == 0) in id_patch. This can be the case for BTF sets that are empty
    (due to disabled config options), hence printing warnings for certain
    builds, most recently seen in [0].
    
    The reason behind this is because id->cnt aliases id->id in btf_id
    struct, leading to empty set showing up as ID 0 when we get to id_patch,
    which triggers the warning. Since sets are an exception here, accomodate
    by reusing hole in btf_id for bool is_set member, setting it to true for
    BTF set when setting id->cnt, and use that to skip extraneous warning.
    
      [0]: https://lore.kernel.org/all/1b99ae14-abb4-d18f-cc6a-d7e523b25542@gmail.com
    
    Before:
    
    ; ./tools/bpf/resolve_btfids/resolve_btfids -v -b vmlinux net/ipv4/tcp_cubic.ko
    adding symbol tcp_cubic_kfunc_ids
    WARN: resolve_btfids: unresolved symbol tcp_cubic_kfunc_ids
    patching addr     0: ID       0 [tcp_cubic_kfunc_ids]
    sorting  addr     4: cnt      0 [tcp_cubic_kfunc_ids]
    update ok for net/ipv4/tcp_cubic.ko
    
    After:
    
    ; ./tools/bpf/resolve_btfids/resolve_btfids -v -b vmlinux net/ipv4/tcp_cubic.ko
    adding symbol tcp_cubic_kfunc_ids
    patching addr     0: ID       0 [tcp_cubic_kfunc_ids]
    sorting  addr     4: cnt      0 [tcp_cubic_kfunc_ids]
    update ok for net/ipv4/tcp_cubic.ko
    
    Fixes: 0e32dfc80bae ("bpf: Enable TCP congestion control kfunc from modules")
    Reported-by: Pavel Skripkin <paskripkin@gmail.com>
    Signed-off-by: Kumar Kartikeya Dwivedi <memxor@gmail.com>
    Signed-off-by: Andrii Nakryiko <andrii@kernel.org>
    Acked-by: Song Liu <songliubraving@fb.com>
    Link: https://lore.kernel.org/bpf/20211122144742.477787-4-memxor@gmail.com

Signed-off-by: Yauheni Kaliuta <ykaliuta@redhat.com>
2022-06-03 17:23:53 +03:00
Yauheni Kaliuta 139cd147cd tools/resolve_btfids: Install libbpf headers when building
Bugzilla: http://bugzilla.redhat.com/2069045

commit 1478994aad82810d833bf9c816fb4e9845553e9b
Author: Quentin Monnet <quentin@isovalent.com>
Date:   Thu Oct 7 20:44:30 2021 +0100

    tools/resolve_btfids: Install libbpf headers when building
    
    API headers from libbpf should not be accessed directly from the
    library's source directory. Instead, they should be exported with "make
    install_headers". Let's make sure that resolve_btfids installs the
    headers properly when building.
    
    When descending from a parent Makefile, the specific output directories
    for building the library and exporting the headers are configurable with
    LIBBPF_OUT and LIBBPF_DESTDIR, respectively. This is in addition to
    OUTPUT, on top of which those variables are constructed by default.
    
    Also adjust the Makefile for the BPF selftests in order to point to the
    (target) libbpf shared with other tools, instead of building a version
    specific to resolve_btfids. Remove libbpf's order-only dependencies on
    the include directories (they are created by libbpf and don't need to
    exist beforehand).
    
    Signed-off-by: Quentin Monnet <quentin@isovalent.com>
    Signed-off-by: Andrii Nakryiko <andrii@kernel.org>
    Acked-by: Andrii Nakryiko <andrii@kernel.org>
    Link: https://lore.kernel.org/bpf/20211007194438.34443-5-quentin@isovalent.com

Signed-off-by: Yauheni Kaliuta <ykaliuta@redhat.com>
2022-06-03 17:23:40 +03:00
Yauheni Kaliuta 86c5effd6d tools: Allow specifying base BTF file in resolve_btfids
Bugzilla: http://bugzilla.redhat.com/2069045

commit f614f2c755b6125c646d680d1c990b3b262bd0a9
Author: Kumar Kartikeya Dwivedi <memxor@gmail.com>
Date:   Sat Oct 2 06:47:52 2021 +0530

    tools: Allow specifying base BTF file in resolve_btfids
    
    This commit allows specifying the base BTF for resolving btf id
    lists/sets during link time in the resolve_btfids tool. The base BTF is
    set to NULL if no path is passed. This allows resolving BTF ids for
    module kernel objects.
    
    Also, drop the --no-fail option, as it is only used in case .BTF_ids
    section is not present, instead make no-fail the default mode. The long
    option name is same as that of pahole.
    
    Signed-off-by: Kumar Kartikeya Dwivedi <memxor@gmail.com>
    Signed-off-by: Alexei Starovoitov <ast@kernel.org>
    Acked-by: Andrii Nakryiko <andrii@kernel.org>
    Link: https://lore.kernel.org/bpf/20211002011757.311265-5-memxor@gmail.com

Signed-off-by: Yauheni Kaliuta <ykaliuta@redhat.com>
2022-06-03 17:23:38 +03:00
Jerome Marchand 29e9220792 tools/resolve_btfids: Emit warnings and patch zero id for missing symbols
Bugzilla: http://bugzilla.redhat.com/2041365

commit 5aad03685185b5133a28e1ee1d4e98d3fd3642a3
Author: Hengqi Chen <hengqi.chen@gmail.com>
Date:   Tue Jul 27 21:25:31 2021 +0800

    tools/resolve_btfids: Emit warnings and patch zero id for missing symbols

    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 <andrii@kernel.org>
    Signed-off-by: Hengqi Chen <hengqi.chen@gmail.com>
    Signed-off-by: Andrii Nakryiko <andrii@kernel.org>
    Acked-by: Yonghong Song <yhs@fb.com>
    Link: https://lore.kernel.org/bpf/20210727132532.2473636-2-hengqi.chen@gmail.com

Signed-off-by: Jerome Marchand <jmarchan@redhat.com>
2022-04-29 18:14:36 +02:00
Tony Ambardar 61e8aeda93 bpf: Fix libelf endian handling in resolv_btfids
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: fbbb68de80 ("bpf: Add resolve_btfids tool to resolve BTF IDs in ELF object")
Signed-off-by: Tony Ambardar <Tony.Ambardar@gmail.com>
Signed-off-by: Daniel Borkmann <daniel@iogearbox.net>
Acked-by: Jiri Olsa <jolsa@redhat.com>
Cc: Frank Eigler <fche@redhat.com>
Cc: Mark Wielaard <mark@klomp.org>
Cc: Jiri Olsa <jolsa@kernel.org>
Cc: Yonghong Song <yhs@fb.com>
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
2021-06-18 17:01:00 +02:00
Stanislav Fomichev e27bfefb21 tools/resolve_btfids: Fix warnings
* 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 <sdf@google.com>
Signed-off-by: Andrii Nakryiko <andrii@kernel.org>
Acked-by: Song Liu <songliubraving@fb.com>
Link: https://lore.kernel.org/bpf/20210329223143.3659983-1-sdf@google.com
2021-03-31 12:09:12 -07:00
Kun-Chuan Hsieh 41462c6e73 tools/resolve_btfids: Fix build error with older host toolchains
Older libelf.h and glibc elf.h might not yet define the ELF compression
types.

Checking and defining SHF_COMPRESSED fix the build error when compiling
with older toolchains. Also, the tool resolve_btfids is compiled with host
toolchain. The host toolchain is more likely to be older than the cross
compile toolchain.

Fixes: 51f6463aac ("tools/resolve_btfids: Fix sections with wrong alignment")
Signed-off-by: Kun-Chuan Hsieh <jetswayss@gmail.com>
Signed-off-by: Daniel Borkmann <daniel@iogearbox.net>
Acked-by: Jiri Olsa <jolsa@redhat.com>
Link: https://lore.kernel.org/bpf/20210224052752.5284-1-jetswayss@gmail.com
2021-02-24 17:19:11 +01:00
Jiri Olsa 6720869280 tools/resolve_btfids: Warn when having multiple IDs for single type
The kernel image can contain multiple types (structs/unions)
with the same name. This causes distinct type hierarchies in
BTF data and makes resolve_btfids fail with error like:

  BTFIDS  vmlinux
FAILED unresolved symbol udp6_sock

as reported by Qais Yousef [1].

This change adds warning when multiple types of the same name
are detected:

  BTFIDS  vmlinux
WARN: multiple IDs found for 'file': 526, 113351 - using 526
WARN: multiple IDs found for 'sk_buff': 2744, 113958 - using 2744

We keep the lower ID for the given type instance and let the
build continue.

Also changing the 'nr' variable name to 'nr_types' to avoid confusion.

[1] https://lore.kernel.org/lkml/20201229151352.6hzmjvu3qh6p2qgg@e107158-lin/

Signed-off-by: Jiri Olsa <jolsa@kernel.org>
Signed-off-by: Alexei Starovoitov <ast@kernel.org>
Acked-by: Andrii Nakryiko <andrii@kernel.org>
Link: https://lore.kernel.org/bpf/20210105234219.970039-1-jolsa@kernel.org
2021-01-05 18:11:55 -08:00
Brendan Jackman 22e8ebe35a tools/resolve_btfids: Fix some error messages
Add missing newlines and fix polarity of strerror argument.

Signed-off-by: Brendan Jackman <jackmanb@google.com>
Signed-off-by: Alexei Starovoitov <ast@kernel.org>
Acked-by: Jiri Olsa <jolsa@redhat.com>
Link: https://lore.kernel.org/bpf/20201203102234.648540-1-jackmanb@google.com
2020-12-03 10:25:47 -08:00
David S. Miller 150f29f5e6 Merge git://git.kernel.org/pub/scm/linux/kernel/git/bpf/bpf-next
Daniel Borkmann says:

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

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

There are two small conflicts when pulling, resolve as follows:

1) Merge conflict in tools/lib/bpf/libbpf.c between 88a8212028 ("libbpf: Factor
   out common ELF operations and improve logging") in bpf-next and 1e891e513e
   ("libbpf: Fix map index used in error message") in net-next. Resolve by taking
   the hunk in bpf-next:

        [...]
        scn = elf_sec_by_idx(obj, obj->efile.btf_maps_shndx);
        data = elf_sec_data(obj, scn);
        if (!scn || !data) {
                pr_warn("elf: failed to get %s map definitions for %s\n",
                        MAPS_ELF_SEC, obj->path);
                return -EINVAL;
        }
        [...]

2) Merge conflict in drivers/net/ethernet/mellanox/mlx5/core/en/xsk/rx.c between
   9647c57b11 ("xsk: i40e: ice: ixgbe: mlx5: Test for dma_need_sync earlier for
   better performance") in bpf-next and e20f0dbf20 ("net/mlx5e: RX, Add a prefetch
   command for small L1_CACHE_BYTES") in net-next. Resolve the two locations by retaining
   net_prefetch() and taking xsk_buff_dma_sync_for_cpu() from bpf-next. Should look like:

        [...]
        xdp_set_data_meta_invalid(xdp);
        xsk_buff_dma_sync_for_cpu(xdp, rq->xsk_pool);
        net_prefetch(xdp->data);
        [...]

We've added 133 non-merge commits during the last 14 day(s) which contain
a total of 246 files changed, 13832 insertions(+), 3105 deletions(-).

The main changes are:

1) Initial support for sleepable BPF programs along with bpf_copy_from_user() helper
   for tracing to reliably access user memory, from Alexei Starovoitov.

2) Add BPF infra for writing and parsing TCP header options, from Martin KaFai Lau.

3) bpf_d_path() helper for returning full path for given 'struct path', from Jiri Olsa.

4) AF_XDP support for shared umems between devices and queues, from Magnus Karlsson.

5) Initial prep work for full BPF-to-BPF call support in libbpf, from Andrii Nakryiko.

6) Generalize bpf_sk_storage map & add local storage for inodes, from KP Singh.

7) Implement sockmap/hash updates from BPF context, from Lorenz Bauer.

8) BPF xor verification for scalar types & add BPF link iterator, from Yonghong Song.

9) Use target's prog type for BPF_PROG_TYPE_EXT prog verification, from Udip Pant.

10) Rework BPF tracing samples to use libbpf loader, from Daniel T. Lee.

11) Fix xdpsock sample to really cycle through all buffers, from Weqaar Janjua.

12) Improve type safety for tun/veth XDP frame handling, from Maciej Żenczykowski.

13) Various smaller cleanups and improvements all over the place.
====================

Signed-off-by: David S. Miller <davem@davemloft.net>
2020-09-01 13:22:59 -07:00
Jiri Olsa a5f53b1d59 tools resolve_btfids: Add support for set symbols
The set symbol does not have the unique number suffix,
so we need to give it a special parsing function.

This was omitted in the first batch, because there was
no set support yet, so it slipped in the testing.

Signed-off-by: Jiri Olsa <jolsa@kernel.org>
Signed-off-by: Alexei Starovoitov <ast@kernel.org>
Acked-by: Andrii Nakryiko <andriin@fb.com>
Link: https://lore.kernel.org/bpf/20200825192124.710397-3-jolsa@kernel.org
2020-08-25 15:37:41 -07:00
Jiri Olsa 193a983c5b tools resolve_btfids: Add size check to get_id function
To make sure we don't crash on malformed symbols.

Signed-off-by: Jiri Olsa <jolsa@kernel.org>
Signed-off-by: Alexei Starovoitov <ast@kernel.org>
Acked-by: Andrii Nakryiko <andriin@fb.com>
Link: https://lore.kernel.org/bpf/20200825192124.710397-2-jolsa@kernel.org
2020-08-25 15:37:41 -07:00
Jiri Olsa 51f6463aac tools/resolve_btfids: Fix sections with wrong alignment
The data of compressed section should be aligned to 4
(for 32bit) or 8 (for 64 bit) bytes.

The binutils ld sets sh_addralign to 1, which makes libelf
fail with misaligned section error during the update as
reported by Jesper:

   FAILED elf_update(WRITE): invalid section alignment

While waiting for ld fix, we can fix compressed sections
sh_addralign value manually.

Adding warning in -vv mode when the fix is triggered:

  $ ./tools/bpf/resolve_btfids/resolve_btfids -vv vmlinux
  ...
  section(36) .comment, size 44, link 0, flags 30, type=1
  section(37) .debug_aranges, size 45684, link 0, flags 800, type=1
   - fixing wrong alignment sh_addralign 16, expected 8
  section(38) .debug_info, size 129104957, link 0, flags 800, type=1
   - fixing wrong alignment sh_addralign 1, expected 8
  section(39) .debug_abbrev, size 1152583, link 0, flags 800, type=1
   - fixing wrong alignment sh_addralign 1, expected 8
  section(40) .debug_line, size 7374522, link 0, flags 800, type=1
   - fixing wrong alignment sh_addralign 1, expected 8
  section(41) .debug_frame, size 702463, link 0, flags 800, type=1
  section(42) .debug_str, size 1017571, link 0, flags 830, type=1
   - fixing wrong alignment sh_addralign 1, expected 8
  section(43) .debug_loc, size 3019453, link 0, flags 800, type=1
   - fixing wrong alignment sh_addralign 1, expected 8
  section(44) .debug_ranges, size 1744583, link 0, flags 800, type=1
   - fixing wrong alignment sh_addralign 16, expected 8
  section(45) .symtab, size 2955888, link 46, flags 0, type=2
  section(46) .strtab, size 2613072, link 0, flags 0, type=3
  ...
  update ok for vmlinux

Another workaround is to disable compressed debug info data
CONFIG_DEBUG_INFO_COMPRESSED kernel option.

Fixes: fbbb68de80 ("bpf: Add resolve_btfids tool to resolve BTF IDs in ELF object")
Reported-by: Jesper Dangaard Brouer <brouer@redhat.com>
Signed-off-by: Jiri Olsa <jolsa@kernel.org>
Signed-off-by: Alexei Starovoitov <ast@kernel.org>
Acked-by: Jesper Dangaard Brouer <brouer@redhat.com>
Acked-by: Yonghong Song <yhs@fb.com>
Cc: Mark Wielaard <mjw@redhat.com>
Cc: Nick Clifton <nickc@redhat.com>
Link: https://lore.kernel.org/bpf/20200819092342.259004-1-jolsa@kernel.org
2020-08-20 14:17:20 -07:00
Stanislav Fomichev d48556f456 bpf: Add missing return to resolve_btfids
int sets_patch(struct object *obj) doesn't have a 'return 0' at the end.

Fixes: fbbb68de80 ("bpf: Add resolve_btfids tool to resolve BTF IDs in ELF object")
Signed-off-by: Stanislav Fomichev <sdf@google.com>
Signed-off-by: Alexei Starovoitov <ast@kernel.org>
Link: https://lore.kernel.org/bpf/20200806155225.637202-1-sdf@google.com
2020-08-06 16:51:11 -07:00
Andrii Nakryiko f86ca3cffe tools/resolve_btfids: Use libbpf's btf__parse() API
Instead of re-implementing generic BTF parsing logic, use libbpf's API.
Also add .gitignore for resolve_btfids's build artifacts.

Signed-off-by: Andrii Nakryiko <andriin@fb.com>
Signed-off-by: Daniel Borkmann <daniel@iogearbox.net>
Link: https://lore.kernel.org/bpf/20200802013219.864880-4-andriin@fb.com
2020-08-03 16:39:48 +02:00
Jiri Olsa fbbb68de80 bpf: Add resolve_btfids tool to resolve BTF IDs in ELF object
The resolve_btfids tool scans elf object for .BTF_ids section
and resolves its symbols with BTF ID values.

It will be used to during linking time to resolve arrays of BTF
ID values used in verifier, so these IDs do not need to be
resolved in runtime.

The expected layout of .BTF_ids section is described in main.c
header. Related kernel changes are coming in following changes.

Build issue reported by 0-DAY CI Kernel Test Service.

Signed-off-by: Jiri Olsa <jolsa@kernel.org>
Signed-off-by: Alexei Starovoitov <ast@kernel.org>
Link: https://lore.kernel.org/bpf/20200711215329.41165-2-jolsa@kernel.org
2020-07-13 10:42:02 -07:00