vsprintf: introduce %pB format specifier
Subsystems (5)
PATCH v2 1/2 vsprintf: introduce %pB format specifier
The %pB format specifier is for stack backtrace. Its handler sprint_backtrace() does symbol lookup using (address-1) to ensure the address will not point outside of the function.
If there is a tail-call to the function marked "noreturn", gcc optimized out the code after the call then causes saved return address points outside of the function (i.e. the start of the next function), so pollutes call trace somewhat. This patch will fix it.
before:
Call Trace: [<ffffffff812a8502>] panic+0x8c/0x18d [<ffffffffa000012a>] deep01+0x0/0x38 [test_panic] <--- bad [<ffffffff81104666>] proc_file_write+0x73/0x8d [<ffffffff811000b3>] proc_reg_write+0x8d/0xac [<ffffffff810c7d32>] vfs_write+0xa1/0xc5 [<ffffffff810c7e0f>] sys_write+0x45/0x6c [<ffffffff8f02943b>] system_call_fastpath+0x16/0x1b
after:
Call Trace: [<ffffffff812bce69>] panic+0x8c/0x18d [<ffffffffa000012a>] panic_write+0x20/0x20 [test_panic] <--- ok [<ffffffff81115fab>] proc_file_write+0x73/0x8d [<ffffffff81111a5f>] proc_reg_write+0x8d/0xac [<ffffffff810d90ee>] vfs_write+0xa1/0xc5 [<ffffffff810d91cb>] sys_write+0x45/0x6c [<ffffffff812c07fb>] system_call_fastpath+0x16/0x1b
--- include/linux/kallsyms.h | 7 +++++++ kernel/kallsyms.c | 44 +++++++++++++++++++++++++++++++++++++++++--- lib/vsprintf.c | 7 ++++++- 3 files changed, 54 insertions(+), 4 deletions(-)
include/linux/kallsyms.h +7 -0
@@ -36,6 +36,7 @@ const char *kallsyms_lookup(unsigned long addr,/* Look up a kernel symbol and return it in a text buffer. */ extern int sprint_symbol (char *buffer,unsigned long address); +extern int sprint_backtrace (char *buffer,unsigned long address);/* Look up a kernel symbol and print it to the kernel messages. */ extern void __print_symbol (const char *fmt,unsigned long address);
@@ -79,6 +80,12 @@ static inline int sprint_symbol(char *buffer, unsigned long addr)return 0 ; } +static inline int sprint_backtrace (char *buffer,unsigned long addr) +{ + *buffer ='\0' ; +return 0 ; +} +static inline int lookup_symbol_name (unsigned long addr,char *symname) {return -ERANGE ;
kernel/kallsyms.c +41 -3
71 lines not on this page · raw message
lib/vsprintf.c +6 -1
@@ -433,7 +433,9 @@ char *symbol_string(char *buf, char *end, void *ptr,unsigned long value = (unsigned long ) ptr;#ifdef CONFIG_KALLSYMS char sym[KSYM_SYMBOL_LEN ]; -if (ext !='f' && ext !='s' ) +if (ext =='B' ) +sprint_backtrace (sym, value); +else if (ext !='f' && ext !='s' )sprint_symbol (sym, value);else kallsyms_lookup (value,NULL ,NULL ,NULL , sym);
@@ -808,6 +810,7 @@ int kptr_restrict = 1;* - 'f' For simple symbolic function names without offset * - 'S' For symbolic direct pointers with offset * - 's' For symbolic direct pointers without offset +* - 'B' For backtraced symbolic direct pointers with offset * - 'R' For decoded struct resource, e.g., [mem 0x0-0x1f 64bit pref] * - 'r' For raw struct resource, e.g., [mem 0x0-0x1f flags 0x201] * - 'M' For a 6-byte MAC address, it prints the address in the
@@ -867,6 +870,7 @@ char *pointer(const char *fmt, char *buf, char *end, void *ptr,/* Fallthrough */ case 'S' :case 's' : +case 'B' :return symbol_string (buf, end, ptr, spec, *fmt);case 'R' :case 'r' :
@@ -1134,6 +1138,7 @@ qualifier:* %ps output the name of a text symbol without offset * %pF output the name of a function pointer with its offset * %pf output the name of a function pointer without its offset +* %pB output the name of a backtrace symbol with its offset * %pR output the address range in a struct resource with decoded flags * %pr output the address range in a struct resource with raw flags * %pM output a 6-byte MAC address with colons
--
1.7.4
PATCH v2 2/2 x86, dumpstack: use %pB format specifier for stack trace
--- arch/x86/kernel/dumpstack.c | 2 +- 1 files changed, 1 insertions(+), 1 deletions(-)
arch/x86/kernel/dumpstack.c +1 -1
@@ -27,7 +27,7 @@ static int die_counter;void printk_address (unsigned long address,int reliable) { -printk (" [<%p>] %s%pS\n" , (void *) address, +printk (" [<%p>] %s%pB\n" , (void *) address, reliable ?"" :"? " , (void *) address); }
--
1.7.4
[tip:core/urgent] x86, dumpstack: Use %pB format specifier for stack trace
Commit-ID: 71f9e59800e5ad4e6b683348424c9fe54306cd43 Gitweb: http://git.kernel.org/tip/71f9e59800e5ad4e6b683348424c9fe54306cd43 Author: Namhyung Kim <[email protected]> AuthorDate: Thu, 24 Mar 2011 11:42:30 +0900 Committer: Ingo Molnar <[email protected]> CommitDate: Thu, 24 Mar 2011 08:36:10 +0100
x86, dumpstack: Use %pB format specifier for stack trace
Improve noreturn function entries in call traces:
Before:
Call Trace: [<ffffffff812a8502>] panic+0x8c/0x18d [<ffffffffa000012a>] deep01+0x0/0x38 [test_panic] <--- bad [<ffffffff81104666>] proc_file_write+0x73/0x8d [<ffffffff811000b3>] proc_reg_write+0x8d/0xac [<ffffffff810c7d32>] vfs_write+0xa1/0xc5 [<ffffffff810c7e0f>] sys_write+0x45/0x6c [<ffffffff8f02943b>] system_call_fastpath+0x16/0x1b
After:
Call Trace: [<ffffffff812bce69>] panic+0x8c/0x18d [<ffffffffa000012a>] panic_write+0x20/0x20 [test_panic] <--- good [<ffffffff81115fab>] proc_file_write+0x73/0x8d [<ffffffff81111a5f>] proc_reg_write+0x8d/0xac [<ffffffff810d90ee>] vfs_write+0xa1/0xc5 [<ffffffff810d91cb>] sys_write+0x45/0x6c [<ffffffff812c07fb>] system_call_fastpath+0x16/0x1b
LKML-Reference: <[email protected]>
--- arch/x86/kernel/dumpstack.c | 2 +- 1 files changed, 1 insertions(+), 1 deletions(-)
arch/x86/kernel/dumpstack.c +1 -1
@@ -27,7 +27,7 @@ static int die_counter;void printk_address (unsigned long address,int reliable) { -printk (" [<%p>] %s%pS\n" , (void *) address, +printk (" [<%p>] %s%pB\n" , (void *) address, reliable ?"" :"? " , (void *) address); }
[tip:core/urgent] vsprintf: Introduce %pB format specifier
In reply to Namhyung KimCommit-ID: 0f77a8d378254f27df4a114a5da67223af1fe93f Gitweb: http://git.kernel.org/tip/0f77a8d378254f27df4a114a5da67223af1fe93f Author: Namhyung Kim <[email protected]> AuthorDate: Thu, 24 Mar 2011 11:42:29 +0900 Committer: Ingo Molnar <[email protected]> CommitDate: Thu, 24 Mar 2011 08:36:10 +0100
vsprintf: Introduce %pB format specifier
The %pB format specifier is for stack backtrace. Its handler sprint_backtrace() does symbol lookup using (address-1) to ensure the address will not point outside of the function.
If there is a tail-call to the function marked "noreturn", gcc optimized out the code after the call then causes saved return address points outside of the function (i.e. the start of the next function), so pollutes call trace somewhat.
This patch adds the %pB printk mechanism that allows architecture call-trace printout functions to improve backtrace printouts.
LKML-Reference: <[email protected]>
--- include/linux/kallsyms.h | 7 +++++++ kernel/kallsyms.c | 44 +++++++++++++++++++++++++++++++++++++++++--- lib/vsprintf.c | 7 ++++++- 3 files changed, 54 insertions(+), 4 deletions(-)
include/linux/kallsyms.h +7 -0
@@ -36,6 +36,7 @@ const char *kallsyms_lookup(unsigned long addr,/* Look up a kernel symbol and return it in a text buffer. */ extern int sprint_symbol (char *buffer,unsigned long address); +extern int sprint_backtrace (char *buffer,unsigned long address);/* Look up a kernel symbol and print it to the kernel messages. */ extern void __print_symbol (const char *fmt,unsigned long address);
@@ -79,6 +80,12 @@ static inline int sprint_symbol(char *buffer, unsigned long addr)return 0 ; } +static inline int sprint_backtrace (char *buffer,unsigned long addr) +{ + *buffer ='\0' ; +return 0 ; +} +static inline int lookup_symbol_name (unsigned long addr,char *symname) {return -ERANGE ;
kernel/kallsyms.c +41 -3
71 lines not on this page · raw message
lib/vsprintf.c +6 -1
@@ -574,7 +574,9 @@ char *symbol_string(char *buf, char *end, void *ptr,unsigned long value = (unsigned long ) ptr;#ifdef CONFIG_KALLSYMS char sym[KSYM_SYMBOL_LEN ]; -if (ext !='f' && ext !='s' ) +if (ext =='B' ) +sprint_backtrace (sym, value); +else if (ext !='f' && ext !='s' )sprint_symbol (sym, value);else kallsyms_lookup (value,NULL ,NULL ,NULL , sym);
@@ -949,6 +951,7 @@ int kptr_restrict = 1;* - 'f' For simple symbolic function names without offset * - 'S' For symbolic direct pointers with offset * - 's' For symbolic direct pointers without offset +* - 'B' For backtraced symbolic direct pointers with offset * - 'R' For decoded struct resource, e.g., [mem 0x0-0x1f 64bit pref] * - 'r' For raw struct resource, e.g., [mem 0x0-0x1f flags 0x201] * - 'M' For a 6-byte MAC address, it prints the address in the
@@ -1008,6 +1011,7 @@ char *pointer(const char *fmt, char *buf, char *end, void *ptr,/* Fallthrough */ case 'S' :case 's' : +case 'B' :return symbol_string (buf, end, ptr, spec, *fmt);case 'R' :case 'r' :
@@ -1279,6 +1283,7 @@ qualifier:* %ps output the name of a text symbol without offset * %pF output the name of a function pointer with its offset * %pf output the name of a function pointer without its offset +* %pB output the name of a backtrace symbol with its offset * %pR output the address range in a struct resource with decoded flags * %pr output the address range in a struct resource with raw flags * %pM output a 6-byte MAC address with colons