From: "Xin Li (Intel)" <xin@zytor.com>
To: linux-kernel@vger.kernel.org
Cc: luto@kernel.org, tglx@linutronix.de, mingo@redhat.com,
bp@alien8.de, dave.hansen@linux.intel.com, x86@kernel.org,
hpa@zytor.com
Subject: [PATCH v1 1/1] x86/fred: Fix int80 emulation for FRED
Date: Fri, 12 Apr 2024 16:40:58 -0700 [thread overview]
Message-ID: <20240412234058.1106744-1-xin@zytor.com> (raw)
Commit 55617fb991df added a bunch of tests to the int $0x80 path, however
they are unnecessary and event wrong in fact under FRED.
First FRED distinguishes external interrupts from software interrupts,
thus int80_emulation() should NEVER be called for handling an external
interrupt, and then int80_is_external() should be skipped under FRED.
Second, the FRED kernel entry handler NEVER dispatches INTx, which is
of event type EVENT_TYPE_SWINT, so the user mode checking in
do_int80_emulation() is redundant, and should be skipped.
It might be even better to strip down do_int80_emulation() to a lean
fred_int80_emulation(), not to mention int80_emulation() does a
CLEAR_BRANCH_HISTORY.
Suggested-by: H. Peter Anvin (Intel) <hpa@zytor.com>
Signed-off-by: Xin Li (Intel) <xin@zytor.com>
---
arch/x86/entry/common.c | 22 ++++++++++++++++++++--
1 file changed, 20 insertions(+), 2 deletions(-)
diff --git a/arch/x86/entry/common.c b/arch/x86/entry/common.c
index 6de50b80702e..aed745fc8333 100644
--- a/arch/x86/entry/common.c
+++ b/arch/x86/entry/common.c
@@ -174,6 +174,18 @@ static __always_inline bool int80_is_external(void)
const unsigned int offs = (0x80 / 32) * 0x10;
const u32 bit = BIT(0x80 % 32);
+ /*
+ * FRED distinguishes external interrupts from software interrupts
+ * with different event types, EVENT_TYPE_EXTINT v.s. EVENT_TYPE_SWINT,
+ * thus we should NEVER get here when FRED is enabled, and then the
+ * following APIC ISR check makes no sense.
+ *
+ * Furthermore, the external interrupt vector 0x80 is available as
+ * a hardware interrupt under FRED.
+ */
+ if (cpu_feature_enabled(X86_FEATURE_FRED))
+ return false;
+
/* The local APIC on XENPV guests is fake */
if (cpu_feature_enabled(X86_FEATURE_XENPV))
return false;
@@ -211,8 +223,14 @@ __visible noinstr void do_int80_emulation(struct pt_regs *regs)
{
int nr;
- /* Kernel does not use INT $0x80! */
- if (unlikely(!user_mode(regs))) {
+ /*
+ * Kernel does not use INT $0x80!
+ *
+ * The FRED kernel entry handler NEVER dispatches INTx (panic or
+ * oops otherwise), so it is redundant to check user mode here.
+ */
+ if (!cpu_feature_enabled(X86_FEATURE_FRED) &&
+ unlikely(!user_mode(regs))) {
irqentry_enter(regs);
instrumentation_begin();
panic("Unexpected external interrupt 0x80\n");
base-commit: 86d1b22a75cffa50160e4621da00311e6f6f48de
--
2.44.0
next reply other threads:[~2024-04-12 23:41 UTC|newest]
Thread overview: 9+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-04-12 23:40 Xin Li (Intel) [this message]
2024-04-15 16:21 ` H. Peter Anvin
2024-04-16 10:11 ` Borislav Petkov
2024-04-16 16:58 ` Xin Li
2024-04-16 18:05 ` H. Peter Anvin
2024-04-16 18:07 ` Borislav Petkov
2024-04-16 18:11 ` H. Peter Anvin
2024-04-16 18:18 ` Borislav Petkov
2024-04-16 18:19 ` H. Peter Anvin
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=20240412234058.1106744-1-xin@zytor.com \
--to=xin@zytor.com \
--cc=bp@alien8.de \
--cc=dave.hansen@linux.intel.com \
--cc=hpa@zytor.com \
--cc=linux-kernel@vger.kernel.org \
--cc=luto@kernel.org \
--cc=mingo@redhat.com \
--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
all inboxes | Powered by JetHome®