Skip to content

Commit 22102f4

Browse files
jpoimboePeter Zijlstra
authored andcommitted
objtool: Make noinstr hacks optional
Objtool has some hacks in place to workaround toolchain limitations which otherwise would break no-instrumentation rules. Make the hacks explicit (and optional for other arches) by turning it into a cmdline option and kernel config option. Signed-off-by: Josh Poimboeuf <[email protected]> Signed-off-by: Peter Zijlstra (Intel) <[email protected]> Reviewed-by: Miroslav Benes <[email protected]> Link: https://lkml.kernel.org/r/b326eeb9c33231b9dfbb925f194ed7ee40edcd7c.1650300597.git.jpoimboe@redhat.com
1 parent 4ab7674 commit 22102f4

File tree

9 files changed

+23
-6
lines changed

9 files changed

+23
-6
lines changed

arch/Kconfig

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1035,6 +1035,9 @@ config HAVE_OBJTOOL
10351035
config HAVE_JUMP_LABEL_HACK
10361036
bool
10371037

1038+
config HAVE_NOINSTR_HACK
1039+
bool
1040+
10381041
config HAVE_STACK_VALIDATION
10391042
bool
10401043
help

arch/x86/Kconfig

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -231,6 +231,7 @@ config X86
231231
select HAVE_MOD_ARCH_SPECIFIC
232232
select HAVE_MOVE_PMD
233233
select HAVE_MOVE_PUD
234+
select HAVE_NOINSTR_HACK if HAVE_OBJTOOL
234235
select HAVE_NMI
235236
select HAVE_OBJTOOL if X86_64
236237
select HAVE_OPTPROBES

lib/Kconfig.debug

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2036,11 +2036,11 @@ config KCOV
20362036
bool "Code coverage for fuzzing"
20372037
depends on ARCH_HAS_KCOV
20382038
depends on CC_HAS_SANCOV_TRACE_PC || GCC_PLUGINS
2039-
depends on !ARCH_WANTS_NO_INSTR || HAVE_OBJTOOL || \
2039+
depends on !ARCH_WANTS_NO_INSTR || HAVE_NOINSTR_HACK || \
20402040
GCC_VERSION >= 120000 || CLANG_VERSION >= 130000
20412041
select DEBUG_FS
20422042
select GCC_PLUGIN_SANCOV if !CC_HAS_SANCOV_TRACE_PC
2043-
select OBJTOOL if HAVE_OBJTOOL
2043+
select OBJTOOL if HAVE_NOINSTR_HACK
20442044
help
20452045
KCOV exposes kernel code coverage information in a form suitable
20462046
for coverage-guided fuzzing (randomized testing).

lib/Kconfig.kcsan

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -187,8 +187,9 @@ config KCSAN_WEAK_MEMORY
187187
# We can either let objtool nop __tsan_func_{entry,exit}() and builtin
188188
# atomics instrumentation in .noinstr.text, or use a compiler that can
189189
# implement __no_kcsan to really remove all instrumentation.
190-
depends on HAVE_OBJTOOL || CC_IS_GCC || CLANG_VERSION >= 140000
191-
select OBJTOOL if HAVE_OBJTOOL
190+
depends on !ARCH_WANTS_NO_INSTR || HAVE_NOINSTR_HACK || \
191+
CC_IS_GCC || CLANG_VERSION >= 140000
192+
select OBJTOOL if HAVE_NOINSTR_HACK
192193
help
193194
Enable support for modeling a subset of weak memory, which allows
194195
detecting a subset of data races due to missing memory barriers.

scripts/Makefile.build

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -228,6 +228,7 @@ objtool := $(objtree)/tools/objtool/objtool
228228

229229
objtool_args = \
230230
$(if $(CONFIG_HAVE_JUMP_LABEL_HACK), --hacks=jump_label) \
231+
$(if $(CONFIG_HAVE_NOINSTR_HACK), --hacks=noinstr) \
231232
$(if $(CONFIG_X86_KERNEL_IBT), --lto --ibt) \
232233
$(if $(CONFIG_FTRACE_MCOUNT_USE_OBJTOOL), --mcount) \
233234
$(if $(CONFIG_UNWINDER_ORC), --orc) \

scripts/link-vmlinux.sh

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -121,6 +121,10 @@ objtool_link()
121121
objtoolopt="${objtoolopt} --hacks=jump_label"
122122
fi
123123

124+
if is_enabled CONFIG_HAVE_NOINSTR_HACK; then
125+
objtoolopt="${objtoolopt} --hacks=noinstr"
126+
fi
127+
124128
if is_enabled CONFIG_X86_KERNEL_IBT; then
125129
objtoolopt="${objtoolopt} --ibt"
126130
fi

tools/objtool/builtin-check.c

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,12 +47,17 @@ static int parse_hacks(const struct option *opt, const char *str, int unset)
4747
found = true;
4848
}
4949

50+
if (!str || strstr(str, "noinstr")) {
51+
opts.hack_noinstr = true;
52+
found = true;
53+
}
54+
5055
return found ? 0 : -1;
5156
}
5257

5358
const struct option check_options[] = {
5459
OPT_GROUP("Actions:"),
55-
OPT_CALLBACK_OPTARG('h', "hacks", NULL, NULL, "jump_label", "patch toolchain bugs/limitations", parse_hacks),
60+
OPT_CALLBACK_OPTARG('h', "hacks", NULL, NULL, "jump_label,noinstr", "patch toolchain bugs/limitations", parse_hacks),
5661
OPT_BOOLEAN('i', "ibt", &opts.ibt, "validate and annotate IBT"),
5762
OPT_BOOLEAN('m', "mcount", &opts.mcount, "annotate mcount/fentry calls for ftrace"),
5863
OPT_BOOLEAN('n', "noinstr", &opts.noinstr, "validate noinstr rules"),
@@ -108,6 +113,7 @@ int cmd_parse_options(int argc, const char **argv, const char * const usage[])
108113
static bool opts_valid(void)
109114
{
110115
if (opts.hack_jump_label ||
116+
opts.hack_noinstr ||
111117
opts.ibt ||
112118
opts.mcount ||
113119
opts.noinstr ||

tools/objtool/check.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1144,7 +1144,7 @@ static void annotate_call_site(struct objtool_file *file,
11441144
* attribute so they need a little help, NOP out any such calls from
11451145
* noinstr text.
11461146
*/
1147-
if (insn->sec->noinstr && sym->profiling_func) {
1147+
if (opts.hack_noinstr && insn->sec->noinstr && sym->profiling_func) {
11481148
if (reloc) {
11491149
reloc->type = R_NONE;
11501150
elf_write_reloc(file->elf, reloc);

tools/objtool/include/objtool/builtin.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ struct opts {
1313
/* actions: */
1414
bool dump_orc;
1515
bool hack_jump_label;
16+
bool hack_noinstr;
1617
bool ibt;
1718
bool mcount;
1819
bool noinstr;

0 commit comments

Comments
 (0)