public inbox for linux-arm-kernel@lists.infradead.org
 help / color / mirror / Atom feed
* [PATCH] arm64/module: ftrace: deal with place relative nature of PLTs
@ 2019-04-13  6:59 Ard Biesheuvel
  2019-04-15 18:47 ` dann frazier
  2019-04-23 11:43 ` Will Deacon
  0 siblings, 2 replies; 3+ messages in thread
From: Ard Biesheuvel @ 2019-04-13  6:59 UTC (permalink / raw)
  To: linux-arm-kernel
  Cc: mark.rutland, Ard Biesheuvel, catalin.marinas, will.deacon, duwe,
	dann.frazier

Another bodge for the ftrace PLT code: plt_entries_equal() now takes
the place relative nature of the ADRP/ADD based PLT entries into
account, which means that a struct trampoline instance on the stack
is no longer equal to the same set of opcodes in the module struct,
given that they don't point to the same place in memory anymore.

Work around this by using memcmp() in the ftrace PLT handling code.

Signed-off-by: Ard Biesheuvel <ard.biesheuvel@linaro.org>
---
 arch/arm64/kernel/ftrace.c | 9 +++++++--
 1 file changed, 7 insertions(+), 2 deletions(-)

diff --git a/arch/arm64/kernel/ftrace.c b/arch/arm64/kernel/ftrace.c
index 07b298120182..65a51331088e 100644
--- a/arch/arm64/kernel/ftrace.c
+++ b/arch/arm64/kernel/ftrace.c
@@ -103,10 +103,15 @@ int ftrace_make_call(struct dyn_ftrace *rec, unsigned long addr)
 		 * to be revisited if support for multiple ftrace entry points
 		 * is added in the future, but for now, the pr_err() below
 		 * deals with a theoretical issue only.
+		 *
+		 * Note that PLTs are place relative, and plt_entries_equal()
+		 * checks whether they point to the same target. Here, we need
+		 * to check if the actual opcodes are in fact identical,
+		 * regardless of the offset in memory so use memcmp() instead.
 		 */
 		trampoline = get_plt_entry(addr, mod->arch.ftrace_trampoline);
