ia64/xen-unstable
changeset 19474:69108560c7eb
x86: unify BUG() & Co, reduce overhead on x86-64
Since it's only the string pointer representations that differ between
i386 and x86-64, abstract out those and make everything else shared.
While touching this code, also use
- proper instructions rather than a mixture of such and raw .byte/
.long/.quad data emissions,
- PC-relative pointers on x86-64 to cut the amount of storage (and
in particular cache space) needed for string references by half.
Signed-off-by: Jan Beulich <jbeulich@novell.com>
Since it's only the string pointer representations that differ between
i386 and x86-64, abstract out those and make everything else shared.
While touching this code, also use
- proper instructions rather than a mixture of such and raw .byte/
.long/.quad data emissions,
- PC-relative pointers on x86-64 to cut the amount of storage (and
in particular cache space) needed for string references by half.
Signed-off-by: Jan Beulich <jbeulich@novell.com>
author | Keir Fraser <keir.fraser@citrix.com> |
---|---|
date | Tue Mar 31 13:23:11 2009 +0100 (2009-03-31) |
parents | 2fa1d38097da |
children | d7bf5a03cf07 |
files | xen/arch/x86/traps.c xen/include/asm-x86/bug.h xen/include/asm-x86/x86_32/bug.h xen/include/asm-x86/x86_64/bug.h |
line diff
1.1 --- a/xen/arch/x86/traps.c Tue Mar 31 13:22:12 2009 +0100 1.2 +++ b/xen/arch/x86/traps.c Tue Mar 31 13:23:11 2009 +0100 1.3 @@ -841,7 +841,7 @@ asmlinkage void do_invalid_op(struct cpu 1.4 { 1.5 struct bug_frame bug; 1.6 struct bug_frame_str bug_str; 1.7 - char *filename, *predicate, *eip = (char *)regs->eip; 1.8 + const char *filename, *predicate, *eip = (char *)regs->eip; 1.9 unsigned long fixup; 1.10 int id, lineno; 1.11 1.12 @@ -873,11 +873,13 @@ asmlinkage void do_invalid_op(struct cpu 1.13 /* WARN, BUG or ASSERT: decode the filename pointer and line number. */ 1.14 if ( !is_kernel(eip) || 1.15 __copy_from_user(&bug_str, eip, sizeof(bug_str)) || 1.16 - memcmp(bug_str.mov, BUG_MOV_STR, sizeof(bug_str.mov)) ) 1.17 + (bug_str.mov != 0xbc) ) 1.18 goto die; 1.19 + filename = bug_str(bug_str, eip); 1.20 eip += sizeof(bug_str); 1.21 1.22 - filename = is_kernel(bug_str.str) ? (char *)bug_str.str : "<unknown>"; 1.23 + if ( !is_kernel(filename) ) 1.24 + filename = "<unknown>"; 1.25 lineno = bug.id >> 2; 1.26 1.27 if ( id == BUGFRAME_warn ) 1.28 @@ -900,11 +902,13 @@ asmlinkage void do_invalid_op(struct cpu 1.29 ASSERT(id == BUGFRAME_assert); 1.30 if ( !is_kernel(eip) || 1.31 __copy_from_user(&bug_str, eip, sizeof(bug_str)) || 1.32 - memcmp(bug_str.mov, BUG_MOV_STR, sizeof(bug_str.mov)) ) 1.33 + (bug_str.mov != 0xbc) ) 1.34 goto die; 1.35 + predicate = bug_str(bug_str, eip); 1.36 eip += sizeof(bug_str); 1.37 1.38 - predicate = is_kernel(bug_str.str) ? (char *)bug_str.str : "<unknown>"; 1.39 + if ( !is_kernel(predicate) ) 1.40 + predicate = "<unknown>"; 1.41 printk("Assertion '%s' failed at %.50s:%d\n", 1.42 predicate, filename, lineno); 1.43 DEBUGGER_trap_fatal(TRAP_invalid_op, regs);
2.1 --- a/xen/include/asm-x86/bug.h Tue Mar 31 13:22:12 2009 +0100 2.2 +++ b/xen/include/asm-x86/bug.h Tue Mar 31 13:23:11 2009 +0100 2.3 @@ -18,4 +18,28 @@ struct bug_frame { 2.4 #define BUGFRAME_bug 2 2.5 #define BUGFRAME_assert 3 2.6 2.7 +#define dump_execution_state() \ 2.8 + asm volatile ( \ 2.9 + "ud2 ; ret $0" \ 2.10 + : : "i" (BUGFRAME_dump) ) 2.11 + 2.12 +#define WARN() \ 2.13 + asm volatile ( \ 2.14 + "ud2 ; ret %0" BUG_STR(1) \ 2.15 + : : "i" (BUGFRAME_warn | (__LINE__<<2)), \ 2.16 + "i" (__FILE__) ) 2.17 + 2.18 +#define BUG() \ 2.19 + asm volatile ( \ 2.20 + "ud2 ; ret %0" BUG_STR(1) \ 2.21 + : : "i" (BUGFRAME_bug | (__LINE__<<2)), \ 2.22 + "i" (__FILE__) ) 2.23 + 2.24 +#define assert_failed(p) \ 2.25 + asm volatile ( \ 2.26 + "ud2 ; ret %0" BUG_STR(1) BUG_STR(2) \ 2.27 + : : "i" (BUGFRAME_assert | (__LINE__<<2)), \ 2.28 + "i" (__FILE__), "i" (#p) ) 2.29 + 2.30 + 2.31 #endif /* __X86_BUG_H__ */
3.1 --- a/xen/include/asm-x86/x86_32/bug.h Tue Mar 31 13:22:12 2009 +0100 3.2 +++ b/xen/include/asm-x86/x86_32/bug.h Tue Mar 31 13:23:11 2009 +0100 3.3 @@ -2,33 +2,10 @@ 3.4 #define __X86_32_BUG_H__ 3.5 3.6 struct bug_frame_str { 3.7 - unsigned char mov[1]; 3.8 + unsigned char mov; 3.9 unsigned long str; 3.10 } __attribute__((packed)); 3.11 -#define BUG_MOV_STR "\xbc" 3.12 - 3.13 -#define dump_execution_state() \ 3.14 - asm volatile ( \ 3.15 - "ud2 ; ret $%c0" \ 3.16 - : : "i" (BUGFRAME_dump) ) 3.17 - 3.18 -#define WARN() \ 3.19 - asm volatile ( \ 3.20 - "ud2 ; ret $%c0 ; .byte 0xbc ; .long %c1" \ 3.21 - : : "i" (BUGFRAME_warn | (__LINE__<<2)), \ 3.22 - "i" (__FILE__) ) 3.23 - 3.24 -#define BUG() \ 3.25 - asm volatile ( \ 3.26 - "ud2 ; ret $%c0 ; .byte 0xbc ; .long %c1" \ 3.27 - : : "i" (BUGFRAME_bug | (__LINE__<<2)), \ 3.28 - "i" (__FILE__) ) 3.29 - 3.30 -#define assert_failed(p) \ 3.31 - asm volatile ( \ 3.32 - "ud2 ; ret $%c0 ; .byte 0xbc ; .long %c1" \ 3.33 - " ; .byte 0xbc ; .long %c2" \ 3.34 - : : "i" (BUGFRAME_assert | (__LINE__<<2)), \ 3.35 - "i" (__FILE__), "i" (#p) ) 3.36 +#define bug_str(b, eip) ((const char *)(b).str) 3.37 +#define BUG_STR(n) "; movl %" #n ", %%esp" 3.38 3.39 #endif /* __X86_32_BUG_H__ */
4.1 --- a/xen/include/asm-x86/x86_64/bug.h Tue Mar 31 13:22:12 2009 +0100 4.2 +++ b/xen/include/asm-x86/x86_64/bug.h Tue Mar 31 13:23:11 2009 +0100 4.3 @@ -2,33 +2,10 @@ 4.4 #define __X86_64_BUG_H__ 4.5 4.6 struct bug_frame_str { 4.7 - unsigned char mov[2]; 4.8 - unsigned long str; 4.9 + unsigned char mov; 4.10 + signed int str_disp; 4.11 } __attribute__((packed)); 4.12 -#define BUG_MOV_STR "\x48\xbc" 4.13 - 4.14 -#define dump_execution_state() \ 4.15 - asm volatile ( \ 4.16 - "ud2 ; ret $%c0" \ 4.17 - : : "i" (BUGFRAME_dump) ) 4.18 - 4.19 -#define WARN() \ 4.20 - asm volatile ( \ 4.21 - "ud2 ; ret $%c0 ; .byte 0x48,0xbc ; .quad %c1" \ 4.22 - : : "i" (BUGFRAME_warn | (__LINE__<<2)), \ 4.23 - "i" (__FILE__) ) 4.24 - 4.25 -#define BUG() \ 4.26 - asm volatile ( \ 4.27 - "ud2 ; ret $%c0 ; .byte 0x48,0xbc ; .quad %c1" \ 4.28 - : : "i" (BUGFRAME_bug | (__LINE__<<2)), \ 4.29 - "i" (__FILE__) ) 4.30 - 4.31 -#define assert_failed(p) \ 4.32 - asm volatile ( \ 4.33 - "ud2 ; ret $%c0 ; .byte 0x48,0xbc ; .quad %c1" \ 4.34 - " ; .byte 0x48,0xbc ; .quad %c2" \ 4.35 - : : "i" (BUGFRAME_assert | (__LINE__<<2)), \ 4.36 - "i" (__FILE__), "i" (#p) ) 4.37 +#define bug_str(b, rip) ((const char *)(rip) + (b).str_disp) 4.38 +#define BUG_STR(n) "; movl %" #n " - ., %%esp" 4.39 4.40 #endif /* __X86_64_BUG_H__ */