Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

powerpc/ftrace: Add a postlink script to validate function tracer

Function tracer on powerpc can only work with vmlinux having a .text
size of up to ~64MB due to powerpc branch instruction having a limited
relative branch range of 32MB. Today, this is only detected on kernel
boot when ftrace is init'ed. Add a post-link script to check the size of
.text so that we can detect this at build time, and break the build if
necessary.

We add a dependency on !COMPILE_TEST for CONFIG_HAVE_FUNCTION_TRACER so
that allyesconfig and other test builds can continue to work without
enabling ftrace.

Signed-off-by: Naveen N Rao <naveen@kernel.org>
Signed-off-by: Hari Bathini <hbathini@linux.ibm.com>
Signed-off-by: Michael Ellerman <mpe@ellerman.id.au>
Link: https://patch.msgid.link/20241030070850.1361304-11-hbathini@linux.ibm.com

authored by

Naveen N Rao and committed by
Michael Ellerman
782f46cb 9670f6d2

+59 -1
+1 -1
arch/powerpc/Kconfig
··· 243 243 select HAVE_FUNCTION_DESCRIPTORS if PPC64_ELF_ABI_V1 244 244 select HAVE_FUNCTION_ERROR_INJECTION 245 245 select HAVE_FUNCTION_GRAPH_TRACER 246 - select HAVE_FUNCTION_TRACER if PPC64 || (PPC32 && CC_IS_GCC) 246 + select HAVE_FUNCTION_TRACER if !COMPILE_TEST && (PPC64 || (PPC32 && CC_IS_GCC)) 247 247 select HAVE_GCC_PLUGINS if GCC_VERSION >= 50200 # plugin support on gcc <= 5.1 is buggy on PPC 248 248 select HAVE_GENERIC_VDSO 249 249 select HAVE_HARDLOCKUP_DETECTOR_ARCH if PPC_BOOK3S_64 && SMP
+50
arch/powerpc/tools/ftrace_check.sh
··· 1 + #!/bin/bash 2 + # SPDX-License-Identifier: GPL-2.0-or-later 3 + # 4 + # This script checks vmlinux to ensure that all functions can call ftrace_caller() either directly, 5 + # or through the stub, ftrace_tramp_text, at the end of kernel text. 6 + 7 + # Error out if any command fails 8 + set -e 9 + 10 + # Allow for verbose output 11 + if [ "$V" = "1" ]; then 12 + set -x 13 + fi 14 + 15 + if [ $# -lt 2 ]; then 16 + echo "$0 [path to nm] [path to vmlinux]" 1>&2 17 + exit 1 18 + fi 19 + 20 + # Have Kbuild supply the path to nm so we handle cross compilation. 21 + nm="$1" 22 + vmlinux="$2" 23 + 24 + stext_addr=$($nm "$vmlinux" | grep -e " [TA] _stext$" | \ 25 + cut -d' ' -f1 | tr '[:lower:]' '[:upper:]') 26 + ftrace_caller_addr=$($nm "$vmlinux" | grep -e " T ftrace_caller$" | \ 27 + cut -d' ' -f1 | tr '[:lower:]' '[:upper:]') 28 + ftrace_tramp_addr=$($nm "$vmlinux" | grep -e " T ftrace_tramp_text$" | \ 29 + cut -d' ' -f1 | tr '[:lower:]' '[:upper:]') 30 + 31 + ftrace_caller_offset=$(echo "ibase=16;$ftrace_caller_addr - $stext_addr" | bc) 32 + ftrace_tramp_offset=$(echo "ibase=16;$ftrace_tramp_addr - $ftrace_caller_addr" | bc) 33 + sz_32m=$(printf "%d" 0x2000000) 34 + sz_64m=$(printf "%d" 0x4000000) 35 + 36 + # ftrace_caller - _stext < 32M 37 + if [ "$ftrace_caller_offset" -ge "$sz_32m" ]; then 38 + echo "ERROR: ftrace_caller (0x$ftrace_caller_addr) is beyond 32MiB of _stext" 1>&2 39 + echo "ERROR: consider disabling CONFIG_FUNCTION_TRACER, or reducing the size \ 40 + of kernel text" 1>&2 41 + exit 1 42 + fi 43 + 44 + # ftrace_tramp_text - ftrace_caller < 64M 45 + if [ "$ftrace_tramp_offset" -ge "$sz_64m" ]; then 46 + echo "ERROR: kernel text extends beyond 64MiB from ftrace_caller" 1>&2 47 + echo "ERROR: consider disabling CONFIG_FUNCTION_TRACER, or reducing the size \ 48 + of kernel text" 1>&2 49 + exit 1 50 + fi