public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
From: Masami Hiramatsu <mhiramat@kernel.org>
To: Steven Rostedt <rostedt@goodmis.org>
Cc: kbuild-all@lists.01.org, linux-kernel@vger.kernel.org,
	Masami Hiramatsu <mhiramat@kernel.org>,
	Nick Desaulniers <ndesaulniers@google.com>
Subject: [PATCH] ARM: kprobes: Make __kretprobe_trampoline as a pure asm function
Date: Tue, 15 Mar 2022 18:52:16 +0900	[thread overview]
Message-ID: <164733793626.1008610.12121025094280924953.stgit@devnote2> (raw)
In-Reply-To: <20220315182558.1a056d8b3975932f6589b60f@kernel.org>

Make __kretprobe_trampoline() as a pure asm function same as the x86
code does. Anyway, it is safe to define the symbol in the asm code
instead of accessing a C symbol from the inline asm.

Without this fix, building arm kernel with GCC-11 may cause below
error.

   /tmp/ccIWiggX.s: Assembler messages:
>> /tmp/ccIWiggX.s:22: Error: invalid literal constant: pool needs to be closer

This fixes the error reported by 0day build bot.

Reported-by: kernel test robot <lkp@intel.com>
Fixes: 7e9bf33b8124 ("ARM: kprobes: Make a frame pointer on __kretprobe_trampoline")
Signed-off-by: Masami Hiramatsu <mhiramat@kernel.org>
---
 arch/arm/probes/kprobes/core.c |   57 +++++++++++++++++++++-------------------
 1 file changed, 30 insertions(+), 27 deletions(-)

diff --git a/arch/arm/probes/kprobes/core.c b/arch/arm/probes/kprobes/core.c
index 4848404ba51b..51f1438456ae 100644
--- a/arch/arm/probes/kprobes/core.c
+++ b/arch/arm/probes/kprobes/core.c
@@ -373,43 +373,46 @@ int __kprobes kprobe_exceptions_notify(struct notifier_block *self,
  * should be enough for stacktrace from the return handler with or
  * without pt_regs.
  */
-void __naked __kprobes __kretprobe_trampoline(void)
-{
-	__asm__ __volatile__ (
+asm(
+	".text\n"
+	".global __kretprobe_trampoline\n"
+	".type __kretprobe_trampoline, %function\n"
+	"__kretprobe_trampoline:\n"
 #ifdef CONFIG_FRAME_POINTER
-		"ldr	lr, =__kretprobe_trampoline	\n\t"
+	"ldr	lr, =__kretprobe_trampoline	\n\t"
 	/* __kretprobe_trampoline makes a framepointer on pt_regs. */
 #ifdef CONFIG_CC_IS_CLANG
-		"stmdb	sp, {sp, lr, pc}	\n\t"
-		"sub	sp, sp, #12		\n\t"
-		/* In clang case, pt_regs->ip = lr. */
-		"stmdb	sp!, {r0 - r11, lr}	\n\t"
-		/* fp points regs->r11 (fp) */
-		"add	fp, sp,	#44		\n\t"
+	"stmdb	sp, {sp, lr, pc}	\n\t"
+	"sub	sp, sp, #12		\n\t"
+	/* In clang case, pt_regs->ip = lr. */
+	"stmdb	sp!, {r0 - r11, lr}	\n\t"
+	/* fp points regs->r11 (fp) */
+	"add	fp, sp,	#44		\n\t"
 #else /* !CONFIG_CC_IS_CLANG */
-		/* In gcc case, pt_regs->ip = fp. */
-		"stmdb	sp, {fp, sp, lr, pc}	\n\t"
-		"sub	sp, sp, #16		\n\t"
-		"stmdb	sp!, {r0 - r11}		\n\t"
-		/* fp points regs->r15 (pc) */
-		"add	fp, sp, #60		\n\t"
+	/* In gcc case, pt_regs->ip = fp. */
+	"stmdb	sp, {fp, sp, lr, pc}	\n\t"
+	"sub	sp, sp, #16		\n\t"
+	"stmdb	sp!, {r0 - r11}		\n\t"
+	/* fp points regs->r15 (pc) */
+	"add	fp, sp, #60		\n\t"
 #endif /* CONFIG_CC_IS_CLANG */
 #else /* !CONFIG_FRAME_POINTER */
-		"sub	sp, sp, #16		\n\t"
-		"stmdb	sp!, {r0 - r11}		\n\t"
+	"sub	sp, sp, #16		\n\t"
+	"stmdb	sp!, {r0 - r11}		\n\t"
 #endif /* CONFIG_FRAME_POINTER */
-		"mov	r0, sp			\n\t"
-		"bl	trampoline_handler	\n\t"
-		"mov	lr, r0			\n\t"
-		"ldmia	sp!, {r0 - r11}		\n\t"
-		"add	sp, sp, #16		\n\t"
+	"mov	r0, sp			\n\t"
+	"bl	trampoline_handler	\n\t"
+	"mov	lr, r0			\n\t"
+	"ldmia	sp!, {r0 - r11}		\n\t"
+	"add	sp, sp, #16		\n\t"
 #ifdef CONFIG_THUMB2_KERNEL
-		"bx	lr			\n\t"
+	"bx	lr			\n\t"
 #else
-		"mov	pc, lr			\n\t"
+	"mov	pc, lr			\n\t"
 #endif
-		: : : "memory");
-}
+	".size __kretprobe_trampoline, .-__kretprobe_trampoline\n"
+);
+NOKPROBE_SYMBOL(__kretprobe_trampoline);
 
 /* Called from __kretprobe_trampoline */
 static __used __kprobes void *trampoline_handler(struct pt_regs *regs)


  reply	other threads:[~2022-03-15  9:52 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-03-14 22:00 /tmp/ccIWiggX.s:22: Error: invalid literal constant: pool needs to be closer kernel test robot
2022-03-15  9:25 ` Masami Hiramatsu
2022-03-15  9:52   ` Masami Hiramatsu [this message]
2022-03-24  6:21     ` [PATCH] ARM: kprobes: Make __kretprobe_trampoline as a pure asm function Masami Hiramatsu
2022-03-24 13:23       ` Masami Hiramatsu
2022-03-24 13:34         ` Ard Biesheuvel
2022-03-24 13:35           ` Ard Biesheuvel
2022-03-24 15:18           ` Masami Hiramatsu

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=164733793626.1008610.12121025094280924953.stgit@devnote2 \
    --to=mhiramat@kernel.org \
    --cc=kbuild-all@lists.01.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=ndesaulniers@google.com \
    --cc=rostedt@goodmis.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
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