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

tracing: Disable branch profiling in noinstr code

CONFIG_TRACE_BRANCH_PROFILING inserts a call to ftrace_likely_update()
for each use of likely() or unlikely(). That breaks noinstr rules if
the affected function is annotated as noinstr.

Disable branch profiling for files with noinstr functions. In addition
to some individual files, this also includes the entire arch/x86
subtree, as well as the kernel/entry, drivers/cpuidle, and drivers/idle
directories, all of which are noinstr-heavy.

Due to the nature of how sched binaries are built by combining multiple
.c files into one, branch profiling is disabled more broadly across the
sched code than would otherwise be needed.

This fixes many warnings like the following:

vmlinux.o: warning: objtool: do_syscall_64+0x40: call to ftrace_likely_update() leaves .noinstr.text section
vmlinux.o: warning: objtool: __rdgsbase_inactive+0x33: call to ftrace_likely_update() leaves .noinstr.text section
vmlinux.o: warning: objtool: handle_bug.isra.0+0x198: call to ftrace_likely_update() leaves .noinstr.text section
...

Reported-by: Ingo Molnar <mingo@kernel.org>
Suggested-by: Steven Rostedt <rostedt@goodmis.org>
Signed-off-by: Josh Poimboeuf <jpoimboe@kernel.org>
Signed-off-by: Ingo Molnar <mingo@kernel.org>
Acked-by: Thomas Gleixner <tglx@linutronix.de>
Cc: Linus Torvalds <torvalds@linux-foundation.org>
Link: https://lore.kernel.org/r/fb94fc9303d48a5ed370498f54500cc4c338eb6d.1742586676.git.jpoimboe@kernel.org

authored by

Josh Poimboeuf and committed by
Ingo Molnar
2cbb20b0 73070466

