Blob Blame History Raw
From: Andy Lutomirski <luto@kernel.org>
Date: Fri, 26 Jun 2020 10:24:30 -0700
Subject: x86/fsgsbase: Fix Xen PV support
Git-commit: d029bff60aa6c7eab281d52602b6a7a971615324
Patch-mainline: v5.9-rc1
References: jsc#SLE-14846

On Xen PV, SWAPGS doesn't work.  Teach __rdfsbase_inactive() and
__wrgsbase_inactive() to use rdmsrl()/wrmsrl() on Xen PV.  The Xen
pvop code will understand this and issue the correct hypercalls.

Signed-off-by: Andy Lutomirski <luto@kernel.org>
Signed-off-by: Thomas Gleixner <tglx@linutronix.de>
Link: https://lkml.kernel.org/r/f07c08f178fe9711915862b656722a207cd52c28.1593192140.git.luto@kernel.org
[ drop the instrumentation_{begin,end}() calls - those will come with a new
  kernel version because backporting the whole entry code rework wrt tracing and
  context tracking would be insane. ]
Acked-by: Borislav Petkov <bp@suse.de>
---
 arch/x86/kernel/process_64.c |   20 ++++++++++++++------
 1 file changed, 14 insertions(+), 6 deletions(-)

--- a/arch/x86/kernel/process_64.c
+++ b/arch/x86/kernel/process_64.c
@@ -165,9 +165,13 @@ static unsigned long __rdgsbase_inactive
 
 	lockdep_assert_irqs_disabled();
 
-	native_swapgs();
-	gsbase = rdgsbase();
-	native_swapgs();
+	if (!static_cpu_has(X86_FEATURE_XENPV)) {
+		native_swapgs();
+		gsbase = rdgsbase();
+		native_swapgs();
+	} else {
+		rdmsrl(MSR_KERNEL_GS_BASE, gsbase);
+	}
 
 	return gsbase;
 }
@@ -184,9 +188,13 @@ static void __wrgsbase_inactive(unsigned
 {
 	lockdep_assert_irqs_disabled();
 
-	native_swapgs();
-	wrgsbase(gsbase);
-	native_swapgs();
+	if (!static_cpu_has(X86_FEATURE_XENPV)) {
+		native_swapgs();
+		wrgsbase(gsbase);
+		native_swapgs();
+	} else {
+		wrmsrl(MSR_KERNEL_GS_BASE, gsbase);
+	}
 }
 
 /*