+ use-generic-bug-for-x86-64.patch added to -mm tree

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



The patch titled

     Use generic BUG for x86-64

has been added to the -mm tree.  Its filename is

     use-generic-bug-for-x86-64.patch

See http://www.zip.com.au/~akpm/linux/patches/stuff/added-to-mm.txt to find
out what to do about this

------------------------------------------------------
Subject: Use generic BUG for x86-64
From: Jeremy Fitzhardinge <jeremy@xxxxxxxx>

This makes x86-64 use the generic BUG machinery.  This changes the behaviour
of BUG in a few ways; most significantly, x86-64 now also records the function
name as well andthe file and line number of each BUG.  This was done to make
it consistent with the powerpc.

The main advantage in using the generic BUG machinery for x86-64 is that the
inlined overhead of BUG is just the ud2a instruction; the file+line(+function)
information are no longer inlined into the instruction stream.  This reduces
cache pollution.

Signed-off-by: Jeremy Fitzhardinge <jeremy@xxxxxxxx>
Cc: Andrew Morton <akpm@xxxxxxxx>
Cc: Andi Kleen <ak@xxxxxx>
Cc: Hugh Dickens <hugh@xxxxxxxxxxx>
Cc: Michael Ellerman <michael@xxxxxxxxxxxxxx>
Cc: Paul Mackerras <paulus@xxxxxxxxx>
Cc: Benjamin Herrenschmidt <benh@xxxxxxxxxxxxxxxxxxx>
Cc: Rusty Russell <rusty@xxxxxxxxxxxxxxx>
Signed-off-by: Andrew Morton <akpm@xxxxxxxx>
---

 arch/x86_64/Kconfig              |    5 +++
 arch/x86_64/kernel/module.c      |    5 ++-
 arch/x86_64/kernel/traps.c       |   36 +++++++----------------
 arch/x86_64/kernel/vmlinux.lds.S |    2 +
 include/asm-x86_64/bug.h         |   45 ++++++++++++++++++++---------
 5 files changed, 55 insertions(+), 38 deletions(-)

diff -puN arch/x86_64/Kconfig~use-generic-bug-for-x86-64 arch/x86_64/Kconfig
--- a/arch/x86_64/Kconfig~use-generic-bug-for-x86-64
+++ a/arch/x86_64/Kconfig
@@ -88,6 +88,11 @@ config AUDIT_ARCH
 	bool
 	default y
 
+config GENERIC_BUG
+	bool
+	default y
+	depends on BUG
+
 source "init/Kconfig"
 
 
diff -puN arch/x86_64/kernel/module.c~use-generic-bug-for-x86-64 arch/x86_64/kernel/module.c
--- a/arch/x86_64/kernel/module.c~use-generic-bug-for-x86-64
+++ a/arch/x86_64/kernel/module.c
@@ -23,6 +23,7 @@
 #include <linux/string.h>
 #include <linux/kernel.h>
 #include <linux/slab.h>
+#include <linux/bug.h>
 
 #include <asm/system.h>
 #include <asm/page.h>
@@ -173,10 +174,12 @@ int module_finalize(const Elf_Ehdr *hdr,
 					    lseg, lseg + locks->sh_size,
 					    tseg, tseg + text->sh_size);
 	}
-	return 0;
+
+	return module_bug_finalize(hdr, sechdrs, me);
 }
 
 void module_arch_cleanup(struct module *mod)
 {
 	alternatives_smp_module_del(mod);
+	module_bug_cleanup(mod);
 }
diff -puN arch/x86_64/kernel/traps.c~use-generic-bug-for-x86-64 arch/x86_64/kernel/traps.c
--- a/arch/x86_64/kernel/traps.c~use-generic-bug-for-x86-64
+++ a/arch/x86_64/kernel/traps.c
@@ -29,6 +29,7 @@
 #include <linux/kprobes.h>
 #include <linux/kexec.h>
 #include <linux/unwind.h>
+#include <linux/bug.h>
 
 #include <asm/system.h>
 #include <asm/uaccess.h>
@@ -502,30 +503,15 @@ bad:
 	printk("\n");
 }	
 
