Skip to content

Commit

Permalink
x86/idt: Annotate alloc_intr_gate() with __init
Browse files Browse the repository at this point in the history
There seems to be no reason to allocate interrupt gates after init. Mark
alloc_intr_gate() as __init and add WARN_ON() checks making sure it is
only used before idt_setup_apic_and_irq_gates() finalizes IDT setup and
maps all un-allocated entries to spurious entries.

Suggested-by: Thomas Gleixner <tglx@linutronix.de>
Signed-off-by: Vitaly Kuznetsov <vkuznets@redhat.com>
Signed-off-by: Thomas Gleixner <tglx@linutronix.de>
Link: https://lkml.kernel.org/r/20200428093824.1451532-3-vkuznets@redhat.com
  • Loading branch information
Vitaly Kuznetsov authored and Thomas Gleixner committed Jun 11, 2020
1 parent a0bb51f commit 0618432
Showing 1 changed file with 13 additions and 3 deletions.
16 changes: 13 additions & 3 deletions arch/x86/kernel/idt.c
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,9 @@ struct idt_data {
#define TSKG(_vector, _gdt) \
G(_vector, NULL, DEFAULT_STACK, GATE_TASK, DPL0, _gdt << 3)


static bool idt_setup_done __initdata;

/*
* Early traps running on the DEFAULT_STACK because the other interrupt
* stacks work only after cpu_init().
Expand Down Expand Up @@ -323,6 +326,7 @@ void __init idt_setup_apic_and_irq_gates(void)
set_intr_gate(i, entry);
}
#endif
idt_setup_done = true;
}

/**
Expand Down Expand Up @@ -352,16 +356,22 @@ void idt_invalidate(void *addr)
load_idt(&idt);
}

/* This goes away once ASYNC_PF is sanitized */
void __init update_intr_gate(unsigned int n, const void *addr)
{
if (WARN_ON_ONCE(!test_bit(n, system_vectors)))
return;
set_intr_gate(n, addr);
}

void alloc_intr_gate(unsigned int n, const void *addr)
void __init alloc_intr_gate(unsigned int n, const void *addr)
{
BUG_ON(n < FIRST_SYSTEM_VECTOR);
if (!test_and_set_bit(n, system_vectors))
if (WARN_ON(n < FIRST_SYSTEM_VECTOR))
return;

if (WARN_ON(idt_setup_done))
return;

if (!WARN_ON(test_and_set_bit(n, system_vectors)))
set_intr_gate(n, addr);
}

0 comments on commit 0618432

Please sign in to comment.