diff options
author | Seiji Aguchi <seiji.aguchi@hds.com> | 2013-06-20 11:45:44 -0400 |
---|---|---|
committer | H. Peter Anvin <hpa@linux.intel.com> | 2013-06-21 01:25:13 -0400 |
commit | 629f4f9d59a27d8e58aa612e886e6a9a63ea7aeb (patch) | |
tree | 049f9d16e2c304a51fa62d47cde34af8b10fc65d | |
parent | eddc0e922a3530e0f22cef170229bcae3a7d5e31 (diff) |
x86: Rename variables for debugging
Rename variables for debugging to describe meaning of them precisely.
Also, introduce a generic way to switch IDT by checking a current state,
debug on/off.
Signed-off-by: Seiji Aguchi <seiji.aguchi@hds.com>
Link: http://lkml.kernel.org/r/51C323A8.7050905@hds.com
Signed-off-by: H. Peter Anvin <hpa@linux.intel.com>
Cc: Steven Rostedt <rostedt@goodmis.org>
-rw-r--r-- | arch/x86/include/asm/desc.h | 47 | ||||
-rw-r--r-- | arch/x86/kernel/cpu/common.c | 16 | ||||
-rw-r--r-- | arch/x86/kernel/head_64.S | 2 | ||||
-rw-r--r-- | arch/x86/kernel/traps.c | 2 |
4 files changed, 54 insertions, 13 deletions
diff --git a/arch/x86/include/asm/desc.h b/arch/x86/include/asm/desc.h index 8bf1c06070d5..af290b8f124a 100644 --- a/arch/x86/include/asm/desc.h +++ b/arch/x86/include/asm/desc.h | |||
@@ -36,8 +36,8 @@ static inline void fill_ldt(struct desc_struct *desc, const struct user_desc *in | |||
36 | 36 | ||
37 | extern struct desc_ptr idt_descr; | 37 | extern struct desc_ptr idt_descr; |
38 | extern gate_desc idt_table[]; | 38 | extern gate_desc idt_table[]; |
39 | extern struct desc_ptr nmi_idt_descr; | 39 | extern struct desc_ptr debug_idt_descr; |
40 | extern gate_desc nmi_idt_table[]; | 40 | extern gate_desc debug_idt_table[]; |
41 | 41 | ||
42 | struct gdt_page { | 42 | struct gdt_page { |
43 | struct desc_struct gdt[GDT_ENTRIES]; | 43 | struct desc_struct gdt[GDT_ENTRIES]; |
@@ -316,7 +316,7 @@ static inline void set_nmi_gate(int gate, void *addr) | |||
316 | gate_desc s; | 316 | gate_desc s; |
317 | 317 | ||
318 | pack_gate(&s, GATE_INTERRUPT, (unsigned long)addr, 0, 0, __KERNEL_CS); | 318 | pack_gate(&s, GATE_INTERRUPT, (unsigned long)addr, 0, 0, __KERNEL_CS); |
319 | write_idt_entry(nmi_idt_table, gate, &s); | 319 | write_idt_entry(debug_idt_table, gate, &s); |
320 | } | 320 | } |
321 | #endif | 321 | #endif |
322 | 322 | ||
@@ -405,4 +405,45 @@ static inline void set_system_intr_gate_ist(int n, void *addr, unsigned ist) | |||
405 | _set_gate(n, GATE_INTERRUPT, addr, 0x3, ist, __KERNEL_CS); | 405 | _set_gate(n, GATE_INTERRUPT, addr, 0x3, ist, __KERNEL_CS); |
406 | } | 406 | } |
407 | 407 | ||
408 | #ifdef CONFIG_X86_64 | ||
409 | DECLARE_PER_CPU(u32, debug_idt_ctr); | ||
410 | static inline bool is_debug_idt_enabled(void) | ||
411 | { | ||
412 | if (this_cpu_read(debug_idt_ctr)) | ||
413 | return true; | ||
414 | |||
415 | return false; | ||
416 | } | ||
417 | |||
418 | static inline void load_debug_idt(void) | ||
419 | { | ||
420 | load_idt((const struct desc_ptr *)&debug_idt_descr); | ||
421 | } | ||
422 | #else | ||
423 | static inline bool is_debug_idt_enabled(void) | ||
424 | { | ||
425 | return false; | ||
426 | } | ||
427 | |||
428 | static inline void load_debug_idt(void) | ||
429 | { | ||
430 | } | ||
431 | #endif | ||
432 | |||
433 | /* | ||
434 | * the load_current_idt() is called with interrupt disabled by local_irq_save() | ||
435 | * to avoid races. That way the IDT will always be set back to the expected | ||
436 | * descriptor. | ||
437 | */ | ||
438 | static inline void load_current_idt(void) | ||
439 | { | ||
440 | unsigned long flags; | ||
441 | |||
442 | local_irq_save(flags); | ||
443 | if (is_debug_idt_enabled()) | ||
444 | load_debug_idt(); | ||
445 | else | ||
446 | load_idt((const struct desc_ptr *)&idt_descr); | ||
447 | local_irq_restore(flags); | ||
448 | } | ||
408 | #endif /* _ASM_X86_DESC_H */ | 449 | #endif /* _ASM_X86_DESC_H */ |
diff --git a/arch/x86/kernel/cpu/common.c b/arch/x86/kernel/cpu/common.c index 22018f70a671..8f6a0f909d6f 100644 --- a/arch/x86/kernel/cpu/common.c +++ b/arch/x86/kernel/cpu/common.c | |||
@@ -1071,8 +1071,8 @@ __setup("clearcpuid=", setup_disablecpuid); | |||
1071 | 1071 | ||
1072 | #ifdef CONFIG_X86_64 | 1072 | #ifdef CONFIG_X86_64 |
1073 | struct desc_ptr idt_descr = { NR_VECTORS * 16 - 1, (unsigned long) idt_table }; | 1073 | struct desc_ptr idt_descr = { NR_VECTORS * 16 - 1, (unsigned long) idt_table }; |
1074 | struct desc_ptr nmi_idt_descr = { NR_VECTORS * 16 - 1, | 1074 | struct desc_ptr debug_idt_descr = { NR_VECTORS * 16 - 1, |
1075 | (unsigned long) nmi_idt_table }; | 1075 | (unsigned long) debug_idt_table }; |
1076 | 1076 | ||
1077 | DEFINE_PER_CPU_FIRST(union irq_stack_union, | 1077 | DEFINE_PER_CPU_FIRST(union irq_stack_union, |
1078 | irq_stack_union) __aligned(PAGE_SIZE); | 1078 | irq_stack_union) __aligned(PAGE_SIZE); |
@@ -1148,20 +1148,20 @@ int is_debug_stack(unsigned long addr) | |||
1148 | addr > (__get_cpu_var(debug_stack_addr) - DEBUG_STKSZ)); | 1148 | addr > (__get_cpu_var(debug_stack_addr) - DEBUG_STKSZ)); |
1149 | } | 1149 | } |
1150 | 1150 | ||
1151 | static DEFINE_PER_CPU(u32, debug_stack_use_ctr); | 1151 | DEFINE_PER_CPU(u32, debug_idt_ctr); |
1152 | 1152 | ||
1153 | void debug_stack_set_zero(void) | 1153 | void debug_stack_set_zero(void) |
1154 | { | 1154 | { |
1155 | this_cpu_inc(debug_stack_use_ctr); | 1155 | this_cpu_inc(debug_idt_ctr); |
1156 | load_idt((const struct desc_ptr *)&nmi_idt_descr); | 1156 | load_current_idt(); |
1157 | } | 1157 | } |
1158 | 1158 | ||
1159 | void debug_stack_reset(void) | 1159 | void debug_stack_reset(void) |
1160 | { | 1160 | { |
1161 | if (WARN_ON(!this_cpu_read(debug_stack_use_ctr))) | 1161 | if (WARN_ON(!this_cpu_read(debug_idt_ctr))) |
1162 | return; | 1162 | return; |
1163 | if (this_cpu_dec_return(debug_stack_use_ctr) == 0) | 1163 | if (this_cpu_dec_return(debug_idt_ctr) == 0) |
1164 | load_idt((const struct desc_ptr *)&idt_descr); | 1164 | load_current_idt(); |
1165 | } | 1165 | } |
1166 | 1166 | ||
1167 | #else /* CONFIG_X86_64 */ | 1167 | #else /* CONFIG_X86_64 */ |
diff --git a/arch/x86/kernel/head_64.S b/arch/x86/kernel/head_64.S index 321d65ebaffe..84fb779d5b74 100644 --- a/arch/x86/kernel/head_64.S +++ b/arch/x86/kernel/head_64.S | |||
@@ -518,7 +518,7 @@ ENTRY(idt_table) | |||
518 | .skip IDT_ENTRIES * 16 | 518 | .skip IDT_ENTRIES * 16 |
519 | 519 | ||
520 | .align L1_CACHE_BYTES | 520 | .align L1_CACHE_BYTES |
521 | ENTRY(nmi_idt_table) | 521 | ENTRY(debug_idt_table) |
522 | .skip IDT_ENTRIES * 16 | 522 | .skip IDT_ENTRIES * 16 |
523 | 523 | ||
524 | __PAGE_ALIGNED_BSS | 524 | __PAGE_ALIGNED_BSS |
diff --git a/arch/x86/kernel/traps.c b/arch/x86/kernel/traps.c index 772e2a846dec..d27182d6ed2a 100644 --- a/arch/x86/kernel/traps.c +++ b/arch/x86/kernel/traps.c | |||
@@ -785,7 +785,7 @@ void __init trap_init(void) | |||
785 | x86_init.irqs.trap_init(); | 785 | x86_init.irqs.trap_init(); |
786 | 786 | ||
787 | #ifdef CONFIG_X86_64 | 787 | #ifdef CONFIG_X86_64 |
788 | memcpy(&nmi_idt_table, &idt_table, IDT_ENTRIES * 16); | 788 | memcpy(&debug_idt_table, &idt_table, IDT_ENTRIES * 16); |
789 | set_nmi_gate(X86_TRAP_DB, &debug); | 789 | set_nmi_gate(X86_TRAP_DB, &debug); |
790 | set_nmi_gate(X86_TRAP_BP, &int3); | 790 | set_nmi_gate(X86_TRAP_BP, &int3); |
791 | #endif | 791 | #endif |