public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
From: Harvey Harrison <harvey.harrison@gmail.com>
To: Ingo Molnar <mingo@elte.hu>
Cc: "H. Peter Anvin" <hpa@zytor.com>,
	LKML <linux-kernel@vger.kernel.org>, Andi Kleen <ak@suse.de>,
	Thomas Gleixner <tglx@linutronix.de>
Subject: [RFC PATCH] x86: Pull out oops printing helper from do_page_fault
Date: Sat, 19 Jan 2008 02:17:14 -0800	[thread overview]
Message-ID: <1200737834.5724.173.camel@brick> (raw)
In-Reply-To: <20080119081331.GB12995@elte.hu>

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@gmail.com>
---
Ingo, for discussion about how the oops traces should look,
pull out a helper function.  This changes the existing format.

 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..e15b80b 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..dce2893 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




  parent reply	other threads:[~2008-01-19 10:17 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2008-01-19  4:22 [PATCH] x86: Unify printk strings in fault_32|64.c Harvey Harrison
2008-01-19  5:08 ` Andi Kleen
2008-01-19  5:12   ` Harvey Harrison
2008-01-19  8:13 ` Ingo Molnar
2008-01-19  9:04   ` Harvey Harrison
2008-01-19 10:17   ` Harvey Harrison [this message]
2008-01-19 10:26     ` [RFC PATCHv2] x86: Pull out oops printing helper from do_page_fault Harvey Harrison

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1200737834.5724.173.camel@brick \
    --to=harvey.harrison@gmail.com \
    --cc=ak@suse.de \
    --cc=hpa@zytor.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=mingo@elte.hu \
    --cc=tglx@linutronix.de \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox