arm64: ftrace fixes/cleanup
Mark Rutland
reviewercover arm64: ftrace fixes/cleanup
Hi,
These patches clean up some issues I spotted while looking at Torsten's FTRACE_WITH_REGS patches. I've pushed these to my arm64/ftrace-cleanup [1] branch, based on my export cleanup patches.
Mark.
[1] git://git.kernel.org/pub/scm/linux/kernel/git/mark/linux.git arm64/ftrace-cleanup
Mark Rutland (6):
linkage: add generic GLOBAL() macro
arm64: ftrace: use GLOBAL()
arm64: ftrace: enable graph FP test
arm64: ftrace: don't adjust the LR value
arm64: ftrace: remove return_regs macros
arm64: ftrace: always pass instrumented pc in x0
arch/arm64/include/asm/ftrace.h | 1 + arch/arm64/kernel/entry-ftrace.S | 51 +++++++++++++++++----------------------- arch/arm64/kernel/ftrace.c | 2 +- include/linux/linkage.h | 6 +++++ 4 files changed, 29 insertions(+), 31 deletions(-)
Signature · 1 line
2.11.0
Mark Rutland
reviewerPATCH 1/6 linkage: add generic GLOBAL() macro
Declaring a global symbol in assembly is tedious, error-prone, and painful to read. While ENTRY() exists, this is supposed to be used for function entry points, and this affects alignment in a potentially undesireable manner.
Instead, let's add a generic GLOBAL() macro for this, as x86 added locally in commit:
95695547a7db44b8 ("x86: asm linkage - introduce GLOBAL macro")
... thus allowing us to use this more freely in the kernel.
--- include/linux/linkage.h | 6 ++++++ 1 file changed, 6 insertions(+)
include/linux/linkage.h +6 -0
@@ -79,6 +79,12 @@#define ALIGN __ALIGN#define ALIGN_STR __ALIGN_STR +#ifndef GLOBAL +#define GLOBAL (name) \ + .globl name ASM_NL \ + name: +#endif +#ifndef ENTRY #define ENTRY (name) \ .globl name ASM_NL \
Signature · 1 line
2.11.0
Mark Rutland
reviewerPATCH 2/6 arm64: ftrace: use GLOBAL()
In reply to Mark RutlandThe global exports of ftrace_call and ftrace_graph_call are somewhat painful to read. Let's use the generic GLOBAL() macro to ameliorate matters.
There should be no functional change as a result of this patch.
--- arch/arm64/kernel/entry-ftrace.S | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-)
arch/arm64/kernel/entry-ftrace.S +2 -4
@@ -154,14 +154,12 @@ ENTRY(ftrace_caller) mcount_get_pc0 x0 // function's pc mcount_get_lr x1 // function's lr - .global ftrace_call -ftrace_call: // tracer(pc, lr); +GLOBAL(ftrace_call) // tracer(pc, lr); nop // This will be replaced with "bl xxx" // where xxx can be any kind of tracer. #ifdef CONFIG_FUNCTION_GRAPH_TRACER - .global ftrace_graph_call -ftrace_graph_call: // ftrace_graph_caller(); +GLOBAL(ftrace_graph_call) // ftrace_graph_caller(); nop // If enabled, this will be replaced // "b ftrace_graph_caller" #endif
Signature · 1 line
2.11.0
Mark Rutland
reviewerPATCH 3/6 arm64: ftrace: enable graph FP test
In reply to Mark RutlandThe core frace code has an optional sanity check on the frame pointer passed by ftrace_graph_caller and return_to_handler. This is cheap, useful, and enabled unconditionally on x86, sparc, and riscv.
Let's do the same on arm64, so that we can catch any problems early.
--- arch/arm64/include/asm/ftrace.h | 1 + arch/arm64/kernel/entry-ftrace.S | 3 +-- 2 files changed, 2 insertions(+), 2 deletions(-)
arch/arm64/include/asm/ftrace.h +1 -0
@@ -13,6 +13,7 @@#include <asm/insn.h> +#define HAVE_FUNCTION_GRAPH_FP_TEST #define MCOUNT_ADDR ((unsigned long)_mcount)#define MCOUNT_INSN_SIZE AARCH64_INSN_SIZE
arch/arm64/kernel/entry-ftrace.S +1 -2
@@ -213,8 +213,7 @@ ENDPROC(ftrace_graph_caller) * void return_to_handler(void) * * Run ftrace_return_to_handler() before going back to parent. - * @fp is checked against the value passed by ftrace_graph_caller() - * only when HAVE_FUNCTION_GRAPH_FP_TEST is enabled. + * @fp is checked against the value passed by ftrace_graph_caller(). */ ENTRY(return_to_handler) save_return_regs
Signature · 1 line
2.11.0
Mark Rutland
reviewerPATCH 4/6 arm64: ftrace: don't adjust the LR value
In reply to Mark RutlandThe core ftrace code requires that when it is handed the PC of an instrumented function, this PC is the address of the instrumented instruction. This is necessary so that the core ftrace code can identify the specific instrumentation site. Since the instrumented function will be a BL, the address of the instrumented function is LR - 4 at entry to the ftrace code.
This fixup is applied in the mcount_get_pc and mcount_get_pc0 helpers, which acquire the PC of the instrumented function.
The mcount_get_lr helper is used to acquire the LR of the instrumented function, whose value does not require this adjustment, and cannot be adjusted to anything meaningful. No adjustment of this value is made on other architectures, including arm. However, arm64 adjusts this value by 4.
This patch brings arm64 in line with other architectures and removes the adjustment of the LR value.
--- arch/arm64/kernel/entry-ftrace.S | 1 - 1 file changed, 1 deletion(-)
arch/arm64/kernel/entry-ftrace.S +0 -1
@@ -81,7 +81,6 @@ .macro mcount_get_lr reg ldr \reg, [x29] ldr \reg, [\reg, #8] - mcount_adjust_addr \reg, \reg .endm .macro mcount_get_lr_addr reg
Signature · 1 line
2.11.0
Mark Rutland
reviewerPATCH 5/6 arm64: ftrace: remove return_regs macros
In reply to Mark RutlandThe save_return_regs and restore_return_regs macros are only used by return_to_handler, and having them defined out-of-line only serves to obscure the logic.
Before we complicate, let's clean this up and fold the logic directly into return_to_handler, saving a few lines of macro boilerplate in the process. At the same time, a missing trailing space is added to the comments, fixing a code style violation.
There should be no functional change as a result of this patch.
--- arch/arm64/kernel/entry-ftrace.S | 35 +++++++++++++++-------------------- 1 file changed, 15 insertions(+), 20 deletions(-)
arch/arm64/kernel/entry-ftrace.S +15 -20
@@ -172,24 +172,6 @@ ENTRY(ftrace_stub) ENDPROC(ftrace_stub) #ifdef CONFIG_FUNCTION_GRAPH_TRACER - /* save return value regs*/ - .macro save_return_regs - sub sp, sp, #64 - stp x0, x1, [sp] - stp x2, x3, [sp, #16] - stp x4, x5, [sp, #32] - stp x6, x7, [sp, #48] - .endm - - /* restore return value regs*/ - .macro restore_return_regs - ldp x0, x1, [sp] - ldp x2, x3, [sp, #16] - ldp x4, x5, [sp, #32] - ldp x6, x7, [sp, #48] - add sp, sp, #64 - .endm - /* * void ftrace_graph_caller(void) *
@@ -215,11 +197,24 @@ ENDPROC(ftrace_graph_caller) * @fp is checked against the value passed by ftrace_graph_caller(). */ ENTRY(return_to_handler) - save_return_regs + /* save return value regs */ + sub sp, sp, #64 + stp x0, x1, [sp] + stp x2, x3, [sp, #16] + stp x4, x5, [sp, #32] + stp x6, x7, [sp, #48] + mov x0, x29 // parent's fp bl ftrace_return_to_handler// addr = ftrace_return_to_hander(fp); mov x30, x0 // restore the original return address - restore_return_regs + + /* restore return value regs */ + ldp x0, x1, [sp] + ldp x2, x3, [sp, #16] + ldp x4, x5, [sp, #32] + ldp x6, x7, [sp, #48] + add sp, sp, #64 + ret END(return_to_handler) #endif /* CONFIG_FUNCTION_GRAPH_TRACER */
Signature · 1 line
2.11.0
Mark Rutland
reviewerPATCH 6/6 arm64: ftrace: always pass instrumented pc in x0
In reply to Mark RutlandThe core ftrace hooks take the instrumented PC in x0, but for some reason arm64's prepare_ftrace_return() takes this in x1.
For consistency, let's flip the argument order and always pass the instrumented PC in x0.
There should be no functional change as a result of this patch.
--- arch/arm64/kernel/entry-ftrace.S | 6 +++--- arch/arm64/kernel/ftrace.c | 2 +- 2 files changed, 4 insertions(+), 4 deletions(-)
arch/arm64/kernel/entry-ftrace.S +3 -3
@@ -182,10 +182,10 @@ ENDPROC(ftrace_stub) * and run return_to_handler() later on its exit. */ ENTRY(ftrace_graph_caller) - mcount_get_lr_addr x0 // pointer to function's saved lr - mcount_get_pc x1 // function's pc + mcount_get_pc x0 // function's pc + mcount_get_lr_addr x1 // pointer to function's saved lr mcount_get_parent_fp x2 // parent's fp - bl prepare_ftrace_return // prepare_ftrace_return(&lr, pc, fp) + bl prepare_ftrace_return // prepare_ftrace_return(pc, &lr, fp) mcount_exit ENDPROC(ftrace_graph_caller)
arch/arm64/kernel/ftrace.c +1 -1
@@ -211,7 +211,7 @@ int __init ftrace_dyn_arch_init(void)* * Note that @frame_pointer is used only for sanity check later. */ -void prepare_ftrace_return (unsigned long *parent,unsigned long self_addr, +void prepare_ftrace_return (unsigned long self_addr,unsigned long *parent,unsigned long frame_pointer) {unsigned long return_hooker = (unsigned long )&return_to_handler;
Signature · 1 line
2.11.0
Quoted 3 lines · Mark Rutland
These patches clean up some issues I spotted while looking at Torsten's
FTRACE_WITH_REGSpatches. I've pushed these to my arm64/ftrace-cleanup [1] branch, based on my export cleanup patches.
This all looks sensible to me, so I've queued it up for 4.21.
Will
_______________________________________________
linux-arm-kernel mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel