* [PATCH 1/6] linkage: add generic GLOBAL() macro
2018-11-15 22:41 [PATCH 0/6] arm64: ftrace fixes/cleanup Mark Rutland
@ 2018-11-15 22:41 ` Mark Rutland
2018-11-15 22:41 ` [PATCH 2/6] arm64: ftrace: use GLOBAL() Mark Rutland
` (5 subsequent siblings)
6 siblings, 0 replies; 8+ messages in thread
From: Mark Rutland @ 2018-11-15 22:41 UTC (permalink / raw)
To: linux-arm-kernel
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.
Signed-off-by: Mark Rutland <mark.rutland@arm.com>
Cc: AKASHI Takahiro <takahiro.akashi@linaro.org>
Cc: Ard Biesheuvel <ard.biesheuvel@linaro.org>
Cc: Catalin Marinas <catalin.marinas@arm.com>
Cc: Torsten Duwe <duwe@suse.de>
Cc: Will Deacon <will.deacon@arm.com>
---
include/linux/linkage.h | 6 ++++++
1 file changed, 6 insertions(+)
diff --git a/include/linux/linkage.h b/include/linux/linkage.h
index 7c47b1a471d4..7e020782ade2 100644
--- a/include/linux/linkage.h
+++ b/include/linux/linkage.h
@@ -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 \
--
2.11.0
^ permalink raw reply related [flat|nested] 8+ messages in thread* [PATCH 2/6] arm64: ftrace: use GLOBAL()
2018-11-15 22:41 [PATCH 0/6] arm64: ftrace fixes/cleanup Mark Rutland
2018-11-15 22:41 ` [PATCH 1/6] linkage: add generic GLOBAL() macro Mark Rutland
@ 2018-11-15 22:41 ` Mark Rutland
2018-11-15 22:42 ` [PATCH 3/6] arm64: ftrace: enable graph FP test Mark Rutland
` (4 subsequent siblings)
6 siblings, 0 replies; 8+ messages in thread
From: Mark Rutland @ 2018-11-15 22:41 UTC (permalink / raw)
To: linux-arm-kernel
The 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.
Signed-off-by: Mark Rutland <mark.rutland@arm.com>
Cc: AKASHI Takahiro <takahiro.akashi@linaro.org>
Cc: Ard Biesheuvel <ard.biesheuvel@linaro.org>
Cc: Catalin Marinas <catalin.marinas@arm.com>
Cc: Torsten Duwe <duwe@suse.de>
Cc: Will Deacon <will.deacon@arm.com>
---
arch/arm64/kernel/entry-ftrace.S | 6 ++----
1 file changed, 2 insertions(+), 4 deletions(-)
diff --git a/arch/arm64/kernel/entry-ftrace.S b/arch/arm64/kernel/entry-ftrace.S
index 98f029c7d4f4..eb4e50d9f75d 100644
--- a/arch/arm64/kernel/entry-ftrace.S
+++ b/arch/arm64/kernel/entry-ftrace.S
@@ -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
--
2.11.0
^ permalink raw reply related [flat|nested] 8+ messages in thread* [PATCH 3/6] arm64: ftrace: enable graph FP test
2018-11-15 22:41 [PATCH 0/6] arm64: ftrace fixes/cleanup Mark Rutland
2018-11-15 22:41 ` [PATCH 1/6] linkage: add generic GLOBAL() macro Mark Rutland
2018-11-15 22:41 ` [PATCH 2/6] arm64: ftrace: use GLOBAL() Mark Rutland
@ 2018-11-15 22:42 ` Mark Rutland
2018-11-15 22:42 ` [PATCH 4/6] arm64: ftrace: don't adjust the LR value Mark Rutland
` (3 subsequent siblings)
6 siblings, 0 replies; 8+ messages in thread
From: Mark Rutland @ 2018-11-15 22:42 UTC (permalink / raw)
To: linux-arm-kernel
The 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.
Signed-off-by: Mark Rutland <mark.rutland@arm.com>
Cc: AKASHI Takahiro <takahiro.akashi@linaro.org>
Cc: Ard Biesheuvel <ard.biesheuvel@linaro.org>
Cc: Catalin Marinas <catalin.marinas@arm.com>
Cc: Torsten Duwe <duwe@suse.de>
Cc: Will Deacon <will.deacon@arm.com>
---
arch/arm64/include/asm/ftrace.h | 1 +
arch/arm64/kernel/entry-ftrace.S | 3 +--
2 files changed, 2 insertions(+), 2 deletions(-)
diff --git a/arch/arm64/include/asm/ftrace.h b/arch/arm64/include/asm/ftrace.h
index caa955f10e19..6795c147cbcc 100644
--- a/arch/arm64/include/asm/ftrace.h
+++ b/arch/arm64/include/asm/ftrace.h
@@ -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
diff --git a/arch/arm64/kernel/entry-ftrace.S b/arch/arm64/kernel/entry-ftrace.S
index eb4e50d9f75d..7d74b2af6d3b 100644
--- a/arch/arm64/kernel/entry-ftrace.S
+++ b/arch/arm64/kernel/entry-ftrace.S
@@ -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
--
2.11.0
^ permalink raw reply related [flat|nested] 8+ messages in thread* [PATCH 4/6] arm64: ftrace: don't adjust the LR value
2018-11-15 22:41 [PATCH 0/6] arm64: ftrace fixes/cleanup Mark Rutland
` (2 preceding siblings ...)
2018-11-15 22:42 ` [PATCH 3/6] arm64: ftrace: enable graph FP test Mark Rutland
@ 2018-11-15 22:42 ` Mark Rutland
2018-11-15 22:42 ` [PATCH 5/6] arm64: ftrace: remove return_regs macros Mark Rutland
` (2 subsequent siblings)
6 siblings, 0 replies; 8+ messages in thread
From: Mark Rutland @ 2018-11-15 22:42 UTC (permalink / raw)
To: linux-arm-kernel
The 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.
Signed-off-by: Mark Rutland <mark.rutland@arm.com>
Cc: AKASHI Takahiro <takahiro.akashi@linaro.org>
Cc: Ard Biesheuvel <ard.biesheuvel@linaro.org>
Cc: Catalin Marinas <catalin.marinas@arm.com>
Cc: Torsten Duwe <duwe@suse.de>
Cc: Will Deacon <will.deacon@arm.com>
---
arch/arm64/kernel/entry-ftrace.S | 1 -
1 file changed, 1 deletion(-)
diff --git a/arch/arm64/kernel/entry-ftrace.S b/arch/arm64/kernel/entry-ftrace.S
index 7d74b2af6d3b..a74d2ff49192 100644
--- a/arch/arm64/kernel/entry-ftrace.S
+++ b/arch/arm64/kernel/entry-ftrace.S
@@ -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
--
2.11.0
^ permalink raw reply related [flat|nested] 8+ messages in thread* [PATCH 5/6] arm64: ftrace: remove return_regs macros
2018-11-15 22:41 [PATCH 0/6] arm64: ftrace fixes/cleanup Mark Rutland
` (3 preceding siblings ...)
2018-11-15 22:42 ` [PATCH 4/6] arm64: ftrace: don't adjust the LR value Mark Rutland
@ 2018-11-15 22:42 ` Mark Rutland
2018-11-15 22:42 ` [PATCH 6/6] arm64: ftrace: always pass instrumented pc in x0 Mark Rutland
2018-11-30 13:29 ` [PATCH 0/6] arm64: ftrace fixes/cleanup Will Deacon
6 siblings, 0 replies; 8+ messages in thread
From: Mark Rutland @ 2018-11-15 22:42 UTC (permalink / raw)
To: linux-arm-kernel
The 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.
Signed-off-by: Mark Rutland <mark.rutland@arm.com>
Cc: AKASHI Takahiro <takahiro.akashi@linaro.org>
Cc: Ard Biesheuvel <ard.biesheuvel@linaro.org>
Cc: Catalin Marinas <catalin.marinas@arm.com>
Cc: Torsten Duwe <duwe@suse.de>
Cc: Will Deacon <will.deacon@arm.com>
---
arch/arm64/kernel/entry-ftrace.S | 35 +++++++++++++++--------------------
1 file changed, 15 insertions(+), 20 deletions(-)
diff --git a/arch/arm64/kernel/entry-ftrace.S b/arch/arm64/kernel/entry-ftrace.S
index a74d2ff49192..6b8230f79a67 100644
--- a/arch/arm64/kernel/entry-ftrace.S
+++ b/arch/arm64/kernel/entry-ftrace.S
@@ -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 */
--
2.11.0
^ permalink raw reply related [flat|nested] 8+ messages in thread* [PATCH 6/6] arm64: ftrace: always pass instrumented pc in x0
2018-11-15 22:41 [PATCH 0/6] arm64: ftrace fixes/cleanup Mark Rutland
` (4 preceding siblings ...)
2018-11-15 22:42 ` [PATCH 5/6] arm64: ftrace: remove return_regs macros Mark Rutland
@ 2018-11-15 22:42 ` Mark Rutland
2018-11-30 13:29 ` [PATCH 0/6] arm64: ftrace fixes/cleanup Will Deacon
6 siblings, 0 replies; 8+ messages in thread
From: Mark Rutland @ 2018-11-15 22:42 UTC (permalink / raw)
To: linux-arm-kernel
The 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.
Signed-off-by: Mark Rutland <mark.rutland@arm.com>
Cc: AKASHI Takahiro <takahiro.akashi@linaro.org>
Cc: Ard Biesheuvel <ard.biesheuvel@linaro.org>
Cc: Catalin Marinas <catalin.marinas@arm.com>
Cc: Torsten Duwe <duwe@suse.de>
Cc: Will Deacon <will.deacon@arm.com>
---
arch/arm64/kernel/entry-ftrace.S | 6 +++---
arch/arm64/kernel/ftrace.c | 2 +-
2 files changed, 4 insertions(+), 4 deletions(-)
diff --git a/arch/arm64/kernel/entry-ftrace.S b/arch/arm64/kernel/entry-ftrace.S
index 6b8230f79a67..7981f18bfe5f 100644
--- a/arch/arm64/kernel/entry-ftrace.S
+++ b/arch/arm64/kernel/entry-ftrace.S
@@ -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)
diff --git a/arch/arm64/kernel/ftrace.c b/arch/arm64/kernel/ftrace.c
index 50986e388d2b..34a80bf0b2ef 100644
--- a/arch/arm64/kernel/ftrace.c
+++ b/arch/arm64/kernel/ftrace.c
@@ -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;
--
2.11.0
^ permalink raw reply related [flat|nested] 8+ messages in thread* Re: [PATCH 0/6] arm64: ftrace fixes/cleanup
2018-11-15 22:41 [PATCH 0/6] arm64: ftrace fixes/cleanup Mark Rutland
` (5 preceding siblings ...)
2018-11-15 22:42 ` [PATCH 6/6] arm64: ftrace: always pass instrumented pc in x0 Mark Rutland
@ 2018-11-30 13:29 ` Will Deacon
6 siblings, 0 replies; 8+ messages in thread
From: Will Deacon @ 2018-11-30 13:29 UTC (permalink / raw)
To: Mark Rutland
Cc: takahiro.akashi, duwe, catalin.marinas, linux-arm-kernel,
ard.biesheuvel
On Thu, Nov 15, 2018 at 10:41:57PM +0000, Mark Rutland wrote:
> 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.
This all looks sensible to me, so I've queued it up for 4.21.
Will
_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel
^ permalink raw reply [flat|nested] 8+ messages in thread