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

ARM: 9066/1: ftrace: pause/unpause function graph tracer in cpu_suspend()

Enabling function_graph tracer on ARM causes kernel panic, because the
function graph tracer updates the "return address" of a function in order
to insert a trace callback on function exit, it saves the function's
original return address in a return trace stack, but cpu_suspend() may not
return through the normal return path.

cpu_suspend() will resume directly via the cpu_resume path, but the return
trace stack has been set-up by the subfunctions of cpu_suspend(), which
makes the "return address" inconsistent with cpu_suspend().

This patch refers to Commit de818bd4522c40ea02a81b387d2fa86f989c9623
("arm64: kernel: pause/unpause function graph tracer in cpu_suspend()"),

fixes the issue by pausing/resuming the function graph tracer on the thread
executing cpu_suspend(), so that the function graph tracer state is kept
consistent across functions that enter power down states and never return
by effectively disabling graph tracer while they are executing.

Signed-off-by: louis.wang <liang26812@gmail.com>
Signed-off-by: Russell King <rmk+kernel@armlinux.org.uk>

authored by

louis.wang and committed by
Russell King
8252ca87 a506bd57

+18 -1
+18 -1
arch/arm/kernel/suspend.c
··· 1 1 // SPDX-License-Identifier: GPL-2.0 2 + #include <linux/ftrace.h> 2 3 #include <linux/init.h> 3 4 #include <linux/slab.h> 4 5 #include <linux/mm_types.h> ··· 27 26 return -EINVAL; 28 27 29 28 /* 29 + * Function graph tracer state gets incosistent when the kernel 30 + * calls functions that never return (aka suspend finishers) hence 31 + * disable graph tracing during their execution. 32 + */ 33 + pause_graph_tracing(); 34 + 35 + /* 30 36 * Provide a temporary page table with an identity mapping for 31 37 * the MMU-enable code, required for resuming. On successful 32 38 * resume (indicated by a zero return code), we need to switch 33 39 * back to the correct page tables. 34 40 */ 35 41 ret = __cpu_suspend(arg, fn, __mpidr); 42 + 43 + unpause_graph_tracing(); 44 + 36 45 if (ret == 0) { 37 46 cpu_switch_mm(mm->pgd, mm); 38 47 local_flush_bp_all(); ··· 56 45 int cpu_suspend(unsigned long arg, int (*fn)(unsigned long)) 57 46 { 58 47 u32 __mpidr = cpu_logical_map(smp_processor_id()); 59 - return __cpu_suspend(arg, fn, __mpidr); 48 + int ret; 49 + 50 + pause_graph_tracing(); 51 + ret = __cpu_suspend(arg, fn, __mpidr); 52 + unpause_graph_tracing(); 53 + 54 + return ret; 60 55 } 61 56 #define idmap_pgd NULL 62 57 #endif