* [PATCH] arm64: ftrace: use function_nocfi for _mcount as well
@ 2021-10-05 10:32 Sumit Garg
2021-10-05 10:41 ` Mark Rutland
0 siblings, 1 reply; 3+ messages in thread
From: Sumit Garg @ 2021-10-05 10:32 UTC (permalink / raw)
To: linux-arm-kernel
Cc: rostedt, mingo, catalin.marinas, will, samitolvanen, ben.dai,
mark.rutland, nathan, keescook, daniel.thompson, linux-kernel,
Sumit Garg
Commit 800618f955a9 ("arm64: ftrace: use function_nocfi for ftrace_call")
only fixed address of ftrace_call but address of _mcount needs to be
fixed as well. Use function_nocfi() to get the actual address of _mcount
function as with CONFIG_CFI_CLANG, the compiler replaces function pointers
with jump table addresses which breaks dynamic ftrace as the address of
_mcount is replaced with the address of _mcount.cfi_jt.
Signed-off-by: Sumit Garg <sumit.garg@linaro.org>
---
arch/arm64/include/asm/ftrace.h | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/arch/arm64/include/asm/ftrace.h b/arch/arm64/include/asm/ftrace.h
index 91fa4baa1a93..347b0cc68f07 100644
--- a/arch/arm64/include/asm/ftrace.h
+++ b/arch/arm64/include/asm/ftrace.h
@@ -15,7 +15,7 @@
#ifdef CONFIG_DYNAMIC_FTRACE_WITH_REGS
#define ARCH_SUPPORTS_FTRACE_OPS 1
#else
-#define MCOUNT_ADDR ((unsigned long)_mcount)
+#define MCOUNT_ADDR ((unsigned long)function_nocfi(_mcount))
#endif
/* The BL at the callsite's adjusted rec->ip */
--
2.17.1
_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel
^ permalink raw reply related [flat|nested] 3+ messages in thread* Re: [PATCH] arm64: ftrace: use function_nocfi for _mcount as well
2021-10-05 10:32 [PATCH] arm64: ftrace: use function_nocfi for _mcount as well Sumit Garg
@ 2021-10-05 10:41 ` Mark Rutland
2021-10-05 12:22 ` Sumit Garg
0 siblings, 1 reply; 3+ messages in thread
From: Mark Rutland @ 2021-10-05 10:41 UTC (permalink / raw)
To: Sumit Garg
Cc: linux-arm-kernel, rostedt, mingo, catalin.marinas, will,
samitolvanen, ben.dai, nathan, keescook, daniel.thompson,
linux-kernel
On Tue, Oct 05, 2021 at 04:02:08PM +0530, Sumit Garg wrote:
> Commit 800618f955a9 ("arm64: ftrace: use function_nocfi for ftrace_call")
> only fixed address of ftrace_call but address of _mcount needs to be
> fixed as well. Use function_nocfi() to get the actual address of _mcount
> function as with CONFIG_CFI_CLANG, the compiler replaces function pointers
> with jump table addresses which breaks dynamic ftrace as the address of
> _mcount is replaced with the address of _mcount.cfi_jt.
It might be worth noting that where the toolchain implements
patchable-function-entry, we'll use that in preference to regular -pg,
and this problem won't apply. i.e. this won't show with recent versions
of clang.
> Signed-off-by: Sumit Garg <sumit.garg@linaro.org>
This probably wants:
Fixes: 9186ad8e66bab6a1 ("arm64: allow CONFIG_CFI_CLANG to be selected")
With that:
Acked-by: Mark Rutland <mark.rutland@arm.com>
Mark.
> ---
> arch/arm64/include/asm/ftrace.h | 2 +-
> 1 file changed, 1 insertion(+), 1 deletion(-)
>
> diff --git a/arch/arm64/include/asm/ftrace.h b/arch/arm64/include/asm/ftrace.h
> index 91fa4baa1a93..347b0cc68f07 100644
> --- a/arch/arm64/include/asm/ftrace.h
> +++ b/arch/arm64/include/asm/ftrace.h
> @@ -15,7 +15,7 @@
> #ifdef CONFIG_DYNAMIC_FTRACE_WITH_REGS
> #define ARCH_SUPPORTS_FTRACE_OPS 1
> #else
> -#define MCOUNT_ADDR ((unsigned long)_mcount)
> +#define MCOUNT_ADDR ((unsigned long)function_nocfi(_mcount))
> #endif
>
> /* The BL at the callsite's adjusted rec->ip */
> --
> 2.17.1
>
_______________________________________________
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] 3+ messages in thread* Re: [PATCH] arm64: ftrace: use function_nocfi for _mcount as well
2021-10-05 10:41 ` Mark Rutland
@ 2021-10-05 12:22 ` Sumit Garg
0 siblings, 0 replies; 3+ messages in thread
From: Sumit Garg @ 2021-10-05 12:22 UTC (permalink / raw)
To: Mark Rutland
Cc: linux-arm-kernel, Steven Rostedt, Ingo Molnar, Catalin Marinas,
Will Deacon, Sami Tolvanen, ben.dai, nathan, Kees Cook,
Daniel Thompson, Linux Kernel Mailing List
On Tue, 5 Oct 2021 at 16:11, Mark Rutland <mark.rutland@arm.com> wrote:
>
> On Tue, Oct 05, 2021 at 04:02:08PM +0530, Sumit Garg wrote:
> > Commit 800618f955a9 ("arm64: ftrace: use function_nocfi for ftrace_call")
> > only fixed address of ftrace_call but address of _mcount needs to be
> > fixed as well. Use function_nocfi() to get the actual address of _mcount
> > function as with CONFIG_CFI_CLANG, the compiler replaces function pointers
> > with jump table addresses which breaks dynamic ftrace as the address of
> > _mcount is replaced with the address of _mcount.cfi_jt.
>
> It might be worth noting that where the toolchain implements
> patchable-function-entry, we'll use that in preference to regular -pg,
> and this problem won't apply. i.e. this won't show with recent versions
> of clang.
Okay, I will add it to the commit description.
>
> > Signed-off-by: Sumit Garg <sumit.garg@linaro.org>
>
> This probably wants:
>
> Fixes: 9186ad8e66bab6a1 ("arm64: allow CONFIG_CFI_CLANG to be selected")
>
Okay, I will add it in v2.
> With that:
>
> Acked-by: Mark Rutland <mark.rutland@arm.com>
>
Thanks,
Sumit
> Mark.
>
> > ---
> > arch/arm64/include/asm/ftrace.h | 2 +-
> > 1 file changed, 1 insertion(+), 1 deletion(-)
> >
> > diff --git a/arch/arm64/include/asm/ftrace.h b/arch/arm64/include/asm/ftrace.h
> > index 91fa4baa1a93..347b0cc68f07 100644
> > --- a/arch/arm64/include/asm/ftrace.h
> > +++ b/arch/arm64/include/asm/ftrace.h
> > @@ -15,7 +15,7 @@
> > #ifdef CONFIG_DYNAMIC_FTRACE_WITH_REGS
> > #define ARCH_SUPPORTS_FTRACE_OPS 1
> > #else
> > -#define MCOUNT_ADDR ((unsigned long)_mcount)
> > +#define MCOUNT_ADDR ((unsigned long)function_nocfi(_mcount))
> > #endif
> >
> > /* The BL at the callsite's adjusted rec->ip */
> > --
> > 2.17.1
> >
_______________________________________________
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] 3+ messages in thread
end of thread, other threads:[~2021-10-05 12:25 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2021-10-05 10:32 [PATCH] arm64: ftrace: use function_nocfi for _mcount as well Sumit Garg
2021-10-05 10:41 ` Mark Rutland
2021-10-05 12:22 ` Sumit Garg
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox