linuxppc-dev.lists.ozlabs.org archive mirror
 help / color / mirror / Atom feed
From: Naveen N Rao <naveen@kernel.org>
To: <linuxppc-dev@lists.ozlabs.org>, <linux-kernel@vger.kernel.org>
Cc: Mark Rutland <mark.rutland@arm.com>,
	Florent Revest <revest@chromium.org>,
	Nicholas Piggin <npiggin@gmail.com>,
	Steven Rostedt <rostedt@goodmis.org>,
	"Aneesh Kumar K.V" <aneesh.kumar@kernel.org>,
	Masami Hiramatsu <mhiramat@kernel.org>
Subject: [RFC PATCH 9/9] samples/ftrace: Add support for ftrace direct samples on powerpc
Date: Fri,  8 Dec 2023 22:00:48 +0530	[thread overview]
Message-ID: <4735fcdfb8977c6f437796590c0e3cbbf644d0de.1702045299.git.naveen@kernel.org> (raw)
In-Reply-To: <cover.1702045299.git.naveen@kernel.org>

Add powerpc 32-bit and 64-bit samples for ftrace direct. This serves to
show the sample instruction sequence to be used by ftrace direct calls
to adhere to the ftrace ABI.

On 64-bit powerpc, TOC setup requires some additional work.

Signed-off-by: Naveen N Rao <naveen@kernel.org>
---
 arch/powerpc/Kconfig                        |   2 +
 samples/ftrace/ftrace-direct-modify.c       |  94 ++++++++++++++++-
 samples/ftrace/ftrace-direct-multi-modify.c | 110 +++++++++++++++++++-
 samples/ftrace/ftrace-direct-multi.c        |  64 +++++++++++-
 samples/ftrace/ftrace-direct-too.c          |  72 ++++++++++++-
 samples/ftrace/ftrace-direct.c              |  61 ++++++++++-
 6 files changed, 398 insertions(+), 5 deletions(-)

diff --git a/arch/powerpc/Kconfig b/arch/powerpc/Kconfig
index 4fe04fdca33a..28de3a5f3e98 100644
--- a/arch/powerpc/Kconfig
+++ b/arch/powerpc/Kconfig
@@ -274,6 +274,8 @@ config PPC
 	select HAVE_REGS_AND_STACK_ACCESS_API
 	select HAVE_RELIABLE_STACKTRACE
 	select HAVE_RSEQ
+	select HAVE_SAMPLE_FTRACE_DIRECT	if HAVE_DYNAMIC_FTRACE_WITH_DIRECT_CALLS
+	select HAVE_SAMPLE_FTRACE_DIRECT_MULTI	if HAVE_DYNAMIC_FTRACE_WITH_DIRECT_CALLS
 	select HAVE_SETUP_PER_CPU_AREA		if PPC64
 	select HAVE_SOFTIRQ_ON_OWN_STACK
 	select HAVE_STACKPROTECTOR		if PPC32 && $(cc-option,-mstack-protector-guard=tls -mstack-protector-guard-reg=r2)
diff --git a/samples/ftrace/ftrace-direct-modify.c b/samples/ftrace/ftrace-direct-modify.c
index e2a6a69352df..bd985035b937 100644
--- a/samples/ftrace/ftrace-direct-modify.c
+++ b/samples/ftrace/ftrace-direct-modify.c
@@ -2,7 +2,7 @@
 #include <linux/module.h>
 #include <linux/kthread.h>
 #include <linux/ftrace.h>
-#ifndef CONFIG_ARM64
+#if !defined(CONFIG_ARM64) && !defined(CONFIG_PPC32)
 #include <asm/asm-offsets.h>
 #endif
 
