Skip to content

Commit e802a51

Browse files
KAGA-KOKOIngo Molnar
authored andcommitted
x86/idt: Consolidate IDT invalidation
kexec and reboot have both code to invalidate IDT. Create a common function and use it. Signed-off-by: Thomas Gleixner <[email protected]> Cc: Andy Lutomirski <[email protected]> Cc: Borislav Petkov <[email protected]> Cc: Brian Gerst <[email protected]> Cc: Denys Vlasenko <[email protected]> Cc: H. Peter Anvin <[email protected]> Cc: Josh Poimboeuf <[email protected]> Cc: Linus Torvalds <[email protected]> Cc: Peter Zijlstra <[email protected]> Cc: Steven Rostedt <[email protected]> Link: http://lkml.kernel.org/r/[email protected] Signed-off-by: Ingo Molnar <[email protected]>
1 parent 8f55868 commit e802a51

File tree

4 files changed

+16
-16
lines changed

4 files changed

+16
-16
lines changed

arch/x86/include/asm/desc.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -503,4 +503,7 @@ static inline void load_current_idt(void)
503503
else
504504
load_idt((const struct desc_ptr *)&idt_descr);
505505
}
506+
507+
extern void idt_invalidate(void *addr);
508+
506509
#endif /* _ASM_X86_DESC_H */

arch/x86/kernel/idt.c

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,3 +24,14 @@ const struct desc_ptr debug_idt_descr = {
2424
.address = (unsigned long) debug_idt_table,
2525
};
2626
#endif
27+
28+
/**
29+
* idt_invalidate - Invalidate interrupt descriptor table
30+
* @addr: The virtual address of the 'invalid' IDT
31+
*/
32+
void idt_invalidate(void *addr)
33+
{
34+
struct desc_ptr idt = { .address = (unsigned long) addr, .size = 0 };
35+
36+
load_idt(&idt);
37+
}

arch/x86/kernel/machine_kexec_32.c

Lines changed: 1 addition & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -26,18 +26,6 @@
2626
#include <asm/set_memory.h>
2727
#include <asm/debugreg.h>
2828

29-
static void set_idt(void *newidt, __u16 limit)
30-
{
31-
struct desc_ptr curidt;
32-
33-
/* ia32 supports unaliged loads & stores */
34-
curidt.size = limit;
35-
curidt.address = (unsigned long)newidt;
36-
37-
load_idt(&curidt);
38-
}
39-
40-
4129
static void set_gdt(void *newgdt, __u16 limit)
4230
{
4331
struct desc_ptr curgdt;
@@ -245,7 +233,7 @@ void machine_kexec(struct kimage *image)
245233
* If you want to load them you must set up your own idt & gdt.
246234
*/
247235
set_gdt(phys_to_virt(0), 0);
248-
set_idt(phys_to_virt(0), 0);
236+
idt_invalidate(phys_to_virt(0));
249237

250238
/* now call it */
251239
image->start = relocate_kernel_ptr((unsigned long)image->head,

arch/x86/kernel/reboot.c

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -38,8 +38,6 @@
3838
void (*pm_power_off)(void);
3939
EXPORT_SYMBOL(pm_power_off);
4040

41-
static const struct desc_ptr no_idt = {};
42-
4341
/*
4442
* This is set if we need to go through the 'emergency' path.
4543
* When machine_emergency_restart() is called, we may be on
@@ -638,7 +636,7 @@ static void native_machine_emergency_restart(void)
638636
break;
639637

640638
case BOOT_TRIPLE:
641-
load_idt(&no_idt);
639+
idt_invalidate(NULL);
642640
__asm__ __volatile__("int3");
643641

644642
/* We're probably dead after this, but... */

0 commit comments

Comments
 (0)