-void handle_BUG(struct pt_regs *regs)
-{ 
-	struct bug_frame f;
-	long len;
-	const char *prefix = "";
+int is_valid_bugaddr(unsigned long rip)
+{
+	unsigned short ud2;
 
-	if (user_mode(regs))
-		return; 
-	if (__copy_from_user(&f, (const void __user *) regs->rip,
-			     sizeof(struct bug_frame)))
-		return; 
-	if (f.filename >= 0 ||
-	    f.ud2[0] != 0x0f || f.ud2[1] != 0x0b) 
-		return;
-	len = __strnlen_user((char *)(long)f.filename, PATH_MAX) - 1;
-	if (len < 0 || len >= PATH_MAX)
-		f.filename = (int)(long)"unmapped filename";
-	else if (len > 50) {
-		f.filename += len - 50;
-		prefix = "...";
-	}
-	printk("----------- [cut here ] --------- [please bite here ] ---------\n");
-	printk(KERN_ALERT "Kernel BUG at %s%.50s:%d\n", prefix, (char *)(long)f.filename, f.line);
-} 
+	if (__copy_from_user(&ud2, (const void __user *) rip, sizeof(ud2)))
+		return 0;
+
+	return ud2 == 0x0b0f;
+}
 
 #ifdef CONFIG_BUG
 void out_of_line_bug(void)
@@ -606,7 +592,9 @@ void die(const char * str, struct pt_reg
 {
 	unsigned long flags = oops_begin();
 
-	handle_BUG(regs);
+	if (!user_mode(regs))
+		report_bug(regs->rip);
+
 	__die(str, regs, err);
 	oops_end(flags);
 	do_exit(SIGSEGV); 
diff -puN arch/x86_64/kernel/vmlinux.lds.S~use-generic-bug-for-x86-64 arch/x86_64/kernel/vmlinux.lds.S
--- a/arch/x86_64/kernel/vmlinux.lds.S~use-generic-bug-for-x86-64
+++ a/arch/x86_64/kernel/vmlinux.lds.S
@@ -50,6 +50,8 @@ SECTIONS
 
   RODATA
 
+  BUG_TABLE
+
 #ifdef CONFIG_STACK_UNWIND
   . = ALIGN(8);
   .eh_frame : AT(ADDR(.eh_frame) - LOAD_OFFSET) {
diff -puN include/asm-x86_64/bug.h~use-generic-bug-for-x86-64 include/asm-x86_64/bug.h
--- a/include/asm-x86_64/bug.h~use-generic-bug-for-x86-64
+++ a/include/asm-x86_64/bug.h
@@ -7,24 +7,43 @@
  * Tell the user there is some problem.  The exception handler decodes 
  * this frame.
  */
-struct bug_frame {
-	unsigned char ud2[2];
-	unsigned char push;
-	signed int filename;
-	unsigned char ret;
+struct bug_entry {
+	unsigned long bug_addr;
+	const char *file, *function;
 	unsigned short line;
 } __attribute__((packed));
 
+static inline int is_warning_bug(const struct bug_entry *b)
+{
+	return 0;
+}
+
+static inline const char *bug_get_file(const struct bug_entry *bug)
+{
+	return bug->file;
+}
+
+static inline const char *bug_get_function(const struct bug_entry *bug)
+{
+	return buf->function;
+}
+
+static inline unsigned bug_get_line(const struct bug_entry *bug)
+{
+	return bug->line;
+}
+
 #ifdef CONFIG_BUG
 #define HAVE_ARCH_BUG
-/* We turn the bug frame into valid instructions to not confuse
-   the disassembler. Thanks to Jan Beulich & Suresh Siddha
-   for nice instruction selection.
-   The magic numbers generate mov $64bitimm,%eax ; ret $offset. */
-#define BUG() 								\
-	asm volatile(							\
-	"ud2 ; pushq $%c1 ; ret $%c0" :: 				\
-		     "i"(__LINE__), "i" (__FILE__))
+
+#define BUG()						\
+	asm volatile("1:ud2\n"				\
+		     ".section __bug_table,\"a\""	\
+		     "\t.quad 1b, %c0, %c1\n"		\
+		     "\t.word %c2\n"			\
+		     ".previous"			\
+		     : : "i" (__FILE__), "i" (__FUNCTION__) ,"i" (__LINE__))
+
 void out_of_line_bug(void);
 #else
 static inline void out_of_line_bug(void) { }
_

Patches currently in -mm which might be from jeremy@xxxxxxxx are

origin.patch
x86-remove-default_ldt-and-simplify-ldt-setting.patch
generic-bug-handling.patch
use-generic-bug-for-i386.patch
use-generic-bug-for-x86-64.patch
use-generic-bug-for-powerpc.patch

-
To unsubscribe from this list: send the line "unsubscribe mm-commits" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at  http://vger.kernel.org/majordomo-info.html

[Index of Archives]     [Kernel Newbies FAQ]     [Kernel Archive]     [IETF Annouce]     [DCCP]     [Netdev]     [Networking]     [Security]     [Bugtraq]     [Photo]     [Yosemite]     [MIPS Linux]     [ARM Linux]     [Linux Security]     [Linux RAID]     [Linux SCSI]

  Powered by Linux