Message ID | 20231124055330.138870-4-weijiang.yang@intel.com |
---|---|
State | New |
Headers |
Return-Path: <linux-kernel-owner@vger.kernel.org> Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:ce62:0:b0:403:3b70:6f57 with SMTP id o2csp983536vqx; Thu, 23 Nov 2023 23:59:44 -0800 (PST) X-Google-Smtp-Source: AGHT+IGZtW0SWLzAGgwEfHGUMgku6tY9Dw4ZS2+xUZ4F7qoVPUqs+xJGY4DzHtttCCKliWSenHKb X-Received: by 2002:a17:90a:bd11:b0:283:9db9:ec74 with SMTP id y17-20020a17090abd1100b002839db9ec74mr7523578pjr.2.1700812784108; Thu, 23 Nov 2023 23:59:44 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1700812784; cv=none; d=google.com; s=arc-20160816; b=IYaHEW08RZnFm4qGjrLstiCMCDgZEFrjs/8AxCjJB6lREkF4Fgx9GxuwLiKRQatitp vRzuQrBqQlQZkii0yDHSWMZtp5QBBgXGvh13RkTnMZy59wC+hEW/yYuFnOR4TLiHeEmR yujOwEE1hw3bQ0ii0slzc5c3H7kRf6gi+/cnUs8SO6mHJ/SOjrjUBDAkJyfEbCt1mpAp REzhO7nHvsxKaJUvf0q1G+zC0Sm2CIt7RhZSlZdGrc5K4T/deBVWnV9mz0ap6mLoiK9S f51ZKy0BvZVvPFnOXAgJUiWc/mmIeWYc7Q6Z1PNREM10TyF/Q210JSZvM7hn8o4wS02s EXXg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=y05SARCY1T6an8WHE+/ITXTVUCYp5gt3Zx8PELwRekI=; fh=uy0EBGgYIm8+MgsxUvKHUXUo3s9z4H9hdLwRv8YoeJU=; b=S9dbPYhbbLoueca9uXTdJ7wtVtsoDK3YTz5lONE2mnHS0D4hl9vgZalpNNCUc7qJKk u6qhjFDBX/F03U4RYrMFZ7Qho5ctMTA1RZM9LR3qa7pfDDsRBJ8Z5mPIeLT/LNjXikUY 3a4NwHOJkVYov9XR67Wrmg0RLmW07ZIbWXabk0bFHosLah+vRRB9SGJ2Me1lU7tu+DnL h9VEuawbHL+eys0Mo/9WGG5XjYOu0ZNBuAiyZZ00qK7e2ope6DZHLm18JDTVV6uaaWgr 3zXI3AxjtwHUQwftx9Wh99cEu8jdiCEWiIyasSlhyaV+Nt7GOQVVT20z4Mg9KDZ29SSj NxYQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=NhV2JNFG; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:2 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=intel.com Received: from agentk.vger.email (agentk.vger.email. [2620:137:e000::3:2]) by mx.google.com with ESMTPS id h1-20020a170902f54100b001cc32df8ecesi2936102plf.513.2023.11.23.23.59.43 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 23 Nov 2023 23:59:44 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:2 as permitted sender) client-ip=2620:137:e000::3:2; Authentication-Results: mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=NhV2JNFG; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:2 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=intel.com Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by agentk.vger.email (Postfix) with ESMTP id E43C080687CC; Thu, 23 Nov 2023 23:59:40 -0800 (PST) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.11 at agentk.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S235227AbjKXH7B (ORCPT <rfc822;jaysivo@gmail.com> + 29 others); Fri, 24 Nov 2023 02:59:01 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:49348 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234724AbjKXH6g (ORCPT <rfc822;linux-kernel@vger.kernel.org>); Fri, 24 Nov 2023 02:58:36 -0500 Received: from mgamail.intel.com (mgamail.intel.com [134.134.136.100]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 336B51718; Thu, 23 Nov 2023 23:58:41 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1700812721; x=1732348721; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=ueFBMa7IWWTU+8CMTyEu010bIW30ttCfBescaRmbKyY=; b=NhV2JNFG7FL5vni/7wNvk37Jg7HjawQodC+XGT2PK85DPqi0kXFWtRRp Dyy3pe7VrMJDBsfx31RL4okmjvjCmJYbpG+575nuVhNT7Pl888vW9jdWY pPSPXS8bR9Uh/xTC5LeIDk4qRWDwJsg1arag3K/U1DpRUj3GfkbNio7gc Xd+qIQahzwviyrsRjselm9yWg20IWpd/eclp/PaSyY2jO1ldRp9kpJ0VY tn7tldecbPCF32Ga28gh9NED5ACiVJxTNI4IuM6DuiUPyclSGOdqD9jyN /zfPmKixAw/6EpSxCHIabwge9YrgWvcZrN2hRQvKahUlSiYFNU3vPwdwg A==; X-IronPort-AV: E=McAfee;i="6600,9927,10902"; a="458872281" X-IronPort-AV: E=Sophos;i="6.04,223,1695711600"; d="scan'208";a="458872281" Received: from fmsmga008.fm.intel.com ([10.253.24.58]) by orsmga105.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 23 Nov 2023 23:58:36 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=McAfee;i="6600,9927,10902"; a="833629798" X-IronPort-AV: E=Sophos;i="6.04,223,1695711600"; d="scan'208";a="833629798" Received: from unknown (HELO embargo.jf.intel.com) ([10.165.9.183]) by fmsmga008-auth.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 23 Nov 2023 23:58:35 -0800 From: Yang Weijiang <weijiang.yang@intel.com> To: seanjc@google.com, pbonzini@redhat.com, dave.hansen@intel.com, kvm@vger.kernel.org, linux-kernel@vger.kernel.org Cc: peterz@infradead.org, chao.gao@intel.com, rick.p.edgecombe@intel.com, mlevitsk@redhat.com, john.allen@amd.com, weijiang.yang@intel.com Subject: [PATCH v7 03/26] x86/fpu/xstate: Add CET supervisor mode state support Date: Fri, 24 Nov 2023 00:53:07 -0500 Message-Id: <20231124055330.138870-4-weijiang.yang@intel.com> X-Mailer: git-send-email 2.27.0 In-Reply-To: <20231124055330.138870-1-weijiang.yang@intel.com> References: <20231124055330.138870-1-weijiang.yang@intel.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-0.9 required=5.0 tests=DKIMWL_WL_HIGH,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on agentk.vger.email Precedence: bulk List-ID: <linux-kernel.vger.kernel.org> X-Mailing-List: linux-kernel@vger.kernel.org X-Greylist: Sender passed SPF test, not delayed by milter-greylist-4.6.4 (agentk.vger.email [0.0.0.0]); Thu, 23 Nov 2023 23:59:41 -0800 (PST) X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1783431465828591254 X-GMAIL-MSGID: 1783431465828591254 |
Series |
Enable CET Virtualization
|
|
Commit Message
Yang, Weijiang
Nov. 24, 2023, 5:53 a.m. UTC
Add supervisor mode state support within FPU xstate management framework.
Although supervisor shadow stack is not enabled/used today in kernel,KVM
requires the support because when KVM advertises shadow stack feature to
guest, architecturally it claims the support for both user and supervisor
modes for guest OSes(Linux or non-Linux).
CET supervisor states not only includes PL{0,1,2}_SSP but also IA32_S_CET
MSR, but the latter is not xsave-managed. In virtualization world, guest
IA32_S_CET is saved/stored into/from VM control structure. With supervisor
xstate support, guest supervisor mode shadow stack state can be properly
saved/restored when 1) guest/host FPU context is swapped 2) vCPU
thread is sched out/in.
The alternative is to enable it in KVM domain, but KVM maintainers NAKed
the solution. The external discussion can be found at [*], it ended up
with adding the support in kernel instead of KVM domain.
Note, in KVM case, guest CET supervisor state i.e., IA32_PL{0,1,2}_MSRs,
are preserved after VM-Exit until host/guest fpstates are swapped, but
since host supervisor shadow stack is disabled, the preserved MSRs won't
hurt host.
[*]: https://lore.kernel.org/all/806e26c2-8d21-9cc9-a0b7-7787dd231729@intel.com/
Signed-off-by: Yang Weijiang <weijiang.yang@intel.com>
---
arch/x86/include/asm/fpu/types.h | 14 ++++++++++++--
arch/x86/include/asm/fpu/xstate.h | 6 +++---
arch/x86/kernel/fpu/xstate.c | 6 +++++-
3 files changed, 20 insertions(+), 6 deletions(-)
Comments
On Fri, Nov 24, 2023 at 12:53:07AM -0500, Yang Weijiang wrote: > Note, in KVM case, guest CET supervisor state i.e., IA32_PL{0,1,2}_MSRs, > are preserved after VM-Exit until host/guest fpstates are swapped, but > since host supervisor shadow stack is disabled, the preserved MSRs won't > hurt host. Just to be clear, with FRED all this changes, right? Then we get more VMCS fields for SSS state.
On 11/24/2023 5:45 PM, Peter Zijlstra wrote: > On Fri, Nov 24, 2023 at 12:53:07AM -0500, Yang Weijiang wrote: > >> Note, in KVM case, guest CET supervisor state i.e., IA32_PL{0,1,2}_MSRs, >> are preserved after VM-Exit until host/guest fpstates are swapped, but >> since host supervisor shadow stack is disabled, the preserved MSRs won't >> hurt host. > Just to be clear, with FRED all this changes, right? Then we get more > VMCS fields for SSS state. Yes, I think so, KVM needs to properly handle guest SSS state and host FRED states. Thanks!
On Fri, 2023-11-24 at 00:53 -0500, Yang Weijiang wrote: > Add supervisor mode state support within FPU xstate management > framework. > Although supervisor shadow stack is not enabled/used today in > kernel,KVM > requires the support because when KVM advertises shadow stack feature > to > guest, architecturally it claims the support for both user and > supervisor > modes for guest OSes(Linux or non-Linux). > > CET supervisor states not only includes PL{0,1,2}_SSP but also > IA32_S_CET > MSR, but the latter is not xsave-managed. In virtualization world, > guest > IA32_S_CET is saved/stored into/from VM control structure. With > supervisor > xstate support, guest supervisor mode shadow stack state can be > properly > saved/restored when 1) guest/host FPU context is swapped 2) vCPU > thread is sched out/in. > > The alternative is to enable it in KVM domain, but KVM maintainers > NAKed > the solution. The external discussion can be found at [*], it ended > up > with adding the support in kernel instead of KVM domain. > > Note, in KVM case, guest CET supervisor state i.e., > IA32_PL{0,1,2}_MSRs, > are preserved after VM-Exit until host/guest fpstates are swapped, > but > since host supervisor shadow stack is disabled, the preserved MSRs > won't > hurt host. > > [*]: > https://lore.kernel.org/all/806e26c2-8d21-9cc9-a0b7-7787dd231729@intel.com/ > > Signed-off-by: Yang Weijiang <weijiang.yang@intel.com> Reviewed-by: Rick Edgecombe <rick.p.edgecombe@intel.com>
On Fri, 2023-11-24 at 00:53 -0500, Yang Weijiang wrote: > Add supervisor mode state support within FPU xstate management framework. > Although supervisor shadow stack is not enabled/used today in kernel,KVM > requires the support because when KVM advertises shadow stack feature to > guest, architecturally it claims the support for both user and supervisor > modes for guest OSes(Linux or non-Linux). > > CET supervisor states not only includes PL{0,1,2}_SSP but also IA32_S_CET > MSR, but the latter is not xsave-managed. In virtualization world, guest > IA32_S_CET is saved/stored into/from VM control structure. With supervisor > xstate support, guest supervisor mode shadow stack state can be properly > saved/restored when 1) guest/host FPU context is swapped 2) vCPU > thread is sched out/in. > > The alternative is to enable it in KVM domain, but KVM maintainers NAKed > the solution. The external discussion can be found at [*], it ended up > with adding the support in kernel instead of KVM domain. > > Note, in KVM case, guest CET supervisor state i.e., IA32_PL{0,1,2}_MSRs, > are preserved after VM-Exit until host/guest fpstates are swapped, but > since host supervisor shadow stack is disabled, the preserved MSRs won't > hurt host. > > [*]: https://lore.kernel.org/all/806e26c2-8d21-9cc9-a0b7-7787dd231729@intel.com/ > > Signed-off-by: Yang Weijiang <weijiang.yang@intel.com> > --- > arch/x86/include/asm/fpu/types.h | 14 ++++++++++++-- > arch/x86/include/asm/fpu/xstate.h | 6 +++--- > arch/x86/kernel/fpu/xstate.c | 6 +++++- > 3 files changed, 20 insertions(+), 6 deletions(-) > > diff --git a/arch/x86/include/asm/fpu/types.h b/arch/x86/include/asm/fpu/types.h > index eb810074f1e7..c6fd13a17205 100644 > --- a/arch/x86/include/asm/fpu/types.h > +++ b/arch/x86/include/asm/fpu/types.h > @@ -116,7 +116,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, > @@ -139,7 +139,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) > @@ -264,6 +264,16 @@ struct cet_user_state { > u64 user_ssp; > }; > > +/* > + * 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/xstate.h > index d4427b88ee12..3b4a038d3c57 100644 > --- a/arch/x86/include/asm/fpu/xstate.h > +++ b/arch/x86/include/asm/fpu/xstate.h > @@ -51,7 +51,8 @@ > > /* 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) > > /* > * A supervisor state component may not always contain valuable information, > @@ -78,8 +79,7 @@ > * Unsupported supervisor features. When a supervisor feature in this mask is > * supported in the future, move it to the supported supervisor feature mask. > */ > -#define XFEATURE_MASK_SUPERVISOR_UNSUPPORTED (XFEATURE_MASK_PT | \ > - XFEATURE_MASK_CET_KERNEL) > +#define XFEATURE_MASK_SUPERVISOR_UNSUPPORTED (XFEATURE_MASK_PT) > > /* 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 6e50a4251e2b..b57d909facca 100644 > --- a/arch/x86/kernel/fpu/xstate.c > +++ b/arch/x86/kernel/fpu/xstate.c > @@ -51,7 +51,7 @@ static const char *xfeature_names[] = > "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", > @@ -73,6 +73,7 @@ static unsigned short xsave_cpuid_features[] __initdata = { > [XFEATURE_PT_UNIMPLEMENTED_SO_FAR] = X86_FEATURE_INTEL_PT, > [XFEATURE_PKRU] = X86_FEATURE_OSPKE, > [XFEATURE_PASID] = X86_FEATURE_ENQCMD, > + [XFEATURE_CET_KERNEL] = X86_FEATURE_SHSTK, > [XFEATURE_XTILE_CFG] = X86_FEATURE_AMX_TILE, > [XFEATURE_XTILE_DATA] = X86_FEATURE_AMX_TILE, > }; > @@ -277,6 +278,7 @@ static void __init print_xstate_features(void) > print_xstate_feature(XFEATURE_MASK_PKRU); > print_xstate_feature(XFEATURE_MASK_PASID); > print_xstate_feature(XFEATURE_MASK_CET_USER); > + print_xstate_feature(XFEATURE_MASK_CET_KERNEL); > print_xstate_feature(XFEATURE_MASK_XTILE_CFG); > print_xstate_feature(XFEATURE_MASK_XTILE_DATA); > } > @@ -346,6 +348,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) > > /* > @@ -546,6 +549,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 true; > default: > XSTATE_WARN_ON(1, "No structure for xstate: %d\n", nr); Any reason why my reviewed-by was not added to this patch? Reviewed-by: Maxim Levitsky <mlevitsk@redhat.com> Best regards, Maxim Levitsky
On 12/1/2023 1:27 AM, Maxim Levitsky wrote: > On Fri, 2023-11-24 at 00:53 -0500, Yang Weijiang wrote: >> Add supervisor mode state support within FPU xstate management framework. >> Although supervisor shadow stack is not enabled/used today in kernel,KVM >> requires the support because when KVM advertises shadow stack feature to >> guest, architecturally it claims the support for both user and supervisor >> modes for guest OSes(Linux or non-Linux). >> >> CET supervisor states not only includes PL{0,1,2}_SSP but also IA32_S_CET >> MSR, but the latter is not xsave-managed. In virtualization world, guest >> IA32_S_CET is saved/stored into/from VM control structure. With supervisor >> xstate support, guest supervisor mode shadow stack state can be properly >> saved/restored when 1) guest/host FPU context is swapped 2) vCPU >> thread is sched out/in. >> >> The alternative is to enable it in KVM domain, but KVM maintainers NAKed >> the solution. The external discussion can be found at [*], it ended up >> with adding the support in kernel instead of KVM domain. >> >> Note, in KVM case, guest CET supervisor state i.e., IA32_PL{0,1,2}_MSRs, >> are preserved after VM-Exit until host/guest fpstates are swapped, but >> since host supervisor shadow stack is disabled, the preserved MSRs won't >> hurt host. >> >> [*]: https://lore.kernel.org/all/806e26c2-8d21-9cc9-a0b7-7787dd231729@intel.com/ >> >> Signed-off-by: Yang Weijiang <weijiang.yang@intel.com> >> --- >> arch/x86/include/asm/fpu/types.h | 14 ++++++++++++-- >> arch/x86/include/asm/fpu/xstate.h | 6 +++--- >> arch/x86/kernel/fpu/xstate.c | 6 +++++- >> 3 files changed, 20 insertions(+), 6 deletions(-) >> >> diff --git a/arch/x86/include/asm/fpu/types.h b/arch/x86/include/asm/fpu/types.h >> index eb810074f1e7..c6fd13a17205 100644 >> --- a/arch/x86/include/asm/fpu/types.h >> +++ b/arch/x86/include/asm/fpu/types.h >> @@ -116,7 +116,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, >> @@ -139,7 +139,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) >> @@ -264,6 +264,16 @@ struct cet_user_state { >> u64 user_ssp; >> }; >> >> +/* >> + * 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/xstate.h >> index d4427b88ee12..3b4a038d3c57 100644 >> --- a/arch/x86/include/asm/fpu/xstate.h >> +++ b/arch/x86/include/asm/fpu/xstate.h >> @@ -51,7 +51,8 @@ >> >> /* 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) >> >> /* >> * A supervisor state component may not always contain valuable information, >> @@ -78,8 +79,7 @@ >> * Unsupported supervisor features. When a supervisor feature in this mask is >> * supported in the future, move it to the supported supervisor feature mask. >> */ >> -#define XFEATURE_MASK_SUPERVISOR_UNSUPPORTED (XFEATURE_MASK_PT | \ >> - XFEATURE_MASK_CET_KERNEL) >> +#define XFEATURE_MASK_SUPERVISOR_UNSUPPORTED (XFEATURE_MASK_PT) >> >> /* 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 6e50a4251e2b..b57d909facca 100644 >> --- a/arch/x86/kernel/fpu/xstate.c >> +++ b/arch/x86/kernel/fpu/xstate.c >> @@ -51,7 +51,7 @@ static const char *xfeature_names[] = >> "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", >> @@ -73,6 +73,7 @@ static unsigned short xsave_cpuid_features[] __initdata = { >> [XFEATURE_PT_UNIMPLEMENTED_SO_FAR] = X86_FEATURE_INTEL_PT, >> [XFEATURE_PKRU] = X86_FEATURE_OSPKE, >> [XFEATURE_PASID] = X86_FEATURE_ENQCMD, >> + [XFEATURE_CET_KERNEL] = X86_FEATURE_SHSTK, >> [XFEATURE_XTILE_CFG] = X86_FEATURE_AMX_TILE, >> [XFEATURE_XTILE_DATA] = X86_FEATURE_AMX_TILE, >> }; >> @@ -277,6 +278,7 @@ static void __init print_xstate_features(void) >> print_xstate_feature(XFEATURE_MASK_PKRU); >> print_xstate_feature(XFEATURE_MASK_PASID); >> print_xstate_feature(XFEATURE_MASK_CET_USER); >> + print_xstate_feature(XFEATURE_MASK_CET_KERNEL); >> print_xstate_feature(XFEATURE_MASK_XTILE_CFG); >> print_xstate_feature(XFEATURE_MASK_XTILE_DATA); >> } >> @@ -346,6 +348,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) >> >> /* >> @@ -546,6 +549,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 true; >> default: >> XSTATE_WARN_ON(1, "No structure for xstate: %d\n", nr); > Any reason why my reviewed-by was not added to this patch? My apology again! I missed the Reviewed-by tag for this patch! Appreciated for your careful review for this series! > Reviewed-by: Maxim Levitsky <mlevitsk@redhat.com> > > Best regards, > Maxim Levitsky > > >
On Fri, 2023-12-01 at 15:01 +0800, Yang, Weijiang wrote: > On 12/1/2023 1:27 AM, Maxim Levitsky wrote: > > On Fri, 2023-11-24 at 00:53 -0500, Yang Weijiang wrote: > > > Add supervisor mode state support within FPU xstate management framework. > > > Although supervisor shadow stack is not enabled/used today in kernel,KVM > > > requires the support because when KVM advertises shadow stack feature to > > > guest, architecturally it claims the support for both user and supervisor > > > modes for guest OSes(Linux or non-Linux). > > > > > > CET supervisor states not only includes PL{0,1,2}_SSP but also IA32_S_CET > > > MSR, but the latter is not xsave-managed. In virtualization world, guest > > > IA32_S_CET is saved/stored into/from VM control structure. With supervisor > > > xstate support, guest supervisor mode shadow stack state can be properly > > > saved/restored when 1) guest/host FPU context is swapped 2) vCPU > > > thread is sched out/in. > > > > > > The alternative is to enable it in KVM domain, but KVM maintainers NAKed > > > the solution. The external discussion can be found at [*], it ended up > > > with adding the support in kernel instead of KVM domain. > > > > > > Note, in KVM case, guest CET supervisor state i.e., IA32_PL{0,1,2}_MSRs, > > > are preserved after VM-Exit until host/guest fpstates are swapped, but > > > since host supervisor shadow stack is disabled, the preserved MSRs won't > > > hurt host. > > > > > > [*]: https://lore.kernel.org/all/806e26c2-8d21-9cc9-a0b7-7787dd231729@intel.com/ > > > > > > Signed-off-by: Yang Weijiang <weijiang.yang@intel.com> > > > --- > > > arch/x86/include/asm/fpu/types.h | 14 ++++++++++++-- > > > arch/x86/include/asm/fpu/xstate.h | 6 +++--- > > > arch/x86/kernel/fpu/xstate.c | 6 +++++- > > > 3 files changed, 20 insertions(+), 6 deletions(-) > > > > > > diff --git a/arch/x86/include/asm/fpu/types.h b/arch/x86/include/asm/fpu/types.h > > > index eb810074f1e7..c6fd13a17205 100644 > > > --- a/arch/x86/include/asm/fpu/types.h > > > +++ b/arch/x86/include/asm/fpu/types.h > > > @@ -116,7 +116,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, > > > @@ -139,7 +139,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) > > > @@ -264,6 +264,16 @@ struct cet_user_state { > > > u64 user_ssp; > > > }; > > > > > > +/* > > > + * 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/xstate.h > > > index d4427b88ee12..3b4a038d3c57 100644 > > > --- a/arch/x86/include/asm/fpu/xstate.h > > > +++ b/arch/x86/include/asm/fpu/xstate.h > > > @@ -51,7 +51,8 @@ > > > > > > /* 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) > > > > > > /* > > > * A supervisor state component may not always contain valuable information, > > > @@ -78,8 +79,7 @@ > > > * Unsupported supervisor features. When a supervisor feature in this mask is > > > * supported in the future, move it to the supported supervisor feature mask. > > > */ > > > -#define XFEATURE_MASK_SUPERVISOR_UNSUPPORTED (XFEATURE_MASK_PT | \ > > > - XFEATURE_MASK_CET_KERNEL) > > > +#define XFEATURE_MASK_SUPERVISOR_UNSUPPORTED (XFEATURE_MASK_PT) > > > > > > /* 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 6e50a4251e2b..b57d909facca 100644 > > > --- a/arch/x86/kernel/fpu/xstate.c > > > +++ b/arch/x86/kernel/fpu/xstate.c > > > @@ -51,7 +51,7 @@ static const char *xfeature_names[] = > > > "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", > > > @@ -73,6 +73,7 @@ static unsigned short xsave_cpuid_features[] __initdata = { > > > [XFEATURE_PT_UNIMPLEMENTED_SO_FAR] = X86_FEATURE_INTEL_PT, > > > [XFEATURE_PKRU] = X86_FEATURE_OSPKE, > > > [XFEATURE_PASID] = X86_FEATURE_ENQCMD, > > > + [XFEATURE_CET_KERNEL] = X86_FEATURE_SHSTK, > > > [XFEATURE_XTILE_CFG] = X86_FEATURE_AMX_TILE, > > > [XFEATURE_XTILE_DATA] = X86_FEATURE_AMX_TILE, > > > }; > > > @@ -277,6 +278,7 @@ static void __init print_xstate_features(void) > > > print_xstate_feature(XFEATURE_MASK_PKRU); > > > print_xstate_feature(XFEATURE_MASK_PASID); > > > print_xstate_feature(XFEATURE_MASK_CET_USER); > > > + print_xstate_feature(XFEATURE_MASK_CET_KERNEL); > > > print_xstate_feature(XFEATURE_MASK_XTILE_CFG); > > > print_xstate_feature(XFEATURE_MASK_XTILE_DATA); > > > } > > > @@ -346,6 +348,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) > > > > > > /* > > > @@ -546,6 +549,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 true; > > > default: > > > XSTATE_WARN_ON(1, "No structure for xstate: %d\n", nr); > > Any reason why my reviewed-by was not added to this patch? > > My apology again! I missed the Reviewed-by tag for this patch! > > Appreciated for your careful review for this series! Thank you very much! Best regards, Maxim Levitsky > > > Reviewed-by: Maxim Levitsky <mlevitsk@redhat.com> > > > > Best regards, > > Maxim Levitsky > > > > > >
diff --git a/arch/x86/include/asm/fpu/types.h b/arch/x86/include/asm/fpu/types.h index eb810074f1e7..c6fd13a17205 100644 --- a/arch/x86/include/asm/fpu/types.h +++ b/arch/x86/include/asm/fpu/types.h @@ -116,7 +116,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, @@ -139,7 +139,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) @@ -264,6 +264,16 @@ struct cet_user_state { u64 user_ssp; }; +/* + * 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/xstate.h index d4427b88ee12..3b4a038d3c57 100644 --- a/arch/x86/include/asm/fpu/xstate.h +++ b/arch/x86/include/asm/fpu/xstate.h @@ -51,7 +51,8 @@ /* 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) /* * A supervisor state component may not always contain valuable information, @@ -78,8 +79,7 @@ * Unsupported supervisor features. When a supervisor feature in this mask is * supported in the future, move it to the supported supervisor feature mask. */ -#define XFEATURE_MASK_SUPERVISOR_UNSUPPORTED (XFEATURE_MASK_PT | \ - XFEATURE_MASK_CET_KERNEL) +#define XFEATURE_MASK_SUPERVISOR_UNSUPPORTED (XFEATURE_MASK_PT) /* 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 6e50a4251e2b..b57d909facca 100644 --- a/arch/x86/kernel/fpu/xstate.c +++ b/arch/x86/kernel/fpu/xstate.c @@ -51,7 +51,7 @@ static const char *xfeature_names[] = "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", @@ -73,6 +73,7 @@ static unsigned short xsave_cpuid_features[] __initdata = { [XFEATURE_PT_UNIMPLEMENTED_SO_FAR] = X86_FEATURE_INTEL_PT, [XFEATURE_PKRU] = X86_FEATURE_OSPKE, [XFEATURE_PASID] = X86_FEATURE_ENQCMD, + [XFEATURE_CET_KERNEL] = X86_FEATURE_SHSTK, [XFEATURE_XTILE_CFG] = X86_FEATURE_AMX_TILE, [XFEATURE_XTILE_DATA] = X86_FEATURE_AMX_TILE, }; @@ -277,6 +278,7 @@ static void __init print_xstate_features(void) print_xstate_feature(XFEATURE_MASK_PKRU); print_xstate_feature(XFEATURE_MASK_PASID); print_xstate_feature(XFEATURE_MASK_CET_USER); + print_xstate_feature(XFEATURE_MASK_CET_KERNEL); print_xstate_feature(XFEATURE_MASK_XTILE_CFG); print_xstate_feature(XFEATURE_MASK_XTILE_DATA); } @@ -346,6 +348,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) /* @@ -546,6 +549,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 true; default: XSTATE_WARN_ON(1, "No structure for xstate: %d\n", nr);