Re: Save a WRMSR GS.base?

From: Borislav Petkov

Date: Fri Jun 05 2026 - 00:27:28 EST


On Thu, Jun 04, 2026 at 08:20:57PM -0700, H. Peter Anvin wrote:
> I guess the question is why there is a "first" one.

That happens when we do:

x86_fsgsbase_load()

loadseg(GS) -> load_gs_index() -> native_load_gs_index() ->
if (cpu_feature_enabled(X86_FEATURE_LKGS))
native_lkgs(selector);

then back in x86_fsgsbase_load() we do:

__wrgsbase_inactive(next->gsbase);

which does

wrmsrq(MSR_KERNEL_GS_BASE, gsbase);

on FRED.

But LKGS already wrote MSR_KERNEL_GS_BASE...

> Logically the sequence should be LKGS first, if needed; then WRMSR(NS). LKGS
> can be replaced with swapgs/mov gs/swapgs on legacy.

Right.

I think avoiding that second WRMSR(MSR_KERNEL_GS_BASE) should give some perf
back...

Although, I need to think how to make it pretty...

--
Regards/Gruss,
Boris.

https://people.kernel.org/tglx/notes-about-netiquette