public inbox for linux-arm-kernel@lists.infradead.org 
 help / color / mirror / Atom feed
From: Ard Biesheuvel <ardb@kernel•org>
To: linux@armlinux•org.uk, linux-arm-kernel@lists•infradead.org
Cc: Ard Biesheuvel <ardb@kernel•org>, Arnd Bergmann <arnd@arndb•de>,
	Linus Walleij <linus.walleij@linaro•org>,
	Nick Desaulniers <ndesaulniers@google•com>
Subject: [PATCH 2/8] ARM: ftrace: use ADD not POP to counter PUSH at entry
Date: Tue, 25 Jan 2022 16:36:50 +0100	[thread overview]
Message-ID: <20220125153656.1802079-3-ardb@kernel.org> (raw)
In-Reply-To: <20220125153656.1802079-1-ardb@kernel.org>

The compiler emitted hook used for ftrace consists of a PUSH {LR} to
preserve the link register, followed by a branch-and-link (BL) to
__gnu_mount_nc. Dynamic ftrace patches away the latter to turn the
combined sequence into a NOP, using a POP {LR} instruction.

This is not necessary, since the link register does not get clobbered in
this case, and simply adding #4 to the stack pointer is sufficient, and
avoids a memory access that may take a few cycles to resolve depending
on the micro-architecture.

Signed-off-by: Ard Biesheuvel <ardb@kernel•org>
---
 arch/arm/kernel/entry-ftrace.S | 2 +-
 arch/arm/kernel/ftrace.c       | 4 ++--
 2 files changed, 3 insertions(+), 3 deletions(-)

diff --git a/arch/arm/kernel/entry-ftrace.S b/arch/arm/kernel/entry-ftrace.S
index f4886fb6e9ba..dca12a09322a 100644
--- a/arch/arm/kernel/entry-ftrace.S
+++ b/arch/arm/kernel/entry-ftrace.S
@@ -27,7 +27,7 @@
  * allows it to be clobbered in subroutines and doesn't use it to hold
  * parameters.)
  *
- * When using dynamic ftrace, we patch out the mcount call by a "pop {lr}"
+ * When using dynamic ftrace, we patch out the mcount call by a "add sp, #4"
  * instead of the __gnu_mcount_nc call (see arch/arm/kernel/ftrace.c).
  */
 
diff --git a/arch/arm/kernel/ftrace.c b/arch/arm/kernel/ftrace.c
index a006585e1c09..db72d3a6522d 100644
--- a/arch/arm/kernel/ftrace.c
+++ b/arch/arm/kernel/ftrace.c
@@ -25,9 +25,9 @@
 #include <asm/patch.h>
 
 #ifdef CONFIG_THUMB2_KERNEL
-#define	NOP		0xf85deb04	/* pop.w {lr} */
+#define	NOP		0xf10d0d04	/* add.w sp, sp, #4 */
 #else
-#define	NOP		0xe8bd4000	/* pop {lr} */
+#define	NOP		0xe28dd004	/* add   sp, sp, #4 */
 #endif
 
 #ifdef CONFIG_DYNAMIC_FTRACE
-- 
2.30.2


_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel@lists•infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel

  parent reply	other threads:[~2022-01-25 15:49 UTC|newest]

Thread overview: 16+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-01-25 15:36 [PATCH 0/8] ARM: ftrace fixes and cleanups Ard Biesheuvel
2022-01-25 15:36 ` [PATCH 1/8] ARM: ftrace: ensure that ADR take Thumb bit into account Ard Biesheuvel
2022-01-25 19:14   ` Nick Desaulniers
2022-02-02 23:53   ` Linus Walleij
2022-01-25 15:36 ` Ard Biesheuvel [this message]
2022-01-25 19:23   ` [PATCH 2/8] ARM: ftrace: use ADD not POP to counter PUSH at entry Nick Desaulniers
2022-02-02 23:59   ` Linus Walleij
2022-01-25 15:36 ` [PATCH 3/8] ARM: ftrace: use trampolines to keep .init.text in branching range Ard Biesheuvel
2022-01-25 20:20   ` Nick Desaulniers
2022-02-03  0:12   ` Linus Walleij
2022-01-25 15:36 ` [PATCH 4/8] ARM: ftrace: avoid redundant loads or clobbering IP Ard Biesheuvel
2022-01-25 15:36 ` [PATCH 5/8] ARM: ftrace: avoid unnecessary literal loads Ard Biesheuvel
2022-01-25 20:27   ` Nick Desaulniers
2022-01-25 15:36 ` [PATCH 6/8] ARM: ftrace: enable HAVE_FUNCTION_GRAPH_FP_TEST Ard Biesheuvel
2022-01-25 15:36 ` [PATCH 7/8] ARM: unwind: track location of LR value in stack frame Ard Biesheuvel
2022-01-25 15:36 ` [PATCH 8/8] ARM: ftrace: enable the graph tracer with the EABI unwinder Ard Biesheuvel

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20220125153656.1802079-3-ardb@kernel.org \
    --to=ardb@kernel$(echo .)org \
    --cc=arnd@arndb$(echo .)de \
    --cc=linus.walleij@linaro$(echo .)org \
    --cc=linux-arm-kernel@lists$(echo .)infradead.org \
    --cc=linux@armlinux$(echo .)org.uk \
    --cc=ndesaulniers@google$(echo .)com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox