From 307ad9fb59d6dc7b5c8277d1c3a623b66dad91ce Mon Sep 17 00:00:00 2001 From: Ben Dai Date: Wed, 9 Mar 2022 17:10:33 +0800 Subject: [PATCH] ANDROID: printk: add vendor hook to record more information about caller With these hooks, printk can provide more information, such as the processor ID. Bug: 223302138 Signed-off-by: Ben Dai Change-Id: Iac60ffd49640d8badf5c5dd446c211d37bbbc6a6 --- drivers/android/vendor_hooks.c | 3 +++ include/trace/hooks/printk.h | 10 ++++++++++ kernel/printk/printk.c | 21 +++++++++++++++++---- 3 files changed, 30 insertions(+), 4 deletions(-) diff --git a/drivers/android/vendor_hooks.c b/drivers/android/vendor_hooks.c index a03683cb5647..c98fa4f0cab2 100644 --- a/drivers/android/vendor_hooks.c +++ b/drivers/android/vendor_hooks.c @@ -89,6 +89,9 @@ EXPORT_TRACEPOINT_SYMBOL_GPL(android_vh_ipi_stop); EXPORT_TRACEPOINT_SYMBOL_GPL(android_vh_sysrq_crash); EXPORT_TRACEPOINT_SYMBOL_GPL(android_vh_dump_throttled_rt_tasks); EXPORT_TRACEPOINT_SYMBOL_GPL(android_vh_printk_hotplug); +EXPORT_TRACEPOINT_SYMBOL_GPL(android_vh_printk_caller_id); +EXPORT_TRACEPOINT_SYMBOL_GPL(android_vh_printk_caller); +EXPORT_TRACEPOINT_SYMBOL_GPL(android_vh_printk_ext_header); EXPORT_TRACEPOINT_SYMBOL_GPL(android_vh_jiffies_update); EXPORT_TRACEPOINT_SYMBOL_GPL(android_vh_gic_v3_set_affinity); EXPORT_TRACEPOINT_SYMBOL_GPL(android_vh_gic_set_affinity); diff --git a/include/trace/hooks/printk.h b/include/trace/hooks/printk.h index 44599c9cd9a2..da99776df6f6 100644 --- a/include/trace/hooks/printk.h +++ b/include/trace/hooks/printk.h @@ -14,6 +14,16 @@ DECLARE_HOOK(android_vh_printk_hotplug, TP_PROTO(int *flag), TP_ARGS(flag)); +DECLARE_HOOK(android_vh_printk_caller_id, + TP_PROTO(u32 *caller_id), + TP_ARGS(caller_id)); +DECLARE_HOOK(android_vh_printk_caller, + TP_PROTO(char *caller, size_t size, u32 id, int *ret), + TP_ARGS(caller, size, id, ret)); +DECLARE_HOOK(android_vh_printk_ext_header, + TP_PROTO(char *caller, size_t size, u32 id, int *ret), + TP_ARGS(caller, size, id, ret)); + #endif /* _TRACE_HOOK_PRINTK_H */ /* This part must be outside protection */ #include diff --git a/kernel/printk/printk.c b/kernel/printk/printk.c index 9eb902a4be3d..491def8f2881 100644 --- a/kernel/printk/printk.c +++ b/kernel/printk/printk.c @@ -557,10 +557,14 @@ static ssize_t info_print_ext_header(char *buf, size_t size, u64 ts_usec = info->ts_nsec; char caller[20]; #ifdef CONFIG_PRINTK_CALLER + int vh_ret = 0; u32 id = info->caller_id; - snprintf(caller, sizeof(caller), ",caller=%c%u", - id & 0x80000000 ? 'C' : 'T', id & ~0x80000000); + trace_android_vh_printk_ext_header(caller, sizeof(caller), id, &vh_ret); + + if (!vh_ret) + snprintf(caller, sizeof(caller), ",caller=%c%u", + id & 0x80000000 ? 'C' : 'T', id & ~0x80000000); #else caller[0] = '\0'; #endif @@ -1269,9 +1273,12 @@ static size_t print_time(u64 ts, char *buf) static size_t print_caller(u32 id, char *buf) { char caller[12]; + int vh_ret = 0; - snprintf(caller, sizeof(caller), "%c%u", - id & 0x80000000 ? 'C' : 'T', id & ~0x80000000); + trace_android_vh_printk_caller(caller, sizeof(caller), id, &vh_ret); + if (!vh_ret) + snprintf(caller, sizeof(caller), "%c%u", + id & 0x80000000 ? 'C' : 'T', id & ~0x80000000); return sprintf(buf, "[%6s]", caller); } #else @@ -2020,6 +2027,12 @@ static inline void printk_delay(void) static inline u32 printk_caller_id(void) { + u32 caller_id = 0; + + trace_android_vh_printk_caller_id(&caller_id); + if (caller_id) + return caller_id; + return in_task() ? task_pid_nr(current) : 0x80000000 + raw_smp_processor_id(); }