Re: [RFC PATCHv2] x86: Pull out oops printing helper fromdo_page_fault

From: Harvey Harrison
Date: Sat Jan 19 2008 - 05:26:48 EST


Pull out an show_fault_oops() helper out from the oops printing
code in do_page_fault.

Try to make 32/64 bit oops traces have more similar format.

Signed-off-by: Harvey Harrison <harvey.harrison@xxxxxxxxx>
---
Clearly that last patch was for discussion only, he's one that
actually compiles (missing comma on args in show_fault_oops)

arch/x86/mm/fault_32.c | 53 ++++++++++++++++++++++++++---------------------
arch/x86/mm/fault_64.c | 24 +++++++++++++++------
2 files changed, 46 insertions(+), 31 deletions(-)

diff --git a/arch/x86/mm/fault_32.c b/arch/x86/mm/fault_32.c
index 0bd2417..83b4c1a 100644
--- a/arch/x86/mm/fault_32.c
+++ b/arch/x86/mm/fault_32.c
@@ -396,6 +396,34 @@ static inline int vmalloc_fault(unsigned long address)
#endif
}

+static void show_fault_oops(struct pt_regs *regs, unsigned long error_code,
+ unsigned long address)
+{
+ if (!oops_may_print())
+ return;
+
+#ifdef CONFIG_X86_PAE
+ if (error_code & PF_INSTR) {
+ int level;
+ pte_t *pte = lookup_address(address, &level);
+
+ if (pte && pte_present(*pte) && !pte_exec(*pte))
+ printk(KERN_CRIT "kernel tried to execute "
+ "NX-protected page - exploit attempt? "
+ "(uid: %d)\n", current->uid);
+ }
+#endif
+ printk(KERN_ALERT "BUG: unable to handle kernel ");
+ if (address < PAGE_SIZE)
+ printk(KERN_CONT "NULL pointer dereference");
+ else
+ printk(KERN_CONT "paging request");
+
+ printk(KERN_CONT " at: %08lx IP: %08lx\n", address, regs->ip);
+
+ dump_pagetable(address);
+}
+
int show_unhandled_signals = 1;

/*
@@ -633,30 +661,7 @@ no_context:

bust_spinlocks(1);

- if (oops_may_print()) {
-
-#ifdef CONFIG_X86_PAE
- if (error_code & PF_INSTR) {
- int level;
- pte_t *pte = lookup_address(address, &level);
-
- if (pte && pte_present(*pte) && !pte_exec(*pte))
- printk(KERN_CRIT "kernel tried to execute "
- "NX-protected page - exploit attempt? "
- "(uid: %d)\n", current->uid);
- }
-#endif
- if (address < PAGE_SIZE)
- printk(KERN_ALERT "BUG: unable to handle kernel NULL "
- "pointer dereference");
- else
- printk(KERN_ALERT "BUG: unable to handle kernel paging"
- " request");
- printk(" at virtual address %08lx\n", address);
- printk(KERN_ALERT "printing ip: %08lx ", regs->ip);
-
- dump_pagetable(address);
- }
+ show_fault_oops(regs, error_code, address);

tsk->thread.cr2 = address;
tsk->thread.trap_no = 14;
diff --git a/arch/x86/mm/fault_64.c b/arch/x86/mm/fault_64.c
index ccbb8e3..34f50f6 100644
--- a/arch/x86/mm/fault_64.c
+++ b/arch/x86/mm/fault_64.c
@@ -384,6 +384,21 @@ static int vmalloc_fault(unsigned long address)
#endif
}

+static void show_fault_oops(struct pt_regs *regs, unsigned long error_code,
+ unsigned long address)
+{
+ printk(KERN_ALERT "BUG: unable to handle kernel ");
+ if (address < PAGE_SIZE)
+ printk(KERN_CONT "NULL pointer dereference");
+ else
+ printk(KERN_CONT "paging request");
+
+ printk(KERN_CONT " at %016lx IP: \n", address);
+ printk_address(regs->ip, 1);
+
+ dump_pagetable(address);
+}
+
int show_unhandled_signals = 1;

/*
@@ -636,13 +651,8 @@ no_context:

flags = oops_begin();

- if (address < PAGE_SIZE)
- printk(KERN_ALERT "Unable to handle kernel NULL pointer dereference");
- else
- printk(KERN_ALERT "Unable to handle kernel paging request");
- printk(" at %016lx RIP: \n" KERN_ALERT, address);
- printk_address(regs->ip, 1);
- dump_pagetable(address);
+ show_fault_oops(regs, error_code, address);
+
tsk->thread.cr2 = address;
tsk->thread.trap_no = 14;
tsk->thread.error_code = error_code;
--
1.5.4.rc3.1118.gf6754c



--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/