All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] reduce x86-64 bug frame by 4 bytes
@ 2005-09-09 11:45 Jan Beulich
  2005-09-09 14:45 ` [discuss] " Andi Kleen
  0 siblings, 1 reply; 2+ messages in thread
From: Jan Beulich @ 2005-09-09 11:45 UTC (permalink / raw)
  To: Andreas Kleen; +Cc: linux-kernel, discuss

[-- Attachment #1: Type: text/plain, Size: 2346 bytes --]

reduce x86-64 bug frame by 4 bytes

From: Jan Beulich <jbeulich@novell.com>

(Note: Patch also attached because the inline version is certain to
get
line wrapped.)

As mentioned before, the size of the bug frame can be further reduced
while
continuing to use instructions to encode the information.

Signed-off-by: Jan Beulich <jbeulich@novell.com>

diff -Npru 2.6.13/arch/x86_64/kernel/traps.c
2.6.13-x86_64-bug-reduction/arch/x86_64/kernel/traps.c
--- 2.6.13/arch/x86_64/kernel/traps.c	2005-08-29 01:41:01.000000000
+0200
+++
2.6.13-x86_64-bug-reduction/arch/x86_64/kernel/traps.c	2005-09-09
11:48:11.009725672 +0200
@@ -323,13 +323,13 @@ void handle_BUG(struct pt_regs *regs)
 	if (__copy_from_user(&f, (struct bug_frame *) regs->rip, 
 			     sizeof(struct bug_frame)))
 		return; 
-	if ((unsigned long)f.filename < __PAGE_OFFSET || 
+	if (f.filename >= 0 || 
 	    f.ud2[0] != 0x0f || f.ud2[1] != 0x0b) 
 		return;
-	if (__get_user(tmp, f.filename))
-		f.filename = "unmapped filename"; 
+	if (__get_user(tmp, (char *)(long)f.filename))
+		f.filename = (int)(long)"unmapped filename"; 
 	printk("----------- [cut here ] --------- [please bite here ]
---------\n");
-	printk(KERN_ALERT "Kernel BUG at %.50s:%d\n", f.filename,
f.line);
+	printk(KERN_ALERT "Kernel BUG at %.50s:%d\n", (char
*)(long)f.filename, f.line);
 } 
 
 #ifdef CONFIG_BUG
diff -Npru 2.6.13/include/asm-x86_64/bug.h
2.6.13-x86_64-bug-reduction/include/asm-x86_64/bug.h
--- 2.6.13/include/asm-x86_64/bug.h	2005-08-29 01:41:01.000000000
+0200
+++
2.6.13-x86_64-bug-reduction/include/asm-x86_64/bug.h	2005-09-09
11:31:11.611697728 +0200
@@ -9,10 +9,8 @@
  */
 struct bug_frame {
 	unsigned char ud2[2];
-	unsigned char mov;
-	/* should use 32bit offset instead, but the assembler doesn't 
-	   like it */
-	char *filename;
+	unsigned char push;
+	signed int filename;
 	unsigned char ret;
 	unsigned short line;
 } __attribute__((packed));
@@ -25,8 +23,8 @@ struct bug_frame {
    The magic numbers generate mov $64bitimm,%eax ; ret $offset. */
 #define BUG()
								\
 	asm
volatile(							\
-	"ud2 ; .byte 0xa3 ; .quad %c1 ; .byte 0xc2 ; .short %c0" ::
	\
-		     "i"(__LINE__), "i" (__stringify(__FILE__)))
+	"ud2 ; pushq $%c1 ; ret $%c0" ::
				\
+		     "i"(__LINE__), "i" (__FILE__))
 void out_of_line_bug(void);
 #else
 static inline void out_of_line_bug(void) { }


[-- Attachment #2: linux-2.6.13-x86_64-bug-reduction.patch --]
[-- Type: application/octet-stream, Size: 2345 bytes --]

reduce x86-64 bug frame by 4 bytes

From: Jan Beulich <jbeulich@novell.com>

(Note: Patch also attached because the inline version is certain to get
line wrapped.)

As mentioned before, the size of the bug frame can be further reduced while
continuing to use instructions to encode the information.

Signed-off-by: Jan Beulich <jbeulich@novell.com>

diff -Npru 2.6.13/arch/x86_64/kernel/traps.c 2.6.13-x86_64-bug-reduction/arch/x86_64/kernel/traps.c
--- 2.6.13/arch/x86_64/kernel/traps.c	2005-08-29 01:41:01.000000000 +0200
+++ 2.6.13-x86_64-bug-reduction/arch/x86_64/kernel/traps.c	2005-09-09 11:48:11.009725672 +0200
@@ -323,13 +323,13 @@ void handle_BUG(struct pt_regs *regs)
 	if (__copy_from_user(&f, (struct bug_frame *) regs->rip, 
 			     sizeof(struct bug_frame)))
 		return; 
-	if ((unsigned long)f.filename < __PAGE_OFFSET || 
+	if (f.filename >= 0 || 
 	    f.ud2[0] != 0x0f || f.ud2[1] != 0x0b) 
 		return;
-	if (__get_user(tmp, f.filename))
-		f.filename = "unmapped filename"; 
+	if (__get_user(tmp, (char *)(long)f.filename))
+		f.filename = (int)(long)"unmapped filename"; 
 	printk("----------- [cut here ] --------- [please bite here ] ---------\n");
-	printk(KERN_ALERT "Kernel BUG at %.50s:%d\n", f.filename, f.line);
+	printk(KERN_ALERT "Kernel BUG at %.50s:%d\n", (char *)(long)f.filename, f.line);
 } 
 
 #ifdef CONFIG_BUG
diff -Npru 2.6.13/include/asm-x86_64/bug.h 2.6.13-x86_64-bug-reduction/include/asm-x86_64/bug.h
--- 2.6.13/include/asm-x86_64/bug.h	2005-08-29 01:41:01.000000000 +0200
+++ 2.6.13-x86_64-bug-reduction/include/asm-x86_64/bug.h	2005-09-09 11:31:11.611697728 +0200
@@ -9,10 +9,8 @@
  */
 struct bug_frame {
 	unsigned char ud2[2];
-	unsigned char mov;
-	/* should use 32bit offset instead, but the assembler doesn't 
-	   like it */
-	char *filename;
+	unsigned char push;
+	signed int filename;
 	unsigned char ret;
 	unsigned short line;
 } __attribute__((packed));
@@ -25,8 +23,8 @@ struct bug_frame {
    The magic numbers generate mov $64bitimm,%eax ; ret $offset. */
 #define BUG() 								\
 	asm volatile(							\
-	"ud2 ; .byte 0xa3 ; .quad %c1 ; .byte 0xc2 ; .short %c0" :: 	\
-		     "i"(__LINE__), "i" (__stringify(__FILE__)))
+	"ud2 ; pushq $%c1 ; ret $%c0" :: 				\
+		     "i"(__LINE__), "i" (__FILE__))
 void out_of_line_bug(void);
 #else
 static inline void out_of_line_bug(void) { }

^ permalink raw reply	[flat|nested] 2+ messages in thread

* Re: [discuss] [PATCH] reduce x86-64 bug frame by 4 bytes
  2005-09-09 11:45 [PATCH] reduce x86-64 bug frame by 4 bytes Jan Beulich
@ 2005-09-09 14:45 ` Andi Kleen
  0 siblings, 0 replies; 2+ messages in thread
From: Andi Kleen @ 2005-09-09 14:45 UTC (permalink / raw)
  To: discuss; +Cc: Jan Beulich, linux-kernel

On Friday 09 September 2005 13:45, Jan Beulich wrote:
> reduce x86-64 bug frame by 4 bytes

Applied thanks.
-Andi


^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2005-09-09 14:45 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2005-09-09 11:45 [PATCH] reduce x86-64 bug frame by 4 bytes Jan Beulich
2005-09-09 14:45 ` [discuss] " Andi Kleen

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.