Commit a25bd949 authored by Arjan van de Ven's avatar Arjan van de Ven Committed by Ingo Molnar

x86: add the "print code before the trapping instruction" feature to 64 bit

The 32 bit x86 tree has a very useful feature that prints the Code: line
for the code even before the trapping instrution (and the start of the
trapping instruction is then denoted with a <>). Unfortunately, the 64 bit
x86 tree does not yet have this feature, making diagnosing backtraces harder
than needed.

This patch adds this feature in the same was as the 32 bit tree has
(including the same kernel boot parameter), and including a bugfix
to make the code use probe_kernel_address() rarther than a buggy (deadlocking)
__get_user.
Signed-off-by: default avatarArjan van de Ven <arjan@linux.intel.com>
Signed-off-by: default avatarIngo Molnar <mingo@elte.hu>
Signed-off-by: default avatarThomas Gleixner <tglx@linutronix.de>
parent 6dab2778
...@@ -416,8 +416,8 @@ and is between 256 and 4096 characters. It is defined in the file ...@@ -416,8 +416,8 @@ and is between 256 and 4096 characters. It is defined in the file
[SPARC64] tick [SPARC64] tick
[X86-64] hpet,tsc [X86-64] hpet,tsc
code_bytes [IA32] How many bytes of object code to print in an code_bytes [IA32/X86_64] How many bytes of object code to print
oops report. in an oops report.
Range: 0 - 8192 Range: 0 - 8192
Default: 64 Default: 64
......
...@@ -74,6 +74,8 @@ asmlinkage void alignment_check(void); ...@@ -74,6 +74,8 @@ asmlinkage void alignment_check(void);
asmlinkage void machine_check(void); asmlinkage void machine_check(void);
asmlinkage void spurious_interrupt_bug(void); asmlinkage void spurious_interrupt_bug(void);
static unsigned int code_bytes = 64;
static inline void conditional_sti(struct pt_regs *regs) static inline void conditional_sti(struct pt_regs *regs)
{ {
if (regs->flags & X86_EFLAGS_IF) if (regs->flags & X86_EFLAGS_IF)
...@@ -459,12 +461,15 @@ EXPORT_SYMBOL(dump_stack); ...@@ -459,12 +461,15 @@ EXPORT_SYMBOL(dump_stack);
void show_registers(struct pt_regs *regs) void show_registers(struct pt_regs *regs)
{ {
int i; int i;
int in_kernel = !user_mode(regs);
unsigned long sp; unsigned long sp;
const int cpu = smp_processor_id(); const int cpu = smp_processor_id();
struct task_struct *cur = cpu_pda(cpu)->pcurrent; struct task_struct *cur = cpu_pda(cpu)->pcurrent;
u8 *ip;
unsigned int code_prologue = code_bytes * 43 / 64;
unsigned int code_len = code_bytes;
sp = regs->sp; sp = regs->sp;
ip = (u8 *) regs->ip - code_prologue;
printk("CPU %d ", cpu); printk("CPU %d ", cpu);
__show_regs(regs); __show_regs(regs);
printk("Process %s (pid: %d, threadinfo %p, task %p)\n", printk("Process %s (pid: %d, threadinfo %p, task %p)\n",
...@@ -474,22 +479,28 @@ void show_registers(struct pt_regs *regs) ...@@ -474,22 +479,28 @@ void show_registers(struct pt_regs *regs)
* When in-kernel, we also print out the stack and code at the * When in-kernel, we also print out the stack and code at the
* time of the fault.. * time of the fault..
*/ */
if (in_kernel) { if (!user_mode(regs)) {
unsigned char c;
printk("Stack: "); printk("Stack: ");
_show_stack(NULL, regs, (unsigned long *)sp, regs->bp); _show_stack(NULL, regs, (unsigned long *)sp, regs->bp);
printk("\n");
printk("\nCode: "); printk(KERN_EMERG "Code: ");
if (regs->ip < PAGE_OFFSET) if (ip < (u8 *)PAGE_OFFSET || probe_kernel_address(ip, c)) {
goto bad; /* try starting at RIP */
ip = (u8 *) regs->ip;
for (i=0; i<20; i++) { code_len = code_len - code_prologue + 1;
unsigned char c; }
if (__get_user(c, &((unsigned char*)regs->ip)[i])) { for (i = 0; i < code_len; i++, ip++) {
bad: if (ip < (u8 *)PAGE_OFFSET ||
probe_kernel_address(ip, c)) {
printk(" Bad RIP value."); printk(" Bad RIP value.");
break; break;
} }
printk("%02x ", c); if (ip == (u8 *)regs->ip)
printk("<%02x> ", c);
else
printk("%02x ", c);
} }
} }
printk("\n"); printk("\n");
...@@ -1164,3 +1175,14 @@ static int __init kstack_setup(char *s) ...@@ -1164,3 +1175,14 @@ static int __init kstack_setup(char *s)
return 0; return 0;
} }
early_param("kstack", kstack_setup); early_param("kstack", kstack_setup);
static int __init code_bytes_setup(char *s)
{
code_bytes = simple_strtoul(s, NULL, 0);
if (code_bytes > 8192)
code_bytes = 8192;
return 1;
}
__setup("code_bytes=", code_bytes_setup);
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment