From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mail.alien8.de (mail.alien8.de [65.109.113.108]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id C747E1EF091 for ; Fri, 5 Jun 2026 02:55:43 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=65.109.113.108 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1780628150; cv=none; b=DPPmdRYZgIBCAUPDsZfeKYEgNpb78lDHFCwD5G9vkKOJ00QKOgN2lr57CfJNDwkrYqLfxuhyFPJSefqfhcl9eXnMa0zppNsI3SydtSu74RgyPQfc+kT7k4FG6Cwa++Q+Cq1h8iaZkq3DBugI/Mb2jcenyA6qNiZ4ODlBZ50h924= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1780628150; c=relaxed/simple; bh=hKBp6F5O+1TFFZ94GjiMKYeFJ0vp69JrEKmpqrpi8l0=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=I+3CvSxyGOGV6//n21bjTZ0MUjg4J9iwsBB31cc3r5aQ90mz5QuEB0F2HAd1dvcmD0GyKYW5DKJ+gSwABjgCrtZj3Ebj2c1GYHR+W5ism1If4pfkgqrRAUoNH8lGWLYCD9RUyBDBKdIU9+mUbslG+7kIn3zTsDOFwxxju2h13vk= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=alien8.de; spf=pass smtp.mailfrom=alien8.de; dkim=pass (4096-bit key) header.d=alien8.de header.i=@alien8.de header.b=SesPwFJ0; arc=none smtp.client-ip=65.109.113.108 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=alien8.de Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=alien8.de Authentication-Results: smtp.subspace.kernel.org; dkim=pass (4096-bit key) header.d=alien8.de header.i=@alien8.de header.b="SesPwFJ0" Received: from localhost (localhost.localdomain [127.0.0.1]) by mail.alien8.de (SuperMail on ZX Spectrum 128k) with ESMTP id 8335A40E0202; Fri, 5 Jun 2026 02:55:41 +0000 (UTC) X-Virus-Scanned: Debian amavisd-new at mail.alien8.de Authentication-Results: mail.alien8.de (amavisd-new); dkim=pass (4096-bit key) header.d=alien8.de Received: from mail.alien8.de ([127.0.0.1]) by localhost (mail.alien8.de [127.0.0.1]) (amavisd-new, port 10026) with ESMTP id mNDaKGrRJwfM; Fri, 5 Jun 2026 02:55:31 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=alien8.de; s=alien8; t=1780628131; bh=5BGdQx+OZ5mQYOK2WDexcmAVLi+38L6Khj+ID56QMWc=; h=Date:From:To:Cc:Subject:References:In-Reply-To:From; b=SesPwFJ0M8EG6eStlLAmF0olDnUlheV/uoIeQ/otZc1XHj6NTZVqtaSa1smdSb0m1 9xPsWTLWWBUb/ZPE1gcktMg5NeTMvGrNxjcSqGqeF37KYU8BSk7gt000jNQwYN/nwR PqQ33qcOjv+Rh+4kGhPAlmj1REIuGCMZvEgkK0hx5ZX3yDPy05uYv/M6MpgtAGLrCt W+ZPN8NC07FOs9m1jVya3OoQlQMHe8/o0gtXKqAqWSbhccOqiecd7lD1FuHxyVw1jn 2bXVeg3yunRmtPY7LlS04oYsrWVy2ah0343g7RN+qoAPRgx/y+d4ZlNPdPRxnYF3c6 6FmdKuta+9vEymwrqj8nODHKMjBiukrSM7Mf3chRuBYJWze9ikc4QKg9Kjq+kBO0K8 VzyTldtDa8vEpHhL+oE/5tOdqq5iVd6o+P0S0vZ+Pp/2+Grc6F/hX9Dn5DV8sRrQSj shYPU48nruHorMP8bnHIkLQDGHrXoT948AVA6IFga+l3rynnZa88LbTrV9szeLKAqi eT+eqEjfilxbsFc+fTl6wf21qIaJzUzIOQCbUjrpD6mUXkGvZHVsQlgKcMkQfscfLE qAwCyPsPwgYzLkJEicbrUHwEzEHJBrr2MEb9M6p6jJeLfRtAP1ZZTXTzjThH5g7b7S rF5vI8gf8E6/H7jKBOfLkoF0= Received: from stx.tnic (unknown [IPv6:2600:1700:38ca:c00::b]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange ECDHE (P-256) server-signature ECDSA (P-256) server-digest SHA256) (No client certificate requested) by mail.alien8.de (SuperMail on ZX Spectrum 128k) with ESMTPSA id F355640E00C0; Fri, 5 Jun 2026 02:55:26 +0000 (UTC) Date: Thu, 4 Jun 2026 19:54:53 -0700 From: Borislav Petkov To: "H. Peter Anvin" Cc: Andrew Cooper , x86-ML , LKML Subject: Re: Save a WRMSR GS.base? Message-ID: <20260605025453.GAaiI6fdfradMwrUEk@fat_crate.local> References: <20260604015303.GEaiDafyuU0bwP4Y05@fat_crate.local> <180aeb02-4ed9-436c-ba61-c8559eb7994c@citrix.com> <20260605022428.GBaiIzXL7TgIjMj8d7@fat_crate.local> <18B4FA09-40DE-43D0-A3D0-DD16DE652B87@zytor.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Disposition: inline In-Reply-To: <18B4FA09-40DE-43D0-A3D0-DD16DE652B87@zytor.com> On Thu, Jun 04, 2026 at 07:36:01PM -0700, H. Peter Anvin wrote: > >diff --git a/arch/x86/kernel/process_64.c b/arch/x86/kernel/process_64.c > >index b85e715ebb30..248c39da9ba0 100644 > >--- a/arch/x86/kernel/process_64.c > >+++ b/arch/x86/kernel/process_64.c > >@@ -391,16 +391,23 @@ static __always_inline void x86_pkru_load(struct thread_struct *prev, > > static __always_inline void x86_fsgsbase_load(struct thread_struct *prev, > > struct thread_struct *next) > > { > >+ bool loaded_gs = false; > >+ > > if (static_cpu_has(X86_FEATURE_FSGSBASE)) { > > /* Update the FS and GS selectors if they could have changed. */ > > if (unlikely(prev->fsindex || next->fsindex)) > > loadseg(FS, next->fsindex); > >- if (unlikely(prev->gsindex || next->gsindex)) > >+ > >+ if (unlikely(prev->gsindex || next->gsindex)) { > > loadseg(GS, next->gsindex); > >+ loaded_gs = true; > >+ } > > > > /* Update the bases. */ > > wrfsbase(next->fsbase); > >- __wrgsbase_inactive(next->gsbase); > >+ > >+ if (!(cpu_feature_enabled(X86_FEATURE_LKGS) && loaded_gs)) > >+ __wrgsbase_inactive(next->gsbase); > > } else { > > load_seg_legacy(prev->fsindex, prev->fsbase, > > next->fsindex, next->fsbase, FS); > > > > > >Thx. > > > > Also consider that user space might have done: > > mov gs,... > wrgsbase ... > > So gs.selector > 3 doesn't necessarily mean that the base is consistent with the descriptor. Right, I want to avoid the second write to KERNEL_GS_BASE iff we have done LKGS before. -- Regards/Gruss, Boris. https://people.kernel.org/tglx/notes-about-netiquette