All of lore.kernel.org
 help / color / mirror / Atom feed
* Save a WRMSR GS.base?
@ 2026-06-04  1:53 Borislav Petkov
  2026-06-04  9:17 ` Andrew Cooper
  0 siblings, 1 reply; 25+ messages in thread
From: Borislav Petkov @ 2026-06-04  1:53 UTC (permalink / raw)
  To: H. Peter Anvin, Andrew Cooper; +Cc: x86-ML, LKML

Hi,

so here:

diff --git a/arch/x86/kernel/process_64.c b/arch/x86/kernel/process_64.c
index b85e715ebb30..ffa894bdb4ee 100644
--- a/arch/x86/kernel/process_64.c
+++ b/arch/x86/kernel/process_64.c
@@ -400,7 +400,9 @@ static __always_inline void x86_fsgsbase_load(struct thread_struct *prev,
 
 		/* Update the bases. */
 		wrfsbase(next->fsbase);
-		__wrgsbase_inactive(next->gsbase);
+
+		if (!cpu_feature_enabled(X86_FEATURE_LKGS))
+			__wrgsbase_inactive(next->gsbase);
 	} else {
 		load_seg_legacy(prev->fsindex, prev->fsbase,
 				next->fsindex, next->fsbase, FS);

a couple of lines above in that function we have:

                if (unlikely(prev->gsindex || next->gsindex))
                        loadseg(GS, next->gsindex);

which, on a FRED machine, would do LKGS. Now that insn does:

		GS.selector := SRC;
		GS.attributes := descriptor.attributes;
		IA32_KERNEL_GS_BASE := descriptor.base; // bits 63:32 cleared

so I can save myself the __wrgsbase_inactive() which ends up doing WRMSR
GS.base. 

Right? I.e., the diff above.

We're also not doing the optimization of checking whether prev.GS.base and
next.GS.base are equal. I see them both 0 in a trace here but I guess
luserpace can change them so I guess we wanna overwrite GS.base on context
switch unconditionally.

But LKGS does that for us so we don't need the WRMSR GS.base there, right?

Or am I missing something?

Thx.

-- 
Regards/Gruss,
    Boris.

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

^ permalink raw reply related	[flat|nested] 25+ messages in thread

end of thread, other threads:[~2026-06-18 18:18 UTC | newest]

Thread overview: 25+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-06-04  1:53 Save a WRMSR GS.base? Borislav Petkov
2026-06-04  9:17 ` Andrew Cooper
2026-06-05  2:24   ` Borislav Petkov
2026-06-05  2:36     ` H. Peter Anvin
2026-06-05  2:54       ` Borislav Petkov
2026-06-05  3:20         ` H. Peter Anvin
2026-06-05  4:26           ` Borislav Petkov
2026-06-05  4:30             ` H. Peter Anvin
2026-06-05  4:38               ` Borislav Petkov
2026-06-05  5:05                 ` H. Peter Anvin
2026-06-05  9:13                   ` Andrew Cooper
2026-06-05 15:13                     ` H. Peter Anvin
2026-06-05 15:16                       ` Andrew Cooper
2026-06-05 15:51                         ` H. Peter Anvin
2026-06-05 17:17                           ` Borislav Petkov
2026-06-08  6:46                             ` H. Peter Anvin
2026-06-08 14:38                               ` Borislav Petkov
2026-06-08 17:30                                 ` H. Peter Anvin
2026-06-08 20:05                                   ` Borislav Petkov
2026-06-08 21:21                                     ` Borislav Petkov
2026-06-08 21:52                                       ` H. Peter Anvin
2026-06-08 22:58                                       ` Andrew Cooper
2026-06-18  1:09                                         ` Borislav Petkov
2026-06-18 10:22                                           ` David Laight
2026-06-18 18:17                                             ` H. Peter Anvin

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.