+39 -10
+4
arch/x86/Kbuild
··· 1 1 # SPDX-License-Identifier: GPL-2.0 2 + 3 + # Branch profiling isn't noinstr-safe. Disable it for arch/x86/* 4 + subdir-ccflags-$(CONFIG_TRACE_BRANCH_PROFILING) += -DDISABLE_BRANCH_PROFILING 5 + 2 6 obj-$(CONFIG_ARCH_HAS_CC_PLATFORM) += coco/ 3 7 4 8 obj-y += entry/
-2
arch/x86/coco/sev/core.c
··· 9 9 10 10 #define pr_fmt(fmt) "SEV: " fmt 11 11 12 - #define DISABLE_BRANCH_PROFILING 13 - 14 12 #include <linux/sched/debug.h> /* For show_regs() */ 15 13 #include <linux/percpu-defs.h> 16 14 #include <linux/cc_platform.h>
-2
arch/x86/kernel/head64.c
··· 5 5 * Copyright (C) 2000 Andrea Arcangeli <andrea@suse.de> SuSE 6 6 */ 7 7 8 - #define DISABLE_BRANCH_PROFILING 9 - 10 8 /* cpu_feature_enabled() cannot be used this early */ 11 9 #define USE_EARLY_PGTABLE_L5 12 10
-1
arch/x86/mm/kasan_init_64.c
··· 1 1 // SPDX-License-Identifier: GPL-2.0 2 - #define DISABLE_BRANCH_PROFILING 3 2 #define pr_fmt(fmt) "kasan: " fmt 4 3 5 4 /* cpu_feature_enabled() cannot be used this early */
-2
arch/x86/mm/mem_encrypt_amd.c
··· 7 7 * Author: Tom Lendacky <thomas.lendacky@amd.com> 8 8 */ 9 9 10 - #define DISABLE_BRANCH_PROFILING 11 - 12 10 #include <linux/linkage.h> 13 11 #include <linux/init.h> 14 12 #include <linux/mm.h>
-2
arch/x86/mm/mem_encrypt_identity.c
··· 7 7 * Author: Tom Lendacky <thomas.lendacky@amd.com> 8 8 */ 9 9 10 - #define DISABLE_BRANCH_PROFILING 11 - 12 10 /* 13 11 * Since we're dealing with identity mappings, physical and virtual 14 12 * addresses are the same, so override these defines which are ultimately
+4
drivers/acpi/Makefile
··· 5 5 6 6 ccflags-$(CONFIG_ACPI_DEBUG) += -DACPI_DEBUG_OUTPUT 7 7 8 + ifdef CONFIG_TRACE_BRANCH_PROFILING 9 + CFLAGS_processor_idle.o += -DDISABLE_BRANCH_PROFILING 10 + endif 11 + 8 12 # 9 13 # ACPI Boot-Time Table Parsing 10 14 #
+3
drivers/cpuidle/Makefile
··· 3 3 # Makefile for cpuidle. 4 4 # 5 5 6 + # Branch profiling isn't noinstr-safe 7 + ccflags-$(CONFIG_TRACE_BRANCH_PROFILING) += -DDISABLE_BRANCH_PROFILING 8 + 6 9 obj-y += cpuidle.o driver.o governor.o sysfs.o governors/ 7 10 obj-$(CONFIG_ARCH_NEEDS_CPU_IDLE_COUPLED) += coupled.o 8 11 obj-$(CONFIG_DT_IDLE_STATES) += dt_idle_states.o
+4 -1
drivers/idle/Makefile
··· 1 1 # SPDX-License-Identifier: GPL-2.0-only 2 - obj-$(CONFIG_INTEL_IDLE) += intel_idle.o 3 2 3 + # Branch profiling isn't noinstr-safe 4 + ccflags-$(CONFIG_TRACE_BRANCH_PROFILING) += -DDISABLE_BRANCH_PROFILING 5 + 6 + obj-$(CONFIG_INTEL_IDLE) += intel_idle.o
+5
kernel/Makefile
··· 21 21 CFLAGS_REMOVE_irq_work.o = $(CC_FLAGS_FTRACE) 22 22 endif 23 23 24 + # Branch profiling isn't noinstr-safe 25 + ifdef CONFIG_TRACE_BRANCH_PROFILING 26 + CFLAGS_context_tracking.o += -DDISABLE_BRANCH_PROFILING 27 + endif 28 + 24 29 # Prevents flicker of uninteresting __do_softirq()/__local_bh_disable_ip() 25 30 # in coverage traces. 26 31 KCOV_INSTRUMENT_softirq.o := n
+3
kernel/entry/Makefile
··· 6 6 UBSAN_SANITIZE := n 7 7 KCOV_INSTRUMENT := n 8 8 9 + # Branch profiling isn't noinstr-safe 10 + ccflags-$(CONFIG_TRACE_BRANCH_PROFILING) += -DDISABLE_BRANCH_PROFILING 11 + 9 12 CFLAGS_REMOVE_common.o = -fstack-protector -fstack-protector-strong 10 13 CFLAGS_common.o += -fno-stack-protector 11 14
+5
kernel/sched/Makefile
··· 22 22 CFLAGS_core.o := $(PROFILING) -fno-omit-frame-pointer 23 23 endif 24 24 25 + # Branch profiling isn't noinstr-safe 26 + ifdef CONFIG_TRACE_BRANCH_PROFILING 27 + CFLAGS_build_policy.o += -DDISABLE_BRANCH_PROFILING 28 + CFLAGS_build_utility.o += -DDISABLE_BRANCH_PROFILING 29 + endif 25 30 # 26 31 # Build efficiency: 27 32 #
+6
kernel/time/Makefile
··· 1 1 # SPDX-License-Identifier: GPL-2.0 2 + 3 + # Branch profiling isn't noinstr-safe 4 + ifdef CONFIG_TRACE_BRANCH_PROFILING 5 + CFLAGS_sched_clock.o += -DDISABLE_BRANCH_PROFILING 6 + endif 7 + 2 8 obj-y += time.o timer.o hrtimer.o sleep_timeout.o 3 9 obj-y += timekeeping.o ntp.o clocksource.o jiffies.o timer_list.o 4 10 obj-y += timeconv.o timecounter.o alarmtimer.o
+5
lib/Makefile
··· 5 5 6 6 ccflags-remove-$(CONFIG_FUNCTION_TRACER) += $(CC_FLAGS_FTRACE) 7 7 8 + # Branch profiling isn't noinstr-safe 9 + ifdef CONFIG_TRACE_BRANCH_PROFILING 10 + CFLAGS_smp_processor_id.o += -DDISABLE_BRANCH_PROFILING 11 + endif 12 + 8 13 # These files are disabled because they produce lots of non-interesting and/or 9 14 # flaky coverage that is not a function of syscall inputs. For example, 10 15 # rbtree can be global and individual rotations don't correlate with inputs.