@@ -164,6 +164,98 @@ asm (
 
 #endif /* CONFIG_LOONGARCH */
 
+#ifdef CONFIG_PPC32
+
+asm (
+"	.pushsection	.text, \"ax\", @progbits\n"
+"	.type		my_tramp1, @function\n"
+"	.globl		my_tramp1\n"
+"   my_tramp1:"
+"	stw		0, 4(1)\n"
+"	stwu		1, -16(1)\n"
+"	mflr		0\n"
+"	stw		0, 4(1)\n"
+"	stwu		1, -16(1)\n"
+"	bl		my_direct_func1\n"
+"	lwz		0, 20(1)\n"
+"	mtlr		0\n"
+"	addi		1, 1, 32\n"
+"	lwz		0, 4(1)\n"
+"	blr\n"
+"	.size		my_tramp1, .-my_tramp1\n"
+
+"	.type		my_tramp2, @function\n"
+"	.globl		my_tramp2\n"
+"   my_tramp2:"
+"	stw		0, 4(1)\n"
+"	stwu		1, -16(1)\n"
+"	mflr		0\n"
+"	stw		0, 4(1)\n"
+"	stwu		1, -16(1)\n"
+"	bl		my_direct_func2\n"
+"	lwz		0, 20(1)\n"
+"	mtlr		0\n"
+"	addi		1, 1, 32\n"
+"	lwz		0, 4(1)\n"
+"	blr\n"
+"	.size		my_tramp2, .-my_tramp2\n"
+"	.popsection\n"
+);
+
+#endif /* CONFIG_PPC32 */
+
+#ifdef CONFIG_PPC64
+
+asm (
+"	.pushsection	.text, \"ax\", @progbits\n"
+"	.type		my_tramp1, @function\n"
+"	.globl		my_tramp1\n"
+"   my_tramp1:"
+"	std		0, 16(1)\n"
+"	stdu		1, -32(1)\n"
+"	mflr		0\n"
+"	std		0, 16(1)\n"
+"	stdu		1, -32(1)\n"
+"	std		2, 24(1)\n"
+"	bcl		20, 31, 1f\n"
+"   1:	mflr		12\n"
+"	ld		2, (2f - 1b)(12)\n"
+"	bl		my_direct_func1\n"
+"	ld		2, 24(1)\n"
+"	ld		0, 48(1)\n"
+"	mtlr		0\n"
+"	addi		1, 1, 64\n"
+"	ld		0, 16(1)\n"
+"	blr\n"
+"   2:	.quad		.TOC.@tocbase\n"
+"	.size		my_tramp1, .-my_tramp1\n"
+
+"	.type		my_tramp2, @function\n"
+"	.globl		my_tramp2\n"
+"   my_tramp2:"
+"	std		0, 16(1)\n"
+"	stdu		1, -32(1)\n"
+"	mflr		0\n"
+"	std		0, 16(1)\n"
+"	stdu		1, -32(1)\n"
+"	std		2, 24(1)\n"
+"	bcl		20, 31, 1f\n"
+"   1:	mflr		12\n"
+"	ld		2, (2f - 1b)(12)\n"
+"	bl		my_direct_func2\n"
+"	ld		2, 24(1)\n"
+"	ld		0, 48(1)\n"
+"	mtlr		0\n"
+"	addi		1, 1, 64\n"
+"	ld		0, 16(1)\n"
+"	blr\n"
+"   2:	.quad		.TOC.@tocbase\n"
+"	.size		my_tramp2, .-my_tramp2\n"
+"	.popsection\n"
+);
+
+#endif /* CONFIG_PPC64 */
+
 static struct ftrace_ops direct;
 
 static unsigned long my_tramp = (unsigned long)my_tramp1;
diff --git a/samples/ftrace/ftrace-direct-multi-modify.c b/samples/ftrace/ftrace-direct-multi-modify.c
index 2e349834d63c..478e879a23af 100644
--- a/samples/ftrace/ftrace-direct-multi-modify.c
+++ b/samples/ftrace/ftrace-direct-multi-modify.c
@@ -2,7 +2,7 @@
 #include <linux/module.h>
 #include <linux/kthread.h>
 #include <linux/ftrace.h>
-#ifndef CONFIG_ARM64
+#if !defined(CONFIG_ARM64) && !defined(CONFIG_PPC32)
 #include <asm/asm-offsets.h>
 #endif
 
@@ -184,6 +184,114 @@ asm (
 
 #endif /* CONFIG_LOONGARCH */
 
+#ifdef CONFIG_PPC32
+
+asm (
+"	.pushsection	.text, \"ax\", @progbits\n"
+"	.type		my_tramp1, @function\n"
+"	.globl		my_tramp1\n"
+"   my_tramp1:"
+"	stw		0, 4(1)\n"
+"	stwu		1, -16(1)\n"
+"	mflr		0\n"
+"	stw		0, 4(1)\n"
+"	stwu		1, -24(1)\n"
+"	stw		3, 16(1)\n"
+"	mr		3, 0\n"
+"	addi		3, 3, 16\n"
+"	bl		my_direct_func1\n"
+"	lwz		3, 16(1)\n"
+"	lwz		0, 28(1)\n"
+"	mtlr		0\n"
+"	addi		1, 1, 40\n"
+"	lwz		0, 4(1)\n"
+"	blr\n"
+"	.size		my_tramp1, .-my_tramp1\n"
+
+"	.type		my_tramp2, @function\n"
+"	.globl		my_tramp2\n"
+"   my_tramp2:"
+"	stw		0, 4(1)\n"
+"	stwu		1, -16(1)\n"
+"	mflr		0\n"
+"	stw		0, 4(1)\n"
+"	stwu		1, -24(1)\n"
+"	stw		3, 16(1)\n"
+"	mr		3, 0\n"
+"	addi		3, 3, 16\n"
+"	bl		my_direct_func2\n"
+"	lwz		3, 16(1)\n"
+"	lwz		0, 28(1)\n"
+"	mtlr		0\n"
+"	addi		1, 1, 40\n"
+"	lwz		0, 4(1)\n"
+"	blr\n"
+"	.size		my_tramp2, .-my_tramp2\n"
+"	.popsection\n"
+);
+
+#endif /* CONFIG_PPC32 */
+
+#ifdef CONFIG_PPC64
+
+asm (
+"	.pushsection	.text, \"ax\", @progbits\n"
+"	.type		my_tramp1, @function\n"
+"	.globl		my_tramp1\n"
+"   my_tramp1:"
+"	std		0, 16(1)\n"
+"	stdu		1, -32(1)\n"
+"	mflr		0\n"
+"	std		0, 16(1)\n"
+"	stdu		1, -48(1)\n"
+"	std		2, 24(1)\n"
+"	bcl		20, 31, 1f\n"
+"   1:	mflr		12\n"
+"	ld		2, (2f - 1b)(12)\n"
+"	std		3, 32(1)\n"
+"	mr		3, 0\n"
+"	addi		3, 3, 20\n"
+"	bl		my_direct_func1\n"
+"	ld		3, 32(1)\n"
+"	ld		2, 24(1)\n"
+"	ld		0, 64(1)\n"
+"	mtlr		0\n"
+"	addi		1, 1, 80\n"
+"	ld		0, 16(1)\n"
+"	blr\n"
+"   2:	.quad		.TOC.@tocbase\n"
+"	.size		my_tramp1, .-my_tramp1\n"
+
+"	.type		my_tramp2, @function\n"
+"	.globl		my_tramp2\n"
+"   my_tramp2:"
+"	std		0, 16(1)\n"
+"	stdu		1, -32(1)\n"
+"	mflr		0\n"
+"	std		0, 16(1)\n"
+"	stdu		1, -48(1)\n"
+"	std		2, 24(1)\n"
+"	bcl		20, 31, 1f\n"
+"   1:	mflr		12\n"
+"	ld		2, (2f - 1b)(12)\n"
+"	std		3, 32(1)\n"
+"	mr		3, 0\n"
+"	addi		3, 3, 20\n"
+"	bl		my_direct_func2\n"
+"	ld		3, 32(1)\n"
+"	ld		2, 24(1)\n"
+"	ld		0, 64(1)\n"
+"	mtlr		0\n"
+"	addi		1, 1, 80\n"
+"	ld		0, 16(1)\n"
+"	blr\n"
+"   2:	.quad		.TOC.@tocbase\n"
+"	.size		my_tramp2, .-my_tramp2\n"
+"	.popsection\n"
+);
+
+#endif /* CONFIG_PPC64 */
+
 static unsigned long my_tramp = (unsigned long)my_tramp1;
 static unsigned long tramps[2] = {
 	(unsigned long)my_tramp1,
diff --git a/samples/ftrace/ftrace-direct-multi.c b/samples/ftrace/ftrace-direct-multi.c
index 9243dbfe4d0c..558f4ad8d84a 100644
--- a/samples/ftrace/ftrace-direct-multi.c
+++ b/samples/ftrace/ftrace-direct-multi.c
@@ -4,7 +4,7 @@
 #include <linux/mm.h> /* for handle_mm_fault() */
 #include <linux/ftrace.h>
 #include <linux/sched/stat.h>
-#ifndef CONFIG_ARM64
+#if !defined(CONFIG_ARM64) && !defined(CONFIG_PPC32)
 #include <asm/asm-offsets.h>
 #endif
 
@@ -116,6 +116,68 @@ asm (
 
 #endif /* CONFIG_LOONGARCH */
 
+#ifdef CONFIG_PPC32
+
+asm (
+"	.pushsection	.text, \"ax\", @progbits\n"
+"	.type		my_tramp, @function\n"
+"	.globl		my_tramp\n"
+"   my_tramp:"
+"	stw		0, 4(1)\n"
+"	stwu		1, -16(1)\n"
+"	mflr		0\n"
+"	stw		0, 4(1)\n"
+"	stwu		1, -24(1)\n"
+"	stw		3, 16(1)\n"
+"	mr		3, 0\n"
+"	addi		3, 3, 16\n"
+"	bl		my_direct_func\n"
+"	lwz		3, 16(1)\n"
+"	lwz		0, 28(1)\n"
+"	mtlr		0\n"
+"	addi		1, 1, 40\n"
+"	lwz		0, 4(1)\n"
+"	blr\n"
+"	.size		my_tramp, .-my_tramp\n"
+"	.popsection\n"
+);
+
+#endif /* CONFIG_PPC32 */
+
+#ifdef CONFIG_PPC64
+
+asm (
+"	.pushsection	.text, \"ax\", @progbits\n"
+"	.type		my_tramp, @function\n"
+"	.globl		my_tramp\n"
+"   my_tramp:"
+"	std		0, 16(1)\n"
+"	stdu		1, -32(1)\n"
+"	mflr		0\n"
+"	std		0, 16(1)\n"
+"	stdu		1, -48(1)\n"
+"	std		2, 24(1)\n"
+"	bcl		20, 31, 1f\n"
+"   1:	mflr		12\n"
+"	ld		2, (2f - 1b)(12)\n"
+"	std		3, 32(1)\n"
+"	mr		3, 0\n"
+"	addi		3, 3, 20\n"
+"	bl		my_direct_func\n"
+"	ld		3, 32(1)\n"
+"	ld		2, 24(1)\n"
+"	ld		0, 64(1)\n"
+"	mtlr		0\n"
+"	addi		1, 1, 80\n"
+"	ld		0, 16(1)\n"
+"	blr\n"
+"   2:	.quad		.TOC.@tocbase\n"
+"	.size		my_tramp, .-my_tramp\n"
+"	.popsection\n"
+);
+
+#endif /* CONFIG_PPC64 */
+
 static struct ftrace_ops direct;
 
 static int __init ftrace_direct_multi_init(void)
diff --git a/samples/ftrace/ftrace-direct-too.c b/samples/ftrace/ftrace-direct-too.c
index e39c3563ae4e..2a35b5d88304 100644
--- a/samples/ftrace/ftrace-direct-too.c
+++ b/samples/ftrace/ftrace-direct-too.c
@@ -3,7 +3,7 @@
 
 #include <linux/mm.h> /* for handle_mm_fault() */
 #include <linux/ftrace.h>
-#ifndef CONFIG_ARM64
+#if !defined(CONFIG_ARM64) && !defined(CONFIG_PPC32)
 #include <asm/asm-offsets.h>
 #endif
 
@@ -125,6 +125,76 @@ asm (
 
 #endif /* CONFIG_LOONGARCH */
 
+#ifdef CONFIG_PPC32
+
+asm (
+"	.pushsection	.text, \"ax\", @progbits\n"
+"	.type		my_tramp, @function\n"
+"	.globl		my_tramp\n"
+"   my_tramp:"
+"	stw		0, 4(1)\n"
+"	stwu		1, -16(1)\n"
+"	mflr		0\n"
+"	stw		0, 4(1)\n"
+"	stwu		1, -32(1)\n"
+"	stw		3, 16(1)\n"
+"	stw		4, 20(1)\n"
+"	stw		5, 24(1)\n"
+"	stw		6, 28(1)\n"
+"	bl		my_direct_func\n"
+"	lwz		6, 28(1)\n"
+"	lwz		5, 24(1)\n"
+"	lwz		4, 20(1)\n"
+"	lwz		3, 16(1)\n"
+"	lwz		0, 36(1)\n"
+"	mtlr		0\n"
+"	addi		1, 1, 48\n"
+"	lwz		0, 4(1)\n"
+"	blr\n"
+"	.size		my_tramp, .-my_tramp\n"
+"	.popsection\n"
+);
+
+#endif /* CONFIG_PPC32 */
+
+#ifdef CONFIG_PPC64
+
+asm (
+"	.pushsection	.text, \"ax\", @progbits\n"
+"	.type		my_tramp, @function\n"
+"	.globl		my_tramp\n"
+"   my_tramp:"
+"	std		0, 16(1)\n"
+"	stdu		1, -32(1)\n"
+"	mflr		0\n"
+"	std		0, 16(1)\n"
+"	stdu		1, -64(1)\n"
+"	std		2, 24(1)\n"
+"	bcl		20, 31, 1f\n"
+"   1:	mflr		12\n"
+"	ld		2, (2f - 1b)(12)\n"
+"	std		3, 32(1)\n"
+"	std		4, 40(1)\n"
+"	std		5, 48(1)\n"
+"	std		6, 56(1)\n"
+"	bl		my_direct_func\n"
+"	ld		6, 56(1)\n"
+"	ld		5, 48(1)\n"
+"	ld		4, 40(1)\n"
+"	ld		3, 32(1)\n"
+"	ld		2, 24(1)\n"
+"	ld		0, 80(1)\n"
+"	mtlr		0\n"
+"	addi		1, 1, 96\n"
+"	ld		0, 16(1)\n"
+"	blr\n"
+"   2:	.quad		.TOC.@tocbase\n"
+"	.size		my_tramp, .-my_tramp\n"
+"	.popsection\n"
+);
+
+#endif /* CONFIG_PPC64 */
+
 static struct ftrace_ops direct;
 
 static int __init ftrace_direct_init(void)
diff --git a/samples/ftrace/ftrace-direct.c b/samples/ftrace/ftrace-direct.c
index 32c477da1e9a..5585ffb6dd41 100644
--- a/samples/ftrace/ftrace-direct.c
+++ b/samples/ftrace/ftrace-direct.c
@@ -3,7 +3,7 @@
 
 #include <linux/sched.h> /* for wake_up_process() */
 #include <linux/ftrace.h>
-#ifndef CONFIG_ARM64
+#if !defined(CONFIG_ARM64) && !defined(CONFIG_PPC32)
 #include <asm/asm-offsets.h>
 #endif
 
@@ -110,6 +110,65 @@ asm (
 
 #endif /* CONFIG_LOONGARCH */
 
+#ifdef CONFIG_PPC32
+
+asm (
+"	.pushsection	.text, \"ax\", @progbits\n"
+"	.type		my_tramp, @function\n"
+"	.globl		my_tramp\n"
+"   my_tramp:"
+"	stw		0, 4(1)\n"
+"	stwu		1, -16(1)\n"
+"	mflr		0\n"
+"	stw		0, 4(1)\n"
+"	stwu		1, -24(1)\n"
+"	stw		3, 16(1)\n"
+"	bl		my_direct_func\n"
+"	lwz		3, 16(1)\n"
+"	lwz		0, 28(1)\n"
+"	mtlr		0\n"
+"	addi		1, 1, 40\n"
+"	lwz		0, 4(1)\n"
+"	blr\n"
+"	.size		my_tramp, .-my_tramp\n"
+"	.popsection\n"
+);
+
+#endif /* CONFIG_PPC32 */
+
+#ifdef CONFIG_PPC64
+
+asm (
+"	.pushsection	.text, \"ax\", @progbits\n"
+"	.type		my_tramp, @function\n"
+"	.globl		my_tramp\n"
+"   my_tramp:"
+"	std		0, 16(1)\n"
+"	stdu		1, -32(1)\n"
+"	mflr		0\n"
+"	std		0, 16(1)\n"
+"	stdu		1, -48(1)\n"
+"	std		2, 24(1)\n"
+"	bcl		20, 31, 1f\n"
+"   1:	mflr		12\n"
+"	ld		2, (2f - 1b)(12)\n"
+"	std		3, 32(1)\n"
+"	bl		my_direct_func\n"
+"	ld		3, 32(1)\n"
+"	ld		2, 24(1)\n"
+"	ld		0, 64(1)\n"
+"	mtlr		0\n"
+"	addi		1, 1, 80\n"
+"	ld		0, 16(1)\n"
+"	blr\n"
+"   2:	.quad		.TOC.@tocbase\n"
+"	.size		my_tramp, .-my_tramp\n"
+"	.popsection\n"
+);
+
+#endif /* CONFIG_PPC64 */
+
+
 static struct ftrace_ops direct;
 
 static int __init ftrace_direct_init(void)
-- 
2.43.0


  parent reply	other threads:[~2023-12-08 16:42 UTC|newest]

Thread overview: 16+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-12-08 16:30 [RFC PATCH 0/9] powerpc: ftrace updates Naveen N Rao
2023-12-08 16:30 ` [RFC PATCH 1/9] powerpc/ftrace: Fix indentation in ftrace.h Naveen N Rao
2023-12-08 16:30 ` [RFC PATCH 2/9] powerpc/ftrace: Unify 32-bit and 64-bit ftrace entry code Naveen N Rao
2023-12-08 16:30 ` [RFC PATCH 3/9] powerpc/ftrace: Remove nops after the call to ftrace_stub Naveen N Rao
2023-12-08 16:30 ` [RFC PATCH 4/9] powerpc/Kconfig: Select FUNCTION_ALIGNMENT_4B Naveen N Rao
2023-12-08 16:30 ` [RFC PATCH 5/9] powerpc/kprobes: Use ftrace to determine if a probe is at function entry Naveen N Rao
2023-12-11  5:39   ` Masami Hiramatsu
2023-12-08 16:30 ` [RFC PATCH 6/9] powerpc/ftrace: Update and move function profile instructions out-of-line Naveen N Rao
2023-12-21 10:46   ` Christophe Leroy
2023-12-21 14:25     ` Steven Rostedt
2023-12-21 15:20       ` Christophe Leroy
2023-12-22 15:01     ` Naveen N Rao
2023-12-08 16:30 ` [RFC PATCH 7/9] powerpc/ftrace: Add support for DYNAMIC_FTRACE_WITH_CALL_OPS Naveen N Rao
2023-12-08 16:30 ` [RFC PATCH 8/9] powerpc/ftrace: Add support for DYNAMIC_FTRACE_WITH_DIRECT_CALLS Naveen N Rao
2023-12-08 16:30 ` Naveen N Rao [this message]
2023-12-21 10:38 ` (subset) [RFC PATCH 0/9] powerpc: ftrace updates Michael Ellerman

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=4735fcdfb8977c6f437796590c0e3cbbf644d0de.1702045299.git.naveen@kernel.org \
    --to=naveen@kernel.org \
    --cc=aneesh.kumar@kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linuxppc-dev@lists.ozlabs.org \
    --cc=mark.rutland@arm.com \
    --cc=mhiramat@kernel.org \
    --cc=npiggin@gmail.com \
    --cc=revest@chromium.org \
    --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;
as well as URLs for NNTP newsgroup(s).