mirror of
https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
synced 2026-10-26 10:57:38 +08:00
Pull bpf updates from Alexei Starovoitov:
"Major changes:
- Introduce scalar evolution (SCEV) analysis in the verifier.
It infers how registers and stack slots change in a loop and lets
the verifier check bounded loops with induction variables as ranges
instead of walking every iteration. The number of processed insns
drops ten fold in programs with loops (Eduard Zingerman)
- Add 'callx' instruction: indirect call of a static BPF subprogram.
The address is taken with ld_imm64 or loaded from read-only data.
Supported by x86-64, arm64 and riscv64 JITs (Alexei Starovoitov, Pu
Lehui)
- Add unwind_goto and unwind_exit instructions, so that Rust panic or
C++ exception can run destructors of every frame it passes through.
The normal path is free of unwind code. Supported by x86-64 and
arm64 JITs (Alexei Starovoitov)
- Support programs compiled by rust-bpf: treat load and store through
a number as arena access with BPF_F_ARENA_SCALAR, accept rust names
in BTF (Alexei Starovoitov)
- Raise BPF program stack size from 512 bytes to 2 KiB on x86-64 and
arm64 (Kumar Kartikeya Dwivedi)
- Support struct, union and __int128 up to 16 bytes passed and
returned by value in BPF subprograms and kfuncs, and fix x86-64 and
arm64 trampolines for such arguments (Yonghong Song)
- Introduce a common way to attach struct_ops to a cgroup via
bpf_link. bpf_tcp_ops is the first user and mirrors TCP sock_ops
callbacks (Martin KaFai Lau, Amery Hung)
- Describe inlined functions in BTF. New kinds tell where the inline
sites are and how to fetch the arguments there.
CONFIG_DEBUG_INFO_BTF_INLINE keeps it apart from the main BTF in
.BTF.inline section or in btf_vmlinux_inline.ko (Alan Maguire)
- Fix many memory safety, lifetime and locking bugs in BPF core,
verifier, iterators, local storage, dynptr, devmap, cpumap and
seg6local (Josef Bacik, Alexei Starovoitov)
- Diff stat is dominated by selftests and by removal of
lib/test_bpf.c. Its 16k lines of instruction tests were converted
to BPF selftests that BPF CI runs on every architecture it covers
(Daniel Borkmann)
Other features and fixes:
- Add KASAN checks to memory accesses of JITed programs on x86-64
(Alexis Lothoré)
- Complete unification of helper, kfunc and subprog argument checks
in the verifier (Amery Hung)
- Add bpf_copy_from_user_mm[_str]() kfuncs (Anastasios Papagiannis)
- Various features and fixes (Daniel Borkmann):
- Add .bpf keyring for program signature verification, modelled
after dm-verity keyring, and support ML-DSA in signing tools
- Emit shorter and faster code in x86-64 JIT for patterns that
LLVM generates
- Fix various issues in gotox handling
- Let BPF LSM set xattrs at inode creation with bpf_inode_init_xattr()
(David Windsor, Daniel Borkmann)
- Use sleepable page allocation in sleepable arena paths. Fix races
between arena free, allocation and user page fault (Emil Tsalapatis)
- Switch BPF crypto from lskcipher to AES-CBC and AES-ECB libraries
(Eric Biggers)
- Add bpf_proactive_reclaim() kfunc (Hui Zhu)
- Render decl_tags in libbpf btf_dump and add tests for bpftool C
dump (Ihor Solodrai)
- Speed up tracing_multi attach on x86 (Jiri Olsa)
- Various features and fixes (Kumar Kartikeya Dwivedi):
- Add BPF_PROG_STREAM_OPEN command to read BPF streams through a
file descriptor with poll support
- Let kernel structs publish arena pointers with __arena type tag
- Fix __uninit kfunc output buffers and fastcall rewrite with
indirect stack accesses
- Refuse CO-RE relocations for signed programs
- Add enqueue_rcvq and dequeue_rcvq hooks to bpf_tcp_ops to adjust
sk_rcvlowat and avoid unnecessary wakeups (Kuniyuki Iwashima)
- Add bpf_ksock_sendto() kfunc and allow ksock connect and send from
bpf_wq (Mahe Tardy)
- Fix racy plt target update in arm64 bpf_arch_text_poke()
(Matthew Wood)
- Restructure BPF selftests Makefile as a layered build
(Mykola Lysenko)
- Speed up hash map lookups for u32 and u64 keys (Mykyta Yatsenko)
- Add signed div/mod, movsx, bswap and gotol to MIPS JITs, signed
div/mod to parisc JITs (Nicholas Dudar, Johan Almbladh)
- Fix stack overflow in build ID parser on 32-bit (Nickolai
Zeldovich)
- Add stack arguments, signed arena loads and gotox to riscv64 JIT.
Pu Lehui is now co-maintainer of riscv BPF JITs (Pu Lehui, Chen
Pei, Feng Jiang)
- Add bpf_call_rcu() and bpf_call_rcu_tasks_trace() kfuncs. Support
fetching and/or/xor atomics in arena on x86-64 (Puranjay Mohan)
- Fix flaky selftests, selftests with clang 23 and bpf-gcc
(Qiliang Yuan, KaFai Wan, Vineet Gupta)
- Fix builds broken by fatal resolve_btfids warnings, BTF generation
on ARC, and define arch_cmpxchg_local() on arc, hexagon and
openrisc (Sasha Levin)
- Reduce memory use of hash maps by up to 50% per element
(T.J. Mercier)
- Mark pointer fields of sched_ext ops arguments as trusted (Tejun
Heo)
- Remove legacy bpf_asm, bpf_dbg and bpf_jit_disasm tools (Xia Yan)
- Fix index overflow in queue and stack maps, arena range tree after
allocation failure, tail call loop after freplace detach, lost
signal in bpf_send_signal() (Yuan Chen)
- Many more fixes and cleanups"
* tag 'bpf-next-7.4' of git://git.kernel.org/pub/scm/linux/kernel/git/bpf/bpf-next: (660 commits)
selftests/bpf: Time tc_edt from its first packet with data
selftests/bpf: Test unwind_exit of an exception callback
selftests/bpf: Tests for 32-bit scalar evolution bounds computation
bpf: Reject unwind_goto and unwind_exit in offloaded progs
bpf: Support 32-bit linear scalar evolution
bpf: Make unwind_exit of an exception callback exit in JITs
selftests/bpf: Test forbidden bpf_ksock_sendto() LSM attach
selftests/bpf: Test ksock sendto()
bpf: Add bpf_ksock_sendto() kfunc
selftests/bpf: Test unwinding from R0: R2 subprog
selftests/bpf: Add a C++ prog with exceptions
selftests/bpf: Add tests for unwind_goto and unwind_exit
bpf, arm64: Support unwind_goto and unwind_exit
bpf, x86: Support unwind_goto and unwind_exit
bpf: Add unwind_goto and unwind_exit insns
tools/bpf: Remove legacy BPF tools
bpf: Annotate data races on bpf_lru_node type
selftests/bpf: Add arena allocation race tests
bpf: Fix arena race between page free and alloc leading to incoherency
bpf: Revalidate faulted arena pages before installing user mappings
...
328 lines
8.2 KiB
Bash
Executable File
328 lines
8.2 KiB
Bash
Executable File
#!/bin/sh
|
|
# SPDX-License-Identifier: GPL-2.0
|
|
#
|
|
# link vmlinux
|
|
#
|
|
# vmlinux is linked from the objects in vmlinux.a and $(KBUILD_VMLINUX_LIBS).
|
|
# vmlinux.a contains objects that are linked unconditionally.
|
|
# $(KBUILD_VMLINUX_LIBS) are archives which are linked conditionally
|
|
# (not within --whole-archive), and do not require symbol indexes added.
|
|
#
|
|
# vmlinux
|
|
# ^
|
|
# |
|
|
# +--< vmlinux.a
|
|
# |
|
|
# +--< $(KBUILD_VMLINUX_LIBS)
|
|
# | +--< lib/lib.a + more
|
|
# |
|
|
# +-< ${kallsymso} (see description in KALLSYMS section)
|
|
#
|
|
# vmlinux version (uname -v) cannot be updated during normal
|
|
# descending-into-subdirs phase since we do not yet know if we need to
|
|
# update vmlinux.
|
|
# Therefore this step is delayed until just before final link of vmlinux.
|
|
#
|
|
# System.map is generated to document addresses of all kernel symbols
|
|
|
|
# Error out on error
|
|
set -e
|
|
|
|
LD="$1"
|
|
KBUILD_LDFLAGS="$2"
|
|
LDFLAGS_vmlinux="$3"
|
|
VMLINUX="$4"
|
|
|
|
is_enabled() {
|
|
grep -q "^$1=y" include/config/auto.conf
|
|
}
|
|
|
|
# Nice output in kbuild format
|
|
# Will be suppressed by "make -s"
|
|
info()
|
|
{
|
|
printf " %-7s %s\n" "${1}" "${2}"
|
|
}
|
|
|
|
# Link of vmlinux
|
|
# ${1} - output file
|
|
vmlinux_link()
|
|
{
|
|
local output=${1}
|
|
local objs
|
|
local libs
|
|
local ld
|
|
local ldflags
|
|
local ldlibs
|
|
|
|
info LD ${output}
|
|
|
|
# skip output file argument
|
|
shift
|
|
|
|
if is_enabled CONFIG_LTO_CLANG || is_enabled CONFIG_X86_KERNEL_IBT ||
|
|
is_enabled CONFIG_KLP_BUILD; then
|
|
# Use vmlinux.o instead of performing the slow LTO link again.
|
|
objs=vmlinux.o
|
|
libs=
|
|
else
|
|
objs=vmlinux.a
|
|
libs="${KBUILD_VMLINUX_LIBS}"
|
|
fi
|
|
|
|
if is_enabled CONFIG_GENERIC_BUILTIN_DTB; then
|
|
objs="${objs} .builtin-dtbs.o"
|
|
fi
|
|
|
|
objs="${objs} .vmlinux.export.o"
|
|
objs="${objs} init/version-timestamp.o"
|
|
|
|
if [ "${SRCARCH}" = "um" ]; then
|
|
wl=-Wl,
|
|
ld="${CC}"
|
|
ldflags="${CFLAGS_vmlinux}"
|
|
ldlibs="-lutil -lrt -lpthread"
|
|
else
|
|
wl=
|
|
ld="${LD}"
|
|
ldflags="${KBUILD_LDFLAGS} ${LDFLAGS_vmlinux}"
|
|
ldlibs=
|
|
fi
|
|
|
|
ldflags="${ldflags} ${wl}--script=${objtree}/${KBUILD_LDS}"
|
|
|
|
# The kallsyms linking does not need debug symbols included.
|
|
if [ -n "${strip_debug}" ] ; then
|
|
ldflags="${ldflags} ${wl}--strip-debug"
|
|
fi
|
|
|
|
# Only the final link actually requires the relocations.
|
|
if [ "${output}" = "${VMLINUX}" ] && is_enabled CONFIG_ARCH_VMLINUX_NEEDS_RELOCS; then
|
|
ldflags="${ldflags} ${wl}--emit-relocs"
|
|
fi
|
|
|
|
if [ -n "${generate_map}" ]; then
|
|
ldflags="${ldflags} ${wl}-Map=vmlinux.map"
|
|
fi
|
|
|
|
${ld} ${ldflags} -o ${output} \
|
|
${wl}--whole-archive ${objs} ${wl}--no-whole-archive \
|
|
${wl}--start-group ${libs} ${wl}--end-group \
|
|
${kallsymso} ${btf_vmlinux_bin_o} ${arch_vmlinux_o} ${ldlibs}
|
|
}
|
|
|
|
# Check if kallsymso_prev and kallsymso differ
|
|
# If symbol sizes within ${kallsymso} change, any symbols within vmlinux are
|
|
# likely to shift, invalidating ${kallsymso}.
|
|
# Since file size can remain unchanged even if symbol sizes change, compare the
|
|
# actual symbols instead of relying on file size only.
|
|
kallsymso_changed()
|
|
{
|
|
${NM} -n "${kallsymso_prev}" > "${kallsymso_prev}.sym"
|
|
${NM} -n "${kallsymso}" > "${kallsymso}.sym"
|
|
! cmp -s "${kallsymso_prev}.sym" "${kallsymso}.sym"
|
|
}
|
|
|
|
# Create ${2}.o with the kallsyms tables for ${1} (the vmlinux, or an empty
|
|
# listing for the first pass); list the symbols used in ${3} if given.
|
|
kallsyms()
|
|
{
|
|
local kallsymopt;
|
|
|
|
if [ -n "${3:-}" ]; then
|
|
kallsymopt="--sysmap=${3}"
|
|
fi
|
|
if is_enabled CONFIG_KALLSYMS_ALL; then
|
|
kallsymopt="${kallsymopt} --all-symbols"
|
|
fi
|
|
|
|
if is_enabled CONFIG_64BIT || is_enabled CONFIG_RELOCATABLE; then
|
|
kallsymopt="${kallsymopt} --pc-relative"
|
|
fi
|
|
|
|
info KSYMS "${2}.S"
|
|
scripts/kallsyms ${kallsymopt} "${1}" "${2}.bin" > "${2}.S"
|
|
|
|
info AS "${2}.o"
|
|
${CC} ${NOSTDINC_FLAGS} ${LINUXINCLUDE} ${KBUILD_CPPFLAGS} \
|
|
${KBUILD_AFLAGS} ${KBUILD_AFLAGS_KERNEL} -c -o "${2}.o" "${2}.S"
|
|
|
|
kallsymso_prev="${kallsymso:-}"
|
|
kallsymso=${2}.o
|
|
}
|
|
|
|
# Perform kallsyms for the given temporary vmlinux.
|
|
sysmap_and_kallsyms()
|
|
{
|
|
kallsyms "${1}" "${1}.kallsyms" "${1}.syms"
|
|
kallsyms_sysmap=${1}.syms
|
|
}
|
|
|
|
# Create map file with all symbols from ${1}
|
|
mksysmap()
|
|
{
|
|
info SYSMAP ${2}
|
|
scripts/kallsyms --sysmap="${2}" "${1}"
|
|
}
|
|
|
|
sorttable()
|
|
{
|
|
${NM} -p -S ${1} > .tmp_vmlinux.nm-sort
|
|
${objtree}/scripts/sorttable -s .tmp_vmlinux.nm-sort ${1}
|
|
}
|
|
|
|
cleanup()
|
|
{
|
|
rm -f .btf.*
|
|
rm -f .tmp_vmlinux.nm-sort
|
|
rm -f System.map
|
|
rm -f vmlinux
|
|
rm -f vmlinux.map
|
|
}
|
|
|
|
# Use "make V=1" to debug this script
|
|
case "${KBUILD_VERBOSE}" in
|
|
*1*)
|
|
set -x
|
|
;;
|
|
esac
|
|
|
|
if [ "$1" = "clean" ]; then
|
|
cleanup
|
|
exit 0
|
|
fi
|
|
|
|
${MAKE} -f "${srctree}/scripts/Makefile.build" obj=init init/version-timestamp.o
|
|
|
|
arch_vmlinux_o=
|
|
if is_enabled CONFIG_ARCH_WANTS_PRE_LINK_VMLINUX; then
|
|
arch_vmlinux_o=arch/${SRCARCH}/tools/vmlinux.arch.o
|
|
fi
|
|
|
|
btf_vmlinux_bin_o=
|
|
btfids_vmlinux=
|
|
kallsymso=
|
|
strip_debug=
|
|
generate_map=
|
|
|
|
# Use "make UT=1" to trigger warnings on unused tracepoints
|
|
case "${WARN_ON_UNUSED_TRACEPOINTS}" in
|
|
*1*)
|
|
${objtree}/scripts/tracepoint-update vmlinux.o
|
|
;;
|
|
esac
|
|
|
|
if is_enabled CONFIG_KALLSYMS; then
|
|
true > .tmp_vmlinux0.syms
|
|
kallsyms .tmp_vmlinux0.syms .tmp_vmlinux0.kallsyms
|
|
fi
|
|
|
|
if is_enabled CONFIG_KALLSYMS || is_enabled CONFIG_DEBUG_INFO_BTF; then
|
|
|
|
# The kallsyms linking does not need debug symbols, but the BTF does.
|
|
if ! is_enabled CONFIG_DEBUG_INFO_BTF; then
|
|
strip_debug=1
|
|
fi
|
|
|
|
vmlinux_link .tmp_vmlinux1
|
|
fi
|
|
|
|
if is_enabled CONFIG_DEBUG_INFO_BTF; then
|
|
info BTF .tmp_vmlinux1
|
|
if ! ${CONFIG_SHELL} ${srctree}/scripts/gen-btf.sh .tmp_vmlinux1; then
|
|
echo >&2 "Failed to generate BTF for vmlinux"
|
|
echo >&2 "Try to disable CONFIG_DEBUG_INFO_BTF"
|
|
exit 1
|
|
fi
|
|
btf_vmlinux_bin_o=.tmp_vmlinux1.btf.o
|
|
btfids_vmlinux=.tmp_vmlinux1.BTF_ids
|
|
fi
|
|
|
|
if is_enabled CONFIG_KALLSYMS; then
|
|
|
|
# kallsyms support
|
|
# Generate section listing all symbols and add it into vmlinux
|
|
# It's a four step process:
|
|
# 0) Generate a dummy __kallsyms with empty symbol list.
|
|
# 1) Link .tmp_vmlinux1.kallsyms so it has all symbols and sections,
|
|
# with a dummy __kallsyms.
|
|
# Running kallsyms on that gives us .tmp_vmlinux1.kallsyms.o with
|
|
# the right size
|
|
# 2) Link .tmp_vmlinux2.kallsyms so it now has a __kallsyms section of
|
|
# the right size, but due to the added section, some
|
|
# addresses have shifted.
|
|
# From here, we generate a correct .tmp_vmlinux2.kallsyms.o
|
|
# 3) That link may have expanded the kernel image enough that
|
|
# more linker branch stubs / trampolines had to be added, which
|
|
# introduces new names, which further expands kallsyms. Do another
|
|
# pass if that is the case. In theory it's possible this results
|
|
# in even more stubs, but unlikely.
|
|
# KALLSYMS_EXTRA_PASS=1 may also used to debug or work around
|
|
# other bugs.
|
|
# 4) The correct ${kallsymso} is linked into the final vmlinux.
|
|
#
|
|
# a) Verify that the System.map from vmlinux matches the map from
|
|
# ${kallsymso}.
|
|
|
|
# The kallsyms linking does not need debug symbols included.
|
|
strip_debug=1
|
|
|
|
sysmap_and_kallsyms .tmp_vmlinux1
|
|
size1=$(${CONFIG_SHELL} "${srctree}/scripts/file-size.sh" ${kallsymso})
|
|
|
|
vmlinux_link .tmp_vmlinux2
|
|
sysmap_and_kallsyms .tmp_vmlinux2
|
|
size2=$(${CONFIG_SHELL} "${srctree}/scripts/file-size.sh" ${kallsymso})
|
|
|
|
# Due to alignment, file size of the kallsymso object file might remain
|
|
# unchanged even if individual symbols within change size. Changed
|
|
# symbol sizes can still shift other symbols, though. Therefore, don't
|
|
# rely on file size alone.
|
|
if [ $size1 -ne $size2 ] || kallsymso_changed || \
|
|
[ -n "${KALLSYMS_EXTRA_PASS}" ]; then
|
|
vmlinux_link .tmp_vmlinux3
|
|
sysmap_and_kallsyms .tmp_vmlinux3
|
|
fi
|
|
fi
|
|
|
|
strip_debug=
|
|
|
|
if is_enabled CONFIG_VMLINUX_MAP; then
|
|
generate_map=1
|
|
fi
|
|
|
|
vmlinux_link "${VMLINUX}"
|
|
|
|
if is_enabled CONFIG_DEBUG_INFO_BTF; then
|
|
info BTFIDS ${VMLINUX}
|
|
if [ "${BTF_INLINE}" = "m" ]; then
|
|
${RESOLVE_BTFIDS} --patch_btfids ${btfids_vmlinux} \
|
|
--btf_link .BTF.inline:btf_vmlinux_inline:vmlinux.BTF.inline \
|
|
${VMLINUX}
|
|
else
|
|
${RESOLVE_BTFIDS} --patch_btfids ${btfids_vmlinux} ${VMLINUX}
|
|
fi
|
|
fi
|
|
|
|
mksysmap "${VMLINUX}" System.map
|
|
|
|
if is_enabled CONFIG_BUILDTIME_TABLE_SORT; then
|
|
info SORTTAB "${VMLINUX}"
|
|
if ! sorttable "${VMLINUX}"; then
|
|
echo >&2 Failed to sort kernel tables
|
|
exit 1
|
|
fi
|
|
fi
|
|
|
|
# step a (see comment above)
|
|
if is_enabled CONFIG_KALLSYMS; then
|
|
if ! cmp -s System.map "${kallsyms_sysmap}"; then
|
|
echo >&2 Inconsistent kallsyms data
|
|
echo >&2 'Try "make KALLSYMS_EXTRA_PASS=1" as a workaround'
|
|
exit 1
|
|
fi
|
|
fi
|
|
|
|
# For fixdep
|
|
echo "${VMLINUX}: $0" > ".${VMLINUX}.d"
|