From nobody Thu Dec 18 00:23:15 2025 Received: from mgamail.intel.com (mgamail.intel.com [192.198.163.13]) (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 8903C20764A; Tue, 18 Mar 2025 15:30:45 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=192.198.163.13 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1742311847; cv=none; b=XbtKy6OQnGr1hjLszgU1ElbHtwewzHSw97SDv+FHU9jSeLSrsg2e+PeAHLbQXYunjDoAVjNBVB9Is6kXraHtqRqmeXVNhj0w4RgUboetEv73cehLz70hTthd9m77Qx5GPITGjKmzG5xdp1Q2G7uoSbFTQCiEBeH/LCmOnPtr88g= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1742311847; c=relaxed/simple; bh=CfBZ+8mXBGLM/YmSmwqXprMbHg+9lkZP+XXoFIjAyQU=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=R8B/G/sU7we8n66uxH8mwlQwasP4ybC5qBk24mhIXJo8umyEjR72YVRS9YtTbwqbejPh6BJC9EuL5erJaIHSHB+Xn9cOTdor42Cvp6zJ4KmvPufCdF4lXq3d+i57g04SBjuaRFfdJsSpJhV7WcEPIGa0Ockt/xVZ6L0Dp+OlG5k= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=intel.com; spf=pass smtp.mailfrom=intel.com; dkim=pass (2048-bit key) header.d=intel.com header.i=@intel.com header.b=iTtumEFa; arc=none smtp.client-ip=192.198.163.13 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=intel.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=intel.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=intel.com header.i=@intel.com header.b="iTtumEFa" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1742311845; x=1773847845; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=CfBZ+8mXBGLM/YmSmwqXprMbHg+9lkZP+XXoFIjAyQU=; b=iTtumEFal+yzrvqryhgliLpaoGCx82RNOjTnN335yzjugcekvl2DoJrI ou5RNz/+LGmiu6U9wuJp3hQkS2WiW7lY/a8JoWRRecjC0b97UrnO6DuGt BexlNyB3OQC3NB4Wky3lAy+HIXsa/y2GUE/wMXFAsDRWsL64xQZbLINzn de/PfgtanWrAD9NPo82jy6B3Ij2QcCXalyJ97SWIh/ppGGEZklM35ZjFq w1eZoSPGzunaBQsoRMEYrX+4SpDZ79o4LGUoJVR3PgejZkJZrE0ObIa45 BVwqnA6FFb42cZTlgTsQnKdwYAOvRf5CzI7J0rfLgVlRYexPxFVw6g0/J w==; X-CSE-ConnectionGUID: qdyjY2MsQDalN7WkPC4O8w== X-CSE-MsgGUID: 4zVn1lY1RXuWFgjM1zX2KA== X-IronPort-AV: E=McAfee;i="6700,10204,11377"; a="46224170" X-IronPort-AV: E=Sophos;i="6.14,257,1736841600"; d="scan'208";a="46224170" Received: from fmviesa006.fm.intel.com ([10.60.135.146]) by fmvoesa107.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 18 Mar 2025 08:30:45 -0700 X-CSE-ConnectionGUID: NsNFwotwTR+UJawzz+EY3A== X-CSE-MsgGUID: 5lm04kP0RnKRQizoVR4irA== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.14,257,1736841600"; d="scan'208";a="122121858" Received: from spr.sh.intel.com ([10.239.53.19]) by fmviesa006-auth.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 18 Mar 2025 08:30:40 -0700 From: Chao Gao To: x86@kernel.org, linux-kernel@vger.kernel.org, kvm@vger.kernel.org, tglx@linutronix.de, dave.hansen@intel.com, seanjc@google.com, pbonzini@redhat.com Cc: peterz@infradead.org, rick.p.edgecombe@intel.com, weijiang.yang@intel.com, john.allen@amd.com, bp@alien8.de, chang.seok.bae@intel.com, xin3.li@intel.com, Chao Gao , Maxim Levitsky , Ingo Molnar , Dave Hansen , "H. Peter Anvin" , Mitchell Levy , Samuel Holland , Aruna Ramakrishna , Vignesh Balasubramanian Subject: [PATCH v4 3/8] x86/fpu/xstate: Add CET supervisor xfeature support Date: Tue, 18 Mar 2025 23:31:53 +0800 Message-ID: <20250318153316.1970147-4-chao.gao@intel.com> X-Mailer: git-send-email 2.46.1 In-Reply-To: <20250318153316.1970147-1-chao.gao@intel.com> References: <20250318153316.1970147-1-chao.gao@intel.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" From: Yang Weijiang To support CET virtualization, KVM needs the kernel to save and restore the CET supervisor xstate in guest FPUs when switching between guest and host FPUs. Add CET supervisor xstate support in preparation for the upcoming CET virtualization in KVM. Currently, host FPUs do not utilize the CET supervisor xstate. Enabling this state for host FPUs would lead to a 24-byte waste in the XSAVE buffer on CET-capable parts. Signed-off-by: Yang Weijiang Signed-off-by: Chao Gao Reviewed-by: Rick Edgecombe Reviewed-by: Maxim Levitsky --- arch/x86/include/asm/fpu/types.h | 14 ++++++++++++-- arch/x86/include/asm/fpu/xstate.h | 6 +++--- arch/x86/kernel/fpu/xstate.c | 5 ++++- 3 files changed, 19 insertions(+), 6 deletions(-) diff --git a/arch/x86/include/asm/fpu/types.h b/arch/x86/include/asm/fpu/ty= pes.h index 9f9ed406b179..d555f89db42f 100644 --- a/arch/x86/include/asm/fpu/types.h +++ b/arch/x86/include/asm/fpu/types.h @@ -118,7 +118,7 @@ enum xfeature { XFEATURE_PKRU, XFEATURE_PASID, XFEATURE_CET_USER, - XFEATURE_CET_KERNEL_UNUSED, + XFEATURE_CET_KERNEL, XFEATURE_RSRVD_COMP_13, XFEATURE_RSRVD_COMP_14, XFEATURE_LBR, @@ -141,7 +141,7 @@ enum xfeature { #define XFEATURE_MASK_PKRU (1 << XFEATURE_PKRU) #define XFEATURE_MASK_PASID (1 << XFEATURE_PASID) #define XFEATURE_MASK_CET_USER (1 << XFEATURE_CET_USER) -#define XFEATURE_MASK_CET_KERNEL (1 << XFEATURE_CET_KERNEL_UNUSED) +#define XFEATURE_MASK_CET_KERNEL (1 << XFEATURE_CET_KERNEL) #define XFEATURE_MASK_LBR (1 << XFEATURE_LBR) #define XFEATURE_MASK_XTILE_CFG (1 << XFEATURE_XTILE_CFG) #define XFEATURE_MASK_XTILE_DATA (1 << XFEATURE_XTILE_DATA) @@ -266,6 +266,16 @@ struct cet_user_state { u64 user_ssp; }; =20 +/* + * State component 12 is Control-flow Enforcement supervisor states + */ +struct cet_supervisor_state { + /* supervisor ssp pointers */ + u64 pl0_ssp; + u64 pl1_ssp; + u64 pl2_ssp; +}; + /* * State component 15: Architectural LBR configuration state. * The size of Arch LBR state depends on the number of LBRs (lbr_depth). diff --git a/arch/x86/include/asm/fpu/xstate.h b/arch/x86/include/asm/fpu/x= state.h index 7f39fe7980c5..8990cf381bef 100644 --- a/arch/x86/include/asm/fpu/xstate.h +++ b/arch/x86/include/asm/fpu/xstate.h @@ -47,7 +47,8 @@ =20 /* All currently supported supervisor features */ #define XFEATURE_MASK_SUPERVISOR_SUPPORTED (XFEATURE_MASK_PASID | \ - XFEATURE_MASK_CET_USER) + XFEATURE_MASK_CET_USER | \ + XFEATURE_MASK_CET_KERNEL) =20 /* * A supervisor state component may not always contain valuable informatio= n, @@ -74,8 +75,7 @@ * Unsupported supervisor features. When a supervisor feature in this mask= is * supported in the future, move it to the supported supervisor feature ma= sk. */ -#define XFEATURE_MASK_SUPERVISOR_UNSUPPORTED (XFEATURE_MASK_PT | \ - XFEATURE_MASK_CET_KERNEL) +#define XFEATURE_MASK_SUPERVISOR_UNSUPPORTED (XFEATURE_MASK_PT) =20 /* All supervisor states including supported and unsupported states. */ #define XFEATURE_MASK_SUPERVISOR_ALL (XFEATURE_MASK_SUPERVISOR_SUPPORTED |= \ diff --git a/arch/x86/kernel/fpu/xstate.c b/arch/x86/kernel/fpu/xstate.c index 40621ee4d65b..14c3a8285f50 100644 --- a/arch/x86/kernel/fpu/xstate.c +++ b/arch/x86/kernel/fpu/xstate.c @@ -55,7 +55,7 @@ static const char *xfeature_names[] =3D "Protection Keys User registers", "PASID state", "Control-flow User registers", - "Control-flow Kernel registers (unused)", + "Control-flow Kernel registers", "unknown xstate feature", "unknown xstate feature", "unknown xstate feature", @@ -78,6 +78,7 @@ static unsigned short xsave_cpuid_features[] __initdata = =3D { [XFEATURE_PKRU] =3D X86_FEATURE_OSPKE, [XFEATURE_PASID] =3D X86_FEATURE_ENQCMD, [XFEATURE_CET_USER] =3D X86_FEATURE_SHSTK, + [XFEATURE_CET_KERNEL] =3D X86_FEATURE_SHSTK, [XFEATURE_XTILE_CFG] =3D X86_FEATURE_AMX_TILE, [XFEATURE_XTILE_DATA] =3D X86_FEATURE_AMX_TILE, }; @@ -340,6 +341,7 @@ static __init void os_xrstor_booting(struct xregs_state= *xstate) XFEATURE_MASK_BNDCSR | \ XFEATURE_MASK_PASID | \ XFEATURE_MASK_CET_USER | \ + XFEATURE_MASK_CET_KERNEL | \ XFEATURE_MASK_XTILE) =20 /* @@ -540,6 +542,7 @@ static bool __init check_xstate_against_struct(int nr) case XFEATURE_PASID: return XCHECK_SZ(sz, nr, struct ia32_pasid_state); case XFEATURE_XTILE_CFG: return XCHECK_SZ(sz, nr, struct xtile_cfg); case XFEATURE_CET_USER: return XCHECK_SZ(sz, nr, struct cet_user_state); + case XFEATURE_CET_KERNEL: return XCHECK_SZ(sz, nr, struct cet_supervisor_= state); case XFEATURE_XTILE_DATA: check_xtile_data_against_struct(sz); return tru= e; default: XSTATE_WARN_ON(1, "No structure for xstate: %d\n", nr); --=20 2.46.1