From: Nicholas Piggin <npiggin@gmail.com>
To: linuxppc-dev@lists.ozlabs.org
Cc: "Naveen N . Rao" <naveen.n.rao@linux.vnet.ibm.com>,
Nicholas Piggin <npiggin@gmail.com>
Subject: [PATCH] powerpc/64: ftrace don't trace real mode
Date: Sat, 21 Mar 2020 01:25:51 +1000 [thread overview]
Message-ID: <20200320152551.1468983-1-npiggin@gmail.com> (raw)
This warns and prevents tracing attempted in a real-mode context.
Signed-off-by: Nicholas Piggin <npiggin@gmail.com>
---
arch/powerpc/kernel/trace/ftrace.c | 3 +++
.../powerpc/kernel/trace/ftrace_64_mprofile.S | 19 +++++++++++++++----
2 files changed, 18 insertions(+), 4 deletions(-)
diff --git a/arch/powerpc/kernel/trace/ftrace.c b/arch/powerpc/kernel/trace/ftrace.c
index 7ea0ca044b65..ef965815fcb9 100644
--- a/arch/powerpc/kernel/trace/ftrace.c
+++ b/arch/powerpc/kernel/trace/ftrace.c
@@ -949,6 +949,9 @@ unsigned long prepare_ftrace_return(unsigned long parent, unsigned long ip,
{
unsigned long return_hooker;
+ if (WARN_ON_ONCE((mfmsr() & (MSR_IR|MSR_DR)) != (MSR_IR|MSR_DR)))
+ goto out;
+
if (unlikely(ftrace_graph_is_dead()))
goto out;
diff --git a/arch/powerpc/kernel/trace/ftrace_64_mprofile.S b/arch/powerpc/kernel/trace/ftrace_64_mprofile.S
index f9fd5f743eba..6205f15cb603 100644
--- a/arch/powerpc/kernel/trace/ftrace_64_mprofile.S
+++ b/arch/powerpc/kernel/trace/ftrace_64_mprofile.S
@@ -51,16 +51,21 @@ _GLOBAL(ftrace_regs_caller)
SAVE_10GPRS(12, r1)
SAVE_10GPRS(22, r1)
- /* Save previous stack pointer (r1) */
- addi r8, r1, SWITCH_FRAME_SIZE
- std r8, GPR1(r1)
-
/* Load special regs for save below */
mfmsr r8
mfctr r9
mfxer r10
mfcr r11
+ /* Shouldn't be called in real mode */
+ andi. r3,r8,(MSR_IR|MSR_DR)
+ cmpdi r3,(MSR_IR|MSR_DR)
+ bne ftrace_bad_realmode
+
+ /* Save previous stack pointer (r1) */
+ addi r8, r1, SWITCH_FRAME_SIZE
+ std r8, GPR1(r1)
+
/* Get the _mcount() call site out of LR */
mflr r7
/* Save it as pt_regs->nip */
@@ -141,6 +146,12 @@ _GLOBAL(ftrace_graph_stub)
_GLOBAL(ftrace_stub)
blr
+ftrace_bad_realmode:
+ REST_4GPRS(8, r1)
+#ifdef CONFIG_BUG
+1: trap
+ EMIT_BUG_ENTRY 1b,__FILE__,__LINE__,(BUGFLAG_WARNING | BUGFLAG_ONCE)
+#endif
ftrace_no_trace:
mflr r3
mtctr r3
--
2.23.0
next reply other threads:[~2020-03-20 15:36 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
2020-03-20 15:25 Nicholas Piggin [this message]
2020-03-20 18:39 ` [PATCH] powerpc/64: ftrace don't trace real mode Naveen N. Rao
2020-03-21 6:32 ` Nicholas Piggin
2020-03-22 16:17 ` Naveen N. Rao
2020-03-23 4:10 ` Nicholas Piggin
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=20200320152551.1468983-1-npiggin@gmail.com \
--to=npiggin@gmail.com \
--cc=linuxppc-dev@lists.ozlabs.org \
--cc=naveen.n.rao@linux.vnet.ibm.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