mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Alan Kao <nonerkao@gmail.com>
To: Palmer Dabbelt <palmer@sifive.com>, Albert Ou <albert@sifive.com>,
	Steven Rostedt <rostedt@goodmis.org>,
	Ingo Molnar <mingo@redhat.com>,
	Masahiro Yamada <yamada.masahiro@socionext.com>,
	Kamil Rytarowski <n54@gmx.com>,
	Andrew Morton <akpm@linux-foundation.org>,
	patches@groups.riscv.org, linux-kernel@vger.kernel.org
Cc: Alan Kao <alankao@andestech.com>, Greentime Hu <greentime@andestech.com>
Subject: [PATCH 6/6] riscv/ftrace: Add HAVE_FUNCTION_GRAPH_RET_ADDR_PTR support
Date: Wed, 10 Jan 2018 15:38:14 +0800	[thread overview]
Message-ID: <20180110073814.32338-7-alankao@andestech.com> (raw)
In-Reply-To: <20180110073814.32338-1-alankao@andestech.com>

When doing unwinding in the function walk_stackframe, the pc now receives 
the address from calling ftrace_graph_ret_addr instead of manual calculation.

Note that the original expression,
	pc = frame->ra - 4
is buggy if the instruction at the return address happened to be a
compressed inst. But since it is not a critical part of ftrace and
is a RISC-V-specific behavior, it is ignored for now to ease the 
review process.

Cc: Greentime Hu <greentime@andestech.com>
Signed-off-by: Alan Kao <alankao@andestech.com>
---
 arch/riscv/include/asm/ftrace.h | 1 +
 arch/riscv/kernel/ftrace.c      | 2 +-
 arch/riscv/kernel/stacktrace.c  | 6 ++++++
 3 files changed, 8 insertions(+), 1 deletion(-)

diff --git a/arch/riscv/include/asm/ftrace.h b/arch/riscv/include/asm/ftrace.h
index 429a6a156645..6e4b4c96b63e 100644
--- a/arch/riscv/include/asm/ftrace.h
+++ b/arch/riscv/include/asm/ftrace.h
@@ -8,6 +8,7 @@
 #if defined(CONFIG_FUNCTION_GRAPH_TRACER) && defined(CONFIG_FRAME_POINTER)
 #define HAVE_FUNCTION_GRAPH_FP_TEST
 #endif
+#define HAVE_FUNCTION_GRAPH_RET_ADDR_PTR
 
 #define ARCH_SUPPORTS_FTRACE_OPS 1
 #ifndef __ASSEMBLY__
diff --git a/arch/riscv/kernel/ftrace.c b/arch/riscv/kernel/ftrace.c
index c9cc884961d7..e02ecd44fe47 100644
--- a/arch/riscv/kernel/ftrace.c
+++ b/arch/riscv/kernel/ftrace.c
@@ -144,7 +144,7 @@ void prepare_ftrace_return(unsigned long *parent, unsigned long self_addr,
 		return;
 
 	err = ftrace_push_return_trace(old, self_addr, &trace.depth,
-				       frame_pointer, NULL);
+				       frame_pointer, parent);
 	if (err == -EBUSY)
 		return;
 	*parent = return_hooker;
diff --git a/arch/riscv/kernel/stacktrace.c b/arch/riscv/kernel/stacktrace.c
index 559aae781154..a4b1d94371a0 100644
--- a/arch/riscv/kernel/stacktrace.c
+++ b/arch/riscv/kernel/stacktrace.c
@@ -18,6 +18,7 @@
 #include <linux/sched/debug.h>
 #include <linux/sched/task_stack.h>
 #include <linux/stacktrace.h>
+#include <linux/ftrace.h>
 
 #ifdef CONFIG_FRAME_POINTER
 
@@ -63,7 +64,12 @@ static void notrace walk_stackframe(struct task_struct *task,
 		frame = (struct stackframe *)fp - 1;
 		sp = fp;
 		fp = frame->fp;
+#ifdef HAVE_FUNCTION_GRAPH_RET_ADDR_PTR
+		pc = ftrace_graph_ret_addr(current, NULL, frame->ra,
+					   (unsigned long *)(fp - 8));
+#else
 		pc = frame->ra - 0x4;
+#endif
 	}
 }
 
-- 
2.15.1

      parent reply	other threads:[~2018-01-10  7:39 UTC|newest]

Thread overview: 12+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2018-01-10  7:38 [PATCH 0/6] Add dynamic ftrace support for RISC-V platforms Alan Kao
2018-01-10  7:38 ` [PATCH 1/6] riscv/ftrace: Add RECORD_MCOUNT support Alan Kao
2018-01-10  7:43   ` [patches] " Christoph Hellwig
2018-01-10  7:54     ` Alan Kao
2018-01-10  7:38 ` [PATCH 2/6] riscv/ftrace: Add dynamic function tracer support Alan Kao
2018-01-10 16:32   ` Steven Rostedt
2018-01-10 16:36   ` Steven Rostedt
2018-01-11  8:02     ` Alan Kao
2018-01-10  7:38 ` [PATCH 3/6] riscv/ftrace: Add dynamic function graph " Alan Kao
2018-01-10  7:38 ` [PATCH 4/6] riscv/ftrace: Add ARCH_SUPPORTS_FTRACE_OPS support Alan Kao
2018-01-10  7:38 ` [PATCH 5/6] riscv/ftrace: Add DYNAMIC_FTRACE_WITH_REGS support Alan Kao
2018-01-10  7:38 ` Alan Kao [this message]

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=20180110073814.32338-7-alankao@andestech.com \
    --to=nonerkao@gmail.com \
    --cc=akpm@linux-foundation.org \
    --cc=alankao@andestech.com \
    --cc=albert@sifive.com \
    --cc=greentime@andestech.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=mingo@redhat.com \
    --cc=n54@gmx.com \
    --cc=palmer@sifive.com \
    --cc=patches@groups.riscv.org \
    --cc=rostedt@goodmis.org \
    --cc=yamada.masahiro@socionext.com \
    /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

Powered by JetHome