Skip to contentSkip to conversation

KVM: x86: Advertise support for LKGS

PATCH Applied Xin Li (Intel) 2 participants 2 messages Jun 26, 2025 – Jul 10, 2025

Subsystems (3)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 KVM: x86: Advertise support for LKGS

Advertise support for LKGS (load into IA32_KERNEL_GS_BASE) to userspace if the instruction is supported by the underlying CPU.

LKGS is introduced with FRED to completely eliminate the need to swapgs explicilty. It behaves like the MOV to GS instruction except that it loads the base address into the IA32_KERNEL_GS_BASE MSR instead of the GS segment’s descriptor cache, which is exactly what Linux kernel does to load a user level GS base. Thus there is no need to SWAPGS away from the kernel GS base.

LKGS is an independent CPU feature that works correctly in a KVM guest without requiring explicit enablement.

---
 arch/x86/kvm/cpuid.c | 1 +
 1 file changed, 1 insertion(+)
arch/x86/kvm/cpuid.c +1 -0
index b2d006756e02..bf4a43bd0a47 100644
@@ -979,6 +979,7 @@ void kvm_set_cpu_caps(void)
 		F(FSRS),
 		F(FSRC),
 		F(WRMSRNS),
+		X86_64_F(LKGS),
 		F(AMX_FP16),
 		F(AVX_IFMA),
 		F(LAM),

base-commit: 05186d7a8e5b8a31be93728089c9c3fee4dab0a2

Signature · 1 line
2.50.0
maintainer Applied
#1 lore raw
Quoted 11 lines · Xin Li (Intel)

Advertise support for LKGS (load into IA32_KERNEL_GS_BASE) to userspace if the instruction is supported by the underlying CPU.

LKGS is introduced with FRED to completely eliminate the need to swapgs explicilty. It behaves like the MOV to GS instruction except that it loads the base address into the IA32_KERNEL_GS_BASE MSR instead of the GS segment’s descriptor cache, which is exactly what Linux kernel does to load a user level GS base. Thus there is no need to SWAPGS away from the kernel GS base.

[...]

Applied to kvm-x86 misc, thanks!

[1/1] KVM: x86: Advertise support for LKGS

      https://github.com/kvm-x86/linux/commit/e88cfd50b606

--
https://github.com/kvm-x86/linux/tree/next