Skip to content

Commit 2cbb20b

Browse files
jpoimboeIngo Molnar
authored andcommitted
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
1 parent 7307046 commit 2cbb20b

File tree

14 files changed

+39
-10
lines changed

14 files changed

+39
-10
lines changed

arch/x86/Kbuild

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,8 @@
11
# 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+
26
obj-$(CONFIG_ARCH_HAS_CC_PLATFORM) += coco/
37

48
obj-y += entry/

arch/x86/coco/sev/core.c

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,6 @@
99

1010
#define pr_fmt(fmt) "SEV: " fmt
1111

12-
#define DISABLE_BRANCH_PROFILING
13-
1412
#include <linux/sched/debug.h> /* For show_regs() */
1513
#include <linux/percpu-defs.h>
1614
#include <linux/cc_platform.h>

arch/x86/kernel/head64.c

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,6 @@
55
* Copyright (C) 2000 Andrea Arcangeli <andrea@suse.de> SuSE
66
*/
77

8-
#define DISABLE_BRANCH_PROFILING
9-
108
/* cpu_feature_enabled() cannot be used this early */
119
#define USE_EARLY_PGTABLE_L5
1210

arch/x86/mm/kasan_init_64.c

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
// SPDX-License-Identifier: GPL-2.0
2-
#define DISABLE_BRANCH_PROFILING
32
#define pr_fmt(fmt) "kasan: " fmt
43

54
/* cpu_feature_enabled() cannot be used this early */

arch/x86/mm/mem_encrypt_amd.c

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,6 @@
77
* Author: Tom Lendacky <thomas.lendacky@amd.com>
88
*/
99

10-
#define DISABLE_BRANCH_PROFILING
11-
1210
#include <linux/linkage.h>
1311
#include <linux/init.h>
1412
#include <linux/mm.h>

arch/x86/mm/mem_encrypt_identity.c

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,6 @@
77
* Author: Tom Lendacky <thomas.lendacky@amd.com>
88
*/
99

10-
#define DISABLE_BRANCH_PROFILING
11-
1210
/*
1311
* Since we're dealing with identity mappings, physical and virtual
1412
* addresses are the same, so override these defines which are ultimately

drivers/acpi/Makefile

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,10 @@
55

66
ccflags-$(CONFIG_ACPI_DEBUG) += -DACPI_DEBUG_OUTPUT
77

8+
ifdef CONFIG_TRACE_BRANCH_PROFILING
9+
CFLAGS_processor_idle.o += -DDISABLE_BRANCH_PROFILING
10+
endif
11+
812
#
913
# ACPI Boot-Time Table Parsing
1014
#

drivers/cpuidle/Makefile

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,9 @@
33
# Makefile for cpuidle.
44
#
55

6+
# Branch profiling isn't noinstr-safe
7+
ccflags-$(CONFIG_TRACE_BRANCH_PROFILING) += -DDISABLE_BRANCH_PROFILING
8+
69
obj-y += cpuidle.o driver.o governor.o sysfs.o governors/
710
obj-$(CONFIG_ARCH_NEEDS_CPU_IDLE_COUPLED) += coupled.o
811
obj-$(CONFIG_DT_IDLE_STATES) += dt_idle_states.o

drivers/idle/Makefile

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
11
# SPDX-License-Identifier: GPL-2.0-only
2-
obj-$(CONFIG_INTEL_IDLE) += intel_idle.o
32

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

kernel/Makefile

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,11 @@ ifdef CONFIG_FUNCTION_TRACER
2121
CFLAGS_REMOVE_irq_work.o = $(CC_FLAGS_FTRACE)
2222
endif
2323

24+
# Branch profiling isn't noinstr-safe
25+
ifdef CONFIG_TRACE_BRANCH_PROFILING
26+
CFLAGS_context_tracking.o += -DDISABLE_BRANCH_PROFILING
27+
endif
28+
2429
# Prevents flicker of uninteresting __do_softirq()/__local_bh_disable_ip()
2530
# in coverage traces.
2631
KCOV_INSTRUMENT_softirq.o := n

0 commit comments

Comments
 (0)