From: Vitaly Kuznetsov <vkuznets@redhat.com>
To: x86@kernel.org
Cc: Thomas Gleixner <tglx@linutronix.de>,
Ingo Molnar <mingo@redhat.com>, Borislav Petkov <bp@alien8.de>,
"H. Peter Anvin" <hpa@zytor.com>,
linux-kernel@vger.kernel.org, Juergen Gross <jgross@suse.com>,
Stefano Stabellini <sstabellini@kernel.org>
Subject: [PATCH v2 2/3] x86/idt: Annotate alloc_intr_gate() with __init
Date: Tue, 28 Apr 2020 11:38:23 +0200 [thread overview]
Message-ID: <20200428093824.1451532-3-vkuznets@redhat.com> (raw)
In-Reply-To: <20200428093824.1451532-1-vkuznets@redhat.com>
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>
---
arch/x86/kernel/idt.c | 16 +++++++++++++---
1 file changed, 13 insertions(+), 3 deletions(-)
diff --git a/arch/x86/kernel/idt.c b/arch/x86/kernel/idt.c
index 87ef69a72c52..f95c3be00e5a 100644
--- a/arch/x86/kernel/idt.c
+++ b/arch/x86/kernel/idt.c
@@ -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().
@@ -323,6 +326,7 @@ void __init idt_setup_apic_and_irq_gates(void)
set_intr_gate(i, entry);
}
#endif
+ idt_setup_done = true;
}
/**
@@ -352,6 +356,7 @@ 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)))
@@ -359,9 +364,14 @@ void __init update_intr_gate(unsigned int n, const void *addr)
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);
}
--
2.25.3
next prev parent reply other threads:[~2020-04-28 9:38 UTC|newest]
Thread overview: 10+ messages / expand[flat|nested] mbox.gz Atom feed top
2020-04-28 9:38 [PATCH v2 0/3] x86/idt: Minor alloc_intr_gate() sanitization Vitaly Kuznetsov
2020-04-28 9:38 ` [PATCH v2 1/3] x86/xen: Split HVM vector callback setup and interrupt gate allocation Vitaly Kuznetsov
2020-05-13 19:16 ` [tip: x86/entry] " tip-bot2 for Vitaly Kuznetsov
2020-04-28 9:38 ` Vitaly Kuznetsov [this message]
2020-05-13 19:16 ` [tip: x86/entry] x86/idt: Annotate alloc_intr_gate() with __init tip-bot2 for Vitaly Kuznetsov
2020-04-28 9:38 ` [PATCH v2 3/3] x86/idt: Keep spurious entries unset in system_vectors Vitaly Kuznetsov
2020-05-13 19:16 ` [tip: x86/entry] " tip-bot2 for Vitaly Kuznetsov
2020-05-13 12:57 ` [PATCH v2 0/3] x86/idt: Minor alloc_intr_gate() sanitization Vitaly Kuznetsov
2020-05-13 19:02 ` Thomas Gleixner
2020-05-14 8:10 ` Vitaly Kuznetsov
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20200428093824.1451532-3-vkuznets@redhat.com \
--to=vkuznets@redhat.com \
--cc=bp@alien8.de \
--cc=hpa@zytor.com \
--cc=jgross@suse.com \
--cc=linux-kernel@vger.kernel.org \
--cc=mingo@redhat.com \
--cc=sstabellini@kernel.org \
--cc=tglx@linutronix.de \
--cc=x86@kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).