Skip to content

Commit 802b911

Browse files
xairywilldeacon
authored andcommitted
arm64: kasan: do not instrument stacktrace.c
Disable KASAN instrumentation of arch/arm64/kernel/stacktrace.c. This speeds up Generic KASAN by 5-20%. As a side-effect, KASAN is now unable to detect bugs in the stack trace collection code. This is taken as an acceptable downside. Also replace READ_ONCE_NOCHECK() with READ_ONCE() in stacktrace.c. As the file is now not instrumented, there is no need to use the NOCHECK version of READ_ONCE(). Suggested-by: Mark Rutland <[email protected]> Acked-by: Mark Rutland <[email protected]> Signed-off-by: Andrey Konovalov <[email protected]> Link: https://lore.kernel.org/r/c4c944a2a905e949760fbeb29258185087171708.1653317461.git.andreyknvl@google.com Signed-off-by: Will Deacon <[email protected]>
1 parent a111daf commit 802b911

File tree

2 files changed

+7
-2
lines changed

2 files changed

+7
-2
lines changed

arch/arm64/kernel/Makefile

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,11 @@ CFLAGS_REMOVE_return_address.o = $(CC_FLAGS_FTRACE)
1414
CFLAGS_REMOVE_syscall.o = -fstack-protector -fstack-protector-strong
1515
CFLAGS_syscall.o += -fno-stack-protector
1616

17+
# When KASAN is enabled, a stack trace is recorded for every alloc/free, which
18+
# can significantly impact performance. Avoid instrumenting the stack trace
19+
# collection code to minimize this impact.
20+
KASAN_SANITIZE_stacktrace.o := n
21+
1722
# It's not safe to invoke KCOV when portions of the kernel environment aren't
1823
# available or are out-of-sync with HW state. Since `noinstr` doesn't always
1924
# inhibit KCOV instrumentation, disable it for the entire compilation unit.

arch/arm64/kernel/stacktrace.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -124,8 +124,8 @@ static int notrace unwind_next(struct task_struct *tsk,
124124
* Record this frame record's values and location. The prev_fp and
125125
* prev_type are only meaningful to the next unwind_next() invocation.
126126
*/
127-
state->fp = READ_ONCE_NOCHECK(*(unsigned long *)(fp));
128-
state->pc = READ_ONCE_NOCHECK(*(unsigned long *)(fp + 8));
127+
state->fp = READ_ONCE(*(unsigned long *)(fp));
128+
state->pc = READ_ONCE(*(unsigned long *)(fp + 8));
129129
state->prev_fp = fp;
130130
state->prev_type = info.type;
131131

0 commit comments

Comments
 (0)