Commit 6e3f3617 authored by Jan Beulich's avatar Jan Beulich Committed by Linus Torvalds

[PATCH] x86_64: make trap information available to die notification handlers

This adjusts things so that handlers of the die() notifier will have
sufficient information about the trap currently being handled. It also
adjusts the notify_die() prototype to (again) match that of i386.
Signed-off-by: default avatarAndi Kleen <ak@suse.de>
Signed-off-by: default avatarLinus Torvalds <torvalds@osdl.org>
parent 5c617cfa
...@@ -169,7 +169,7 @@ void do_machine_check(struct pt_regs * regs, long error_code) ...@@ -169,7 +169,7 @@ void do_machine_check(struct pt_regs * regs, long error_code)
int panicm_found = 0; int panicm_found = 0;
if (regs) if (regs)
notify_die(DIE_NMI, "machine check", regs, error_code, 255, SIGKILL); notify_die(DIE_NMI, "machine check", regs, error_code, 18, SIGKILL);
if (!banks) if (!banks)
return; return;
......
...@@ -382,7 +382,7 @@ void __die(const char * str, struct pt_regs * regs, long err) ...@@ -382,7 +382,7 @@ void __die(const char * str, struct pt_regs * regs, long err)
printk("DEBUG_PAGEALLOC"); printk("DEBUG_PAGEALLOC");
#endif #endif
printk("\n"); printk("\n");
notify_die(DIE_OOPS, (char *)str, regs, err, 255, SIGSEGV); notify_die(DIE_OOPS, str, regs, err, current->thread.trap_no, SIGSEGV);
show_registers(regs); show_registers(regs);
/* Executive summary in case the oops scrolled away */ /* Executive summary in case the oops scrolled away */
printk(KERN_ALERT "RIP "); printk(KERN_ALERT "RIP ");
...@@ -421,19 +421,20 @@ static void __kprobes do_trap(int trapnr, int signr, char *str, ...@@ -421,19 +421,20 @@ static void __kprobes do_trap(int trapnr, int signr, char *str,
struct pt_regs * regs, long error_code, struct pt_regs * regs, long error_code,
siginfo_t *info) siginfo_t *info)
{ {
struct task_struct *tsk = current;
conditional_sti(regs); conditional_sti(regs);
if (user_mode(regs)) { tsk->thread.error_code = error_code;
struct task_struct *tsk = current; tsk->thread.trap_no = trapnr;
if (user_mode(regs)) {
if (exception_trace && unhandled_signal(tsk, signr)) if (exception_trace && unhandled_signal(tsk, signr))
printk(KERN_INFO printk(KERN_INFO
"%s[%d] trap %s rip:%lx rsp:%lx error:%lx\n", "%s[%d] trap %s rip:%lx rsp:%lx error:%lx\n",
tsk->comm, tsk->pid, str, tsk->comm, tsk->pid, str,
regs->rip,regs->rsp,error_code); regs->rip,regs->rsp,error_code);
tsk->thread.error_code = error_code;
tsk->thread.trap_no = trapnr;
if (info) if (info)
force_sig_info(signr, info, tsk); force_sig_info(signr, info, tsk);
else else
...@@ -493,19 +494,20 @@ DO_ERROR( 8, SIGSEGV, "double fault", double_fault) ...@@ -493,19 +494,20 @@ DO_ERROR( 8, SIGSEGV, "double fault", double_fault)
asmlinkage void __kprobes do_general_protection(struct pt_regs * regs, asmlinkage void __kprobes do_general_protection(struct pt_regs * regs,
long error_code) long error_code)
{ {
struct task_struct *tsk = current;
conditional_sti(regs); conditional_sti(regs);
if (user_mode(regs)) { tsk->thread.error_code = error_code;
struct task_struct *tsk = current; tsk->thread.trap_no = 13;
if (user_mode(regs)) {
if (exception_trace && unhandled_signal(tsk, SIGSEGV)) if (exception_trace && unhandled_signal(tsk, SIGSEGV))
printk(KERN_INFO printk(KERN_INFO
"%s[%d] general protection rip:%lx rsp:%lx error:%lx\n", "%s[%d] general protection rip:%lx rsp:%lx error:%lx\n",
tsk->comm, tsk->pid, tsk->comm, tsk->pid,
regs->rip,regs->rsp,error_code); regs->rip,regs->rsp,error_code);
tsk->thread.error_code = error_code;
tsk->thread.trap_no = 13;
force_sig(SIGSEGV, tsk); force_sig(SIGSEGV, tsk);
return; return;
} }
...@@ -568,7 +570,7 @@ asmlinkage void default_do_nmi(struct pt_regs *regs) ...@@ -568,7 +570,7 @@ asmlinkage void default_do_nmi(struct pt_regs *regs)
reason = get_nmi_reason(); reason = get_nmi_reason();
if (!(reason & 0xc0)) { if (!(reason & 0xc0)) {
if (notify_die(DIE_NMI_IPI, "nmi_ipi", regs, reason, 0, SIGINT) if (notify_die(DIE_NMI_IPI, "nmi_ipi", regs, reason, 2, SIGINT)
== NOTIFY_STOP) == NOTIFY_STOP)
return; return;
#ifdef CONFIG_X86_LOCAL_APIC #ifdef CONFIG_X86_LOCAL_APIC
...@@ -584,7 +586,7 @@ asmlinkage void default_do_nmi(struct pt_regs *regs) ...@@ -584,7 +586,7 @@ asmlinkage void default_do_nmi(struct pt_regs *regs)
unknown_nmi_error(reason, regs); unknown_nmi_error(reason, regs);
return; return;
} }
if (notify_die(DIE_NMI, "nmi", regs, reason, 0, SIGINT) == NOTIFY_STOP) if (notify_die(DIE_NMI, "nmi", regs, reason, 2, SIGINT) == NOTIFY_STOP)
return; return;
/* AK: following checks seem to be broken on modern chipsets. FIXME */ /* AK: following checks seem to be broken on modern chipsets. FIXME */
...@@ -693,7 +695,7 @@ asmlinkage void __kprobes do_debug(struct pt_regs * regs, ...@@ -693,7 +695,7 @@ asmlinkage void __kprobes do_debug(struct pt_regs * regs,
regs->eflags &= ~TF_MASK; regs->eflags &= ~TF_MASK;
} }
static int kernel_math_error(struct pt_regs *regs, char *str) static int kernel_math_error(struct pt_regs *regs, const char *str, int trapnr)
{ {
const struct exception_table_entry *fixup; const struct exception_table_entry *fixup;
fixup = search_exception_tables(regs->rip); fixup = search_exception_tables(regs->rip);
...@@ -701,8 +703,9 @@ static int kernel_math_error(struct pt_regs *regs, char *str) ...@@ -701,8 +703,9 @@ static int kernel_math_error(struct pt_regs *regs, char *str)
regs->rip = fixup->fixup; regs->rip = fixup->fixup;
return 1; return 1;
} }
notify_die(DIE_GPF, str, regs, 0, 16, SIGFPE); notify_die(DIE_GPF, str, regs, 0, trapnr, SIGFPE);
/* Illegal floating point operation in the kernel */ /* Illegal floating point operation in the kernel */
current->thread.trap_no = trapnr;
die(str, regs, 0); die(str, regs, 0);
return 0; return 0;
} }
...@@ -721,7 +724,7 @@ asmlinkage void do_coprocessor_error(struct pt_regs *regs) ...@@ -721,7 +724,7 @@ asmlinkage void do_coprocessor_error(struct pt_regs *regs)
conditional_sti(regs); conditional_sti(regs);
if (!user_mode(regs) && if (!user_mode(regs) &&
kernel_math_error(regs, "kernel x87 math error")) kernel_math_error(regs, "kernel x87 math error", 16))
return; return;
/* /*
...@@ -790,7 +793,7 @@ asmlinkage void do_simd_coprocessor_error(struct pt_regs *regs) ...@@ -790,7 +793,7 @@ asmlinkage void do_simd_coprocessor_error(struct pt_regs *regs)
conditional_sti(regs); conditional_sti(regs);
if (!user_mode(regs) && if (!user_mode(regs) &&
kernel_math_error(regs, "kernel simd math error")) kernel_math_error(regs, "kernel simd math error", 19))
return; return;
/* /*
......
...@@ -222,10 +222,15 @@ static noinline void pgtable_bad(unsigned long address, struct pt_regs *regs, ...@@ -222,10 +222,15 @@ static noinline void pgtable_bad(unsigned long address, struct pt_regs *regs,
unsigned long error_code) unsigned long error_code)
{ {
unsigned long flags = oops_begin(); unsigned long flags = oops_begin();
struct task_struct *tsk;
printk(KERN_ALERT "%s: Corrupted page table at address %lx\n", printk(KERN_ALERT "%s: Corrupted page table at address %lx\n",
current->comm, address); current->comm, address);
dump_pagetable(address); dump_pagetable(address);
tsk = current;
tsk->thread.cr2 = address;
tsk->thread.trap_no = 14;
tsk->thread.error_code = error_code;
__die("Bad pagetable", regs, error_code); __die("Bad pagetable", regs, error_code);
oops_end(flags); oops_end(flags);
do_exit(SIGKILL); do_exit(SIGKILL);
...@@ -521,6 +526,9 @@ asmlinkage void __kprobes do_page_fault(struct pt_regs *regs, ...@@ -521,6 +526,9 @@ asmlinkage void __kprobes do_page_fault(struct pt_regs *regs,
printk_address(regs->rip); printk_address(regs->rip);
printk("\n"); printk("\n");
dump_pagetable(address); dump_pagetable(address);
tsk->thread.cr2 = address;
tsk->thread.trap_no = 14;
tsk->thread.error_code = error_code;
__die("Oops", regs, error_code); __die("Oops", regs, error_code);
/* Executive summary in case the body of the oops scrolled away */ /* Executive summary in case the body of the oops scrolled away */
printk(KERN_EMERG "CR2: %016lx\n", address); printk(KERN_EMERG "CR2: %016lx\n", address);
......
...@@ -35,9 +35,16 @@ enum die_val { ...@@ -35,9 +35,16 @@ enum die_val {
DIE_PAGE_FAULT, DIE_PAGE_FAULT,
}; };
static inline int notify_die(enum die_val val,char *str,struct pt_regs *regs,long err,int trap, int sig) static inline int notify_die(enum die_val val, const char *str,
struct pt_regs *regs, long err, int trap, int sig)
{ {
struct die_args args = { .regs=regs, .str=str, .err=err, .trapnr=trap,.signr=sig }; struct die_args args = {
.regs = regs,
.str = str,
.err = err,
.trapnr = trap,
.signr = sig
};
return notifier_call_chain(&die_chain, val, &args); return notifier_call_chain(&die_chain, val, &args);
} }
......
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