Skip to content

Commit 2cbb20b

Browse files
jpoimboeIngo Molnar
authored and
Ingo Molnar
committed
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 <[email protected]> Suggested-by: Steven Rostedt <[email protected]> Signed-off-by: Josh Poimboeuf <[email protected]> Signed-off-by: Ingo Molnar <[email protected]> Acked-by: Thomas Gleixner <[email protected]> Cc: Linus Torvalds <[email protected]> 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

Diff for: arch/x86/Kbuild

+4
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/

Diff for: arch/x86/coco/sev/core.c

-2
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>

Diff for: arch/x86/kernel/head64.c

-2
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,6 @@
55
* Copyright (C) 2000 Andrea Arcangeli <[email protected]> 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

Diff for: arch/x86/mm/kasan_init_64.c

-1
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 */

Diff for: arch/x86/mm/mem_encrypt_amd.c

-2
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,6 @@
77
* Author: Tom Lendacky <[email protected]>
88
*/
99

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

Diff for: arch/x86/mm/mem_encrypt_identity.c

-2
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,6 @@
77
* Author: Tom Lendacky <[email protected]>
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

Diff for: drivers/acpi/Makefile

+4
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
#

Diff for: drivers/cpuidle/Makefile

+3
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

Diff for: drivers/idle/Makefile

+4-1
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

Diff for: kernel/Makefile

+5
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

Diff for: kernel/entry/Makefile

+3
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,9 @@ KASAN_SANITIZE := n
66
UBSAN_SANITIZE := n
77
KCOV_INSTRUMENT := n
88

9+
# Branch profiling isn't noinstr-safe
10+
ccflags-$(CONFIG_TRACE_BRANCH_PROFILING) += -DDISABLE_BRANCH_PROFILING
11+
912
CFLAGS_REMOVE_common.o = -fstack-protector -fstack-protector-strong
1013
CFLAGS_common.o += -fno-stack-protector
1114

Diff for: kernel/sched/Makefile

+5
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,11 @@ ifneq ($(CONFIG_SCHED_OMIT_FRAME_POINTER),y)
2222
CFLAGS_core.o := $(PROFILING) -fno-omit-frame-pointer
2323
endif
2424

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
2530
#
2631
# Build efficiency:
2732
#

Diff for: kernel/time/Makefile

+6
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,10 @@
11
# 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+
28
obj-y += time.o timer.o hrtimer.o sleep_timeout.o
39
obj-y += timekeeping.o ntp.o clocksource.o jiffies.o timer_list.o
410
obj-y += timeconv.o timecounter.o alarmtimer.o

Diff for: lib/Makefile

+5
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,11 @@
55

66
ccflags-remove-$(CONFIG_FUNCTION_TRACER) += $(CC_FLAGS_FTRACE)
77

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+
813
# These files are disabled because they produce lots of non-interesting and/or
914
# flaky coverage that is not a function of syscall inputs. For example,
1015
# rbtree can be global and individual rotations don't correlate with inputs.

0 commit comments

Comments
 (0)