* [PATCH] arm: ftrace: Adds support for ftrace operations @ 2014-11-07 14:59 ` Jean-Jacques Hiblot 0 siblings, 0 replies; 20+ messages in thread From: Jean-Jacques Hiblot @ 2014-11-07 14:59 UTC (permalink / raw) To: jslaby, linux, rostedt, mingo, nsekhar, stefano.stabellini, christoffer.dall Cc: linux-arm-kernel, linux-kernel, Jean-Jacques Hiblot Hi all, This patch adds support for ftrace operations on the ARM architecture. This support is needed by kgraft and possibly other ftrace-based tools. My goal is to have kgraft working on ARM and aarch64. I tested this patch with a toy implementation of kgraft for ARM and basic usage of function and function_graph tracers It doesn't show any problem with the ftrace selftests and the tests found today in branch ftrace/testing-mystuff of linux-trace repository (git://git.kernel.org/pub/scm/linux/kernel/git/rostedt/linux-trace.git) Jean-Jacques Hiblot (1): arm: ftrace: Adds support for ftrace operations arch/arm/Kconfig | 2 ++ arch/arm/include/asm/ftrace.h | 3 ++ arch/arm/kernel/entry-common.S | 68 +++++++++++++++++++++++++++++++++++++++++- arch/arm/kernel/ftrace.c | 34 +++++++++++++++++++++ 4 files changed, 106 insertions(+), 1 deletion(-) -- 2.1.3 ^ permalink raw reply [flat|nested] 20+ messages in thread
* [PATCH] arm: ftrace: Adds support for ftrace operations @ 2014-11-07 14:59 ` Jean-Jacques Hiblot 0 siblings, 0 replies; 20+ messages in thread From: Jean-Jacques Hiblot @ 2014-11-07 14:59 UTC (permalink / raw) To: linux-arm-kernel Hi all, This patch adds support for ftrace operations on the ARM architecture. This support is needed by kgraft and possibly other ftrace-based tools. My goal is to have kgraft working on ARM and aarch64. I tested this patch with a toy implementation of kgraft for ARM and basic usage of function and function_graph tracers It doesn't show any problem with the ftrace selftests and the tests found today in branch ftrace/testing-mystuff of linux-trace repository (git://git.kernel.org/pub/scm/linux/kernel/git/rostedt/linux-trace.git) Jean-Jacques Hiblot (1): arm: ftrace: Adds support for ftrace operations arch/arm/Kconfig | 2 ++ arch/arm/include/asm/ftrace.h | 3 ++ arch/arm/kernel/entry-common.S | 68 +++++++++++++++++++++++++++++++++++++++++- arch/arm/kernel/ftrace.c | 34 +++++++++++++++++++++ 4 files changed, 106 insertions(+), 1 deletion(-) -- 2.1.3 ^ permalink raw reply [flat|nested] 20+ messages in thread
* [PATCH 01/01] arm: ftrace: Adds support for ftrace operations 2014-11-07 14:59 ` Jean-Jacques Hiblot @ 2014-11-07 14:59 ` Jean-Jacques Hiblot -1 siblings, 0 replies; 20+ messages in thread From: Jean-Jacques Hiblot @ 2014-11-07 14:59 UTC (permalink / raw) To: jslaby, linux, rostedt, mingo, nsekhar, stefano.stabellini, christoffer.dall Cc: linux-arm-kernel, linux-kernel, Jean-Jacques Hiblot Ftrace operations require that DYNAMIC_FTRACE_WITH_REGS is enabled. This patch introduces a new ftrace handler that store the registers on the stack before calling the next stage. The registers are also restored from the stack before going back to the instrumented function. Signed-off-by: Jean-Jacques Hiblot <jjhiblot@traphandler.com> --- arch/arm/Kconfig | 2 ++ arch/arm/include/asm/ftrace.h | 3 ++ arch/arm/kernel/entry-common.S | 68 +++++++++++++++++++++++++++++++++++++++++- arch/arm/kernel/ftrace.c | 34 +++++++++++++++++++++ 4 files changed, 106 insertions(+), 1 deletion(-) diff --git a/arch/arm/Kconfig b/arch/arm/Kconfig index 32cbbd5..6f928ee 100644 --- a/arch/arm/Kconfig +++ b/arch/arm/Kconfig @@ -39,6 +39,7 @@ config ARM select HAVE_DMA_ATTRS select HAVE_DMA_CONTIGUOUS if MMU select HAVE_DYNAMIC_FTRACE if (!XIP_KERNEL) + select HAVE_DYNAMIC_FTRACE_WITH_REGS if HAVE_DYNAMIC_FTRACE select HAVE_EFFICIENT_UNALIGNED_ACCESS if (CPU_V6 || CPU_V6K || CPU_V7) && MMU select HAVE_FTRACE_MCOUNT_RECORD if (!XIP_KERNEL) select HAVE_FUNCTION_GRAPH_TRACER if (!THUMB2_KERNEL) @@ -72,6 +73,7 @@ config ARM select PERF_USE_VMALLOC select RTC_LIB select SYS_SUPPORTS_APM_EMULATION + select FRAME_POINTER if DYNAMIC_FTRACE_WITH_REGS && FUNCTION_GRAPH_TRACER # Above selects are sorted alphabetically; please add new ones # according to that. Thanks. help diff --git a/arch/arm/include/asm/ftrace.h b/arch/arm/include/asm/ftrace.h index 39eb16b..d8e9bea 100644 --- a/arch/arm/include/asm/ftrace.h +++ b/arch/arm/include/asm/ftrace.h @@ -10,6 +10,9 @@ extern void mcount(void); extern void __gnu_mcount_nc(void); #ifdef CONFIG_DYNAMIC_FTRACE + +#define ARCH_SUPPORTS_FTRACE_OPS 1 + struct dyn_arch_ftrace { #ifdef CONFIG_OLD_MCOUNT bool old_mcount; diff --git a/arch/arm/kernel/entry-common.S b/arch/arm/kernel/entry-common.S index e52fe5a..9594fe2 100644 --- a/arch/arm/kernel/entry-common.S +++ b/arch/arm/kernel/entry-common.S @@ -197,7 +197,10 @@ ENDPROC(ret_from_fork) mcount_get_lr r1 @ lr of instrumented func mcount_adjust_addr r0, lr @ instrumented function - + ldr r2, =function_trace_op + ldr r2, [r2] @ pointer to the current + @ function tracing op + mov r3, #0 @ regs is NULL .globl ftrace_call\suffix ftrace_call\suffix: bl ftrace_stub @@ -211,6 +214,38 @@ ftrace_graph_call\suffix: mcount_exit .endm +.macro __ftrace_regs_caller + + add ip, sp, #4 @ move in IP the value of SP as it was + @ before the push {lr} of the mcount mechanism + stmdb sp!, {ip,lr,pc} + stmdb sp!, {r0-r11,lr} + @ stack content at this point: + @ 0 4 44 48 52 56 60 64 + @ RO | R1 | ... | R11 | LR | SP + 4 | LR | PC | previous LR | + + mov r3, sp @ struct pt_regs* + ldr r2, =function_trace_op + ldr r2, [r2] @ pointer to the current + @ function tracing op + ldr r1, [sp, #64] @ lr of instrumented func + mcount_adjust_addr r0, lr @ instrumented function + + .globl ftrace_regs_call +ftrace_regs_call: + bl ftrace_stub + +#ifdef CONFIG_FUNCTION_GRAPH_TRACER + .globl ftrace_graph_regs_call +ftrace_graph_regs_call: + mov r0, r0 +#endif + ldr lr, [sp, #64] @ get the previous LR value from stack + ldmia sp, {r0-r11, ip, sp} @ pop the saved registers INCLUDING + @ the stack pointer + ret ip +.endm + .macro __ftrace_graph_caller sub r0, fp, #4 @ &lr of instrumented routine (&parent) #ifdef CONFIG_DYNAMIC_FTRACE @@ -226,6 +261,24 @@ ftrace_graph_call\suffix: mcount_exit .endm + +.macro __ftrace_graph_regs_caller + + sub r0, fp, #4 @ &lr of instrumented routine (&parent) + + @ called from __ftrace_regs_caller + ldr r1, [sp, #56] @ instrumented routine (func) + mcount_adjust_addr r1, r1 + + mov r2, fp @ frame pointer + bl prepare_ftrace_return + + ldr lr, [fp, #-4] @ restore LR from the stack + ldmia sp, {r0-r11, ip, sp} @ pop the saved registers INCLUDING + @ the stack pointer + ret ip +.endm + #ifdef CONFIG_OLD_MCOUNT /* * mcount @@ -312,14 +365,27 @@ UNWIND(.fnstart) __ftrace_caller UNWIND(.fnend) ENDPROC(ftrace_caller) + +ENTRY(ftrace_regs_caller) +UNWIND(.fnstart) + __ftrace_regs_caller +UNWIND(.fnend) +ENDPROC(ftrace_regs_caller) #endif + #ifdef CONFIG_FUNCTION_GRAPH_TRACER ENTRY(ftrace_graph_caller) UNWIND(.fnstart) __ftrace_graph_caller UNWIND(.fnend) ENDPROC(ftrace_graph_caller) + +ENTRY(ftrace_graph_regs_caller) +UNWIND(.fnstart) + __ftrace_graph_regs_caller +UNWIND(.fnend) +ENDPROC(ftrace_graph_regs_caller) #endif .purgem mcount_enter diff --git a/arch/arm/kernel/ftrace.c b/arch/arm/kernel/ftrace.c index af9a8a9..35c5743 100644 --- a/arch/arm/kernel/ftrace.c +++ b/arch/arm/kernel/ftrace.c @@ -130,6 +130,16 @@ int ftrace_update_ftrace_func(ftrace_func_t func) } #endif + +#ifdef CONFIG_DYNAMIC_FTRACE_WITH_REGS + if (!ret) { + pc = (unsigned long)&ftrace_regs_call; + new = ftrace_call_replace(pc, (unsigned long)func); + + ret = ftrace_modify_code(pc, 0, new, false); + } +#endif + return ret; } @@ -139,6 +149,20 @@ int ftrace_make_call(struct dyn_ftrace *rec, unsigned long addr) unsigned long ip = rec->ip; old = ftrace_nop_replace(rec); + + new = ftrace_call_replace(ip, adjust_address(rec, addr)); + + return ftrace_modify_code(rec->ip, old, new, true); +} + +int ftrace_modify_call(struct dyn_ftrace *rec, unsigned long old_addr, + unsigned long addr) +{ + unsigned long new, old; + unsigned long ip = rec->ip; + + old = ftrace_call_replace(ip, adjust_address(rec, old_addr)); + new = ftrace_call_replace(ip, adjust_address(rec, addr)); return ftrace_modify_code(rec->ip, old, new, true); @@ -211,6 +235,9 @@ void prepare_ftrace_return(unsigned long *parent, unsigned long self_addr, extern unsigned long ftrace_graph_call; extern unsigned long ftrace_graph_call_old; extern void ftrace_graph_caller_old(void); +extern unsigned long ftrace_graph_regs_call; +extern void ftrace_graph_regs_caller(void); + static int __ftrace_modify_caller(unsigned long *callsite, void (*func) (void), bool enable) @@ -240,6 +267,13 @@ static int ftrace_modify_graph_caller(bool enable) enable); #endif +#ifdef CONFIG_DYNAMIC_FTRACE_WITH_REGS + if (!ret) + ret = __ftrace_modify_caller(&ftrace_graph_regs_call, + ftrace_graph_regs_caller, + enable); +#endif + return ret; } -- 2.1.3 ^ permalink raw reply related [flat|nested] 20+ messages in thread
* [PATCH 01/01] arm: ftrace: Adds support for ftrace operations @ 2014-11-07 14:59 ` Jean-Jacques Hiblot 0 siblings, 0 replies; 20+ messages in thread From: Jean-Jacques Hiblot @ 2014-11-07 14:59 UTC (permalink / raw) To: linux-arm-kernel Ftrace operations require that DYNAMIC_FTRACE_WITH_REGS is enabled. This patch introduces a new ftrace handler that store the registers on the stack before calling the next stage. The registers are also restored from the stack before going back to the instrumented function. Signed-off-by: Jean-Jacques Hiblot <jjhiblot@traphandler.com> --- arch/arm/Kconfig | 2 ++ arch/arm/include/asm/ftrace.h | 3 ++ arch/arm/kernel/entry-common.S | 68 +++++++++++++++++++++++++++++++++++++++++- arch/arm/kernel/ftrace.c | 34 +++++++++++++++++++++ 4 files changed, 106 insertions(+), 1 deletion(-) diff --git a/arch/arm/Kconfig b/arch/arm/Kconfig index 32cbbd5..6f928ee 100644 --- a/arch/arm/Kconfig +++ b/arch/arm/Kconfig @@ -39,6 +39,7 @@ config ARM select HAVE_DMA_ATTRS select HAVE_DMA_CONTIGUOUS if MMU select HAVE_DYNAMIC_FTRACE if (!XIP_KERNEL) + select HAVE_DYNAMIC_FTRACE_WITH_REGS if HAVE_DYNAMIC_FTRACE select HAVE_EFFICIENT_UNALIGNED_ACCESS if (CPU_V6 || CPU_V6K || CPU_V7) && MMU select HAVE_FTRACE_MCOUNT_RECORD if (!XIP_KERNEL) select HAVE_FUNCTION_GRAPH_TRACER if (!THUMB2_KERNEL) @@ -72,6 +73,7 @@ config ARM select PERF_USE_VMALLOC select RTC_LIB select SYS_SUPPORTS_APM_EMULATION + select FRAME_POINTER if DYNAMIC_FTRACE_WITH_REGS && FUNCTION_GRAPH_TRACER # Above selects are sorted alphabetically; please add new ones # according to that. Thanks. help diff --git a/arch/arm/include/asm/ftrace.h b/arch/arm/include/asm/ftrace.h index 39eb16b..d8e9bea 100644 --- a/arch/arm/include/asm/ftrace.h +++ b/arch/arm/include/asm/ftrace.h @@ -10,6 +10,9 @@ extern void mcount(void); extern void __gnu_mcount_nc(void); #ifdef CONFIG_DYNAMIC_FTRACE + +#define ARCH_SUPPORTS_FTRACE_OPS 1 + struct dyn_arch_ftrace { #ifdef CONFIG_OLD_MCOUNT bool old_mcount; diff --git a/arch/arm/kernel/entry-common.S b/arch/arm/kernel/entry-common.S index e52fe5a..9594fe2 100644 --- a/arch/arm/kernel/entry-common.S +++ b/arch/arm/kernel/entry-common.S @@ -197,7 +197,10 @@ ENDPROC(ret_from_fork) mcount_get_lr r1 @ lr of instrumented func mcount_adjust_addr r0, lr @ instrumented function - + ldr r2, =function_trace_op + ldr r2, [r2] @ pointer to the current + @ function tracing op + mov r3, #0 @ regs is NULL .globl ftrace_call\suffix ftrace_call\suffix: bl ftrace_stub @@ -211,6 +214,38 @@ ftrace_graph_call\suffix: mcount_exit .endm +.macro __ftrace_regs_caller + + add ip, sp, #4 @ move in IP the value of SP as it was + @ before the push {lr} of the mcount mechanism + stmdb sp!, {ip,lr,pc} + stmdb sp!, {r0-r11,lr} + @ stack content at this point: + @ 0 4 44 48 52 56 60 64 + @ RO | R1 | ... | R11 | LR | SP + 4 | LR | PC | previous LR | + + mov r3, sp @ struct pt_regs* + ldr r2, =function_trace_op + ldr r2, [r2] @ pointer to the current + @ function tracing op + ldr r1, [sp, #64] @ lr of instrumented func + mcount_adjust_addr r0, lr @ instrumented function + + .globl ftrace_regs_call +ftrace_regs_call: + bl ftrace_stub + +#ifdef CONFIG_FUNCTION_GRAPH_TRACER + .globl ftrace_graph_regs_call +ftrace_graph_regs_call: + mov r0, r0 +#endif + ldr lr, [sp, #64] @ get the previous LR value from stack + ldmia sp, {r0-r11, ip, sp} @ pop the saved registers INCLUDING + @ the stack pointer + ret ip +.endm + .macro __ftrace_graph_caller sub r0, fp, #4 @ &lr of instrumented routine (&parent) #ifdef CONFIG_DYNAMIC_FTRACE @@ -226,6 +261,24 @@ ftrace_graph_call\suffix: mcount_exit .endm + +.macro __ftrace_graph_regs_caller + + sub r0, fp, #4 @ &lr of instrumented routine (&parent) + + @ called from __ftrace_regs_caller + ldr r1, [sp, #56] @ instrumented routine (func) + mcount_adjust_addr r1, r1 + + mov r2, fp @ frame pointer + bl prepare_ftrace_return + + ldr lr, [fp, #-4] @ restore LR from the stack + ldmia sp, {r0-r11, ip, sp} @ pop the saved registers INCLUDING + @ the stack pointer + ret ip +.endm + #ifdef CONFIG_OLD_MCOUNT /* * mcount @@ -312,14 +365,27 @@ UNWIND(.fnstart) __ftrace_caller UNWIND(.fnend) ENDPROC(ftrace_caller) + +ENTRY(ftrace_regs_caller) +UNWIND(.fnstart) + __ftrace_regs_caller +UNWIND(.fnend) +ENDPROC(ftrace_regs_caller) #endif + #ifdef CONFIG_FUNCTION_GRAPH_TRACER ENTRY(ftrace_graph_caller) UNWIND(.fnstart) __ftrace_graph_caller UNWIND(.fnend) ENDPROC(ftrace_graph_caller) + +ENTRY(ftrace_graph_regs_caller) +UNWIND(.fnstart) + __ftrace_graph_regs_caller +UNWIND(.fnend) +ENDPROC(ftrace_graph_regs_caller) #endif .purgem mcount_enter diff --git a/arch/arm/kernel/ftrace.c b/arch/arm/kernel/ftrace.c index af9a8a9..35c5743 100644 --- a/arch/arm/kernel/ftrace.c +++ b/arch/arm/kernel/ftrace.c @@ -130,6 +130,16 @@ int ftrace_update_ftrace_func(ftrace_func_t func) } #endif + +#ifdef CONFIG_DYNAMIC_FTRACE_WITH_REGS + if (!ret) { + pc = (unsigned long)&ftrace_regs_call; + new = ftrace_call_replace(pc, (unsigned long)func); + + ret = ftrace_modify_code(pc, 0, new, false); + } +#endif + return ret; } @@ -139,6 +149,20 @@ int ftrace_make_call(struct dyn_ftrace *rec, unsigned long addr) unsigned long ip = rec->ip; old = ftrace_nop_replace(rec); + + new = ftrace_call_replace(ip, adjust_address(rec, addr)); + + return ftrace_modify_code(rec->ip, old, new, true); +} + +int ftrace_modify_call(struct dyn_ftrace *rec, unsigned long old_addr, + unsigned long addr) +{ + unsigned long new, old; + unsigned long ip = rec->ip; + + old = ftrace_call_replace(ip, adjust_address(rec, old_addr)); + new = ftrace_call_replace(ip, adjust_address(rec, addr)); return ftrace_modify_code(rec->ip, old, new, true); @@ -211,6 +235,9 @@ void prepare_ftrace_return(unsigned long *parent, unsigned long self_addr, extern unsigned long ftrace_graph_call; extern unsigned long ftrace_graph_call_old; extern void ftrace_graph_caller_old(void); +extern unsigned long ftrace_graph_regs_call; +extern void ftrace_graph_regs_caller(void); + static int __ftrace_modify_caller(unsigned long *callsite, void (*func) (void), bool enable) @@ -240,6 +267,13 @@ static int ftrace_modify_graph_caller(bool enable) enable); #endif +#ifdef CONFIG_DYNAMIC_FTRACE_WITH_REGS + if (!ret) + ret = __ftrace_modify_caller(&ftrace_graph_regs_call, + ftrace_graph_regs_caller, + enable); +#endif + return ret; } -- 2.1.3 ^ permalink raw reply related [flat|nested] 20+ messages in thread
* Re: [PATCH] arm: ftrace: Adds support for ftrace operations 2014-11-07 14:59 ` Jean-Jacques Hiblot @ 2014-11-07 16:52 ` Steven Rostedt -1 siblings, 0 replies; 20+ messages in thread From: Steven Rostedt @ 2014-11-07 16:52 UTC (permalink / raw) To: Jean-Jacques Hiblot Cc: jslaby, linux, mingo, nsekhar, stefano.stabellini, christoffer.dall, linux-arm-kernel, linux-kernel On Fri, 7 Nov 2014 15:59:11 +0100 Jean-Jacques Hiblot <jjhiblot@traphandler.com> wrote: > Hi all, > > This patch adds support for ftrace operations on the ARM architecture. > This support is needed by kgraft and possibly other ftrace-based tools. > My goal is to have kgraft working on ARM and aarch64. Can you add this to the change log of the patch. As that would be what goes into git history. Because honestly, I had no idea what you meant by "ftrace operations". If I don't understand that term, how can you expect anyone else to? > > I tested this patch with a toy implementation of kgraft for ARM and basic > usage of function and function_graph tracers > It doesn't show any problem with the ftrace selftests and the tests found > today in branch ftrace/testing-mystuff of linux-trace repository > (git://git.kernel.org/pub/scm/linux/kernel/git/rostedt/linux-trace.git) Those tests are no where near what I have. Does this code work on the beagle bone white? If so, I can probably run my full suite on it. -- Steve > > Jean-Jacques Hiblot (1): > arm: ftrace: Adds support for ftrace operations > > arch/arm/Kconfig | 2 ++ > arch/arm/include/asm/ftrace.h | 3 ++ > arch/arm/kernel/entry-common.S | 68 +++++++++++++++++++++++++++++++++++++++++- > arch/arm/kernel/ftrace.c | 34 +++++++++++++++++++++ > 4 files changed, 106 insertions(+), 1 deletion(-) > ^ permalink raw reply [flat|nested] 20+ messages in thread
* [PATCH] arm: ftrace: Adds support for ftrace operations @ 2014-11-07 16:52 ` Steven Rostedt 0 siblings, 0 replies; 20+ messages in thread From: Steven Rostedt @ 2014-11-07 16:52 UTC (permalink / raw) To: linux-arm-kernel On Fri, 7 Nov 2014 15:59:11 +0100 Jean-Jacques Hiblot <jjhiblot@traphandler.com> wrote: > Hi all, > > This patch adds support for ftrace operations on the ARM architecture. > This support is needed by kgraft and possibly other ftrace-based tools. > My goal is to have kgraft working on ARM and aarch64. Can you add this to the change log of the patch. As that would be what goes into git history. Because honestly, I had no idea what you meant by "ftrace operations". If I don't understand that term, how can you expect anyone else to? > > I tested this patch with a toy implementation of kgraft for ARM and basic > usage of function and function_graph tracers > It doesn't show any problem with the ftrace selftests and the tests found > today in branch ftrace/testing-mystuff of linux-trace repository > (git://git.kernel.org/pub/scm/linux/kernel/git/rostedt/linux-trace.git) Those tests are no where near what I have. Does this code work on the beagle bone white? If so, I can probably run my full suite on it. -- Steve > > Jean-Jacques Hiblot (1): > arm: ftrace: Adds support for ftrace operations > > arch/arm/Kconfig | 2 ++ > arch/arm/include/asm/ftrace.h | 3 ++ > arch/arm/kernel/entry-common.S | 68 +++++++++++++++++++++++++++++++++++++++++- > arch/arm/kernel/ftrace.c | 34 +++++++++++++++++++++ > 4 files changed, 106 insertions(+), 1 deletion(-) > ^ permalink raw reply [flat|nested] 20+ messages in thread
* Re: [PATCH] arm: ftrace: Adds support for ftrace operations 2014-11-07 16:52 ` Steven Rostedt @ 2014-11-07 17:01 ` Jean-Jacques Hiblot -1 siblings, 0 replies; 20+ messages in thread From: Jean-Jacques Hiblot @ 2014-11-07 17:01 UTC (permalink / raw) To: Steven Rostedt Cc: linux, stefano.stabellini, nsekhar, linux-kernel, mingo, linux-arm-kernel, jslaby, christoffer.dall On 11/07/2014 05:52 PM, Steven Rostedt wrote: > On Fri, 7 Nov 2014 15:59:11 +0100 > Jean-Jacques Hiblot <jjhiblot@traphandler.com> wrote: > >> Hi all, >> >> This patch adds support for ftrace operations on the ARM architecture. >> This support is needed by kgraft and possibly other ftrace-based tools. >> My goal is to have kgraft working on ARM and aarch64. > > Can you add this to the change log of the patch. As that would be what > goes into git history. Because honestly, I had no idea what you meant > by "ftrace operations". If I don't understand that term, how can you > expect anyone else to? I'll try to come up with a clearer commit log. > >> >> I tested this patch with a toy implementation of kgraft for ARM and basic >> usage of function and function_graph tracers >> It doesn't show any problem with the ftrace selftests and the tests found >> today in branch ftrace/testing-mystuff of linux-trace repository >> (git://git.kernel.org/pub/scm/linux/kernel/git/rostedt/linux-trace.git) > > Those tests are no where near what I have. Does this code work on the > beagle bone white? If so, I can probably run my full suite on it. It should work on any arm processor, It's not platform or SOC dependent > > -- Steve > >> >> Jean-Jacques Hiblot (1): >> arm: ftrace: Adds support for ftrace operations >> >> arch/arm/Kconfig | 2 ++ >> arch/arm/include/asm/ftrace.h | 3 ++ >> arch/arm/kernel/entry-common.S | 68 +++++++++++++++++++++++++++++++++++++++++- >> arch/arm/kernel/ftrace.c | 34 +++++++++++++++++++++ >> 4 files changed, 106 insertions(+), 1 deletion(-) >> > > > _______________________________________________ > 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] 20+ messages in thread
* [PATCH] arm: ftrace: Adds support for ftrace operations @ 2014-11-07 17:01 ` Jean-Jacques Hiblot 0 siblings, 0 replies; 20+ messages in thread From: Jean-Jacques Hiblot @ 2014-11-07 17:01 UTC (permalink / raw) To: linux-arm-kernel On 11/07/2014 05:52 PM, Steven Rostedt wrote: > On Fri, 7 Nov 2014 15:59:11 +0100 > Jean-Jacques Hiblot <jjhiblot@traphandler.com> wrote: > >> Hi all, >> >> This patch adds support for ftrace operations on the ARM architecture. >> This support is needed by kgraft and possibly other ftrace-based tools. >> My goal is to have kgraft working on ARM and aarch64. > > Can you add this to the change log of the patch. As that would be what > goes into git history. Because honestly, I had no idea what you meant > by "ftrace operations". If I don't understand that term, how can you > expect anyone else to? I'll try to come up with a clearer commit log. > >> >> I tested this patch with a toy implementation of kgraft for ARM and basic >> usage of function and function_graph tracers >> It doesn't show any problem with the ftrace selftests and the tests found >> today in branch ftrace/testing-mystuff of linux-trace repository >> (git://git.kernel.org/pub/scm/linux/kernel/git/rostedt/linux-trace.git) > > Those tests are no where near what I have. Does this code work on the > beagle bone white? If so, I can probably run my full suite on it. It should work on any arm processor, It's not platform or SOC dependent > > -- Steve > >> >> Jean-Jacques Hiblot (1): >> arm: ftrace: Adds support for ftrace operations >> >> arch/arm/Kconfig | 2 ++ >> arch/arm/include/asm/ftrace.h | 3 ++ >> arch/arm/kernel/entry-common.S | 68 +++++++++++++++++++++++++++++++++++++++++- >> arch/arm/kernel/ftrace.c | 34 +++++++++++++++++++++ >> 4 files changed, 106 insertions(+), 1 deletion(-) >> > > > _______________________________________________ > linux-arm-kernel mailing list > linux-arm-kernel at lists.infradead.org > http://lists.infradead.org/mailman/listinfo/linux-arm-kernel > ^ permalink raw reply [flat|nested] 20+ messages in thread
* Re: [PATCH] arm: ftrace: Adds support for ftrace operations 2014-11-07 17:01 ` Jean-Jacques Hiblot @ 2014-11-24 9:59 ` Jean-Jacques Hiblot -1 siblings, 0 replies; 20+ messages in thread From: Jean-Jacques Hiblot @ 2014-11-24 9:59 UTC (permalink / raw) To: Steven Rostedt, jslaby Cc: Russell King - ARM Linux, Stefano Stabellini, nsekhar, Linux Kernel Mailing List, mingo, linux-arm-kernel, Christoffer Dall 2014-11-07 18:01 GMT+01:00 Jean-Jacques Hiblot <jjhiblot@traphandler.com>: > > > On 11/07/2014 05:52 PM, Steven Rostedt wrote: >> On Fri, 7 Nov 2014 15:59:11 +0100 >> Jean-Jacques Hiblot <jjhiblot@traphandler.com> wrote: >> >>> Hi all, >>> >>> This patch adds support for ftrace operations on the ARM architecture. >>> This support is needed by kgraft and possibly other ftrace-based tools. >>> My goal is to have kgraft working on ARM and aarch64. >> >> Can you add this to the change log of the patch. As that would be what >> goes into git history. Because honestly, I had no idea what you meant >> by "ftrace operations". If I don't understand that term, how can you >> expect anyone else to? > I'll try to come up with a clearer commit log. >> >>> >>> I tested this patch with a toy implementation of kgraft for ARM and basic >>> usage of function and function_graph tracers >>> It doesn't show any problem with the ftrace selftests and the tests found >>> today in branch ftrace/testing-mystuff of linux-trace repository >>> (git://git.kernel.org/pub/scm/linux/kernel/git/rostedt/linux-trace.git) >> >> Those tests are no where near what I have. Does this code work on the >> beagle bone white? If so, I can probably run my full suite on it. > It should work on any arm processor, It's not platform or SOC dependent >> Hi Steve, did you get a chance of running your tests suite on real hardware with this patch? I'd be really interested in the results. Jiri, would you be interested in the patchs to run kgraft on ARM ? The modifications required in kgraft core are minimal, it's mostly architecture specific. Jean-Jacques >> -- Steve >> >>> >>> Jean-Jacques Hiblot (1): >>> arm: ftrace: Adds support for ftrace operations >>> >>> arch/arm/Kconfig | 2 ++ >>> arch/arm/include/asm/ftrace.h | 3 ++ >>> arch/arm/kernel/entry-common.S | 68 +++++++++++++++++++++++++++++++++++++++++- >>> arch/arm/kernel/ftrace.c | 34 +++++++++++++++++++++ >>> 4 files changed, 106 insertions(+), 1 deletion(-) >>> >> >> >> _______________________________________________ >> 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] 20+ messages in thread
* [PATCH] arm: ftrace: Adds support for ftrace operations @ 2014-11-24 9:59 ` Jean-Jacques Hiblot 0 siblings, 0 replies; 20+ messages in thread From: Jean-Jacques Hiblot @ 2014-11-24 9:59 UTC (permalink / raw) To: linux-arm-kernel 2014-11-07 18:01 GMT+01:00 Jean-Jacques Hiblot <jjhiblot@traphandler.com>: > > > On 11/07/2014 05:52 PM, Steven Rostedt wrote: >> On Fri, 7 Nov 2014 15:59:11 +0100 >> Jean-Jacques Hiblot <jjhiblot@traphandler.com> wrote: >> >>> Hi all, >>> >>> This patch adds support for ftrace operations on the ARM architecture. >>> This support is needed by kgraft and possibly other ftrace-based tools. >>> My goal is to have kgraft working on ARM and aarch64. >> >> Can you add this to the change log of the patch. As that would be what >> goes into git history. Because honestly, I had no idea what you meant >> by "ftrace operations". If I don't understand that term, how can you >> expect anyone else to? > I'll try to come up with a clearer commit log. >> >>> >>> I tested this patch with a toy implementation of kgraft for ARM and basic >>> usage of function and function_graph tracers >>> It doesn't show any problem with the ftrace selftests and the tests found >>> today in branch ftrace/testing-mystuff of linux-trace repository >>> (git://git.kernel.org/pub/scm/linux/kernel/git/rostedt/linux-trace.git) >> >> Those tests are no where near what I have. Does this code work on the >> beagle bone white? If so, I can probably run my full suite on it. > It should work on any arm processor, It's not platform or SOC dependent >> Hi Steve, did you get a chance of running your tests suite on real hardware with this patch? I'd be really interested in the results. Jiri, would you be interested in the patchs to run kgraft on ARM ? The modifications required in kgraft core are minimal, it's mostly architecture specific. Jean-Jacques >> -- Steve >> >>> >>> Jean-Jacques Hiblot (1): >>> arm: ftrace: Adds support for ftrace operations >>> >>> arch/arm/Kconfig | 2 ++ >>> arch/arm/include/asm/ftrace.h | 3 ++ >>> arch/arm/kernel/entry-common.S | 68 +++++++++++++++++++++++++++++++++++++++++- >>> arch/arm/kernel/ftrace.c | 34 +++++++++++++++++++++ >>> 4 files changed, 106 insertions(+), 1 deletion(-) >>> >> >> >> _______________________________________________ >> linux-arm-kernel mailing list >> linux-arm-kernel at lists.infradead.org >> http://lists.infradead.org/mailman/listinfo/linux-arm-kernel >> ^ permalink raw reply [flat|nested] 20+ messages in thread
* Re: [PATCH] arm: ftrace: Adds support for ftrace operations 2014-11-24 9:59 ` Jean-Jacques Hiblot @ 2014-11-25 23:20 ` Steven Rostedt -1 siblings, 0 replies; 20+ messages in thread From: Steven Rostedt @ 2014-11-25 23:20 UTC (permalink / raw) To: Jean-Jacques Hiblot Cc: jslaby, Russell King - ARM Linux, Stefano Stabellini, nsekhar, Linux Kernel Mailing List, mingo, linux-arm-kernel, Christoffer Dall On Mon, 24 Nov 2014 10:59:24 +0100 Jean-Jacques Hiblot <jjhiblot@traphandler.com> wrote: > Hi Steve, > did you get a chance of running your tests suite on real hardware with > this patch? I'd be really interested in the results. Yes I finally got it working on my beaglebone white. It passed all the tests that passed without it. Although I'm not sure this patch itself was tested as I didn't have kprobes which might use it. -- Steve ^ permalink raw reply [flat|nested] 20+ messages in thread
* [PATCH] arm: ftrace: Adds support for ftrace operations @ 2014-11-25 23:20 ` Steven Rostedt 0 siblings, 0 replies; 20+ messages in thread From: Steven Rostedt @ 2014-11-25 23:20 UTC (permalink / raw) To: linux-arm-kernel On Mon, 24 Nov 2014 10:59:24 +0100 Jean-Jacques Hiblot <jjhiblot@traphandler.com> wrote: > Hi Steve, > did you get a chance of running your tests suite on real hardware with > this patch? I'd be really interested in the results. Yes I finally got it working on my beaglebone white. It passed all the tests that passed without it. Although I'm not sure this patch itself was tested as I didn't have kprobes which might use it. -- Steve ^ permalink raw reply [flat|nested] 20+ messages in thread
* Re: [PATCH] arm: ftrace: Adds support for ftrace operations 2014-11-25 23:20 ` Steven Rostedt @ 2014-11-27 10:23 ` Jean-Jacques Hiblot -1 siblings, 0 replies; 20+ messages in thread From: Jean-Jacques Hiblot @ 2014-11-27 10:23 UTC (permalink / raw) To: Steven Rostedt Cc: Jean-Jacques Hiblot, Russell King - ARM Linux, Stefano Stabellini, nsekhar, Linux Kernel Mailing List, mingo, Christoffer Dall, jslaby, linux-arm-kernel 2014-11-26 0:20 GMT+01:00 Steven Rostedt <rostedt@goodmis.org>: > On Mon, 24 Nov 2014 10:59:24 +0100 > Jean-Jacques Hiblot <jjhiblot@traphandler.com> wrote: > >> Hi Steve, >> did you get a chance of running your tests suite on real hardware with >> this patch? I'd be really interested in the results. > > Yes I finally got it working on my beaglebone white. It passed all the > tests that passed without it. Although I'm not sure this patch itself > was tested as I didn't have kprobes which might use it. > Thanks for testing it. At least it doesn't cause regression. What do you mean by not having krpobes which might use it ? Are you thinking of the kprobe optimization based on ftrace ? JJ > -- Steve > > _______________________________________________ > 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] 20+ messages in thread
* [PATCH] arm: ftrace: Adds support for ftrace operations @ 2014-11-27 10:23 ` Jean-Jacques Hiblot 0 siblings, 0 replies; 20+ messages in thread From: Jean-Jacques Hiblot @ 2014-11-27 10:23 UTC (permalink / raw) To: linux-arm-kernel 2014-11-26 0:20 GMT+01:00 Steven Rostedt <rostedt@goodmis.org>: > On Mon, 24 Nov 2014 10:59:24 +0100 > Jean-Jacques Hiblot <jjhiblot@traphandler.com> wrote: > >> Hi Steve, >> did you get a chance of running your tests suite on real hardware with >> this patch? I'd be really interested in the results. > > Yes I finally got it working on my beaglebone white. It passed all the > tests that passed without it. Although I'm not sure this patch itself > was tested as I didn't have kprobes which might use it. > Thanks for testing it. At least it doesn't cause regression. What do you mean by not having krpobes which might use it ? Are you thinking of the kprobe optimization based on ftrace ? JJ > -- Steve > > _______________________________________________ > linux-arm-kernel mailing list > linux-arm-kernel at lists.infradead.org > http://lists.infradead.org/mailman/listinfo/linux-arm-kernel ^ permalink raw reply [flat|nested] 20+ messages in thread
* Re: [PATCH] arm: ftrace: Adds support for ftrace operations 2014-11-27 10:23 ` Jean-Jacques Hiblot @ 2014-11-27 14:58 ` Steven Rostedt -1 siblings, 0 replies; 20+ messages in thread From: Steven Rostedt @ 2014-11-27 14:58 UTC (permalink / raw) To: Jean-Jacques Hiblot Cc: Russell King - ARM Linux, Stefano Stabellini, nsekhar, Linux Kernel Mailing List, mingo, Christoffer Dall, jslaby, linux-arm-kernel On Thu, 27 Nov 2014 11:23:45 +0100 Jean-Jacques Hiblot <jjhiblot@traphandler.com> wrote: > 2014-11-26 0:20 GMT+01:00 Steven Rostedt <rostedt@goodmis.org>: > > On Mon, 24 Nov 2014 10:59:24 +0100 > > Jean-Jacques Hiblot <jjhiblot@traphandler.com> wrote: > > > >> Hi Steve, > >> did you get a chance of running your tests suite on real hardware with > >> this patch? I'd be really interested in the results. > > > > Yes I finally got it working on my beaglebone white. It passed all the > > tests that passed without it. Although I'm not sure this patch itself > > was tested as I didn't have kprobes which might use it. > > > Thanks for testing it. At least it doesn't cause regression. > What do you mean by not having krpobes which might use it ? Are you > thinking of the kprobe optimization based on ftrace ? > Yep. My tests use that. But as ARM doesn't have an mfentry where functions probed by kprobes at the start are optimized with ftrace, my tests wont test it. I also didn't have kprobes enabled on this board. Is it fully supported in ARM, and does kprobes use it there too? -- Steve ^ permalink raw reply [flat|nested] 20+ messages in thread
* [PATCH] arm: ftrace: Adds support for ftrace operations @ 2014-11-27 14:58 ` Steven Rostedt 0 siblings, 0 replies; 20+ messages in thread From: Steven Rostedt @ 2014-11-27 14:58 UTC (permalink / raw) To: linux-arm-kernel On Thu, 27 Nov 2014 11:23:45 +0100 Jean-Jacques Hiblot <jjhiblot@traphandler.com> wrote: > 2014-11-26 0:20 GMT+01:00 Steven Rostedt <rostedt@goodmis.org>: > > On Mon, 24 Nov 2014 10:59:24 +0100 > > Jean-Jacques Hiblot <jjhiblot@traphandler.com> wrote: > > > >> Hi Steve, > >> did you get a chance of running your tests suite on real hardware with > >> this patch? I'd be really interested in the results. > > > > Yes I finally got it working on my beaglebone white. It passed all the > > tests that passed without it. Although I'm not sure this patch itself > > was tested as I didn't have kprobes which might use it. > > > Thanks for testing it. At least it doesn't cause regression. > What do you mean by not having krpobes which might use it ? Are you > thinking of the kprobe optimization based on ftrace ? > Yep. My tests use that. But as ARM doesn't have an mfentry where functions probed by kprobes at the start are optimized with ftrace, my tests wont test it. I also didn't have kprobes enabled on this board. Is it fully supported in ARM, and does kprobes use it there too? -- Steve ^ permalink raw reply [flat|nested] 20+ messages in thread
* [PATCH v2 00/01] arm: ftrace: Adds support for CONFIG_DYNAMIC_FTRACE_WITH_REGS 2014-11-07 16:52 ` Steven Rostedt @ 2014-11-10 8:56 ` Jean-Jacques Hiblot -1 siblings, 0 replies; 20+ messages in thread From: Jean-Jacques Hiblot @ 2014-11-10 8:56 UTC (permalink / raw) To: jslaby, linux, rostedt, mingo, nsekhar, stefano.stabellini, christoffer.dall Cc: linux-arm-kernel, linux-kernel, Jean-Jacques Hiblot This patch adds support for ftrace operations on the ARM architecture. This support is needed by kgraft and possibly other ftrace-based tools. My goal is to have kgraft working on ARM and aarch64. I tested this patch with a toy implementation of kgraft for ARM and basic usage of function and function_graph tracers It doesn't show any problem with the ftrace selftests and the tests found today in branch ftrace/testing-mystuff of linux-trace repository (git://git.kernel.org/pub/scm/linux/kernel/git/rostedt/linux-trace.git) change since v1: - changed the title and the commit log of the patch to make it more understandable Jean-Jacques Hiblot (1): arm: ftrace: Adds support for CONFIG_DYNAMIC_FTRACE_WITH_REGS arch/arm/Kconfig | 2 ++ arch/arm/include/asm/ftrace.h | 3 ++ arch/arm/kernel/entry-common.S | 68 +++++++++++++++++++++++++++++++++++++++++- arch/arm/kernel/ftrace.c | 34 +++++++++++++++++++++ 4 files changed, 106 insertions(+), 1 deletion(-) -- 2.1.3 ^ permalink raw reply [flat|nested] 20+ messages in thread
* [PATCH v2 00/01] arm: ftrace: Adds support for CONFIG_DYNAMIC_FTRACE_WITH_REGS @ 2014-11-10 8:56 ` Jean-Jacques Hiblot 0 siblings, 0 replies; 20+ messages in thread From: Jean-Jacques Hiblot @ 2014-11-10 8:56 UTC (permalink / raw) To: linux-arm-kernel This patch adds support for ftrace operations on the ARM architecture. This support is needed by kgraft and possibly other ftrace-based tools. My goal is to have kgraft working on ARM and aarch64. I tested this patch with a toy implementation of kgraft for ARM and basic usage of function and function_graph tracers It doesn't show any problem with the ftrace selftests and the tests found today in branch ftrace/testing-mystuff of linux-trace repository (git://git.kernel.org/pub/scm/linux/kernel/git/rostedt/linux-trace.git) change since v1: - changed the title and the commit log of the patch to make it more understandable Jean-Jacques Hiblot (1): arm: ftrace: Adds support for CONFIG_DYNAMIC_FTRACE_WITH_REGS arch/arm/Kconfig | 2 ++ arch/arm/include/asm/ftrace.h | 3 ++ arch/arm/kernel/entry-common.S | 68 +++++++++++++++++++++++++++++++++++++++++- arch/arm/kernel/ftrace.c | 34 +++++++++++++++++++++ 4 files changed, 106 insertions(+), 1 deletion(-) -- 2.1.3 ^ permalink raw reply [flat|nested] 20+ messages in thread
* [PATCH v2 01/01] arm: ftrace: Adds support for CONFIG_DYNAMIC_FTRACE_WITH_REGS 2014-11-10 8:56 ` Jean-Jacques Hiblot @ 2014-11-10 8:56 ` Jean-Jacques Hiblot -1 siblings, 0 replies; 20+ messages in thread From: Jean-Jacques Hiblot @ 2014-11-10 8:56 UTC (permalink / raw) To: jslaby, linux, rostedt, mingo, nsekhar, stefano.stabellini, christoffer.dall Cc: linux-arm-kernel, linux-kernel, Jean-Jacques Hiblot The DYNAMIC_FTRACE_WITH_REGS configuration makes it possible for a ftrace operation to specify if registers need to saved/restored by the ftrace handler. This is needed by kgraft and possibly other ftrace-based tools, and the ARM architecture is currently lacking this feature. It would also be the first step to support the "Kprobes-on-ftrace" optimization on ARM. This patch introduces a new ftrace handler that stores the registers on the stack before calling the next stage. The registers are restored from the stack before going back to the instrumented function. A side-effect of this patch is to activate the support for ftrace_modify_call() as it defines ARCH_SUPPORTS_FTRACE_OPS for the ARM architecture Signed-off-by: Jean-Jacques Hiblot <jjhiblot@traphandler.com> --- arch/arm/Kconfig | 2 ++ arch/arm/include/asm/ftrace.h | 3 ++ arch/arm/kernel/entry-common.S | 68 +++++++++++++++++++++++++++++++++++++++++- arch/arm/kernel/ftrace.c | 34 +++++++++++++++++++++ 4 files changed, 106 insertions(+), 1 deletion(-) diff --git a/arch/arm/Kconfig b/arch/arm/Kconfig index 32cbbd5..6f928ee 100644 --- a/arch/arm/Kconfig +++ b/arch/arm/Kconfig @@ -39,6 +39,7 @@ config ARM select HAVE_DMA_ATTRS select HAVE_DMA_CONTIGUOUS if MMU select HAVE_DYNAMIC_FTRACE if (!XIP_KERNEL) + select HAVE_DYNAMIC_FTRACE_WITH_REGS if HAVE_DYNAMIC_FTRACE select HAVE_EFFICIENT_UNALIGNED_ACCESS if (CPU_V6 || CPU_V6K || CPU_V7) && MMU select HAVE_FTRACE_MCOUNT_RECORD if (!XIP_KERNEL) select HAVE_FUNCTION_GRAPH_TRACER if (!THUMB2_KERNEL) @@ -72,6 +73,7 @@ config ARM select PERF_USE_VMALLOC select RTC_LIB select SYS_SUPPORTS_APM_EMULATION + select FRAME_POINTER if DYNAMIC_FTRACE_WITH_REGS && FUNCTION_GRAPH_TRACER # Above selects are sorted alphabetically; please add new ones # according to that. Thanks. help diff --git a/arch/arm/include/asm/ftrace.h b/arch/arm/include/asm/ftrace.h index 39eb16b..d8e9bea 100644 --- a/arch/arm/include/asm/ftrace.h +++ b/arch/arm/include/asm/ftrace.h @@ -10,6 +10,9 @@ extern void mcount(void); extern void __gnu_mcount_nc(void); #ifdef CONFIG_DYNAMIC_FTRACE + +#define ARCH_SUPPORTS_FTRACE_OPS 1 + struct dyn_arch_ftrace { #ifdef CONFIG_OLD_MCOUNT bool old_mcount; diff --git a/arch/arm/kernel/entry-common.S b/arch/arm/kernel/entry-common.S index e52fe5a..9594fe2 100644 --- a/arch/arm/kernel/entry-common.S +++ b/arch/arm/kernel/entry-common.S @@ -197,7 +197,10 @@ ENDPROC(ret_from_fork) mcount_get_lr r1 @ lr of instrumented func mcount_adjust_addr r0, lr @ instrumented function - + ldr r2, =function_trace_op + ldr r2, [r2] @ pointer to the current + @ function tracing op + mov r3, #0 @ regs is NULL .globl ftrace_call\suffix ftrace_call\suffix: bl ftrace_stub @@ -211,6 +214,38 @@ ftrace_graph_call\suffix: mcount_exit .endm +.macro __ftrace_regs_caller + + add ip, sp, #4 @ move in IP the value of SP as it was + @ before the push {lr} of the mcount mechanism + stmdb sp!, {ip,lr,pc} + stmdb sp!, {r0-r11,lr} + @ stack content at this point: + @ 0 4 44 48 52 56 60 64 + @ RO | R1 | ... | R11 | LR | SP + 4 | LR | PC | previous LR | + + mov r3, sp @ struct pt_regs* + ldr r2, =function_trace_op + ldr r2, [r2] @ pointer to the current + @ function tracing op + ldr r1, [sp, #64] @ lr of instrumented func + mcount_adjust_addr r0, lr @ instrumented function + + .globl ftrace_regs_call +ftrace_regs_call: + bl ftrace_stub + +#ifdef CONFIG_FUNCTION_GRAPH_TRACER + .globl ftrace_graph_regs_call +ftrace_graph_regs_call: + mov r0, r0 +#endif + ldr lr, [sp, #64] @ get the previous LR value from stack + ldmia sp, {r0-r11, ip, sp} @ pop the saved registers INCLUDING + @ the stack pointer + ret ip +.endm + .macro __ftrace_graph_caller sub r0, fp, #4 @ &lr of instrumented routine (&parent) #ifdef CONFIG_DYNAMIC_FTRACE @@ -226,6 +261,24 @@ ftrace_graph_call\suffix: mcount_exit .endm + +.macro __ftrace_graph_regs_caller + + sub r0, fp, #4 @ &lr of instrumented routine (&parent) + + @ called from __ftrace_regs_caller + ldr r1, [sp, #56] @ instrumented routine (func) + mcount_adjust_addr r1, r1 + + mov r2, fp @ frame pointer + bl prepare_ftrace_return + + ldr lr, [fp, #-4] @ restore LR from the stack + ldmia sp, {r0-r11, ip, sp} @ pop the saved registers INCLUDING + @ the stack pointer + ret ip +.endm + #ifdef CONFIG_OLD_MCOUNT /* * mcount @@ -312,14 +365,27 @@ UNWIND(.fnstart) __ftrace_caller UNWIND(.fnend) ENDPROC(ftrace_caller) + +ENTRY(ftrace_regs_caller) +UNWIND(.fnstart) + __ftrace_regs_caller +UNWIND(.fnend) +ENDPROC(ftrace_regs_caller) #endif + #ifdef CONFIG_FUNCTION_GRAPH_TRACER ENTRY(ftrace_graph_caller) UNWIND(.fnstart) __ftrace_graph_caller UNWIND(.fnend) ENDPROC(ftrace_graph_caller) + +ENTRY(ftrace_graph_regs_caller) +UNWIND(.fnstart) + __ftrace_graph_regs_caller +UNWIND(.fnend) +ENDPROC(ftrace_graph_regs_caller) #endif .purgem mcount_enter diff --git a/arch/arm/kernel/ftrace.c b/arch/arm/kernel/ftrace.c index af9a8a9..35c5743 100644 --- a/arch/arm/kernel/ftrace.c +++ b/arch/arm/kernel/ftrace.c @@ -130,6 +130,16 @@ int ftrace_update_ftrace_func(ftrace_func_t func) } #endif + +#ifdef CONFIG_DYNAMIC_FTRACE_WITH_REGS + if (!ret) { + pc = (unsigned long)&ftrace_regs_call; + new = ftrace_call_replace(pc, (unsigned long)func); + + ret = ftrace_modify_code(pc, 0, new, false); + } +#endif + return ret; } @@ -139,6 +149,20 @@ int ftrace_make_call(struct dyn_ftrace *rec, unsigned long addr) unsigned long ip = rec->ip; old = ftrace_nop_replace(rec); + + new = ftrace_call_replace(ip, adjust_address(rec, addr)); + + return ftrace_modify_code(rec->ip, old, new, true); +} + +int ftrace_modify_call(struct dyn_ftrace *rec, unsigned long old_addr, + unsigned long addr) +{ + unsigned long new, old; + unsigned long ip = rec->ip; + + old = ftrace_call_replace(ip, adjust_address(rec, old_addr)); + new = ftrace_call_replace(ip, adjust_address(rec, addr)); return ftrace_modify_code(rec->ip, old, new, true); @@ -211,6 +235,9 @@ void prepare_ftrace_return(unsigned long *parent, unsigned long self_addr, extern unsigned long ftrace_graph_call; extern unsigned long ftrace_graph_call_old; extern void ftrace_graph_caller_old(void); +extern unsigned long ftrace_graph_regs_call; +extern void ftrace_graph_regs_caller(void); + static int __ftrace_modify_caller(unsigned long *callsite, void (*func) (void), bool enable) @@ -240,6 +267,13 @@ static int ftrace_modify_graph_caller(bool enable) enable); #endif +#ifdef CONFIG_DYNAMIC_FTRACE_WITH_REGS + if (!ret) + ret = __ftrace_modify_caller(&ftrace_graph_regs_call, + ftrace_graph_regs_caller, + enable); +#endif + return ret; } -- 2.1.3 ^ permalink raw reply related [flat|nested] 20+ messages in thread
* [PATCH v2 01/01] arm: ftrace: Adds support for CONFIG_DYNAMIC_FTRACE_WITH_REGS @ 2014-11-10 8:56 ` Jean-Jacques Hiblot 0 siblings, 0 replies; 20+ messages in thread From: Jean-Jacques Hiblot @ 2014-11-10 8:56 UTC (permalink / raw) To: linux-arm-kernel The DYNAMIC_FTRACE_WITH_REGS configuration makes it possible for a ftrace operation to specify if registers need to saved/restored by the ftrace handler. This is needed by kgraft and possibly other ftrace-based tools, and the ARM architecture is currently lacking this feature. It would also be the first step to support the "Kprobes-on-ftrace" optimization on ARM. This patch introduces a new ftrace handler that stores the registers on the stack before calling the next stage. The registers are restored from the stack before going back to the instrumented function. A side-effect of this patch is to activate the support for ftrace_modify_call() as it defines ARCH_SUPPORTS_FTRACE_OPS for the ARM architecture Signed-off-by: Jean-Jacques Hiblot <jjhiblot@traphandler.com> --- arch/arm/Kconfig | 2 ++ arch/arm/include/asm/ftrace.h | 3 ++ arch/arm/kernel/entry-common.S | 68 +++++++++++++++++++++++++++++++++++++++++- arch/arm/kernel/ftrace.c | 34 +++++++++++++++++++++ 4 files changed, 106 insertions(+), 1 deletion(-) diff --git a/arch/arm/Kconfig b/arch/arm/Kconfig index 32cbbd5..6f928ee 100644 --- a/arch/arm/Kconfig +++ b/arch/arm/Kconfig @@ -39,6 +39,7 @@ config ARM select HAVE_DMA_ATTRS select HAVE_DMA_CONTIGUOUS if MMU select HAVE_DYNAMIC_FTRACE if (!XIP_KERNEL) + select HAVE_DYNAMIC_FTRACE_WITH_REGS if HAVE_DYNAMIC_FTRACE select HAVE_EFFICIENT_UNALIGNED_ACCESS if (CPU_V6 || CPU_V6K || CPU_V7) && MMU select HAVE_FTRACE_MCOUNT_RECORD if (!XIP_KERNEL) select HAVE_FUNCTION_GRAPH_TRACER if (!THUMB2_KERNEL) @@ -72,6 +73,7 @@ config ARM select PERF_USE_VMALLOC select RTC_LIB select SYS_SUPPORTS_APM_EMULATION + select FRAME_POINTER if DYNAMIC_FTRACE_WITH_REGS && FUNCTION_GRAPH_TRACER # Above selects are sorted alphabetically; please add new ones # according to that. Thanks. help diff --git a/arch/arm/include/asm/ftrace.h b/arch/arm/include/asm/ftrace.h index 39eb16b..d8e9bea 100644 --- a/arch/arm/include/asm/ftrace.h +++ b/arch/arm/include/asm/ftrace.h @@ -10,6 +10,9 @@ extern void mcount(void); extern void __gnu_mcount_nc(void); #ifdef CONFIG_DYNAMIC_FTRACE + +#define ARCH_SUPPORTS_FTRACE_OPS 1 + struct dyn_arch_ftrace { #ifdef CONFIG_OLD_MCOUNT bool old_mcount; diff --git a/arch/arm/kernel/entry-common.S b/arch/arm/kernel/entry-common.S index e52fe5a..9594fe2 100644 --- a/arch/arm/kernel/entry-common.S +++ b/arch/arm/kernel/entry-common.S @@ -197,7 +197,10 @@ ENDPROC(ret_from_fork) mcount_get_lr r1 @ lr of instrumented func mcount_adjust_addr r0, lr @ instrumented function - + ldr r2, =function_trace_op + ldr r2, [r2] @ pointer to the current + @ function tracing op + mov r3, #0 @ regs is NULL .globl ftrace_call\suffix ftrace_call\suffix: bl ftrace_stub @@ -211,6 +214,38 @@ ftrace_graph_call\suffix: mcount_exit .endm +.macro __ftrace_regs_caller + + add ip, sp, #4 @ move in IP the value of SP as it was + @ before the push {lr} of the mcount mechanism + stmdb sp!, {ip,lr,pc} + stmdb sp!, {r0-r11,lr} + @ stack content at this point: + @ 0 4 44 48 52 56 60 64 + @ RO | R1 | ... | R11 | LR | SP + 4 | LR | PC | previous LR | + + mov r3, sp @ struct pt_regs* + ldr r2, =function_trace_op + ldr r2, [r2] @ pointer to the current + @ function tracing op + ldr r1, [sp, #64] @ lr of instrumented func + mcount_adjust_addr r0, lr @ instrumented function + + .globl ftrace_regs_call +ftrace_regs_call: + bl ftrace_stub + +#ifdef CONFIG_FUNCTION_GRAPH_TRACER + .globl ftrace_graph_regs_call +ftrace_graph_regs_call: + mov r0, r0 +#endif + ldr lr, [sp, #64] @ get the previous LR value from stack + ldmia sp, {r0-r11, ip, sp} @ pop the saved registers INCLUDING + @ the stack pointer + ret ip +.endm + .macro __ftrace_graph_caller sub r0, fp, #4 @ &lr of instrumented routine (&parent) #ifdef CONFIG_DYNAMIC_FTRACE @@ -226,6 +261,24 @@ ftrace_graph_call\suffix: mcount_exit .endm + +.macro __ftrace_graph_regs_caller + + sub r0, fp, #4 @ &lr of instrumented routine (&parent) + + @ called from __ftrace_regs_caller + ldr r1, [sp, #56] @ instrumented routine (func) + mcount_adjust_addr r1, r1 + + mov r2, fp @ frame pointer + bl prepare_ftrace_return + + ldr lr, [fp, #-4] @ restore LR from the stack + ldmia sp, {r0-r11, ip, sp} @ pop the saved registers INCLUDING + @ the stack pointer + ret ip +.endm + #ifdef CONFIG_OLD_MCOUNT /* * mcount @@ -312,14 +365,27 @@ UNWIND(.fnstart) __ftrace_caller UNWIND(.fnend) ENDPROC(ftrace_caller) + +ENTRY(ftrace_regs_caller) +UNWIND(.fnstart) + __ftrace_regs_caller +UNWIND(.fnend) +ENDPROC(ftrace_regs_caller) #endif + #ifdef CONFIG_FUNCTION_GRAPH_TRACER ENTRY(ftrace_graph_caller) UNWIND(.fnstart) __ftrace_graph_caller UNWIND(.fnend) ENDPROC(ftrace_graph_caller) + +ENTRY(ftrace_graph_regs_caller) +UNWIND(.fnstart) + __ftrace_graph_regs_caller +UNWIND(.fnend) +ENDPROC(ftrace_graph_regs_caller) #endif .purgem mcount_enter diff --git a/arch/arm/kernel/ftrace.c b/arch/arm/kernel/ftrace.c index af9a8a9..35c5743 100644 --- a/arch/arm/kernel/ftrace.c +++ b/arch/arm/kernel/ftrace.c @@ -130,6 +130,16 @@ int ftrace_update_ftrace_func(ftrace_func_t func) } #endif + +#ifdef CONFIG_DYNAMIC_FTRACE_WITH_REGS + if (!ret) { + pc = (unsigned long)&ftrace_regs_call; + new = ftrace_call_replace(pc, (unsigned long)func); + + ret = ftrace_modify_code(pc, 0, new, false); + } +#endif + return ret; } @@ -139,6 +149,20 @@ int ftrace_make_call(struct dyn_ftrace *rec, unsigned long addr) unsigned long ip = rec->ip; old = ftrace_nop_replace(rec); + + new = ftrace_call_replace(ip, adjust_address(rec, addr)); + + return ftrace_modify_code(rec->ip, old, new, true); +} + +int ftrace_modify_call(struct dyn_ftrace *rec, unsigned long old_addr, + unsigned long addr) +{ + unsigned long new, old; + unsigned long ip = rec->ip; + + old = ftrace_call_replace(ip, adjust_address(rec, old_addr)); + new = ftrace_call_replace(ip, adjust_address(rec, addr)); return ftrace_modify_code(rec->ip, old, new, true); @@ -211,6 +235,9 @@ void prepare_ftrace_return(unsigned long *parent, unsigned long self_addr, extern unsigned long ftrace_graph_call; extern unsigned long ftrace_graph_call_old; extern void ftrace_graph_caller_old(void); +extern unsigned long ftrace_graph_regs_call; +extern void ftrace_graph_regs_caller(void); + static int __ftrace_modify_caller(unsigned long *callsite, void (*func) (void), bool enable) @@ -240,6 +267,13 @@ static int ftrace_modify_graph_caller(bool enable) enable); #endif +#ifdef CONFIG_DYNAMIC_FTRACE_WITH_REGS + if (!ret) + ret = __ftrace_modify_caller(&ftrace_graph_regs_call, + ftrace_graph_regs_caller, + enable); +#endif + return ret; } -- 2.1.3 ^ permalink raw reply related [flat|nested] 20+ messages in thread
end of thread, other threads:[~2014-11-27 15:06 UTC | newest] Thread overview: 20+ messages (download: mbox.gz / follow: Atom feed) -- links below jump to the message on this page -- 2014-11-07 14:59 [PATCH] arm: ftrace: Adds support for ftrace operations Jean-Jacques Hiblot 2014-11-07 14:59 ` Jean-Jacques Hiblot 2014-11-07 14:59 ` [PATCH 01/01] " Jean-Jacques Hiblot 2014-11-07 14:59 ` Jean-Jacques Hiblot 2014-11-07 16:52 ` [PATCH] " Steven Rostedt 2014-11-07 16:52 ` Steven Rostedt 2014-11-07 17:01 ` Jean-Jacques Hiblot 2014-11-07 17:01 ` Jean-Jacques Hiblot 2014-11-24 9:59 ` Jean-Jacques Hiblot 2014-11-24 9:59 ` Jean-Jacques Hiblot 2014-11-25 23:20 ` Steven Rostedt 2014-11-25 23:20 ` Steven Rostedt 2014-11-27 10:23 ` Jean-Jacques Hiblot 2014-11-27 10:23 ` Jean-Jacques Hiblot 2014-11-27 14:58 ` Steven Rostedt 2014-11-27 14:58 ` Steven Rostedt 2014-11-10 8:56 ` [PATCH v2 00/01] arm: ftrace: Adds support for CONFIG_DYNAMIC_FTRACE_WITH_REGS Jean-Jacques Hiblot 2014-11-10 8:56 ` Jean-Jacques Hiblot 2014-11-10 8:56 ` [PATCH v2 01/01] " Jean-Jacques Hiblot 2014-11-10 8:56 ` Jean-Jacques Hiblot
This is an external index of several public inboxes, see mirroring instructions on how to clone and mirror all data and code used by this external index.