linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Sangmoon Kim <sangmoon.kim@samsung.com>
To: Catalin Marinas <catalin.marinas@arm.com>, Will Deacon <will@kernel.org>
Cc: jordan.lim@samsung.com, Sangmoon Kim <sangmoon.kim@samsung.com>,
	Steven Rostedt <rostedt@goodmis.org>,
	Ingo Molnar <mingo@redhat.com>, Dave Martin <Dave.Martin@arm.com>,
	Mark Brown <broonie@kernel.org>,
	Mark Rutland <mark.rutland@arm.com>,
	Dmitry Safonov <0x7f454c46@gmail.com>,
	Amit Daniel Kachhap <amit.kachhap@arm.com>,
	Peter Collingbourne <pcc@google.com>,
	Gavin Shan <gshan@redhat.com>,
	linux-arm-kernel@lists.infradead.org,
	linux-kernel@vger.kernel.org
Subject: [PATCH] arm64: traps: add tracepoints for unusal exception cases
Date: Fri,  5 Mar 2021 21:36:30 +0900	[thread overview]
Message-ID: <20210305123635.27492-1-sangmoon.kim@samsung.com> (raw)
In-Reply-To: CGME20210305124537epcas1p1930302083680f1b1cf87e37630556460@epcas1p1.samsung.com

When kernel panic occurs, a kernel module can use either the
panic_notifier or die_notifier to obtain the debugging information.

However, in case of these exceptions like do_undefinstr(), regs and
esr data are not passed on. Although a module might be able to find
those data in the console messages, parsing text messages is very
expensive behavior for a module especially on mobile devices.

These bare tracepoints allow a module to probe regs and esr information
for debugging purpose. _tp suffix comes from bare tracepoints of
sched/core.c

Signed-off-by: Sangmoon Kim <sangmoon.kim@samsung.com>
---
 arch/arm64/kernel/traps.c    | 15 +++++++++++++
 include/trace/events/traps.h | 41 ++++++++++++++++++++++++++++++++++++
 2 files changed, 56 insertions(+)
 create mode 100644 include/trace/events/traps.h

diff --git a/arch/arm64/kernel/traps.c b/arch/arm64/kernel/traps.c
index a05d34f0e82a..e58797743442 100644
--- a/arch/arm64/kernel/traps.c
+++ b/arch/arm64/kernel/traps.c
@@ -45,6 +45,17 @@
 #include <asm/system_misc.h>
 #include <asm/sysreg.h>
 
+#define CREATE_TRACE_POINTS
+#include <trace/events/traps.h>
+
+/*
+ * Export tracepoints that act as a bare tracehook (ie: have no trace event
+ * associated with them) to allow external modules to probe them.
+ */
+EXPORT_TRACEPOINT_SYMBOL_GPL(traps_undefinstr_tp);
+EXPORT_TRACEPOINT_SYMBOL_GPL(traps_bad_mode_tp);
+EXPORT_TRACEPOINT_SYMBOL_GPL(traps_serror_panic_tp);
+
 static const char *handler[] = {
 	"Synchronous Abort",
 	"IRQ",
@@ -403,6 +414,8 @@ void do_undefinstr(struct pt_regs *regs)
 	if (call_undef_hook(regs) == 0)
 		return;
 
+	if (!user_mode(regs))
+		trace_traps_undefinstr_tp(regs, 0);
 	BUG_ON(!user_mode(regs));
 	force_signal_inject(SIGILL, ILL_ILLOPC, regs->pc, 0);
 }
@@ -766,6 +779,7 @@ asmlinkage void notrace bad_mode(struct pt_regs *regs, int reason, unsigned int
 
 	__show_regs(regs);
 	local_daif_mask();
+	trace_traps_bad_mode_tp(regs, esr);
 	panic("bad mode");
 }
 
@@ -832,6 +846,7 @@ void __noreturn arm64_serror_panic(struct pt_regs *regs, u32 esr)
 	if (regs)
 		__show_regs(regs);
 
+	trace_traps_serror_panic_tp(regs, esr);
 	nmi_panic(regs, "Asynchronous SError Interrupt");
 
 	cpu_park_loop();
diff --git a/include/trace/events/traps.h b/include/trace/events/traps.h
new file mode 100644
index 000000000000..b4f53db90ce7
--- /dev/null
+++ b/include/trace/events/traps.h
@@ -0,0 +1,41 @@
+/* SPDX-License-Identifier: GPL-2.0 */
+#undef TRACE_SYSTEM
+#define TRACE_SYSTEM traps
+
+#if !defined(_TRACE_TRAPS_H) || defined(TRACE_HEADER_MULTI_READ)
+#define _TRACE_TRAPS_H
+
+#include <linux/tracepoint.h>
+
+/*
+ * Following tracepoints are not exported in tracefs and provide hooking
+ * mechanisms only for testing and debugging purposes.
+ *
+ * Postfixed with _tp to make them easily identifiable in the code.
+ */
+
+/*
+ * Tracepoint for unhandled undefined exception at EL1.
+ */
+DECLARE_TRACE(traps_undefinstr_tp,
+	TP_PROTO(struct pt_regs *regs, unsigned int esr),
+	TP_ARGS(regs, esr));
+
+/*
+ * Tracepoint for bad_mode for the impossible case in the exception vector.
+ */
+DECLARE_TRACE(traps_bad_mode_tp,
+	TP_PROTO(struct pt_regs *regs, unsigned int esr),
+	TP_ARGS(regs, esr));
+
+/*
+ * Tracepoint for unhandled SError exception.
+ */
+DECLARE_TRACE(traps_serror_panic_tp,
+	TP_PROTO(struct pt_regs *regs, unsigned int esr),
+	TP_ARGS(regs, esr));
+
+#endif /* _TRACE_TRAPS_H */
+
+/* This part must be outside protection */
+#include <trace/define_trace.h>
-- 
2.17.1


       reply	other threads:[~2021-03-05 12:46 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
     [not found] <CGME20210305124537epcas1p1930302083680f1b1cf87e37630556460@epcas1p1.samsung.com>
2021-03-05 12:36 ` Sangmoon Kim [this message]
2021-03-08 13:31   ` [PATCH] arm64: traps: add tracepoints for unusal exception cases Mark Brown
     [not found]     ` <CGME20210316134622epcas1p488fe019ee343dd156dc077c6df9322da@epcas1p4.samsung.com>
2021-03-16 13:37       ` Sangmoon Kim
2021-03-16 15:28     ` Steven Rostedt

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=20210305123635.27492-1-sangmoon.kim@samsung.com \
    --to=sangmoon.kim@samsung.com \
    --cc=0x7f454c46@gmail.com \
    --cc=Dave.Martin@arm.com \
    --cc=amit.kachhap@arm.com \
    --cc=broonie@kernel.org \
    --cc=catalin.marinas@arm.com \
    --cc=gshan@redhat.com \
    --cc=jordan.lim@samsung.com \
    --cc=linux-arm-kernel@lists.infradead.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=mark.rutland@arm.com \
    --cc=mingo@redhat.com \
    --cc=pcc@google.com \
    --cc=rostedt@goodmis.org \
    --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).