Re: Save a WRMSR GS.base?
From: H. Peter Anvin
Date: Fri Jun 05 2026 - 00:31:08 EST
On June 4, 2026 9:26:52 PM PDT, Borislav Petkov <bp@xxxxxxxxx> wrote:
>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...
>
Should be doing wrmsrns...