-		if (!plt_entries_equal(mod->arch.ftrace_trampoline,
-				       &trampoline)) {
+		if (memcmp(mod->arch.ftrace_trampoline, &trampoline,
+			   sizeof(trampoline))) {
 			if (plt_entry_is_initialized(mod->arch.ftrace_trampoline)) {
 				pr_err("ftrace: far branches to multiple entry points unsupported inside a single module\n");
 				return -EINVAL;
-- 
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/module: ftrace: deal with place relative nature of PLTs
  2019-04-13  6:59 [PATCH] arm64/module: ftrace: deal with place relative nature of PLTs Ard Biesheuvel
@ 2019-04-15 18:47 ` dann frazier
  2019-04-23 11:43 ` Will Deacon
  1 sibling, 0 replies; 3+ messages in thread
From: dann frazier @ 2019-04-15 18:47 UTC (permalink / raw)
  To: Ard Biesheuvel
  Cc: mark.rutland, catalin.marinas, duwe, will.deacon,
	linux-arm-kernel

On Fri, Apr 12, 2019 at 11:59:25PM -0700, Ard Biesheuvel wrote:
> Another bodge for the ftrace PLT code: plt_entries_equal() now takes
> the place relative nature of the ADRP/ADD based PLT entries into
> account, which means that a struct trampoline instance on the stack
> is no longer equal to the same set of opcodes in the module struct,
> given that they don't point to the same place in memory anymore.
> 
> Work around this by using memcmp() in the ftrace PLT handling code.

This fixes an issue I was seeing on a HiSilicon D06 server:
  https://bugs.launchpad.net/bugs/1822871

> Signed-off-by: Ard Biesheuvel <ard.biesheuvel@linaro.org>

Tested-by: dann frazier <dann.frazier@canonical.com>

  -dann

> ---
>  arch/arm64/kernel/ftrace.c | 9 +++++++--
>  1 file changed, 7 insertions(+), 2 deletions(-)
> 
> diff --git a/arch/arm64/kernel/ftrace.c b/arch/arm64/kernel/ftrace.c
> index 07b298120182..65a51331088e 100644
> --- a/arch/arm64/kernel/ftrace.c
> +++ b/arch/arm64/kernel/ftrace.c
> @@ -103,10 +103,15 @@ int ftrace_make_call(struct dyn_ftrace *rec, unsigned long addr)
>  		 * to be revisited if support for multiple ftrace entry points
>  		 * is added in the future, but for now, the pr_err() below
>  		 * deals with a theoretical issue only.
> +		 *
> +		 * Note that PLTs are place relative, and plt_entries_equal()
> +		 * checks whether they point to the same target. Here, we need
> +		 * to check if the actual opcodes are in fact identical,
> +		 * regardless of the offset in memory so use memcmp() instead.
>  		 */
>  		trampoline = get_plt_entry(addr, mod->arch.ftrace_trampoline);
> -		if (!plt_entries_equal(mod->arch.ftrace_trampoline,
> -				       &trampoline)) {
> +		if (memcmp(mod->arch.ftrace_trampoline, &trampoline,
> +			   sizeof(trampoline))) {
>  			if (plt_entry_is_initialized(mod->arch.ftrace_trampoline)) {
>  				pr_err("ftrace: far branches to multiple entry points unsupported inside a single module\n");
>  				return -EINVAL;

_______________________________________________
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/module: ftrace: deal with place relative nature of PLTs
  2019-04-13  6:59 [PATCH] arm64/module: ftrace: deal with place relative nature of PLTs Ard Biesheuvel
  2019-04-15 18:47 ` dann frazier
@ 2019-04-23 11:43 ` Will Deacon
  1 sibling, 0 replies; 3+ messages in thread
From: Will Deacon @ 2019-04-23 11:43 UTC (permalink / raw)
  To: Ard Biesheuvel, catalin.marinas
  Cc: mark.rutland, dann.frazier, duwe, linux-arm-kernel

On Fri, Apr 12, 2019 at 11:59:25PM -0700, Ard Biesheuvel wrote:
> Another bodge for the ftrace PLT code: plt_entries_equal() now takes
> the place relative nature of the ADRP/ADD based PLT entries into
> account, which means that a struct trampoline instance on the stack
> is no longer equal to the same set of opcodes in the module struct,
> given that they don't point to the same place in memory anymore.
> 
> Work around this by using memcmp() in the ftrace PLT handling code.
> 
> Signed-off-by: Ard Biesheuvel <ard.biesheuvel@linaro.org>
> ---
>  arch/arm64/kernel/ftrace.c | 9 +++++++--
>  1 file changed, 7 insertions(+), 2 deletions(-)
> 
> diff --git a/arch/arm64/kernel/ftrace.c b/arch/arm64/kernel/ftrace.c
> index 07b298120182..65a51331088e 100644
> --- a/arch/arm64/kernel/ftrace.c
> +++ b/arch/arm64/kernel/ftrace.c
> @@ -103,10 +103,15 @@ int ftrace_make_call(struct dyn_ftrace *rec, unsigned long addr)
>  		 * to be revisited if support for multiple ftrace entry points
>  		 * is added in the future, but for now, the pr_err() below
>  		 * deals with a theoretical issue only.
> +		 *
> +		 * Note that PLTs are place relative, and plt_entries_equal()
> +		 * checks whether they point to the same target. Here, we need
> +		 * to check if the actual opcodes are in fact identical,
> +		 * regardless of the offset in memory so use memcmp() instead.
>  		 */
>  		trampoline = get_plt_entry(addr, mod->arch.ftrace_trampoline);
> -		if (!plt_entries_equal(mod->arch.ftrace_trampoline,
> -				       &trampoline)) {
> +		if (memcmp(mod->arch.ftrace_trampoline, &trampoline,
> +			   sizeof(trampoline))) {
>  			if (plt_entry_is_initialized(mod->arch.ftrace_trampoline)) {
>  				pr_err("ftrace: far branches to multiple entry points unsupported inside a single module\n");
>  				return -EINVAL;

Acked-by: Will Deacon <will.deacon@arm.com>

I guess this can also go in as a fix via Catalin.

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] 3+ messages in thread

end of thread, other threads:[~2019-04-23 11:43 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2019-04-13  6:59 [PATCH] arm64/module: ftrace: deal with place relative nature of PLTs Ard Biesheuvel
2019-04-15 18:47 ` dann frazier
2019-04-23 11:43 ` Will Deacon

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox