Skip to content

Commit 208d8c7

Browse files
H. Peter Anvin (Intel)bp3tk0v
authored andcommitted
x86/fred: Invoke FRED initialization code to enable FRED
Let cpu_init_exception_handling() call cpu_init_fred_exceptions() to initialize FRED. However if FRED is unavailable or disabled, it falls back to set up TSS IST and initialize IDT. Co-developed-by: Xin Li <xin3.li@intel.com> Signed-off-by: H. Peter Anvin (Intel) <hpa@zytor.com> Signed-off-by: Xin Li <xin3.li@intel.com> Signed-off-by: Thomas Gleixner <tglx@linutronix.de> Signed-off-by: Borislav Petkov (AMD) <bp@alien8.de> Tested-by: Shan Kang <shan.kang@intel.com> Link: https://lore.kernel.org/r/20231205105030.8698-36-xin3.li@intel.com
1 parent cdd99dd commit 208d8c7

File tree

3 files changed

+27
-7
lines changed

3 files changed

+27
-7
lines changed

arch/x86/kernel/cpu/common.c

Lines changed: 17 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,7 @@
6161
#include <asm/microcode.h>
6262
#include <asm/intel-family.h>
6363
#include <asm/cpu_device_id.h>
64+
#include <asm/fred.h>
6465
#include <asm/uv/uv.h>
6566
#include <asm/ia32.h>
6667
#include <asm/set_memory.h>
@@ -2107,7 +2108,15 @@ void syscall_init(void)
21072108
/* The default user and kernel segments */
21082109
wrmsr(MSR_STAR, 0, (__USER32_CS << 16) | __KERNEL_CS);
21092110

2110-
idt_syscall_init();
2111+
/*
2112+
* Except the IA32_STAR MSR, there is NO need to setup SYSCALL and
2113+
* SYSENTER MSRs for FRED, because FRED uses the ring 3 FRED
2114+
* entrypoint for SYSCALL and SYSENTER, and ERETU is the only legit
2115+
* instruction to return to ring 3 (both sysexit and sysret cause
2116+
* #UD when FRED is enabled).
2117+
*/
2118+
if (!cpu_feature_enabled(X86_FEATURE_FRED))
2119+
idt_syscall_init();
21112120
}
21122121

21132122
#else /* CONFIG_X86_64 */
@@ -2213,8 +2222,9 @@ void cpu_init_exception_handling(void)
22132222
/* paranoid_entry() gets the CPU number from the GDT */
22142223
setup_getcpu(cpu);
22152224

2216-
/* IST vectors need TSS to be set up. */
2217-
tss_setup_ist(tss);
2225+
/* For IDT mode, IST vectors need to be set in TSS. */
2226+
if (!cpu_feature_enabled(X86_FEATURE_FRED))
2227+
tss_setup_ist(tss);
22182228
tss_setup_io_bitmap(tss);
22192229
set_tss_desc(cpu, &get_cpu_entry_area(cpu)->tss.x86_tss);
22202230

@@ -2223,8 +2233,10 @@ void cpu_init_exception_handling(void)
22232233
/* GHCB needs to be setup to handle #VC. */
22242234
setup_ghcb();
22252235

2226-
/* Finally load the IDT */
2227-
load_current_idt();
2236+
if (cpu_feature_enabled(X86_FEATURE_FRED))
2237+
cpu_init_fred_exceptions();
2238+
else
2239+
load_current_idt();
22282240
}
22292241

22302242
/*

arch/x86/kernel/irqinit.c

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@
2828
#include <asm/setup.h>
2929
#include <asm/i8259.h>
3030
#include <asm/traps.h>
31+
#include <asm/fred.h>
3132
#include <asm/prom.h>
3233

3334
/*
@@ -96,7 +97,11 @@ void __init native_init_IRQ(void)
9697
/* Execute any quirks before the call gates are initialised: */
9798
x86_init.irqs.pre_vector_init();
9899

99-
idt_setup_apic_and_irq_gates();
100+
if (cpu_feature_enabled(X86_FEATURE_FRED))
101+
fred_complete_exception_setup();
102+
else
103+
idt_setup_apic_and_irq_gates();
104+
100105
lapic_assign_system_vectors();
101106

102107
if (!acpi_ioapic && !of_ioapic && nr_legacy_irqs()) {

arch/x86/kernel/traps.c

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1438,7 +1438,10 @@ void __init trap_init(void)
14381438

14391439
/* Initialize TSS before setting up traps so ISTs work */
14401440
cpu_init_exception_handling();
1441+
14411442
/* Setup traps as cpu_init() might #GP */
1442-
idt_setup_traps();
1443+
if (!cpu_feature_enabled(X86_FEATURE_FRED))
1444+
idt_setup_traps();
1445+
14431446
cpu_init();
14441447
}

0 commit comments

Comments
 (0)