From bb8c223f2f0b301c0d1440472c8cb2d23fa3ee27 Mon Sep 17 00:00:00 2001 From: Sangmoon Kim Date: Tue, 19 Jan 2021 21:24:58 +0900 Subject: [PATCH] ANDROID: arm64: add vendor hooks for unusal abort cases Add hooks to gather data of unsual aborts and summarize it with other information. Bug: 273189923 Signed-off-by: Sangmoon Kim Change-Id: I74eb36b8551ed9a5e6dc87507939a7f4d81c9c18 (cherry picked from commit 102255d1e45607da700f715c5c100427170751a2) --- arch/arm64/kernel/entry-common.c | 3 +++ arch/arm64/kernel/traps.c | 7 +++++++ drivers/android/vendor_hooks.c | 6 ++++++ include/trace/hooks/traps.h | 35 ++++++++++++++++++++++++++++++++ 4 files changed, 51 insertions(+) create mode 100644 include/trace/hooks/traps.h diff --git a/arch/arm64/kernel/entry-common.c b/arch/arm64/kernel/entry-common.c index 27369fa1c032..08015c9e19b7 100644 --- a/arch/arm64/kernel/entry-common.c +++ b/arch/arm64/kernel/entry-common.c @@ -27,6 +27,8 @@ #include #include +#include + /* * Handle IRQ/context state management when entering from kernel mode. * Before this function is called it is not safe to call regular kernel code, @@ -292,6 +294,7 @@ static void noinstr __panic_unhandled(struct pt_regs *regs, const char *vector, vector, smp_processor_id(), esr, esr_get_class_string(esr)); + trace_android_rvh_panic_unhandled(regs, vector, esr); __show_regs(regs); panic("Unhandled exception"); } diff --git a/arch/arm64/kernel/traps.c b/arch/arm64/kernel/traps.c index 23d281ed7621..96ba7018947f 100644 --- a/arch/arm64/kernel/traps.c +++ b/arch/arm64/kernel/traps.c @@ -46,6 +46,8 @@ #include #include +#include + static bool __kprobes __check_eq(unsigned long pstate) { return (pstate & PSR_Z_BIT) != 0; @@ -495,6 +497,7 @@ void do_undefinstr(struct pt_regs *regs, unsigned long esr) if (call_undef_hook(regs) == 0) return; + trace_android_rvh_do_undefinstr(regs, esr); if (!user_mode(regs)) die("Oops - Undefined instruction", regs, esr); @@ -509,6 +512,7 @@ void do_el0_bti(struct pt_regs *regs) void do_el1_bti(struct pt_regs *regs, unsigned long esr) { + trace_android_rvh_do_el1_bti(regs, esr); die("Oops - BTI", regs, esr); } NOKPROBE_SYMBOL(do_el1_bti); @@ -524,6 +528,7 @@ void do_el1_fpac(struct pt_regs *regs, unsigned long esr) * Unexpected FPAC exception in the kernel: kill the task before it * does any more harm. */ + trace_android_rvh_do_el1_fpac(regs, esr); die("Oops - FPAC", regs, esr); } NOKPROBE_SYMBOL(do_el1_fpac) @@ -915,6 +920,8 @@ void __noreturn arm64_serror_panic(struct pt_regs *regs, unsigned long esr) pr_crit("SError Interrupt on CPU%d, code 0x%016lx -- %s\n", smp_processor_id(), esr, esr_get_class_string(esr)); + + trace_android_rvh_arm64_serror_panic(regs, esr); if (regs) __show_regs(regs); diff --git a/drivers/android/vendor_hooks.c b/drivers/android/vendor_hooks.c index 7890fcee9306..ba3377a48d00 100644 --- a/drivers/android/vendor_hooks.c +++ b/drivers/android/vendor_hooks.c @@ -53,6 +53,7 @@ #include #include #include +#include /* * Export tracepoints that act as a bare tracehook (ie: have no trace event @@ -165,3 +166,8 @@ EXPORT_TRACEPOINT_SYMBOL_GPL(android_vh_try_to_freeze_todo_unfrozen); EXPORT_TRACEPOINT_SYMBOL_GPL(android_rvh_die_kernel_fault); EXPORT_TRACEPOINT_SYMBOL_GPL(android_rvh_do_sea); EXPORT_TRACEPOINT_SYMBOL_GPL(android_rvh_do_sp_pc_abort); +EXPORT_TRACEPOINT_SYMBOL_GPL(android_rvh_do_undefinstr); +EXPORT_TRACEPOINT_SYMBOL_GPL(android_rvh_do_el1_bti); +EXPORT_TRACEPOINT_SYMBOL_GPL(android_rvh_do_el1_fpac); +EXPORT_TRACEPOINT_SYMBOL_GPL(android_rvh_panic_unhandled); +EXPORT_TRACEPOINT_SYMBOL_GPL(android_rvh_arm64_serror_panic); diff --git a/include/trace/hooks/traps.h b/include/trace/hooks/traps.h new file mode 100644 index 000000000000..a11a1d32ccc0 --- /dev/null +++ b/include/trace/hooks/traps.h @@ -0,0 +1,35 @@ +/* SPDX-License-Identifier: GPL-2.0 */ +#undef TRACE_SYSTEM +#define TRACE_SYSTEM traps +#define TRACE_INCLUDE_PATH trace/hooks + +#if !defined(_TRACE_HOOK_TRAPS_H) || defined(TRACE_HEADER_MULTI_READ) +#define _TRACE_HOOK_TRAPS_H +#include + +struct pt_regs; + +DECLARE_RESTRICTED_HOOK(android_rvh_do_undefinstr, + TP_PROTO(struct pt_regs *regs, unsigned long esr), + TP_ARGS(regs, esr), + TP_CONDITION(!user_mode(regs))); + +DECLARE_RESTRICTED_HOOK(android_rvh_do_el1_bti, + TP_PROTO(struct pt_regs *regs, unsigned long esr), + TP_ARGS(regs, esr), 1); + +DECLARE_RESTRICTED_HOOK(android_rvh_do_el1_fpac, + TP_PROTO(struct pt_regs *regs, unsigned long esr), + TP_ARGS(regs, esr), 1); + +DECLARE_RESTRICTED_HOOK(android_rvh_panic_unhandled, + TP_PROTO(struct pt_regs *regs, const char *vector, unsigned long esr), + TP_ARGS(regs, vector, esr), 1); + +DECLARE_RESTRICTED_HOOK(android_rvh_arm64_serror_panic, + TP_PROTO(struct pt_regs *regs, unsigned long esr), + TP_ARGS(regs, esr), 1); + +#endif /* _TRACE_HOOK_TRAPS_H */ +/* This part must be outside protection */ +#include