Skip to content

Commit 4ed308c

Browse files
committed
ftrace: Have architectures opt-in for mcount build time sorting
First S390 complained that the sorting of the mcount sections at build time caused the kernel to crash on their architecture. Now PowerPC is complaining about it too. And also ARM64 appears to be having issues. It may be necessary to also update the relocation table for the values in the mcount table. Not only do we have to sort the table, but also update the relocations that may be applied to the items in the table. If the system is not relocatable, then it is fine to sort, but if it is, some architectures may have issues (although x86 does not as it shifts all addresses the same). Add a HAVE_BUILDTIME_MCOUNT_SORT that an architecture can set to say it is safe to do the sorting at build time. Also update the config to compile in build time sorting in the sorttable code in scripts/ to depend on CONFIG_BUILDTIME_MCOUNT_SORT. Link: https://lore.kernel.org/all/[email protected]/ Link: https://lkml.kernel.org/r/[email protected] Cc: Ingo Molnar <[email protected]> Cc: Andrew Morton <[email protected]> Cc: Russell King <[email protected]> Cc: Yinan Liu <[email protected]> Cc: Ard Biesheuvel <[email protected]> Cc: Kees Cook <[email protected]> Reported-by: Sachin Sant <[email protected]> Reviewed-by: Mark Rutland <[email protected]> Tested-by: Mark Rutland <[email protected]> [arm64] Tested-by: Sachin Sant <[email protected]> Fixes: 72b3942 ("scripts: ftrace - move the sort-processing in ftrace_init") Signed-off-by: Steven Rostedt (Google) <[email protected]>
1 parent e783362 commit 4ed308c

File tree

4 files changed

+10
-2
lines changed

4 files changed

+10
-2
lines changed

arch/arm/Kconfig

+1
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,7 @@ config ARM
8383
select HAVE_EBPF_JIT if !CPU_ENDIAN_BE32
8484
select HAVE_CONTEXT_TRACKING
8585
select HAVE_C_RECORDMCOUNT
86+
select HAVE_BUILDTIME_MCOUNT_SORT
8687
select HAVE_DEBUG_KMEMLEAK if !XIP_KERNEL
8788
select HAVE_DMA_CONTIGUOUS if MMU
8889
select HAVE_DYNAMIC_FTRACE if !XIP_KERNEL && !CPU_ENDIAN_BE32 && MMU

arch/x86/Kconfig

+1
Original file line numberDiff line numberDiff line change
@@ -186,6 +186,7 @@ config X86
186186
select HAVE_CONTEXT_TRACKING_OFFSTACK if HAVE_CONTEXT_TRACKING
187187
select HAVE_C_RECORDMCOUNT
188188
select HAVE_OBJTOOL_MCOUNT if STACK_VALIDATION
189+
select HAVE_BUILDTIME_MCOUNT_SORT
189190
select HAVE_DEBUG_KMEMLEAK
190191
select HAVE_DMA_CONTIGUOUS
191192
select HAVE_DYNAMIC_FTRACE

kernel/trace/Kconfig

+7-1
Original file line numberDiff line numberDiff line change
@@ -70,10 +70,16 @@ config HAVE_C_RECORDMCOUNT
7070
help
7171
C version of recordmcount available?
7272

73+
config HAVE_BUILDTIME_MCOUNT_SORT
74+
bool
75+
help
76+
An architecture selects this if it sorts the mcount_loc section
77+
at build time.
78+
7379
config BUILDTIME_MCOUNT_SORT
7480
bool
7581
default y
76-
depends on BUILDTIME_TABLE_SORT && !S390
82+
depends on HAVE_BUILDTIME_MCOUNT_SORT && DYNAMIC_FTRACE
7783
help
7884
Sort the mcount_loc section at build time.
7985

scripts/Makefile

+1-1
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ HOSTCFLAGS_sorttable.o += -I$(srctree)/tools/arch/x86/include
2525
HOSTCFLAGS_sorttable.o += -DUNWINDER_ORC_ENABLED
2626
endif
2727

28-
ifdef CONFIG_DYNAMIC_FTRACE
28+
ifdef CONFIG_BUILDTIME_MCOUNT_SORT
2929
HOSTCFLAGS_sorttable.o += -DMCOUNT_SORT_ENABLED
3030
endif
3131

0 commit comments

Comments
 (0)