From nobody Mon Jun 8 09:50:05 2026 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 8A6AE1EFFA1 for ; Thu, 4 Jun 2026 01:53:24 +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=1780538006; cv=none; b=RLNFq8CsJAwocBl/TfeS026AWJtEi6eTQ9iyeAXd3/B1qzr1yzWQRVwaaAlcTB3osSxo1Nhr9YgFGwqGoEaUPq0wHsqQFrIfuTQDx1gUnpGQA53Lh7UZ+IyNQueiOvCIjrH+tZ5PHyzn+avf0/KMxZmoEyPph+AqxBqgRuWIqKg= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1780538006; c=relaxed/simple; bh=/x8RcCneeqIG4qKAjHZeAySkYfqqzQAC66XayjDCKGc=; h=Date:From:To:Cc:Subject:Message-ID:MIME-Version:Content-Type: Content-Disposition; b=ombHSRv47XpHhP+Ja/ERguZDtjtp+wwSSxc69UhNcvYg/VDPzA166uDlAI5QKAqzIyw5h0ddeV6QJ+U57MWzKGv5euqHBs0m7rMjuCxKdWKe4RzTJFto1f64CIC47TBooY3D6a1LDzJQWKyyf2lb2YRXgisfUi1dxR7yRdL70vI= 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=ggpId5v4; 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="ggpId5v4" Received: from localhost (localhost.localdomain [127.0.0.1]) by mail.alien8.de (SuperMail on ZX Spectrum 128k) with ESMTP id A07A840E01B5; Thu, 4 Jun 2026 01:53:22 +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 M2Ncwc4CRVHK; Thu, 4 Jun 2026 01:53:13 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=alien8.de; s=alien8; t=1780537991; bh=yAWfa2sM0A7gBkiODFAt7vAfL0FYCW8psFb7DRk586Q=; h=Date:From:To:Cc:Subject:From; b=ggpId5v4FSGTKy5y4OBt2kwsEmcBbH2ORoDQ3pihcNvo9Yrkc5L+XmAhZVoKp6OlN k2PUaF7SoPCqauwhUwtaUd6OYrm5zLbFrf0FjXJLvxUzPF3stTM66ykG4kFadwbGTv GfCXeozS1+0zdC1Zy/CGfQ3wzJItlUgBTJze9y4yLhZ2bv+nxtxsv3oST+JzvXL5IS e37lJdWYB1q53sF7UP77FbyL4anKx2GfRAl4rkBGepEkOrFddFx2BeJErGby7qo5OU QTOhEw4UEBvgZh0eiBhD2U6L8Z5GhWySFKro5aj/kZheO8Kiso/WIWKrR2fFkZgZHx GwH4v0rJLVM5YA/Kcvx2ZuxnUlCNg6i7UGcDPTmwRRcqEvA6DqkNgtSmAytb+KagkN Bl2zn9TJ+ZkGkkJTbiz0PB2p7gcljdvsNLzv7b4Os0/Xms/7tYzCIIgi0abDN9KV1D CJoftDoermMammkrOwNzK8m6XZRCSG1erZgNgWPkLKHWCAeFGLMcnLoel+SDxOXhll n/3w5XFd4tt4gquHPXi3eCxgRfLx0RQCYwnz/haQ8r7Bh0PzNUjponSJX02km0PEni Gni8u9pS497d2MacbqSufe4fZUZcuKVzlujaICLmXviE5mtWxxvIU5LQsSR4K2I0Tj IRgEFr9BBUKlBo+CeRyInQ1I= Received: from stx.tnic (unknown [IPv6:2600:1700:38ca:c00::f]) (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 B482740E0031; Thu, 4 Jun 2026 01:53:06 +0000 (UTC) Date: Wed, 3 Jun 2026 18:53:03 -0700 From: Borislav Petkov To: "H. Peter Anvin" , Andrew Cooper Cc: x86-ML , LKML Subject: Save a WRMSR GS.base? Message-ID: <20260604015303.GEaiDafyuU0bwP4Y05@fat_crate.local> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Disposition: inline Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" 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 th= read_struct *prev, =20 /* 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 :=3D SRC; GS.attributes :=3D descriptor.attributes; IA32_KERNEL_GS_BASE :=3D descriptor.base; // bits 63:32 cleared so I can save myself the __wrgsbase_inactive() which ends up doing WRMSR GS.base.=20 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. --=20 Regards/Gruss, Boris. https://people.kernel.org/tglx/notes-about-netiquette