Skip to content

Commit 51c2ee6

Browse files
nickdesaulnierskees
authored andcommitted
Kconfig: Introduce ARCH_WANTS_NO_INSTR and CC_HAS_NO_PROFILE_FN_ATTR
We don't want compiler instrumentation to touch noinstr functions, which are annotated with the no_profile_instrument_function function attribute. Add a Kconfig test for this and make GCOV depend on it, and in the future, PGO. If an architecture is using noinstr, it should denote that via this Kconfig value. That makes Kconfigs that depend on noinstr able to express dependencies in an architecturally agnostic way. Cc: Masahiro Yamada <[email protected]> Link: https://lore.kernel.org/lkml/[email protected]/ Link: https://lore.kernel.org/lkml/YMcssV%[email protected]/ Suggested-by: Nathan Chancellor <[email protected]> Suggested-by: Peter Zijlstra <[email protected]> Signed-off-by: Nick Desaulniers <[email protected]> Reviewed-by: Peter Oberparleiter <[email protected]> Reviewed-by: Nathan Chancellor <[email protected]> Acked-by: Mark Rutland <[email protected]> Acked-by: Heiko Carstens <[email protected]> Acked-by: Peter Zijlstra (Intel) <[email protected]> Signed-off-by: Kees Cook <[email protected]> Link: https://lore.kernel.org/r/[email protected]
1 parent ae4d682 commit 51c2ee6

File tree

6 files changed

+14
-0
lines changed

6 files changed

+14
-0
lines changed

arch/Kconfig

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -285,6 +285,13 @@ config ARCH_THREAD_STACK_ALLOCATOR
285285
config ARCH_WANTS_DYNAMIC_TASK_STRUCT
286286
bool
287287

288+
config ARCH_WANTS_NO_INSTR
289+
bool
290+
help
291+
An architecture should select this if the noinstr macro is being used on
292+
functions to denote that the toolchain should avoid instrumenting such
293+
functions and is required for correctness.
294+
288295
config ARCH_32BIT_OFF_T
289296
bool
290297
depends on !64BIT

arch/arm64/Kconfig

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,7 @@ config ARM64
9393
select ARCH_WANT_FRAME_POINTERS
9494
select ARCH_WANT_HUGE_PMD_SHARE if ARM64_4K_PAGES || (ARM64_16K_PAGES && !ARM64_VA_BITS_36)
9595
select ARCH_WANT_LD_ORPHAN_WARN
96+
select ARCH_WANTS_NO_INSTR
9697
select ARCH_HAS_UBSAN_SANITIZE_ALL
9798
select ARM_AMBA
9899
select ARM_ARCH_TIMER

arch/s390/Kconfig

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -117,6 +117,7 @@ config S390
117117
select ARCH_USE_BUILTIN_BSWAP
118118
select ARCH_USE_CMPXCHG_LOCKREF
119119
select ARCH_WANTS_DYNAMIC_TASK_STRUCT
120+
select ARCH_WANTS_NO_INSTR
120121
select ARCH_WANT_DEFAULT_BPF_JIT
121122
select ARCH_WANT_IPC_PARSE_VERSION
122123
select BUILDTIME_TABLE_SORT

arch/x86/Kconfig

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -113,6 +113,7 @@ config X86
113113
select ARCH_WANT_BATCHED_UNMAP_TLB_FLUSH
114114
select ARCH_WANT_DEFAULT_BPF_JIT if X86_64
115115
select ARCH_WANTS_DYNAMIC_TASK_STRUCT
116+
select ARCH_WANTS_NO_INSTR
116117
select ARCH_WANT_HUGE_PMD_SHARE
117118
select ARCH_WANT_LD_ORPHAN_WARN
118119
select ARCH_WANTS_THP_SWAP if X86_64

init/Kconfig

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,9 @@ config TOOLS_SUPPORT_RELR
8383
config CC_HAS_ASM_INLINE
8484
def_bool $(success,echo 'void foo(void) { asm inline (""); }' | $(CC) -x c - -c -o /dev/null)
8585

86+
config CC_HAS_NO_PROFILE_FN_ATTR
87+
def_bool $(success,echo '__attribute__((no_profile_instrument_function)) int x();' | $(CC) -x c - -c -o /dev/null -Werror)
88+
8689
config CONSTRUCTORS
8790
bool
8891

kernel/gcov/Kconfig

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ config GCOV_KERNEL
55
bool "Enable gcov-based kernel profiling"
66
depends on DEBUG_FS
77
depends on !CC_IS_CLANG || CLANG_VERSION >= 110000
8+
depends on !ARCH_WANTS_NO_INSTR || CC_HAS_NO_PROFILE_FN_ATTR
89
select CONSTRUCTORS
910
default n
1011
help

0 commit comments

Comments
 (0)