linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Mark Rutland <mark.rutland@arm.com>
To: linux-arm-kernel@lists.infradead.org
Cc: aou@eecs.berkeley.edu, borntraeger@de.ibm.com, bp@alien8.de,
	broonie@kernel.org, catalin.marinas@arm.com,
	dave.hansen@linux.intel.com, gor@linux.ibm.com,
	hca@linux.ibm.com, linux-kernel@vger.kernel.org,
	madvenka@linux.microsoft.com, mark.rutland@arm.com,
	mhiramat@kernel.org, mingo@redhat.com, mpe@ellerman.id.au,
	palmer@dabbelt.com, paul.walmsley@sifive.com,
	peterz@infradead.org, rostedt@goodmis.org, tglx@linutronix.de,
	will@kernel.org
Subject: [PATCH 7/9] arm64: Make profile_pc() use arch_stack_walk()
Date: Wed, 17 Nov 2021 14:07:35 +0000	[thread overview]
Message-ID: <20211117140737.44420-8-mark.rutland@arm.com> (raw)
In-Reply-To: <20211117140737.44420-1-mark.rutland@arm.com>

From: "Madhavan T. Venkataraman" <madvenka@linux.microsoft.com>

To enable RELIABLE_STACKTRACE and LIVEPATCH on arm64, we need to
substantially rework arm64's unwinding code. As part of this, we want to
minimize the set of unwind interfaces we expose, and avoid open-coding
of unwind logic outside of stacktrace.c.

Currently profile_pc() walks the stack of an interrupted context by
calling start_backtrace() with the context's PC and FP, and iterating
unwind steps using walk_stackframe(). This is functionally equivalent to
calling arch_stack_walk() with the interrupted context's pt_regs, which
will start with the PC and FP from the regs.

Make profile_pc() use arch_stack_walk(). This simplifies profile_pc(),
and in future will alow us to make walk_stackframe() private to
stacktrace.c.

At the same time, we remove the early return for when regs->pc is not in
lock functions, as this will be handled by the first call to the
profile_pc_cb() callback.

There should be no functional change as a result of this patch.

Signed-off-by: Madhavan T. Venkataraman <madvenka@linux.microsoft.com>
Reviewed-by: Mark Rutland <mark.rutland@arm.com>
[Mark: remove unnecessary early return, elaborate commit message]
Signed-off-by: Mark Rutland <mark.rutland@arm.com>
---
 arch/arm64/kernel/time.c | 23 ++++++++++++-----------
 1 file changed, 12 insertions(+), 11 deletions(-)

diff --git a/arch/arm64/kernel/time.c b/arch/arm64/kernel/time.c
index eebbc8d7123e..070d4427327f 100644
--- a/arch/arm64/kernel/time.c
+++ b/arch/arm64/kernel/time.c
@@ -32,22 +32,23 @@
 #include <asm/stacktrace.h>
 #include <asm/paravirt.h>
 
-unsigned long profile_pc(struct pt_regs *regs)
+static bool profile_pc_cb(void *arg, unsigned long pc)
 {
-	struct stackframe frame;
+	unsigned long *prof_pc = arg;
 
-	if (!in_lock_functions(regs->pc))
-		return regs->pc;
+	if (in_lock_functions(pc))
+		return true;
+	*prof_pc = pc;
+	return false;
+}
 
-	start_backtrace(&frame, regs->regs[29], regs->pc);
+unsigned long profile_pc(struct pt_regs *regs)
+{
+	unsigned long prof_pc = 0;
 
-	do {
-		int ret = unwind_frame(NULL, &frame);
-		if (ret < 0)
-			return 0;
-	} while (in_lock_functions(frame.pc));
+	arch_stack_walk(profile_pc_cb, &prof_pc, current, regs);
 
-	return frame.pc;
+	return prof_pc;
 }
 EXPORT_SYMBOL(profile_pc);
 
-- 
2.11.0


  parent reply	other threads:[~2021-11-17 14:08 UTC|newest]

Thread overview: 18+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-11-17 14:07 [PATCH 0/9] arm64: stacktrace: unify unwind code Mark Rutland
2021-11-17 14:07 ` [PATCH 1/9] arch: Make ARCH_STACKWALK independent of STACKTRACE Mark Rutland
2021-11-17 14:07 ` [PATCH 2/9] arm64: Add comment for stack_info::kr_cur Mark Rutland
2021-11-17 15:23   ` Mark Brown
2021-11-18 22:25   ` Masami Hiramatsu
2021-11-23 11:47   ` Mark Rutland
2021-11-17 14:07 ` [PATCH 3/9] arm64: Mark __switch_to() as __sched Mark Rutland
2021-11-17 15:42   ` Mark Brown
2021-11-17 14:07 ` [PATCH 4/9] arm64: Make perf_callchain_kernel() use arch_stack_walk() Mark Rutland
2021-11-17 14:07 ` [PATCH 5/9] arm64: Make __get_wchan() " Mark Rutland
2021-11-17 15:50   ` Mark Brown
2021-11-17 14:07 ` [PATCH 6/9] arm64: Make return_address() " Mark Rutland
2021-11-17 14:07 ` Mark Rutland [this message]
2021-11-17 15:31   ` [PATCH 7/9] arm64: Make profile_pc() " Mark Brown
2021-11-17 14:07 ` [PATCH 8/9] arm64: Make dump_backtrace() " Mark Rutland
2021-11-17 15:36   ` Mark Brown
2021-11-17 14:07 ` [PATCH 9/9] arm64: Make some stacktrace functions private Mark Rutland
2021-11-17 15:39   ` Mark Brown

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=20211117140737.44420-8-mark.rutland@arm.com \
    --to=mark.rutland@arm.com \
    --cc=aou@eecs.berkeley.edu \
    --cc=borntraeger@de.ibm.com \
    --cc=bp@alien8.de \
    --cc=broonie@kernel.org \
    --cc=catalin.marinas@arm.com \
    --cc=dave.hansen@linux.intel.com \
    --cc=gor@linux.ibm.com \
    --cc=hca@linux.ibm.com \
    --cc=linux-arm-kernel@lists.infradead.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=madvenka@linux.microsoft.com \
    --cc=mhiramat@kernel.org \
    --cc=mingo@redhat.com \
    --cc=mpe@ellerman.id.au \
    --cc=palmer@dabbelt.com \
    --cc=paul.walmsley@sifive.com \
    --cc=peterz@infradead.org \
    --cc=rostedt@goodmis.org \
    --cc=tglx@linutronix.de \
    --cc=will@kernel.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).