From: "H. Peter Anvin (Intel)" <h...@zytor.com>

Add a syscall initialization function fred_syscall_init() for FRED,
and this is really just to skip setting up SYSCALL/SYSENTER related
MSRs, e.g., MSR_LSTAR and invalidate SYSENTER configurations, because
FRED uses the ring 3 FRED entrypoint for SYSCALL and SYSENTER, and
ERETU is the only legit instruction to return to ring 3 per FRED spec
5.0.

Signed-off-by: H. Peter Anvin (Intel) <h...@zytor.com>
Tested-by: Shan Kang <shan.k...@intel.com>
Signed-off-by: Xin Li <xin3...@intel.com>
---
 arch/x86/kernel/cpu/common.c | 17 +++++++++++++++++
 1 file changed, 17 insertions(+)

diff --git a/arch/x86/kernel/cpu/common.c b/arch/x86/kernel/cpu/common.c
index d960b7276008..4cb36e241c9a 100644
--- a/arch/x86/kernel/cpu/common.c
+++ b/arch/x86/kernel/cpu/common.c
@@ -2105,6 +2105,23 @@ static inline void idt_syscall_init(void)
               X86_EFLAGS_AC|X86_EFLAGS_ID);
 }
 
+static inline void fred_syscall_init(void)
+{
+       /*
+        * Per FRED spec 5.0, FRED uses the ring 3 FRED entrypoint for SYSCALL
+        * and SYSENTER, and ERETU is the only legit instruction to return to
+        * ring 3, as a result there is _no_ need to setup the SYSCALL and
+        * SYSENTER MSRs.
+        *
+        * Note, both sysexit and sysret cause #UD when FRED is enabled.
+        */
+       wrmsrl(MSR_LSTAR, 0ULL);
+       wrmsrl_cstar(0ULL);
+       wrmsrl_safe(MSR_IA32_SYSENTER_CS, (u64)GDT_ENTRY_INVALID_SEG);
+       wrmsrl_safe(MSR_IA32_SYSENTER_ESP, 0ULL);
+       wrmsrl_safe(MSR_IA32_SYSENTER_EIP, 0ULL);
+}
+
 /* May not be marked __init: used by software suspend */
 void syscall_init(void)
 {
-- 
2.34.1


Reply via email to