Introduce support for guest CET feature
Subsystems (4)
v15 cover Introduce support for guest CET feature
Control-flow Enforcement Technology (CET) provides protection against Return/Jump-Oriented Programming (ROP/JOP) attack. There're two CET
subfeatures: Shadow Stack (SHSTK) and Indirect Branch Tracking (IBT). SHSTK is to prevent ROP and IBT is to prevent JOP.
Several parts in KVM have been updated to provide guest CET support, including:
CPUID/XSAVES settings, MSR passthrough, user-space MSR access interface, vmentry/vmexit config, nested VM etc. These patches are dependent on CET kernel patches for XSAVES support and CET definitions, e.g., MSR and related feature flags.
CET kernel patches: refer to [1], [2].
Previous CET KVM patches: refer to [3].
CET QEMU patches: refer to [4].
CET KVM unit-test patch: refer to [5].
[1]: CET Shadow Stack patches v18:
https://lkml.kernel.org/linux-api/[email protected]/
[2]: Indirect Branch Tracking patches v18:
https://lkml.kernel.org/linux-api/[email protected]/
[3]: CET KVM patches v14:
https://lkml.kernel.org/kvm/[email protected]/
[4]: CET QEMU patches:
https://patchwork.ozlabs.org/project/qemu-devel/patch/[email protected]/
[5]: CET KVM unit-test patch:
https://patchwork.kernel.org/project/kvm/patch/[email protected]/
Changes in v15:
- Changed patches per Paolo's review feedback on v14.
- Added a new patch for GUEST_SSP save/restore in guest SMM case.
- Fixed guest call-trace issue due to CET MSR interception.
- Removed unnecessary guest CET state cleanup in VMCS.
- Rebased patches to 5.11-rc6.
Sean Christopherson (2):
KVM: x86: Report XSS as an MSR to be saved if there are supported
features
KVM: x86: Load guest fpu state when accessing MSRs managed by XSAVES
Yang Weijiang (12):
KVM: x86: Refresh CPUID on writes to MSR_IA32_XSS
KVM: x86: Add #CP support in guest exception dispatch
KVM: VMX: Introduce CET VMCS fields and flags
KVM: x86: Add fault checks for CR4.CET
KVM: VMX: Emulate reads and writes to CET MSRs
KVM: VMX: Add a synthetic MSR to allow userspace VMM to access
GUEST_SSP
KVM: x86: Report CET MSRs as to-be-saved if CET is supported
KVM: x86: Enable CET virtualization for VMX and advertise CET to
userspace
KVM: VMX: Pass through CET MSRs to the guest when supported
KVM: nVMX: Add helper to check the vmcs01 MSR bitmap for MSR
pass-through
KVM: nVMX: Enable CET support for nested VMX
KVM: x86: Save/Restore GUEST_SSP to/from SMRAM
arch/x86/include/asm/kvm_host.h | 4 +- arch/x86/include/asm/vmx.h | 8 ++ arch/x86/include/uapi/asm/kvm.h | 1 + arch/x86/include/uapi/asm/kvm_para.h | 1 + arch/x86/kvm/cpuid.c | 26 +++- arch/x86/kvm/emulate.c | 11 ++ arch/x86/kvm/vmx/capabilities.h | 5 + arch/x86/kvm/vmx/nested.c | 57 ++++++-- arch/x86/kvm/vmx/vmcs12.c | 6 + arch/x86/kvm/vmx/vmcs12.h | 14 +- arch/x86/kvm/vmx/vmx.c | 202 ++++++++++++++++++++++++++- arch/x86/kvm/x86.c | 67 ++++++++- arch/x86/kvm/x86.h | 10 +- 13 files changed, 387 insertions(+), 25 deletions(-)
Signature · 1 line
2.26.2
PATCH v15 1/14 KVM: x86: Report XSS as an MSR to be saved if there are supported features
From: Sean Christopherson <[email protected]>
Add MSR_IA32_XSS to the list of MSRs reported to userspace if supported_xss is non-zero, i.e. KVM supports at least one XSS based feature.
--- arch/x86/kvm/x86.c | 6 ++++++ 1 file changed, 6 insertions(+)
arch/x86/kvm/x86.c +6 -0
@@ -1255,6 +1255,8 @@ static const u32 msrs_to_save_all[] = {MSR_ARCH_PERFMON_EVENTSEL0 +12 ,MSR_ARCH_PERFMON_EVENTSEL0 +13 ,MSR_ARCH_PERFMON_EVENTSEL0 +14 ,MSR_ARCH_PERFMON_EVENTSEL0 +15 ,MSR_ARCH_PERFMON_EVENTSEL0 +16 ,MSR_ARCH_PERFMON_EVENTSEL0 +17 , + + MSR_IA32_XSS, };static u32 msrs_to_save[ARRAY_SIZE (msrs_to_save_all)];
@@ -5795,6 +5797,10 @@ static void kvm_init_msr_list(void) min(INTEL_PMC_MAX_GENERIC, x86_pmu.num_counters_gp)) continue;break ; +case MSR_IA32_XSS : +if (!supported_xss) +continue ; +break ;default :break ; }
Signature · 1 line
2.26.2
PATCH v15 2/14 KVM: x86: Refresh CPUID on writes to MSR_IA32_XSS
In reply to Yang WeijiangUpdated CPUID.0xD.0x1, which reports the current required storage size of all features enabled via XCR0 | XSS, when the guest's XSS is modified.
Note, KVM does not yet support any XSS based features, i.e. supported_xss is guaranteed to be zero at this time.
--- arch/x86/include/asm/kvm_host.h | 1 + arch/x86/kvm/cpuid.c | 21 ++++++++++++++++++--- arch/x86/kvm/x86.c | 7 +++++-- 3 files changed, 24 insertions(+), 5 deletions(-)
arch/x86/include/asm/kvm_host.h +1 -0
@@ -611,6 +611,7 @@ struct kvm_vcpu_arch {u64 xcr0;u64 guest_supported_xcr0; +u64 guest_supported_xss;struct kvm_pio_request pio;void *pio_data;
arch/x86/kvm/cpuid.c +18 -3
@@ -129,9 +129,24 @@ void kvm_update_cpuid_runtime(struct kvm_vcpu *vcpu) best->ebx =xstate_required_size (vcpu->arch.xcr0, false); best =kvm_find_cpuid_entry (vcpu,0xD ,1 ); -if (best && (cpuid_entry_has (best,X86_FEATURE_XSAVES ) || -cpuid_entry_has (best,X86_FEATURE_XSAVEC ))) - best->ebx =xstate_required_size (vcpu->arch.xcr0, true); +if (best) { +if (cpuid_entry_has (best,X86_FEATURE_XSAVES ) || +cpuid_entry_has (best,X86_FEATURE_XSAVEC )) { +u64 xstate = vcpu->arch.xcr0 | vcpu->arch.ia32_xss; + + best->ebx =xstate_required_size (xstate, true); + } + +if (!cpuid_entry_has (best,X86_FEATURE_XSAVES )) { + best->ecx =0 ; + best->edx =0 ; + } + vcpu->arch.guest_supported_xss = + (((u64 )best->edx <<32 ) | best->ecx) & supported_xss; + + }else { + vcpu->arch.guest_supported_xss =0 ; + } best =kvm_find_cpuid_entry (vcpu,KVM_CPUID_FEATURES ,0 ); if (kvm_hlt_in_guest(vcpu->kvm) && best &&
arch/x86/kvm/x86.c +5 -2
@@ -3133,9 +3133,12 @@ int kvm_set_msr_common(struct kvm_vcpu *vcpu, struct msr_data *msr_info)* IA32_XSS[bit 8]. Guests have to use RDMSR/WRMSR rather than * XSAVES/XRSTORS to save/restore PT MSRs. */ -if (data & ~supported_xss) +if (data & ~vcpu->arch.guest_supported_xss)return 1 ; - vcpu->arch.ia32_xss = data; +if (vcpu->arch.ia32_xss != data) { + vcpu->arch.ia32_xss = data; +kvm_update_cpuid_runtime (vcpu); + }break ;case MSR_SMI_COUNT :if (!msr_info->host_initiated)
Signature · 1 line
2.26.2
PATCH v15 3/14 KVM: x86: Load guest fpu state when accessing MSRs managed by XSAVES
In reply to Yang WeijiangFrom: Sean Christopherson <[email protected]>
A handful of CET MSRs are not context switched through "traditional" methods, e.g. VMCS or manual switching, but rather are passed through to the guest and are saved and restored by XSAVES/XRSTORS, i.e. in the guest's FPU state.
Load the guest's FPU state if userspace is accessing MSRs whose values are managed by XSAVES so that the MSR helper, e.g. vmx_{get,set}_xsave_msr(), can simply do {RD,WR}MSR to access the guest's value.
Because is also used for the KVM_GET_MSRS device ioctl(), explicitly check that @vcpu is non-null before attempting to load guest state. The XSS supporting MSRs cannot be retrieved via the device ioctl() without loading guest FPU state (which doesn't exist).
Note that guest_cpuid_has() is not queried as host userspace is allowed to access MSRs that have not been exposed to the guest, e.g. it might do KVM_SET_MSRS prior to KVM_SET_CPUID2.
--- arch/x86/kvm/x86.c | 19 ++++++++++++++++++- 1 file changed, 18 insertions(+), 1 deletion(-)
arch/x86/kvm/x86.c +18 -1
@@ -110,6 +110,8 @@ static void enter_smm(struct kvm_vcpu *vcpu);static void __kvm_set_rflags (struct kvm_vcpu *vcpu,unsigned long rflags);static void store_regs (struct kvm_vcpu *vcpu);static int sync_regs (struct kvm_vcpu *vcpu); +static void kvm_load_guest_fpu (struct kvm_vcpu *vcpu); +static void kvm_put_guest_fpu (struct kvm_vcpu *vcpu);struct kvm_x86_ops kvm_x86_ops__read_mostly ;EXPORT_SYMBOL_GPL (kvm_x86_ops);
@@ -3618,6 +3620,12 @@ int kvm_get_msr_common(struct kvm_vcpu *vcpu, struct msr_data *msr_info) }EXPORT_SYMBOL_GPL (kvm_get_msr_common); +static bool is_xsaves_msr (u32 index) +{ +return index ==MSR_IA32_U_CET || + (index >=MSR_IA32_PL0_SSP && index <=MSR_IA32_PL3_SSP ); +} +/* * Read or write a bunch of msrs. All parameters are kernel addresses. *
@@ -3628,11 +3636,20 @@ static int __msr_io(struct kvm_vcpu *vcpu, struct kvm_msrs *msrs,int (*do_msr)(struct kvm_vcpu *vcpu, unsigned index, u64 *data)) { +bool fpu_loaded = false;int i; -for (i =0 ; i < msrs->nmsrs; ++i) +for (i =0 ; i < msrs->nmsrs; ++i) { +if (vcpu && !fpu_loaded && supported_xss && +is_xsaves_msr (entries[i].index)) { +kvm_load_guest_fpu (vcpu); + fpu_loaded = true; + }if (do_msr (vcpu, entries[i].index, &entries[i].data))break ; + } +if (fpu_loaded) +kvm_put_guest_fpu (vcpu);return i; }
Signature · 1 line
2.26.2
kernel test robot
build botRe: [PATCH v15 03/14] KVM: x86: Load guest fpu state when accessing MSRs managed by XSAVES
I love your patch! Yet something to improve:
Hi Yang,
I love your patch! Yet something to improve:
[auto build test ERROR on kvm/linux-next]
[also build test ERROR on v5.11-rc6 next-20210125]
[If your patch is applied to the wrong git tree, kindly drop us a note. And when submitting patch, we suggest to use '--base' as documented in
https://git-scm.com/docs/git-format-patch]
url: https://github.com/0day-ci/linux/commits/Yang-Weijiang/Introduce-support-for-guest-CET-feature/20210203-193042 base: https://git.kernel.org/pub/scm/virt/kvm/kvm.git linux-next config: x86_64-allyesconfig (attached as .config) compiler: gcc-9 (Debian 9.3.0-15) 9.3.0 reproduce (this is a W=1 build): # https://github.com/0day-ci/linux/commit/d3250ea62a7338a6b7d585d4febcc8fe2b1fe505 git remote add linux-review https://github.com/0day-ci/linux git fetch --no-tags linux-review Yang-Weijiang/Introduce-support-for-guest-CET-feature/20210203-193042 git checkout d3250ea62a7338a6b7d585d4febcc8fe2b1fe505 # save the attached .config to linux build tree make W=1 ARCH=x86_64
If you fix the issue, kindly add following tag as appropriate
Note: the linux-review/Yang-Weijiang/Introduce-support-for-guest-CET-feature/20210203-193042 HEAD 5acec8164b77fb86385602af0f7e20589879e145 builds fine.
It only hurts bisectibility.
All errors (new ones prefixed by >>):
arch/x86/kvm/x86.c: In function 'is_xsaves_msr':
>> arch/x86/kvm/x86.c:3624:18: error: 'MSR_IA32_U_CET' undeclared (first use in this function); did you mean 'MSR_IA32_TSC'?
3624 | return index == MSR_IA32_U_CET ||
| ^~~~~~~~~~~~~~
| MSR_IA32_TSC
arch/x86/kvm/x86.c:3624:18: note: each undeclared identifier is reported only once for each function it appears in
>> arch/x86/kvm/x86.c:3625:19: error: 'MSR_IA32_PL0_SSP' undeclared (first use in this function); did you mean 'MSR_IA32_MCG_ESP'?
3625 | (index >= MSR_IA32_PL0_SSP && index <= MSR_IA32_PL3_SSP);
| ^~~~~~~~~~~~~~~~
| MSR_IA32_MCG_ESP
>> arch/x86/kvm/x86.c:3625:48: error: 'MSR_IA32_PL3_SSP' undeclared (first use in this function); did you mean 'MSR_IA32_MCG_ESP'?
3625 | (index >= MSR_IA32_PL0_SSP && index <= MSR_IA32_PL3_SSP);
| ^~~~~~~~~~~~~~~~
| MSR_IA32_MCG_ESP
arch/x86/kvm/x86.c:3626:1: error: control reaches end of non-void function [-Werror=return-type]
3626 | }
| ^cc1: some warnings being treated as errors
vim +3624 arch/x86/kvm/x86.c
3621
3622 static bool is_xsaves_msr(u32 index)
3623 {
> 3624 return index == MSR_IA32_U_CET || > 3625 (index >= MSR_IA32_PL0_SSP && index <= MSR_IA32_PL3_SSP);
3626 }
3627
---
0-DAY CI Kernel Test Service, Intel Corporation
https://lists.01.org/hyperkitty/list/[email protected]
PATCH v15 4/14 KVM: x86: Add #CP support in guest exception dispatch
In reply to Yang WeijiangAdd handling for Control Protection (#CP) exceptions, vector 21, used and introduced by Intel's Control-Flow Enforcement Technology (CET). relevant CET violation case. See Intel's SDM for details.
--- arch/x86/include/uapi/asm/kvm.h | 1 + arch/x86/kvm/x86.c | 1 + arch/x86/kvm/x86.h | 2 +- 3 files changed, 3 insertions(+), 1 deletion(-)
arch/x86/include/uapi/asm/kvm.h +1 -0
@@ -32,6 +32,7 @@#define MC_VECTOR 18#define XM_VECTOR 19#define VE_VECTOR 20 +#define CP_VECTOR 21/* Select x86 specific features in <linux/kvm.h> */ #define __KVM_HAVE_PIT
arch/x86/kvm/x86.c +1 -0
@@ -436,6 +436,7 @@ static int exception_class(int vector)case NP_VECTOR :case SS_VECTOR :case GP_VECTOR : +case CP_VECTOR :return EXCPT_CONTRIBUTORY ;default :break ;
arch/x86/kvm/x86.h +1 -1
@@ -116,7 +116,7 @@ static inline bool x86_exception_has_error_code(unsigned int vector) {static u32 exception_has_error_code =BIT (DF_VECTOR ) |BIT (TS_VECTOR ) |BIT (NP_VECTOR ) |BIT (SS_VECTOR ) |BIT (GP_VECTOR ) | -BIT (PF_VECTOR ) |BIT (AC_VECTOR ); +BIT (PF_VECTOR ) |BIT (AC_VECTOR ) |BIT (CP_VECTOR );return (1U << vector) & exception_has_error_code; }
Signature · 1 line
2.26.2
Sean Christopherson
maintainerRe: [PATCH v15 04/14] KVM: x86: Add #CP support in guest exception dispatch
Quoted 40 lines · Yang Weijiang
Add handling for Control Protection (#CP) exceptions, vector 21, used and introduced by Intel's Control-Flow Enforcement Technology (CET). relevant CET violation case. See Intel's SDM for details.
Signed-off-by Yang Weijiang <[email protected]>--- arch/x86/include/uapi/asm/kvm.h | 1 + arch/x86/kvm/x86.c | 1 + arch/x86/kvm/x86.h | 2 +- 3 files changed, 3 insertions(+), 1 deletion(-)arch/x86/include/uapi/asm/kvm.h +1
-0@@ -32,6 +32,7 @@#define MC_VECTOR 18#define XM_VECTOR 19#define VE_VECTOR 20 +#define CP_VECTOR 21/* Select x86 specific features in <linux/kvm.h> */ #define __KVM_HAVE_PITarch/x86/kvm/x86.c +1
-0@@ -436,6 +436,7 @@ static int exception_class(int vector)case NP_VECTOR :case SS_VECTOR :case GP_VECTOR : +case CP_VECTOR :return EXCPT_CONTRIBUTORY ;default :break ;arch/x86/kvm/x86.h +0
-0
arch/x86/kvm/x86.h static inline bool x86_exception_has_error_code(unsigned int vector) · line 119
Quoted 5 lines
arch/x86/kvm/x86.h +1
-1@@ -116,7 +116,7 @@ static inline bool x86_exception_has_error_code(unsigned int vector) {static u32 exception_has_error_code =BIT (DF_VECTOR ) |BIT (TS_VECTOR ) |BIT (NP_VECTOR ) |BIT (SS_VECTOR ) |BIT (GP_VECTOR ) | -BIT (PF_VECTOR ) |BIT (AC_VECTOR ); +BIT (PF_VECTOR ) |BIT (AC_VECTOR ) |BIT (CP_VECTOR );
These need to be conditional on CET being exposed to the guest. TBD exceptions are non-contributory and don't have an error code. Found when running unit tests in L1 with a kvm/queue as L1, but an older L0. cr4_guest_rsvd_bits can be used to avoid guest_cpuid_has() lookups.
The SDM also gets this wrong. Section 26.2.1.3, VM-Entry Control Fields, needs to be updated to add #CP to the list.
— The field's deliver-error-code bit (bit 11) is 1 if each of the following
holds: (1) the interruption type is hardware exception; (2) bit 0
(corresponding to CR0.PE) is set in the CR0 field in the guest-state area;
(3) IA32_VMX_BASIC[56] is read as 0 (see Appendix A.1); and (4) the vector
indicates one of the following exceptions: #DF (vector 8), #TS (10),
#NP (11), #SS (12), #GP (13), #PF (14), or #AC (17).arch/x86/kvm/vmx/nested.c +1 -1
@@ -2811,7 +2811,7 @@ static int nested_check_vm_entry_controls(struct kvm_vcpu *vcpu,/* VM-entry interruption-info field: deliver error code */ should_have_error_code = intr_type ==INTR_TYPE_HARD_EXCEPTION && prot_mode && -x86_exception_has_error_code (vector); +x86_exception_has_error_code (vcpu, vector);if (CC (has_error_code != should_have_error_code))return -EINVAL ;
arch/x86/kvm/x86.c +7 -4
@@ -437,17 +437,20 @@ EXPORT_SYMBOL_GPL(kvm_spurious_fault);#define EXCPT_CONTRIBUTORY 1#define EXCPT_PF 2 -static int exception_class (int vector) +static int exception_class (struct kvm_vcpu *vcpu,int vector) {switch (vector) {case PF_VECTOR :return EXCPT_PF ; +case CP_VECTOR : +if (vcpu->arch.cr4_guest_rsvd_bits &X86_CR4_CET ) +return EXCPT_BENIGN ; +return EXCPT_CONTRIBUTORY ;case DE_VECTOR :case TS_VECTOR :case NP_VECTOR :case SS_VECTOR :case GP_VECTOR : -case CP_VECTOR :return EXCPT_CONTRIBUTORY ;default :break ;
@@ -588,8 +591,8 @@ static void kvm_multiple_exception(struct kvm_vcpu *vcpu,kvm_make_request (KVM_REQ_TRIPLE_FAULT , vcpu);return ; } - class1 =exception_class (prev_nr); - class2 =exception_class (nr); + class1 =exception_class (vcpu, prev_nr); + class2 =exception_class (vcpu, nr);if ((class1 ==EXCPT_CONTRIBUTORY && class2 ==EXCPT_CONTRIBUTORY ) || (class1 ==EXCPT_PF && class2 !=EXCPT_BENIGN )) {/*
arch/x86/kvm/x86.h +5 -1
@@ -120,12 +120,16 @@ static inline bool is_la57_mode(struct kvm_vcpu *vcpu)#endif } -static inline bool x86_exception_has_error_code (unsigned int vector) +static inline bool x86_exception_has_error_code (struct kvm_vcpu *vcpu, +unsigned int vector) {static u32 exception_has_error_code =BIT (DF_VECTOR ) |BIT (TS_VECTOR ) |BIT (NP_VECTOR ) |BIT (SS_VECTOR ) |BIT (GP_VECTOR ) |BIT (PF_VECTOR ) |BIT (AC_VECTOR ) |BIT (CP_VECTOR ); +if (vector ==CP_VECTOR && (vcpu->arch.cr4_guest_rsvd_bits &X86_CR4_CET )) +return false; +return (1U << vector) & exception_has_error_code; }
Re: [PATCH v15 04/14] KVM: x86: Add #CP support in guest exception dispatch
Quoted 124 lines · Sean Christopherson
Quoted 40 lines · Yang Weijiang
Add handling for Control Protection (#CP) exceptions, vector 21, used and introduced by Intel's Control-Flow Enforcement Technology (CET). relevant CET violation case. See Intel's SDM for details.
Signed-off-by Yang Weijiang <[email protected]>--- arch/x86/include/uapi/asm/kvm.h | 1 + arch/x86/kvm/x86.c | 1 + arch/x86/kvm/x86.h | 2 +- 3 files changed, 3 insertions(+), 1 deletion(-)arch/x86/include/uapi/asm/kvm.h +1
-0@@ -32,6 +32,7 @@#define MC_VECTOR 18#define XM_VECTOR 19#define VE_VECTOR 20 +#define CP_VECTOR 21/* Select x86 specific features in <linux/kvm.h> */ #define __KVM_HAVE_PITarch/x86/kvm/x86.c +1
-0@@ -436,6 +436,7 @@ static int exception_class(int vector)case NP_VECTOR :case SS_VECTOR :case GP_VECTOR : +case CP_VECTOR :return EXCPT_CONTRIBUTORY ;default :break ;arch/x86/kvm/x86.h +0
-0arch/x86/kvm/x86.h static inline bool x86_exception_has_error_code(unsigned int vector) · line 119
Quoted 5 lines
arch/x86/kvm/x86.h +1
-1@@ -116,7 +116,7 @@ static inline bool x86_exception_has_error_code(unsigned int vector) {static u32 exception_has_error_code =BIT (DF_VECTOR ) |BIT (TS_VECTOR ) |BIT (NP_VECTOR ) |BIT (SS_VECTOR ) |BIT (GP_VECTOR ) | -BIT (PF_VECTOR ) |BIT (AC_VECTOR ); +BIT (PF_VECTOR ) |BIT (AC_VECTOR ) |BIT (CP_VECTOR );These need to be conditional on CET being exposed to the guest. TBD exceptions are non-contributory and don't have an error code. Found when running unit tests in L1 with a kvm/queue as L1, but an older L0.
cr4_guest_rsvd_bitscan be used to avoidguest_cpuid_has()lookups.The SDM also gets this wrong. Section 26.2.1.3, VM-Entry Control Fields, needs to be updated to add #CP to the list.
— The field's deliver-error-code bit (bit 11) is 1 if each of the following
holds: (1) the interruption type is hardware exception; (2) bit 0 (corresponding to CR0.PE) is set in the CR0 field in the guest-state area; (3) IA32_VMX_BASIC[56] is read as 0 (see Appendix A.1); and (4) the vector indicates one of the following exceptions: #DF (vector 8), #TS (10), #NP (11), #SS (12), #GP (13), #PF (14), or #AC (17).arch/x86/kvm/vmx/nested.c +1
-1@@ -2811,7 +2811,7 @@ static int nested_check_vm_entry_controls(struct kvm_vcpu *vcpu,/* VM-entry interruption-info field: deliver error code */ should_have_error_code = intr_type ==INTR_TYPE_HARD_EXCEPTION && prot_mode && -x86_exception_has_error_code (vector); +x86_exception_has_error_code (vcpu, vector);if (CC (has_error_code != should_have_error_code))return -EINVAL ;arch/x86/kvm/x86.c +7
-4@@ -437,17 +437,20 @@ EXPORT_SYMBOL_GPL(kvm_spurious_fault);#define EXCPT_CONTRIBUTORY 1#define EXCPT_PF 2 -static int exception_class (int vector) +static int exception_class (struct kvm_vcpu *vcpu,int vector) {switch (vector) {case PF_VECTOR :return EXCPT_PF ; +case CP_VECTOR : +if (vcpu->arch.cr4_guest_rsvd_bits &X86_CR4_CET ) +return EXCPT_BENIGN ; +return EXCPT_CONTRIBUTORY ;case DE_VECTOR :case TS_VECTOR :case NP_VECTOR :case SS_VECTOR :case GP_VECTOR : -case CP_VECTOR :return EXCPT_CONTRIBUTORY ;default :break ;@@ -588,8 +591,8 @@ static void kvm_multiple_exception(struct kvm_vcpu *vcpu,kvm_make_request (KVM_REQ_TRIPLE_FAULT , vcpu);return ; } - class1 =exception_class (prev_nr); - class2 =exception_class (nr); + class1 =exception_class (vcpu, prev_nr); + class2 =exception_class (vcpu, nr);if ((class1 ==EXCPT_CONTRIBUTORY && class2 ==EXCPT_CONTRIBUTORY ) || (class1 ==EXCPT_PF && class2 !=EXCPT_BENIGN )) {/* arch/x86/kvm/x86.h +2
-1@@ -120,12 +120,16 @@ static inline bool is_la57_mode(struct kvm_vcpu *vcpu)#endif } -static inline bool x86_exception_has_error_code (unsigned int vector) +static inline bool x86_exception_has_error_code (struct kvm_vcpu *vcpu, +unsigned int vector)
arch/x86/kvm/x86.h static inline bool is_la57_mode(struct kvm_vcpu *vcpu) · line 134
Quoted 10 lines
arch/x86/kvm/x86.h +3
-0{static u32 exception_has_error_code =BIT (DF_VECTOR ) |BIT (TS_VECTOR ) |BIT (NP_VECTOR ) |BIT (SS_VECTOR ) |BIT (GP_VECTOR ) |BIT (PF_VECTOR ) |BIT (AC_VECTOR ) |BIT (CP_VECTOR ); +if (vector ==CP_VECTOR && (vcpu->arch.cr4_guest_rsvd_bits &X86_CR4_CET )) +return false; +return (1U << vector) & exception_has_error_code; }
Thanks Sean for catching this!
Hi, Paolo,
Do I need to send another version to include Sean's change?
Quoted 3 lines
Paolo Bonzini
maintainerRe: [PATCH v15 04/14] KVM: x86: Add #CP support in guest exception dispatch
Quoted 4 lines · Yang Weijiang
Thanks Sean for catching this!
Hi, Paolo,
Do I need to send another version to include Sean's change?
No, it's okay.
Paolo
Paolo Bonzini
maintainerRe: [PATCH v15 04/14] KVM: x86: Add #CP support in guest exception dispatch
In reply to Sean ChristophersonQuoted 67 lines · Sean Christopherson
arch/x86/kvm/vmx/nested.c +1
-1@@ -2811,7 +2811,7 @@ static int nested_check_vm_entry_controls(struct kvm_vcpu *vcpu,/* VM-entry interruption-info field: deliver error code */ should_have_error_code = intr_type ==INTR_TYPE_HARD_EXCEPTION && prot_mode && -x86_exception_has_error_code (vector); +x86_exception_has_error_code (vcpu, vector);if (CC (has_error_code != should_have_error_code))return -EINVAL ;arch/x86/kvm/x86.c +7
-4@@ -437,17 +437,20 @@ EXPORT_SYMBOL_GPL(kvm_spurious_fault);#define EXCPT_CONTRIBUTORY 1#define EXCPT_PF 2 -static int exception_class (int vector) +static int exception_class (struct kvm_vcpu *vcpu,int vector) {switch (vector) {case PF_VECTOR :return EXCPT_PF ; +case CP_VECTOR : +if (vcpu->arch.cr4_guest_rsvd_bits &X86_CR4_CET ) +return EXCPT_BENIGN ; +return EXCPT_CONTRIBUTORY ;case DE_VECTOR :case TS_VECTOR :case NP_VECTOR :case SS_VECTOR :case GP_VECTOR : -case CP_VECTOR :return EXCPT_CONTRIBUTORY ;default :break ;@@ -588,8 +591,8 @@ static void kvm_multiple_exception(struct kvm_vcpu *vcpu,kvm_make_request (KVM_REQ_TRIPLE_FAULT , vcpu);return ; } - class1 =exception_class (prev_nr); - class2 =exception_class (nr); + class1 =exception_class (vcpu, prev_nr); + class2 =exception_class (vcpu, nr);if ((class1 ==EXCPT_CONTRIBUTORY && class2 ==EXCPT_CONTRIBUTORY ) || (class1 ==EXCPT_PF && class2 !=EXCPT_BENIGN )) {/* arch/x86/kvm/x86.h +2
-1@@ -120,12 +120,16 @@ static inline bool is_la57_mode(struct kvm_vcpu *vcpu)#endif } -static inline bool x86_exception_has_error_code (unsigned int vector) +static inline bool x86_exception_has_error_code (struct kvm_vcpu *vcpu, +unsigned int vector) {
arch/x86/kvm/x86.h static inline bool is_la57_mode(struct kvm_vcpu *vcpu) · line 135
Quoted 10 lines
arch/x86/kvm/x86.h +3
-0static u32 exception_has_error_code =BIT (DF_VECTOR ) |BIT (TS_VECTOR ) |BIT (NP_VECTOR ) |BIT (SS_VECTOR ) |BIT (GP_VECTOR ) |BIT (PF_VECTOR ) |BIT (AC_VECTOR ) |BIT (CP_VECTOR ); +if (vector ==CP_VECTOR && (vcpu->arch.cr4_guest_rsvd_bits &X86_CR4_CET )) +return false; +return (1U << vector) & exception_has_error_code; }
Squashed, thanks. I made a small change to the last hunk:
if (!((1U << vector) & exception_has_error_code))
return false;
if (vector == CP_VECTOR)
return !(vcpu->arch.cr4_guest_rsvd_bits & X86_CR4_CET);
return true;Sean Christopherson
maintainerRe: [PATCH v15 04/14] KVM: x86: Add #CP support in guest exception dispatch
Quoted 23 lines · Paolo Bonzini
Quoted 22 lines · Sean Christopherson
arch/x86/kvm/vmx/nested.c +1
-1@@ -2811,7 +2811,7 @@ static int nested_check_vm_entry_controls(struct kvm_vcpu *vcpu,/* VM-entry interruption-info field: deliver error code */ should_have_error_code = intr_type ==INTR_TYPE_HARD_EXCEPTION && prot_mode && -x86_exception_has_error_code (vector); +x86_exception_has_error_code (vcpu, vector);if (CC (has_error_code != should_have_error_code))return -EINVAL ;arch/x86/kvm/x86.c +0
-0@@ -437,17 +437,20 @@ EXPORT_SYMBOL_GPL(kvm_spurious_fault);#define EXCPT_CONTRIBUTORY 1#define EXCPT_PF 2
Quoted 16 lines
Quoted 6 lines
arch/x86/kvm/x86.c +1
-1-static int exception_class (int vector) +static int exception_class (struct kvm_vcpu *vcpu,int vector) {switch (vector) {case PF_VECTOR :return EXCPT_PF ;arch/x86/kvm/x86.c EXPORT_SYMBOL_GPL(kvm_spurious_fault); · line 450
Quoted 10 lines
arch/x86/kvm/x86.c +4
-1+case CP_VECTOR : +if (vcpu->arch.cr4_guest_rsvd_bits &X86_CR4_CET ) +return EXCPT_BENIGN ; +return EXCPT_CONTRIBUTORY ;case DE_VECTOR :case TS_VECTOR :case NP_VECTOR :case SS_VECTOR :case GP_VECTOR : -case CP_VECTOR :
This removal got lost when squasing.
arch/x86/kvm/x86.c: In function ‘exception_class’:arch/x86/kvm/x86.c:455:2: error: duplicate case value
455 | case CP_VECTOR:
| ^~~~
arch/x86/kvm/x86.c:446:2: note: previously used here
446 | case CP_VECTOR:
| ^~~~Quoted 42 lines
Quoted 29 lines
arch/x86/kvm/x86.c +2
-2return EXCPT_CONTRIBUTORY ;default :break ;@@ -588,8 +591,8 @@ static void kvm_multiple_exception(struct kvm_vcpu *vcpu,kvm_make_request (KVM_REQ_TRIPLE_FAULT , vcpu);return ; } - class1 =exception_class (prev_nr); - class2 =exception_class (nr); + class1 =exception_class (vcpu, prev_nr); + class2 =exception_class (vcpu, nr);if ((class1 ==EXCPT_CONTRIBUTORY && class2 ==EXCPT_CONTRIBUTORY ) || (class1 ==EXCPT_PF && class2 !=EXCPT_BENIGN )) {/* arch/x86/kvm/x86.h +2
-1@@ -120,12 +120,16 @@ static inline bool is_la57_mode(struct kvm_vcpu *vcpu)#endif } -static inline bool x86_exception_has_error_code (unsigned int vector) +static inline bool x86_exception_has_error_code (struct kvm_vcpu *vcpu, +unsigned int vector) {arch/x86/kvm/x86.h static inline bool is_la57_mode(struct kvm_vcpu *vcpu) · line 135
Quoted 10 lines
arch/x86/kvm/x86.h +3
-0static u32 exception_has_error_code =BIT (DF_VECTOR ) |BIT (TS_VECTOR ) |BIT (NP_VECTOR ) |BIT (SS_VECTOR ) |BIT (GP_VECTOR ) |BIT (PF_VECTOR ) |BIT (AC_VECTOR ) |BIT (CP_VECTOR ); +if (vector ==CP_VECTOR && (vcpu->arch.cr4_guest_rsvd_bits &X86_CR4_CET )) +return false; +return (1U << vector) & exception_has_error_code; }Squashed, thanks. I made a small change to the last hunk:
Quoted 7 lines
if (!((1U << vector) & exception_has_error_code))
return false;
if (vector == CP_VECTOR)
return !(vcpu->arch.cr4_guest_rsvd_bits & X86_CR4_CET);
return true;Ha, I guessed wrong, that was my first pass at it :-)
Paolo Bonzini
maintainerRe: [PATCH v15 04/14] KVM: x86: Add #CP support in guest exception dispatch
Quoted 43 lines · Sean Christopherson
Quoted 23 lines · Paolo Bonzini
Quoted 22 lines · Sean Christopherson
arch/x86/kvm/vmx/nested.c +1
-1@@ -2811,7 +2811,7 @@ static int nested_check_vm_entry_controls(struct kvm_vcpu *vcpu,/* VM-entry interruption-info field: deliver error code */ should_have_error_code = intr_type ==INTR_TYPE_HARD_EXCEPTION && prot_mode && -x86_exception_has_error_code (vector); +x86_exception_has_error_code (vcpu, vector);if (CC (has_error_code != should_have_error_code))return -EINVAL ;arch/x86/kvm/x86.c +0
-0@@ -437,17 +437,20 @@ EXPORT_SYMBOL_GPL(kvm_spurious_fault);#define EXCPT_CONTRIBUTORY 1#define EXCPT_PF 2Quoted 16 lines
Quoted 6 lines
arch/x86/kvm/x86.c +1
-1-static int exception_class (int vector) +static int exception_class (struct kvm_vcpu *vcpu,int vector) {switch (vector) {case PF_VECTOR :return EXCPT_PF ;arch/x86/kvm/x86.c EXPORT_SYMBOL_GPL(kvm_spurious_fault); · line 450
Quoted 10 lines
arch/x86/kvm/x86.c +4
-1+case CP_VECTOR : +if (vcpu->arch.cr4_guest_rsvd_bits &X86_CR4_CET ) +return EXCPT_BENIGN ; +return EXCPT_CONTRIBUTORY ;case DE_VECTOR :case TS_VECTOR :case NP_VECTOR :case SS_VECTOR :case GP_VECTOR : -case CP_VECTOR :This removal got lost when squasing.
Quoted 7 lines
arch/x86/kvm/x86.c: In function ‘exception_class’:arch/x86/kvm/x86.c:455:2: error: duplicate case value455 | case CP_VECTOR: | ^~~~ arch/x86/kvm/x86.c:446:2: note: previously used here 446 | case CP_VECTOR: | ^~~~
Well, it shows that I haven't even started including those unlikely-for-5.12 patches (CET and #DB bus lock) in my builds, since today I was focusing on getting a kvm/next push done.
I'll probably push all those to kvm/intel-queue and remove them from everyone's view, for now.
Paolo
PATCH v15 5/14 KVM: VMX: Introduce CET VMCS fields and flags
In reply to Yang WeijiangCET (Control-flow Enforcement Technology) is a CPU feature used to prevent Return/Jump-Oriented Programming (ROP/JOP) attacks. CET introduces a new exception type, Control Protection (#CP), and two sub-features to defend against ROP/JOP style control-flow subversion attacks:
Shadow Stack (SHSTK):
A shadow stack is a second stack used exclusively for control transfer operations. The shadow stack is separate from the data/normal stack and can be enabled individually in user and kernel mode. When shadow stacks are enabled, CALL pushes the return address on both the data and shadow stack. RET pops the return address from both stacks and compares them. If the return addresses from the two stacks do not match, the processor signals a #CP.
Indirect Branch Tracking (IBT):
IBT adds a new instrution, ENDBRANCH, that is used to mark valid target addresses of indirect branches (CALL, JMP, ENCLU[EEXIT], etc...). If an indirect branch is executed and the next instruction is _not_ an ENDBRANCH, the processor signals a #CP.
Several new CET MSRs are defined to support CET:
MSR_IA32_{U,S}_CET: Controls the CET settings for user mode and kernel
mode respectively.
MSR_IA32_PL{0,1,2,3}_SSP: Stores shadow stack pointers for CPL-0,1,2,3
protection respectively.
MSR_IA32_INT_SSP_TAB: Stores base address of shadow stack pointer table.
Two XSAVES state bits are introduced for CET:
IA32_XSS:[bit 11]: Control saving/restoring user mode CET states IA32_XSS:[bit 12]: Control saving/restoring kernel mode CET states.
Six VMCS fields are introduced for CET:
{HOST,GUEST}_S_CET: Stores CET settings for kernel mode. {HOST,GUEST}_SSP: Stores shadow stack pointer of current task/thread. {HOST,GUEST}_INTR_SSP_TABLE: Stores base address of shadow stack pointer table.
If VM_EXIT_LOAD_HOST_CET_STATE = 1, the host CET states are restored from the following VMCS fields at VM-Exit:
HOST_S_CET
HOST_SSP
HOST_INTR_SSP_TABLE
If VM_ENTRY_LOAD_GUEST_CET_STATE = 1, the guest CET states are loaded from the following VMCS fields at VM-Entry:
GUEST_S_CET
GUEST_SSP
GUEST_INTR_SSP_TABLE
--- arch/x86/include/asm/vmx.h | 8 ++++++++ 1 file changed, 8 insertions(+)
arch/x86/include/asm/vmx.h +8 -0
@@ -94,6 +94,7 @@#define VM_EXIT_CLEAR_BNDCFGS 0x00800000#define VM_EXIT_PT_CONCEAL_PIP 0x01000000#define VM_EXIT_CLEAR_IA32_RTIT_CTL 0x02000000 +#define VM_EXIT_LOAD_CET_STATE 0x10000000#define VM_EXIT_ALWAYSON_WITHOUT_TRUE_MSR 0x00036dff
@@ -107,6 +108,7 @@#define VM_ENTRY_LOAD_BNDCFGS 0x00010000#define VM_ENTRY_PT_CONCEAL_PIP 0x00020000#define VM_ENTRY_LOAD_IA32_RTIT_CTL 0x00040000 +#define VM_ENTRY_LOAD_CET_STATE 0x00100000#define VM_ENTRY_ALWAYSON_WITHOUT_TRUE_MSR 0x000011ff
@@ -329,6 +331,9 @@ enum vmcs_field {GUEST_PENDING_DBG_EXCEPTIONS =0x00006822 ,GUEST_SYSENTER_ESP =0x00006824 ,GUEST_SYSENTER_EIP =0x00006826 , +GUEST_S_CET =0x00006828 , +GUEST_SSP =0x0000682a , +GUEST_INTR_SSP_TABLE =0x0000682c ,HOST_CR0 =0x00006c00 ,HOST_CR3 =0x00006c02 , HOST_CR4 = 0x00006c04,
@@ -341,6 +346,9 @@ enum vmcs_field {HOST_IA32_SYSENTER_EIP =0x00006c12 ,HOST_RSP =0x00006c14 ,HOST_RIP =0x00006c16 , +HOST_S_CET =0x00006c18 , +HOST_SSP =0x00006c1a , + HOST_INTR_SSP_TABLE = 0x00006c1c };/*
Signature · 1 line
2.26.2
PATCH v15 6/14 KVM: x86: Add fault checks for CR4.CET
In reply to Yang WeijiangAdd the fault checks for CR4.CET, which is the master control for all CET features (SHSTK and IBT). In addition to basic support checks, CET can be enabled if and only if CR0.WP==1, i.e. setting CR4.CET=1 faults if CR0.WP==0 and setting CR0.WP=0 fails if CR4.CET==1.
--- arch/x86/kvm/x86.c | 6 ++++++ arch/x86/kvm/x86.h | 3 +++ 2 files changed, 9 insertions(+)
arch/x86/kvm/x86.c +6 -0
@@ -868,6 +868,9 @@ int kvm_set_cr0(struct kvm_vcpu *vcpu, unsigned long cr0)if (!(cr0 &X86_CR0_PG ) &&kvm_read_cr4_bits (vcpu,X86_CR4_PCIDE ))return 1 ; +if (!(cr0 &X86_CR0_WP ) &&kvm_read_cr4_bits (vcpu,X86_CR4_CET )) +return 1 ; + kvm_x86_ops.set_cr0 (vcpu, cr0);kvm_post_set_cr0 (vcpu, old_cr0, cr0);
@@ -1034,6 +1037,9 @@ int kvm_set_cr4(struct kvm_vcpu *vcpu, unsigned long cr4)return 1 ; } +if ((cr4 &X86_CR4_CET ) && !(kvm_read_cr0 (vcpu) &X86_CR0_WP )) +return 1 ; + kvm_x86_ops.set_cr4 (vcpu, cr4);kvm_post_set_cr4 (vcpu, old_cr4, cr4);
arch/x86/kvm/x86.h +3 -0
@@ -425,6 +425,9 @@ bool kvm_msr_allowed(struct kvm_vcpu *vcpu, u32 index, u32 type); __reserved_bits |=X86_CR4_UMIP ; \if (!__cpu_has (__c,X86_FEATURE_VMX )) \ __reserved_bits |=X86_CR4_VMXE ; \ +if (!__cpu_has (__c,X86_FEATURE_SHSTK ) && \ + !__cpu_has (__c,X86_FEATURE_IBT )) \ + __reserved_bits |=X86_CR4_CET ; \ __reserved_bits; \ })
Signature · 1 line
2.26.2
kernel test robot
build botRe: [PATCH v15 06/14] KVM: x86: Add fault checks for CR4.CET
Thank you for the patch! Yet something to improve:
Hi Yang,
Thank you for the patch! Yet something to improve:
[auto build test ERROR on kvm/linux-next]
[also build test ERROR on v5.11-rc6 next-20210125]
[If your patch is applied to the wrong git tree, kindly drop us a note. And when submitting patch, we suggest to use '--base' as documented in
https://git-scm.com/docs/git-format-patch]
url: https://github.com/0day-ci/linux/commits/Yang-Weijiang/Introduce-support-for-guest-CET-feature/20210203-193042 base: https://git.kernel.org/pub/scm/virt/kvm/kvm.git linux-next config: x86_64-allyesconfig (attached as .config) compiler: gcc-9 (Debian 9.3.0-15) 9.3.0 reproduce (this is a W=1 build): # https://github.com/0day-ci/linux/commit/bc17249d58e9e7a1b49ad5d8a4f504e3dda0263d git remote add linux-review https://github.com/0day-ci/linux git fetch --no-tags linux-review Yang-Weijiang/Introduce-support-for-guest-CET-feature/20210203-193042 git checkout bc17249d58e9e7a1b49ad5d8a4f504e3dda0263d # save the attached .config to linux build tree make W=1 ARCH=x86_64
If you fix the issue, kindly add following tag as appropriate
All errors (new ones prefixed by >>):
arch/x86/kvm/x86.c: In function 'kvm_set_cr0':
>> arch/x86/kvm/x86.c:870:53: error: 'X86_CR4_CET' undeclared (first use in this function); did you mean 'X86_CR4_MCE'?
870 | if (!(cr0 & X86_CR0_WP) && kvm_read_cr4_bits(vcpu, X86_CR4_CET))
| ^~~~~~~~~~~
| X86_CR4_MCE
arch/x86/kvm/x86.c:870:53: note: each undeclared identifier is reported only once for each function it appears in
arch/x86/kvm/x86.c: In function 'kvm_set_cr4':
arch/x86/kvm/x86.c:1039:13: error: 'X86_CR4_CET' undeclared (first use in this function); did you mean 'X86_CR4_MCE'?
1039 | if ((cr4 & X86_CR4_CET) && !(kvm_read_cr0(vcpu) & X86_CR0_WP))
| ^~~~~~~~~~~
| X86_CR4_MCE
arch/x86/kvm/x86.c: In function 'is_xsaves_msr':
arch/x86/kvm/x86.c:3631:18: error: 'MSR_IA32_U_CET' undeclared (first use in this function); did you mean 'MSR_IA32_TSC'?
3631 | return index == MSR_IA32_U_CET ||
| ^~~~~~~~~~~~~~
| MSR_IA32_TSC
arch/x86/kvm/x86.c:3632:19: error: 'MSR_IA32_PL0_SSP' undeclared (first use in this function); did you mean 'MSR_IA32_MCG_ESP'?
3632 | (index >= MSR_IA32_PL0_SSP && index <= MSR_IA32_PL3_SSP);
| ^~~~~~~~~~~~~~~~
| MSR_IA32_MCG_ESP
arch/x86/kvm/x86.c:3632:48: error: 'MSR_IA32_PL3_SSP' undeclared (first use in this function); did you mean 'MSR_IA32_MCG_ESP'?
3632 | (index >= MSR_IA32_PL0_SSP && index <= MSR_IA32_PL3_SSP);
| ^~~~~~~~~~~~~~~~
| MSR_IA32_MCG_ESP
arch/x86/kvm/x86.c: In function 'kvm_arch_hardware_setup':
>> arch/x86/kvm/x86.h:428:22: error: 'X86_FEATURE_SHSTK' undeclared (first use in this function); did you mean 'X86_FEATURE_EST'?
428 | if (!__cpu_has(__c, X86_FEATURE_SHSTK) && \
| ^~~~~~~~~~~~~~~~~
arch/x86/kvm/x86.c:10303:55: note: in definition of macro '__kvm_cpu_cap_has'
10303 | #define __kvm_cpu_cap_has(UNUSED_, f) kvm_cpu_cap_has(f)
| ^
arch/x86/kvm/x86.c:10304:22: note: in expansion of macro '__cr4_reserved_bits'
10304 | cr4_reserved_bits = __cr4_reserved_bits(__kvm_cpu_cap_has, UNUSED_);
| ^~~~~~~~~~~~~~~~~~~
>> arch/x86/kvm/x86.h:429:22: error: 'X86_FEATURE_IBT' undeclared (first use in this function); did you mean 'X86_FEATURE_IBS'?
429 | !__cpu_has(__c, X86_FEATURE_IBT)) \
| ^~~~~~~~~~~~~~~
arch/x86/kvm/x86.c:10303:55: note: in definition of macro '__kvm_cpu_cap_has'
10303 | #define __kvm_cpu_cap_has(UNUSED_, f) kvm_cpu_cap_has(f)
| ^
arch/x86/kvm/x86.c:10304:22: note: in expansion of macro '__cr4_reserved_bits'
10304 | cr4_reserved_bits = __cr4_reserved_bits(__kvm_cpu_cap_has, UNUSED_);
| ^~~~~~~~~~~~~~~~~~~
In file included from arch/x86/kvm/cpuid.h:5,
from arch/x86/kvm/mmu.h:7,
from arch/x86/kvm/x86.c:22:
>> arch/x86/kvm/x86.h:430:22: error: 'X86_CR4_CET' undeclared (first use in this function); did you mean 'X86_CR4_MCE'?
430 | __reserved_bits |= X86_CR4_CET; \
| ^~~~~~~~~~~
arch/x86/kvm/x86.c:10304:22: note: in expansion of macro '__cr4_reserved_bits'
10304 | cr4_reserved_bits = __cr4_reserved_bits(__kvm_cpu_cap_has, UNUSED_);
| ^~~~~~~~~~~~~~~~~~~
In file included from arch/x86/include/asm/thread_info.h:53,
from include/linux/thread_info.h:38,
from arch/x86/include/asm/preempt.h:7,
from include/linux/preempt.h:78,
from include/linux/percpu.h:6,
from include/linux/context_tracking_state.h:5,
from include/linux/hardirq.h:5,
from include/linux/kvm_host.h:7,
from arch/x86/kvm/x86.c:19:
arch/x86/kvm/x86.c: In function 'kvm_arch_check_processor_compat':
>> arch/x86/kvm/x86.h:428:22: error: 'X86_FEATURE_SHSTK' undeclared (first use in this function); did you mean 'X86_FEATURE_EST'?
428 | if (!__cpu_has(__c, X86_FEATURE_SHSTK) && \
| ^~~~~~~~~~~~~~~~~
arch/x86/include/asm/cpufeature.h:118:24: note: in definition of macro 'cpu_has'
118 | (__builtin_constant_p(bit) && REQUIRED_MASK_BIT_SET(bit) ? 1 : \
| ^~~
arch/x86/kvm/x86.c:10337:6: note: in expansion of macro '__cr4_reserved_bits'
10337 | if (__cr4_reserved_bits(cpu_has, c) !=
| ^~~~~~~~~~~~~~~~~~~
>> arch/x86/kvm/x86.h:429:22: error: 'X86_FEATURE_IBT' undeclared (first use in this function); did you mean 'X86_FEATURE_IBS'?
429 | !__cpu_has(__c, X86_FEATURE_IBT)) \
| ^~~~~~~~~~~~~~~
arch/x86/include/asm/cpufeature.h:118:24: note: in definition of macro 'cpu_has'
118 | (__builtin_constant_p(bit) && REQUIRED_MASK_BIT_SET(bit) ? 1 : \
| ^~~
arch/x86/kvm/x86.c:10337:6: note: in expansion of macro '__cr4_reserved_bits'
10337 | if (__cr4_reserved_bits(cpu_has, c) !=
| ^~~~~~~~~~~~~~~~~~~
In file included from arch/x86/kvm/cpuid.h:5,
from arch/x86/kvm/mmu.h:7,
from arch/x86/kvm/x86.c:22:
>> arch/x86/kvm/x86.h:430:22: error: 'X86_CR4_CET' undeclared (first use in this function); did you mean 'X86_CR4_MCE'?
430 | __reserved_bits |= X86_CR4_CET; \
| ^~~~~~~~~~~
arch/x86/kvm/x86.c:10337:6: note: in expansion of macro '__cr4_reserved_bits'
10337 | if (__cr4_reserved_bits(cpu_has, c) !=
| ^~~~~~~~~~~~~~~~~~~
arch/x86/kvm/x86.c: In function 'is_xsaves_msr':
arch/x86/kvm/x86.c:3633:1: error: control reaches end of non-void function [-Werror=return-type]
3633 | }
| ^
cc1: some warnings being treated as errors
--
In file included from arch/x86/kvm/cpuid.h:5,
from arch/x86/kvm/cpuid.c:21:
arch/x86/kvm/cpuid.c: In function 'kvm_vcpu_after_set_cpuid':
>> arch/x86/kvm/x86.h:428:22: error: 'X86_FEATURE_SHSTK' undeclared (first use in this function); did you mean 'X86_FEATURE_EST'?
428 | if (!__cpu_has(__c, X86_FEATURE_SHSTK) && \
| ^~~~~~~~~~~~~~~~~
arch/x86/kvm/cpuid.c:195:6: note: in expansion of macro '__cr4_reserved_bits'
195 | __cr4_reserved_bits(guest_cpuid_has, vcpu);
| ^~~~~~~~~~~~~~~~~~~
arch/x86/kvm/x86.h:428:22: note: each undeclared identifier is reported only once for each function it appears in
428 | if (!__cpu_has(__c, X86_FEATURE_SHSTK) && \
| ^~~~~~~~~~~~~~~~~
arch/x86/kvm/cpuid.c:195:6: note: in expansion of macro '__cr4_reserved_bits'
195 | __cr4_reserved_bits(guest_cpuid_has, vcpu);
| ^~~~~~~~~~~~~~~~~~~
>> arch/x86/kvm/x86.h:429:22: error: 'X86_FEATURE_IBT' undeclared (first use in this function); did you mean 'X86_FEATURE_IBS'?
429 | !__cpu_has(__c, X86_FEATURE_IBT)) \
| ^~~~~~~~~~~~~~~
arch/x86/kvm/cpuid.c:195:6: note: in expansion of macro '__cr4_reserved_bits'
195 | __cr4_reserved_bits(guest_cpuid_has, vcpu);
| ^~~~~~~~~~~~~~~~~~~
>> arch/x86/kvm/x86.h:430:22: error: 'X86_CR4_CET' undeclared (first use in this function); did you mean 'X86_CR4_MCE'?
430 | __reserved_bits |= X86_CR4_CET; \
| ^~~~~~~~~~~
arch/x86/kvm/cpuid.c:195:6: note: in expansion of macro '__cr4_reserved_bits'
195 | __cr4_reserved_bits(guest_cpuid_has, vcpu);
| ^~~~~~~~~~~~~~~~~~~vim +870 arch/x86/kvm/x86.c
841
842 cr0 &= ~CR0_RESERVED_BITS;
843
844 if ((cr0 & X86_CR0_NW) && !(cr0 & X86_CR0_CD))
845 return 1;
846
847 if ((cr0 & X86_CR0_PG) && !(cr0 & X86_CR0_PE))
848 return 1;
849
850 #ifdef CONFIG_X86_64
851 if ((vcpu->arch.efer & EFER_LME) && !is_paging(vcpu) &&
852 (cr0 & X86_CR0_PG)) {
853 int cs_db, cs_l;
854
855 if (!is_pae(vcpu))
856 return 1;
857 kvm_x86_ops.get_cs_db_l_bits(vcpu, &cs_db, &cs_l);
858 if (cs_l)
859 return 1;
860 }
861 #endif
862 if (!(vcpu->arch.efer & EFER_LME) && (cr0 & X86_CR0_PG) &&
863 is_pae(vcpu) && ((cr0 ^ old_cr0) & pdptr_bits) &&
864 !load_pdptrs(vcpu, vcpu->arch.walk_mmu, kvm_read_cr3(vcpu)))
865 return 1;
866
867 if (!(cr0 & X86_CR0_PG) && kvm_read_cr4_bits(vcpu, X86_CR4_PCIDE))
868 return 1;
869
> 870 if (!(cr0 & X86_CR0_WP) && kvm_read_cr4_bits(vcpu, X86_CR4_CET))
871 return 1;
872
873 kvm_x86_ops.set_cr0(vcpu, cr0);
874
875 kvm_post_set_cr0(vcpu, old_cr0, cr0);
876
877 return 0;
878 }
879 EXPORT_SYMBOL_GPL(kvm_set_cr0);
880
---
0-DAY CI Kernel Test Service, Intel Corporation
https://lists.01.org/hyperkitty/list/kbuild-all(a)lists.01.org
PATCH v15 7/14 KVM: VMX: Emulate reads and writes to CET MSRs
In reply to Yang WeijiangAdd support for emulating read and write accesses to CET MSRs. CET MSRs are universally "special" as they are either context switched via dedicated VMCS fields or via XSAVES, i.e. no additional in-memory tracking is needed, but emulated reads/writes are more expensive.
MSRs that are switched through XSAVES are especially annoying due to the possibility of the kernel's FPU being used in IRQ context. Disable IRQs and ensure the guest's FPU state is loaded when accessing such MSRs.
--- arch/x86/kvm/vmx/vmx.c | 105 +++++++++++++++++++++++++++++++++++++++++ arch/x86/kvm/x86.h | 5 ++ 2 files changed, 110 insertions(+)
arch/x86/kvm/vmx/vmx.c +105 -0
@@ -1787,6 +1787,66 @@ static int vmx_get_msr_feature(struct kvm_msr_entry *msr) } } +static void vmx_get_xsave_msr (struct msr_data *msr_info) +{ +local_irq_disable (); +if (test_thread_flag (TIF_NEED_FPU_LOAD )) +switch_fpu_return (); +rdmsrl (msr_info->index, msr_info->data); +local_irq_enable (); +} + +static void vmx_set_xsave_msr (struct msr_data *msr_info) +{ +local_irq_disable (); +if (test_thread_flag (TIF_NEED_FPU_LOAD )) +switch_fpu_return (); +wrmsrl (msr_info->index, msr_info->data); +local_irq_enable (); +} + +static bool cet_is_ssp_msr_accessible (struct kvm_vcpu *vcpu, +struct msr_data *msr) +{ +u64 mask; + +if (!kvm_cet_supported ()) +return false; + +if (msr->host_initiated) +return true; + +if (!guest_cpuid_has (vcpu,X86_FEATURE_SHSTK )) +return false; + +if (msr->index ==MSR_IA32_INT_SSP_TAB ) +return true; + + mask = (msr->index ==MSR_IA32_PL3_SSP ) ?XFEATURE_MASK_CET_USER : +XFEATURE_MASK_CET_KERNEL ; +return !!(vcpu->arch.guest_supported_xss & mask); +} + +static bool cet_is_control_msr_accessible (struct kvm_vcpu *vcpu, +struct msr_data *msr) +{ +u64 mask; + +if (!kvm_cet_supported ()) +return false; + +if (msr->host_initiated) +return true; + +if (!guest_cpuid_has (vcpu,X86_FEATURE_SHSTK ) && + !guest_cpuid_has (vcpu,X86_FEATURE_IBT )) +return false; + + mask = (msr->index ==MSR_IA32_U_CET ) ?XFEATURE_MASK_CET_USER : +XFEATURE_MASK_CET_KERNEL ; +return !!(vcpu->arch.guest_supported_xss & mask); +} +/* * Reads an msr value (of 'msr_index') into 'pdata'. * Returns 0 on success, non-0 otherwise.
@@ -1919,6 +1979,26 @@ static int vmx_get_msr(struct kvm_vcpu *vcpu, struct msr_data *msr_info)else msr_info->data = vmx->pt_desc.guest.addr_a[index /2 ];break ; +case MSR_IA32_S_CET : +if (!cet_is_control_msr_accessible (vcpu, msr_info)) +return 1 ; + msr_info->data =vmcs_readl (GUEST_S_CET ); +break ; +case MSR_IA32_U_CET : +if (!cet_is_control_msr_accessible (vcpu, msr_info)) +return 1 ; +vmx_get_xsave_msr (msr_info); +break ; +case MSR_IA32_INT_SSP_TAB : +if (!cet_is_ssp_msr_accessible (vcpu, msr_info)) +return 1 ; + msr_info->data =vmcs_readl (GUEST_INTR_SSP_TABLE ); +break ; + case MSR_IA32_PL0_SSP ... MSR_IA32_PL3_SSP: +if (!cet_is_ssp_msr_accessible (vcpu, msr_info)) +return 1 ; +vmx_get_xsave_msr (msr_info); +break ;case MSR_TSC_AUX :if (!msr_info->host_initiated && !guest_cpuid_has (vcpu,X86_FEATURE_RDTSCP ))
@@ -2188,6 +2268,31 @@ static int vmx_set_msr(struct kvm_vcpu *vcpu, struct msr_data *msr_info)else vmx->pt_desc.guest.addr_a[index /2 ] = data;break ; +case MSR_IA32_S_CET : +case MSR_IA32_U_CET : +if (!cet_is_control_msr_accessible (vcpu, msr_info)) +return 1 ; +if (data &GENMASK (9 ,6 )) +return 1 ; +if (msr_index ==MSR_IA32_S_CET ) +vmcs_writel (GUEST_S_CET , data); +else +vmx_set_xsave_msr (msr_info); +break ; +case MSR_IA32_INT_SSP_TAB : +if (!cet_is_control_msr_accessible (vcpu, msr_info)) +return 1 ; +if (is_noncanonical_address (data, vcpu)) +return 1 ; +vmcs_writel (GUEST_INTR_SSP_TABLE , data); +break ; + case MSR_IA32_PL0_SSP ... MSR_IA32_PL3_SSP: +if (!cet_is_ssp_msr_accessible (vcpu, msr_info)) +return 1 ; +if ((data &GENMASK (2 ,0 )) ||is_noncanonical_address (data, vcpu)) +return 1 ; +vmx_set_xsave_msr (msr_info); +break ;case MSR_TSC_AUX :if (!msr_info->host_initiated && !guest_cpuid_has (vcpu,X86_FEATURE_RDTSCP ))
arch/x86/kvm/x86.h +5 -0
@@ -288,6 +288,11 @@ static inline bool kvm_mpx_supported(void) == (XFEATURE_MASK_BNDREGS | XFEATURE_MASK_BNDCSR); } +static inline bool kvm_cet_supported (void ) +{ +return supported_xss &XFEATURE_MASK_CET_USER ; +} +extern unsigned int min_timer_period_us;extern bool enable_vmware_backdoor;
Signature · 1 line
2.26.2
Paolo Bonzini
maintainerRe: [PATCH v15 07/14] KVM: VMX: Emulate reads and writes to CET MSRs
Quoted 1 line · Yang Weijiang
MSRs that are switched through XSAVES are especially annoying due to the possibility of the kernel's FPU being used in IRQ context. Disable IRQs and ensure the guest's FPU state is loaded when accessing such MSRs.
Good catch! This should be in x86.h and named kvm_get/set_xsave_msr because it's not VMX specific. The commit message should also be there as a comment.
In addition,
arch/x86/kvm/vmx/vmx.c static int vmx_get_msr(struct kvm_vcpu *vcpu, struct msr_data *msr_info) · line 1991
Quoted 10 lines
arch/x86/kvm/vmx/vmx.c +10
-0+case MSR_IA32_S_CET : +if (!cet_is_control_msr_accessible (vcpu, msr_info)) +return 1 ; + msr_info->data =vmcs_readl (GUEST_S_CET ); +break ; +case MSR_IA32_U_CET : +if (!cet_is_control_msr_accessible (vcpu, msr_info)) +return 1 ; +vmx_get_xsave_msr (msr_info); +break ;
these two might as well be the same "case" for symmetry with the handling of WRMSR.
I've fixed this up locally, since these patches will not be pushed to Linus until the corresponding bare metal support is there.
Paolo
Re: [PATCH v15 07/14] KVM: VMX: Emulate reads and writes to CET MSRs
Quoted 8 lines · Paolo Bonzini
Quoted 3 lines · Yang Weijiang
MSRs that are switched through XSAVES are especially annoying due to the possibility of the kernel's FPU being used in IRQ context. Disable IRQs and ensure the guest's FPU state is loaded when accessing such MSRs.
Good catch! This should be in
x86.hand named kvm_get/set_xsave_msr because it's not VMX specific. The commit message should also be there as a comment.
Thanks a lot for reviewing! These words came from Sean! :-D
Quoted 17 lines
In addition,
arch/x86/kvm/vmx/vmx.c static int vmx_get_msr(struct kvm_vcpu *vcpu, struct msr_data *msr_info) · line 1991
Quoted 10 lines
arch/x86/kvm/vmx/vmx.c +10
-0+case MSR_IA32_S_CET : +if (!cet_is_control_msr_accessible (vcpu, msr_info)) +return 1 ; + msr_info->data =vmcs_readl (GUEST_S_CET ); +break ; +case MSR_IA32_U_CET : +if (!cet_is_control_msr_accessible (vcpu, msr_info)) +return 1 ; +vmx_get_xsave_msr (msr_info); +break ;these two might as well be the same "case" for symmetry with the handling of WRMSR.
Quoted 2 lines
I've fixed this up locally, since these patches will not be pushed to Linus until the corresponding bare metal support is there.
Got it!
Quoted 2 lines
Paolo
kernel test robot
build botRe: [PATCH v15 07/14] KVM: VMX: Emulate reads and writes to CET MSRs
In reply to Yang WeijiangThank you for the patch! Yet something to improve:
Hi Yang,
Thank you for the patch! Yet something to improve:
[auto build test ERROR on kvm/linux-next]
[also build test ERROR on v5.11-rc6 next-20210125]
[If your patch is applied to the wrong git tree, kindly drop us a note. And when submitting patch, we suggest to use '--base' as documented in
https://git-scm.com/docs/git-format-patch]
url: https://github.com/0day-ci/linux/commits/Yang-Weijiang/Introduce-support-for-guest-CET-feature/20210203-193042 base: https://git.kernel.org/pub/scm/virt/kvm/kvm.git linux-next config: x86_64-allyesconfig (attached as .config) compiler: gcc-9 (Debian 9.3.0-15) 9.3.0 reproduce (this is a W=1 build): # https://github.com/0day-ci/linux/commit/458cd3365137bf0803f3a6a4e8788a2c01f0b65c git remote add linux-review https://github.com/0day-ci/linux git fetch --no-tags linux-review Yang-Weijiang/Introduce-support-for-guest-CET-feature/20210203-193042 git checkout 458cd3365137bf0803f3a6a4e8788a2c01f0b65c # save the attached .config to linux build tree make W=1 ARCH=x86_64
If you fix the issue, kindly add following tag as appropriate
All errors (new ones prefixed by >>):
In file included from arch/x86/kvm/cpuid.h:5,
from arch/x86/kvm/mmu.h:7,
from arch/x86/kvm/x86.c:22:
arch/x86/kvm/x86.h: In function 'kvm_cet_supported':
>> arch/x86/kvm/x86.h:293:25: error: 'XFEATURE_MASK_CET_USER' undeclared (first use in this function); did you mean 'XFEATURE_MASK_BNDCSR'?
293 | return supported_xss & XFEATURE_MASK_CET_USER;
| ^~~~~~~~~~~~~~~~~~~~~~
| XFEATURE_MASK_BNDCSR
arch/x86/kvm/x86.h:293:25: note: each undeclared identifier is reported only once for each function it appears in
arch/x86/kvm/x86.c: In function 'kvm_set_cr0':
arch/x86/kvm/x86.c:870:53: error: 'X86_CR4_CET' undeclared (first use in this function); did you mean 'X86_CR4_MCE'?
870 | if (!(cr0 & X86_CR0_WP) && kvm_read_cr4_bits(vcpu, X86_CR4_CET))
| ^~~~~~~~~~~
| X86_CR4_MCE
arch/x86/kvm/x86.c: In function 'kvm_set_cr4':
arch/x86/kvm/x86.c:1039:13: error: 'X86_CR4_CET' undeclared (first use in this function); did you mean 'X86_CR4_MCE'?
1039 | if ((cr4 & X86_CR4_CET) && !(kvm_read_cr0(vcpu) & X86_CR0_WP))
| ^~~~~~~~~~~
| X86_CR4_MCE
arch/x86/kvm/x86.c: In function 'is_xsaves_msr':
arch/x86/kvm/x86.c:3631:18: error: 'MSR_IA32_U_CET' undeclared (first use in this function); did you mean 'MSR_IA32_TSC'?
3631 | return index == MSR_IA32_U_CET ||
| ^~~~~~~~~~~~~~
| MSR_IA32_TSC
arch/x86/kvm/x86.c:3632:19: error: 'MSR_IA32_PL0_SSP' undeclared (first use in this function); did you mean 'MSR_IA32_MCG_ESP'?
3632 | (index >= MSR_IA32_PL0_SSP && index <= MSR_IA32_PL3_SSP);
| ^~~~~~~~~~~~~~~~
| MSR_IA32_MCG_ESP
arch/x86/kvm/x86.c:3632:48: error: 'MSR_IA32_PL3_SSP' undeclared (first use in this function); did you mean 'MSR_IA32_MCG_ESP'?
3632 | (index >= MSR_IA32_PL0_SSP && index <= MSR_IA32_PL3_SSP);
| ^~~~~~~~~~~~~~~~
| MSR_IA32_MCG_ESP
arch/x86/kvm/x86.c: In function 'kvm_arch_hardware_setup':
arch/x86/kvm/x86.h:433:22: error: 'X86_FEATURE_SHSTK' undeclared (first use in this function); did you mean 'X86_FEATURE_EST'?
433 | if (!__cpu_has(__c, X86_FEATURE_SHSTK) && \
| ^~~~~~~~~~~~~~~~~
arch/x86/kvm/x86.c:10303:55: note: in definition of macro '__kvm_cpu_cap_has'
10303 | #define __kvm_cpu_cap_has(UNUSED_, f) kvm_cpu_cap_has(f)
| ^
arch/x86/kvm/x86.c:10304:22: note: in expansion of macro '__cr4_reserved_bits'
10304 | cr4_reserved_bits = __cr4_reserved_bits(__kvm_cpu_cap_has, UNUSED_);
| ^~~~~~~~~~~~~~~~~~~
arch/x86/kvm/x86.h:434:22: error: 'X86_FEATURE_IBT' undeclared (first use in this function); did you mean 'X86_FEATURE_IBS'?
434 | !__cpu_has(__c, X86_FEATURE_IBT)) \
| ^~~~~~~~~~~~~~~
arch/x86/kvm/x86.c:10303:55: note: in definition of macro '__kvm_cpu_cap_has'
10303 | #define __kvm_cpu_cap_has(UNUSED_, f) kvm_cpu_cap_has(f)
| ^
arch/x86/kvm/x86.c:10304:22: note: in expansion of macro '__cr4_reserved_bits'
10304 | cr4_reserved_bits = __cr4_reserved_bits(__kvm_cpu_cap_has, UNUSED_);
| ^~~~~~~~~~~~~~~~~~~
In file included from arch/x86/kvm/cpuid.h:5,
from arch/x86/kvm/mmu.h:7,
from arch/x86/kvm/x86.c:22:
arch/x86/kvm/x86.h:435:22: error: 'X86_CR4_CET' undeclared (first use in this function); did you mean 'X86_CR4_MCE'?
435 | __reserved_bits |= X86_CR4_CET; \
| ^~~~~~~~~~~
arch/x86/kvm/x86.c:10304:22: note: in expansion of macro '__cr4_reserved_bits'
10304 | cr4_reserved_bits = __cr4_reserved_bits(__kvm_cpu_cap_has, UNUSED_);
| ^~~~~~~~~~~~~~~~~~~
In file included from arch/x86/include/asm/thread_info.h:53,
from include/linux/thread_info.h:38,
from arch/x86/include/asm/preempt.h:7,
from include/linux/preempt.h:78,
from include/linux/percpu.h:6,
from include/linux/context_tracking_state.h:5,
from include/linux/hardirq.h:5,
from include/linux/kvm_host.h:7,
from arch/x86/kvm/x86.c:19:
arch/x86/kvm/x86.c: In function 'kvm_arch_check_processor_compat':
arch/x86/kvm/x86.h:433:22: error: 'X86_FEATURE_SHSTK' undeclared (first use in this function); did you mean 'X86_FEATURE_EST'?
433 | if (!__cpu_has(__c, X86_FEATURE_SHSTK) && \
| ^~~~~~~~~~~~~~~~~
arch/x86/include/asm/cpufeature.h:118:24: note: in definition of macro 'cpu_has'
118 | (__builtin_constant_p(bit) && REQUIRED_MASK_BIT_SET(bit) ? 1 : \
| ^~~
arch/x86/kvm/x86.c:10337:6: note: in expansion of macro '__cr4_reserved_bits'
10337 | if (__cr4_reserved_bits(cpu_has, c) !=
| ^~~~~~~~~~~~~~~~~~~
arch/x86/kvm/x86.h:434:22: error: 'X86_FEATURE_IBT' undeclared (first use in this function); did you mean 'X86_FEATURE_IBS'?
434 | !__cpu_has(__c, X86_FEATURE_IBT)) \
| ^~~~~~~~~~~~~~~
arch/x86/include/asm/cpufeature.h:118:24: note: in definition of macro 'cpu_has'
118 | (__builtin_constant_p(bit) && REQUIRED_MASK_BIT_SET(bit) ? 1 : \
| ^~~
arch/x86/kvm/x86.c:10337:6: note: in expansion of macro '__cr4_reserved_bits'
10337 | if (__cr4_reserved_bits(cpu_has, c) !=
| ^~~~~~~~~~~~~~~~~~~
In file included from arch/x86/kvm/cpuid.h:5,
from arch/x86/kvm/mmu.h:7,
from arch/x86/kvm/x86.c:22:
arch/x86/kvm/x86.h:435:22: error: 'X86_CR4_CET' undeclared (first use in this function); did you mean 'X86_CR4_MCE'?
435 | __reserved_bits |= X86_CR4_CET; \
| ^~~~~~~~~~~
arch/x86/kvm/x86.c:10337:6: note: in expansion of macro '__cr4_reserved_bits'
10337 | if (__cr4_reserved_bits(cpu_has, c) !=
| ^~~~~~~~~~~~~~~~~~~
arch/x86/kvm/x86.c: In function 'is_xsaves_msr':
arch/x86/kvm/x86.c:3633:1: error: control reaches end of non-void function [-Werror=return-type]
3633 | }
| ^ cc1: some warnings being treated as errors
--
In file included from arch/x86/kvm/emulate.c:29:
arch/x86/kvm/x86.h: In function 'kvm_cet_supported':
>> arch/x86/kvm/x86.h:293:25: error: 'XFEATURE_MASK_CET_USER' undeclared (first use in this function); did you mean 'XFEATURE_MASK_BNDCSR'?
293 | return supported_xss & XFEATURE_MASK_CET_USER;
| ^~~~~~~~~~~~~~~~~~~~~~
| XFEATURE_MASK_BNDCSR
arch/x86/kvm/x86.h:293:25: note: each undeclared identifier is reported only once for each function it appears in
--
In file included from arch/x86/kvm/cpuid.h:5,
from arch/x86/kvm/cpuid.c:21:
arch/x86/kvm/x86.h: In function 'kvm_cet_supported':
>> arch/x86/kvm/x86.h:293:25: error: 'XFEATURE_MASK_CET_USER' undeclared (first use in this function); did you mean 'XFEATURE_MASK_BNDCSR'?
293 | return supported_xss & XFEATURE_MASK_CET_USER;
| ^~~~~~~~~~~~~~~~~~~~~~
| XFEATURE_MASK_BNDCSR
arch/x86/kvm/x86.h:293:25: note: each undeclared identifier is reported only once for each function it appears in
arch/x86/kvm/cpuid.c: In function 'kvm_vcpu_after_set_cpuid':
arch/x86/kvm/x86.h:433:22: error: 'X86_FEATURE_SHSTK' undeclared (first use in this function); did you mean 'X86_FEATURE_EST'?
433 | if (!__cpu_has(__c, X86_FEATURE_SHSTK) && \
| ^~~~~~~~~~~~~~~~~
arch/x86/kvm/cpuid.c:195:6: note: in expansion of macro '__cr4_reserved_bits'
195 | __cr4_reserved_bits(guest_cpuid_has, vcpu);
| ^~~~~~~~~~~~~~~~~~~
arch/x86/kvm/x86.h:434:22: error: 'X86_FEATURE_IBT' undeclared (first use in this function); did you mean 'X86_FEATURE_IBS'?
434 | !__cpu_has(__c, X86_FEATURE_IBT)) \
| ^~~~~~~~~~~~~~~
arch/x86/kvm/cpuid.c:195:6: note: in expansion of macro '__cr4_reserved_bits'
195 | __cr4_reserved_bits(guest_cpuid_has, vcpu);
| ^~~~~~~~~~~~~~~~~~~
arch/x86/kvm/x86.h:435:22: error: 'X86_CR4_CET' undeclared (first use in this function); did you mean 'X86_CR4_MCE'?
435 | __reserved_bits |= X86_CR4_CET; \
| ^~~~~~~~~~~
arch/x86/kvm/cpuid.c:195:6: note: in expansion of macro '__cr4_reserved_bits'
195 | __cr4_reserved_bits(guest_cpuid_has, vcpu);
| ^~~~~~~~~~~~~~~~~~~
--
In file included from arch/x86/kvm/cpuid.h:5,
from arch/x86/kvm/vmx/vmx.c:51:
arch/x86/kvm/x86.h: In function 'kvm_cet_supported':
>> arch/x86/kvm/x86.h:293:25: error: 'XFEATURE_MASK_CET_USER' undeclared (first use in this function); did you mean 'XFEATURE_MASK_BNDCSR'?
293 | return supported_xss & XFEATURE_MASK_CET_USER;
| ^~~~~~~~~~~~~~~~~~~~~~
| XFEATURE_MASK_BNDCSR
arch/x86/kvm/x86.h:293:25: note: each undeclared identifier is reported only once for each function it appears in
arch/x86/kvm/vmx/vmx.c: In function 'cet_is_ssp_msr_accessible':
>> arch/x86/kvm/vmx/vmx.c:1819:29: error: 'X86_FEATURE_SHSTK' undeclared (first use in this function); did you mean 'X86_FEATURE_EST'?
1819 | if (!guest_cpuid_has(vcpu, X86_FEATURE_SHSTK))
| ^~~~~~~~~~~~~~~~~
| X86_FEATURE_EST
>> arch/x86/kvm/vmx/vmx.c:1822:20: error: 'MSR_IA32_INT_SSP_TAB' undeclared (first use in this function)
1822 | if (msr->index == MSR_IA32_INT_SSP_TAB)
| ^~~~~~~~~~~~~~~~~~~~
>> arch/x86/kvm/vmx/vmx.c:1825:24: error: 'MSR_IA32_PL3_SSP' undeclared (first use in this function); did you mean 'MSR_IA32_MCG_ESP'?
1825 | mask = (msr->index == MSR_IA32_PL3_SSP) ? XFEATURE_MASK_CET_USER :
| ^~~~~~~~~~~~~~~~
| MSR_IA32_MCG_ESP
>> arch/x86/kvm/vmx/vmx.c:1825:44: error: 'XFEATURE_MASK_CET_USER' undeclared (first use in this function); did you mean 'XFEATURE_MASK_BNDCSR'?
1825 | mask = (msr->index == MSR_IA32_PL3_SSP) ? XFEATURE_MASK_CET_USER :
| ^~~~~~~~~~~~~~~~~~~~~~
| XFEATURE_MASK_BNDCSR
>> arch/x86/kvm/vmx/vmx.c:1826:9: error: 'XFEATURE_MASK_CET_KERNEL' undeclared (first use in this function); did you mean 'XFEATURE_MASK_EXTEND'?
1826 | XFEATURE_MASK_CET_KERNEL;
| ^~~~~~~~~~~~~~~~~~~~~~~~
| XFEATURE_MASK_EXTEND
arch/x86/kvm/vmx/vmx.c: In function 'cet_is_control_msr_accessible':
arch/x86/kvm/vmx/vmx.c:1841:29: error: 'X86_FEATURE_SHSTK' undeclared (first use in this function); did you mean 'X86_FEATURE_EST'?
1841 | if (!guest_cpuid_has(vcpu, X86_FEATURE_SHSTK) &&
| ^~~~~~~~~~~~~~~~~
| X86_FEATURE_EST
>> arch/x86/kvm/vmx/vmx.c:1842:29: error: 'X86_FEATURE_IBT' undeclared (first use in this function); did you mean 'X86_FEATURE_IBS'?
1842 | !guest_cpuid_has(vcpu, X86_FEATURE_IBT))
| ^~~~~~~~~~~~~~~
| X86_FEATURE_IBS
>> arch/x86/kvm/vmx/vmx.c:1845:24: error: 'MSR_IA32_U_CET' undeclared (first use in this function); did you mean 'MSR_IA32_TSC'?
1845 | mask = (msr->index == MSR_IA32_U_CET) ? XFEATURE_MASK_CET_USER :
| ^~~~~~~~~~~~~~
| MSR_IA32_TSC
arch/x86/kvm/vmx/vmx.c:1845:42: error: 'XFEATURE_MASK_CET_USER' undeclared (first use in this function); did you mean 'XFEATURE_MASK_BNDCSR'?
1845 | mask = (msr->index == MSR_IA32_U_CET) ? XFEATURE_MASK_CET_USER :
| ^~~~~~~~~~~~~~~~~~~~~~
| XFEATURE_MASK_BNDCSR
arch/x86/kvm/vmx/vmx.c:1846:7: error: 'XFEATURE_MASK_CET_KERNEL' undeclared (first use in this function); did you mean 'XFEATURE_MASK_EXTEND'?
1846 | XFEATURE_MASK_CET_KERNEL;
| ^~~~~~~~~~~~~~~~~~~~~~~~
| XFEATURE_MASK_EXTEND
arch/x86/kvm/vmx/vmx.c: In function 'vmx_get_msr':
>> arch/x86/kvm/vmx/vmx.c:1982:7: error: 'MSR_IA32_S_CET' undeclared (first use in this function); did you mean 'MSR_IA32_TSC'?
1982 | case MSR_IA32_S_CET:
| ^~~~~~~~~~~~~~
| MSR_IA32_TSC
arch/x86/kvm/vmx/vmx.c:1987:7: error: 'MSR_IA32_U_CET' undeclared (first use in this function); did you mean 'MSR_IA32_TSC'?
1987 | case MSR_IA32_U_CET:
| ^~~~~~~~~~~~~~
| MSR_IA32_TSC
arch/x86/kvm/vmx/vmx.c:1992:7: error: 'MSR_IA32_INT_SSP_TAB' undeclared (first use in this function)
1992 | case MSR_IA32_INT_SSP_TAB:
| ^~~~~~~~~~~~~~~~~~~~
>> arch/x86/kvm/vmx/vmx.c:1997:7: error: 'MSR_IA32_PL0_SSP' undeclared (first use in this function); did you mean 'MSR_IA32_MCG_ESP'?
1997 | case MSR_IA32_PL0_SSP ... MSR_IA32_PL3_SSP:
| ^~~~~~~~~~~~~~~~
| MSR_IA32_MCG_ESP
arch/x86/kvm/vmx/vmx.c:1997:28: error: 'MSR_IA32_PL3_SSP' undeclared (first use in this function); did you mean 'MSR_IA32_MCG_ESP'?
1997 | case MSR_IA32_PL0_SSP ... MSR_IA32_PL3_SSP:
| ^~~~~~~~~~~~~~~~
| MSR_IA32_MCG_ESP
arch/x86/kvm/vmx/vmx.c: In function 'vmx_set_msr':
arch/x86/kvm/vmx/vmx.c:2271:7: error: 'MSR_IA32_S_CET' undeclared (first use in this function); did you mean 'MSR_IA32_TSC'?
2271 | case MSR_IA32_S_CET:
| ^~~~~~~~~~~~~~
| MSR_IA32_TSC
arch/x86/kvm/vmx/vmx.c:2272:7: error: 'MSR_IA32_U_CET' undeclared (first use in this function); did you mean 'MSR_IA32_TSC'?
2272 | case MSR_IA32_U_CET:
| ^~~~~~~~~~~~~~
| MSR_IA32_TSC
arch/x86/kvm/vmx/vmx.c:2282:7: error: 'MSR_IA32_INT_SSP_TAB' undeclared (first use in this function)
2282 | case MSR_IA32_INT_SSP_TAB:
| ^~~~~~~~~~~~~~~~~~~~
arch/x86/kvm/vmx/vmx.c:2289:7: error: 'MSR_IA32_PL0_SSP' undeclared (first use in this function); did you mean 'MSR_IA32_MCG_ESP'?
2289 | case MSR_IA32_PL0_SSP ... MSR_IA32_PL3_SSP:
| ^~~~~~~~~~~~~~~~
| MSR_IA32_MCG_ESP
arch/x86/kvm/vmx/vmx.c:2289:28: error: 'MSR_IA32_PL3_SSP' undeclared (first use in this function); did you mean 'MSR_IA32_MCG_ESP'?
2289 | case MSR_IA32_PL0_SSP ... MSR_IA32_PL3_SSP:
| ^~~~~~~~~~~~~~~~
| MSR_IA32_MCG_ESP
--
In file included from arch/x86/kvm/vmx/../cpuid.h:5,
from arch/x86/kvm/vmx/evmcs.c:7:
arch/x86/kvm/vmx/../x86.h: In function 'kvm_cet_supported':
>> arch/x86/kvm/vmx/../x86.h:293:25: error: 'XFEATURE_MASK_CET_USER' undeclared (first use in this function); did you mean 'XFEATURE_MASK_BNDCSR'?
293 | return supported_xss & XFEATURE_MASK_CET_USER;
| ^~~~~~~~~~~~~~~~~~~~~~
| XFEATURE_MASK_BNDCSR arch/x86/kvm/vmx/../x86.h:293:25: note: each undeclared identifier is reported only once for each function it appears in
vim +293 arch/x86/kvm/x86.h
290
291 static inline bool kvm_cet_supported(void)
292 {
> 293 return supported_xss & XFEATURE_MASK_CET_USER;
294 }
295
---
0-DAY CI Kernel Test Service, Intel Corporation
https://lists.01.org/hyperkitty/list/kbuild-all(a)lists.01.org
Re: [PATCH v15 07/14] KVM: VMX: Emulate reads and writes to CET MSRs
In reply to Yang WeijiangQuoted 131 lines · Yang Weijiang
Add support for emulating read and write accesses to CET MSRs. CET MSRs are universally "special" as they are either context switched via dedicated VMCS fields or via XSAVES, i.e. no additional in-memory tracking is needed, but emulated reads/writes are more expensive.
MSRs that are switched through XSAVES are especially annoying due to the possibility of the kernel's FPU being used in IRQ context. Disable IRQs and ensure the guest's FPU state is loaded when accessing such MSRs.
Co-developed-by Sean Christopherson <[email protected]>Signed-off-by Sean Christopherson <[email protected]>Signed-off-by Yang Weijiang <[email protected]>--- arch/x86/kvm/vmx/vmx.c | 105 +++++++++++++++++++++++++++++++++++++++++ arch/x86/kvm/x86.h | 5 ++ 2 files changed, 110 insertions(+)arch/x86/kvm/vmx/vmx.c +92
-0@@ -1787,6 +1787,66 @@ static int vmx_get_msr_feature(struct kvm_msr_entry *msr) } } +static void vmx_get_xsave_msr (struct msr_data *msr_info) +{ +local_irq_disable (); +if (test_thread_flag (TIF_NEED_FPU_LOAD )) +switch_fpu_return (); +rdmsrl (msr_info->index, msr_info->data); +local_irq_enable (); +} + +static void vmx_set_xsave_msr (struct msr_data *msr_info) +{ +local_irq_disable (); +if (test_thread_flag (TIF_NEED_FPU_LOAD )) +switch_fpu_return (); +wrmsrl (msr_info->index, msr_info->data); +local_irq_enable (); +} + +static bool cet_is_ssp_msr_accessible (struct kvm_vcpu *vcpu, +struct msr_data *msr) +{ +u64 mask; + +if (!kvm_cet_supported ()) +return false; + +if (msr->host_initiated) +return true; + +if (!guest_cpuid_has (vcpu,X86_FEATURE_SHSTK )) +return false; + +if (msr->index ==MSR_IA32_INT_SSP_TAB ) +return true; + + mask = (msr->index ==MSR_IA32_PL3_SSP ) ?XFEATURE_MASK_CET_USER : +XFEATURE_MASK_CET_KERNEL ; +return !!(vcpu->arch.guest_supported_xss & mask); +} + +static bool cet_is_control_msr_accessible (struct kvm_vcpu *vcpu, +struct msr_data *msr) +{ +u64 mask; + +if (!kvm_cet_supported ()) +return false; + +if (msr->host_initiated) +return true; + +if (!guest_cpuid_has (vcpu,X86_FEATURE_SHSTK ) && + !guest_cpuid_has (vcpu,X86_FEATURE_IBT )) +return false; + + mask = (msr->index ==MSR_IA32_U_CET ) ?XFEATURE_MASK_CET_USER : +XFEATURE_MASK_CET_KERNEL ; +return !!(vcpu->arch.guest_supported_xss & mask); +} +/* * Reads an msr value (of 'msr_index') into 'pdata'. * Returns 0 on success, non-0 otherwise. @@ -1919,6 +1979,26 @@ static int vmx_get_msr(struct kvm_vcpu *vcpu, struct msr_data *msr_info)else msr_info->data = vmx->pt_desc.guest.addr_a[index /2 ];break ; +case MSR_IA32_S_CET : +if (!cet_is_control_msr_accessible (vcpu, msr_info)) +return 1 ; + msr_info->data =vmcs_readl (GUEST_S_CET ); +break ; +case MSR_IA32_U_CET : +if (!cet_is_control_msr_accessible (vcpu, msr_info)) +return 1 ; +vmx_get_xsave_msr (msr_info); +break ; +case MSR_IA32_INT_SSP_TAB : +if (!cet_is_ssp_msr_accessible (vcpu, msr_info)) +return 1 ; + msr_info->data =vmcs_readl (GUEST_INTR_SSP_TABLE ); +break ; + case MSR_IA32_PL0_SSP ... MSR_IA32_PL3_SSP: +if (!cet_is_ssp_msr_accessible (vcpu, msr_info)) +return 1 ; +vmx_get_xsave_msr (msr_info); +break ;case MSR_TSC_AUX :if (!msr_info->host_initiated && !guest_cpuid_has (vcpu,X86_FEATURE_RDTSCP ))@@ -2188,6 +2268,31 @@ static int vmx_set_msr(struct kvm_vcpu *vcpu, struct msr_data *msr_info)else vmx->pt_desc.guest.addr_a[index /2 ] = data;break ; +case MSR_IA32_S_CET : +case MSR_IA32_U_CET : +if (!cet_is_control_msr_accessible (vcpu, msr_info)) +return 1 ; +if (data &GENMASK (9 ,6 )) +return 1 ; +if (msr_index ==MSR_IA32_S_CET ) +vmcs_writel (GUEST_S_CET , data); +else +vmx_set_xsave_msr (msr_info); +break ; +case MSR_IA32_INT_SSP_TAB :
arch/x86/kvm/vmx/vmx.c static int vmx_set_msr(struct kvm_vcpu *vcpu, struct msr_data *msr_info) · line 2292
Quoted 10 lines
arch/x86/kvm/vmx/vmx.c +10
-0+if (!cet_is_control_msr_accessible (vcpu, msr_info)) +return 1 ; +if (is_noncanonical_address (data, vcpu)) +return 1 ; +vmcs_writel (GUEST_INTR_SSP_TABLE , data); +break ; + case MSR_IA32_PL0_SSP ... MSR_IA32_PL3_SSP: +if (!cet_is_ssp_msr_accessible (vcpu, msr_info)) +return 1 ; +if ((data &GENMASK (2 ,0 )) ||is_noncanonical_address (data, vcpu))
Sorry to revive this old thread. I'm working on the corresponding SVM bits for shadow stack and I noticed the above check. Why isn't this GENMASK(1, 0)? The *SSP MSRs should be a 4-byte aligned canonical address meaning that just bits 1 and 0 should always be zero. I was looking through the previous versions of the set and found that this changed between versions 11 and 12, but I don't see any discussion related to this on the list.
Thanks,
John
Quoted 25 lines
arch/x86/kvm/vmx/vmx.c +3
-0+return 1 ; +vmx_set_xsave_msr (msr_info); +break ;case MSR_TSC_AUX :if (!msr_info->host_initiated && !guest_cpuid_has (vcpu,X86_FEATURE_RDTSCP ))arch/x86/kvm/x86.h +5
-0@@ -288,6 +288,11 @@ static inline bool kvm_mpx_supported(void) == (XFEATURE_MASK_BNDREGS | XFEATURE_MASK_BNDCSR); } +static inline bool kvm_cet_supported (void ) +{ +return supported_xss &XFEATURE_MASK_CET_USER ; +} +extern unsigned int min_timer_period_us;extern bool enable_vmware_backdoor;Signature · 1 line
2.26.2
Sean Christopherson
maintainerRe: [PATCH v15 07/14] KVM: VMX: Emulate reads and writes to CET MSRs
Quoted 13 lines · John Allen
arch/x86/kvm/vmx/vmx.c static int vmx_set_msr(struct kvm_vcpu *vcpu, struct msr_data *msr_info) · line 2292
Quoted 4 lines · Yang Weijiang
arch/x86/kvm/vmx/vmx.c +4
-0+ case MSR_IA32_PL0_SSP ... MSR_IA32_PL3_SSP: +if (!cet_is_ssp_msr_accessible (vcpu, msr_info)) +return 1 ; +if ((data &GENMASK (2 ,0 )) ||is_noncanonical_address (data, vcpu))Sorry to revive this old thread. I'm working on the corresponding SVM bits for shadow stack and I noticed the above check. Why isn't this
GENMASK(1, 0)? The *SSP MSRs should be a 4-byte aligned canonical address meaning that just bits 1 and 0 should always be zero. I was looking through the previous versions of the set and found that this changed between versions 11 and 12, but I don't see any discussion related to this on the list.
Huh. I'm not entirely sure what to make of the SDM's wording:
The linear address written must be aligned to 8 bytes and bits 2:0 must be 0 (hardware requires bits 1:0 to be 0).
Looking at the rest of the CET stuff, I believe requiring 8-byte alignment is correct, and that the "hardware requires" blurb is trying to call out that the SSP stored in hardware will always be 4-byte aligned but not necessarily 8-byte aligned in order to play nice with 32-bit/compatibility mode. But "base" addresses that come from software, e.g. via MSRs and whatnot, must always be 8-byte aligned.
Re: [PATCH v15 07/14] KVM: VMX: Emulate reads and writes to CET MSRs
Quoted 15 lines · Sean Christopherson
Quoted 12 lines · John Allen
arch/x86/kvm/vmx/vmx.c static int vmx_set_msr(struct kvm_vcpu *vcpu, struct msr_data *msr_info) · line 2292
Quoted 4 lines · Yang Weijiang
arch/x86/kvm/vmx/vmx.c +4
-0+ case MSR_IA32_PL0_SSP ... MSR_IA32_PL3_SSP: +if (!cet_is_ssp_msr_accessible (vcpu, msr_info)) +return 1 ; +if ((data &GENMASK (2 ,0 )) ||is_noncanonical_address (data, vcpu))Sorry to revive this old thread. I'm working on the corresponding SVM bits for shadow stack and I noticed the above check. Why isn't this
GENMASK(1, 0)? The *SSP MSRs should be a 4-byte aligned canonical address meaning that just bits 1 and 0 should always be zero. I was looking through the previous versions of the set and found that this changed between versions 11 and 12, but I don't see any discussion related to this on the list.Huh. I'm not entirely sure what to make of the SDM's wording:
Quoted 8 lines
The linear address written must be aligned to 8 bytes and bits 2:0 must be 0 (hardware requires bits 1:0 to be 0).
Looking at the rest of the CET stuff, I believe requiring 8-byte alignment is correct, and that the "hardware requires" blurb is trying to call out that the SSP stored in hardware will always be 4-byte aligned but not necessarily 8-byte aligned in order to play nice with 32-bit/compatibility mode. But "base" addresses that come from software, e.g. via MSRs and whatnot, must always be 8-byte aligned.
Thanks Sean, I cannot agree more ;-)
PATCH v15 8/14 KVM: VMX: Add a synthetic MSR to allow userspace VMM to access GUEST_SSP
In reply to Yang WeijiangIntroduce a host-only synthetic MSR, MSR_KVM_GUEST_SSP so that the VMM can read/write the guest's SSP, e.g. to migrate CET state. Use a synthetic MSR, e.g. as opposed to a VCPU_REG_, as GUEST_SSP is subject to the same consistency checks as the PL*_SSP MSRs, i.e. can share code.
--- arch/x86/include/uapi/asm/kvm_para.h | 1 + arch/x86/kvm/vmx/vmx.c | 14 ++++++++++++-- 2 files changed, 13 insertions(+), 2 deletions(-)
arch/x86/include/uapi/asm/kvm_para.h +1 -0
@@ -54,6 +54,7 @@#define MSR_KVM_POLL_CONTROL 0x4b564d05#define MSR_KVM_ASYNC_PF_INT 0x4b564d06#define MSR_KVM_ASYNC_PF_ACK 0x4b564d07 +#define MSR_KVM_GUEST_SSP 0x4b564d08struct kvm_steal_time {__u64 steal;
arch/x86/kvm/vmx/vmx.c +12 -2
@@ -1816,7 +1816,8 @@ static bool cet_is_ssp_msr_accessible(struct kvm_vcpu *vcpu,if (msr->host_initiated)return true; -if (!guest_cpuid_has (vcpu,X86_FEATURE_SHSTK )) +if (!guest_cpuid_has (vcpu,X86_FEATURE_SHSTK ) || + msr->index ==MSR_KVM_GUEST_SSP )return false;if (msr->index ==MSR_IA32_INT_SSP_TAB )
@@ -1994,6 +1995,11 @@ static int vmx_get_msr(struct kvm_vcpu *vcpu, struct msr_data *msr_info)return 1 ; msr_info->data =vmcs_readl (GUEST_INTR_SSP_TABLE );break ; +case MSR_KVM_GUEST_SSP : +if (!cet_is_ssp_msr_accessible (vcpu, msr_info)) +return 1 ; + msr_info->data =vmcs_readl (GUEST_SSP ); +break ; case MSR_IA32_PL0_SSP ... MSR_IA32_PL3_SSP:if (!cet_is_ssp_msr_accessible (vcpu, msr_info))return 1 ;
@@ -2286,12 +2292,16 @@ static int vmx_set_msr(struct kvm_vcpu *vcpu, struct msr_data *msr_info)return 1 ;vmcs_writel (GUEST_INTR_SSP_TABLE , data);break ; +case MSR_KVM_GUEST_SSP : case MSR_IA32_PL0_SSP ... MSR_IA32_PL3_SSP:if (!cet_is_ssp_msr_accessible (vcpu, msr_info))return 1 ;if ((data &GENMASK (2 ,0 )) ||is_noncanonical_address (data, vcpu))return 1 ; -vmx_set_xsave_msr (msr_info); +if (msr_index ==MSR_KVM_GUEST_SSP ) +vmcs_writel (GUEST_SSP , data); +else +vmx_set_xsave_msr (msr_info);break ;case MSR_TSC_AUX : if (!msr_info->host_initiated &&
Signature · 1 line
2.26.2
PATCH v15 9/14 KVM: x86: Report CET MSRs as to-be-saved if CET is supported
In reply to Yang WeijiangReport all CET MSRs, including the synthetic GUEST_SSP MSR, as to-be-saved, e.g. for migration, if CET is supported by KVM.
--- arch/x86/kvm/x86.c | 10 ++++++++++ 1 file changed, 10 insertions(+)
arch/x86/kvm/x86.c +10 -0
@@ -1266,6 +1266,8 @@ static const u32 msrs_to_save_all[] = {MSR_ARCH_PERFMON_EVENTSEL0 +16 ,MSR_ARCH_PERFMON_EVENTSEL0 +17 ,MSR_IA32_XSS , +MSR_IA32_U_CET ,MSR_IA32_S_CET ,MSR_IA32_INT_SSP_TAB ,MSR_KVM_GUEST_SSP , + MSR_IA32_PL0_SSP, MSR_IA32_PL1_SSP, MSR_IA32_PL2_SSP, MSR_IA32_PL3_SSP, };static u32 msrs_to_save[ARRAY_SIZE (msrs_to_save_all)];
@@ -5828,6 +5830,14 @@ static void kvm_init_msr_list(void)if (!supported_xss)continue ;break ; +case MSR_KVM_GUEST_SSP : +case MSR_IA32_U_CET : +case MSR_IA32_S_CET : +case MSR_IA32_INT_SSP_TAB : + case MSR_IA32_PL0_SSP ... MSR_IA32_PL3_SSP: +if (!kvm_cet_supported ()) +continue ; +break ;default :break ; }
Signature · 1 line
2.26.2
PATCH v15 10/14 KVM: x86: Enable CET virtualization for VMX and advertise CET to userspace
In reply to Yang WeijiangSet the feature bits so that CET capabilities can be seen in guest via CPUID enumeration. Add CR4.CET bit support in order to allow guest set CET master control bit(CR4.CET).
Disable KVM CET feature if unrestricted_guest is unsupported/disabled as KVM does not support emulating CET.
Don't expose CET feature if dependent CET bits are cleared in host XSS, or if XSAVES isn't supported. Updating the CET features in common x86 is a little ugly, but there is on clean solution without risking breakage of SVM if SVM hardware ever gains support for CET, e.g. moving everything to common x86 would prematurely expose CET on SVM. The alternative is to put all the logic in VMX, but that means rereading host_xss in VMX and duplicating the XSAVES check across VMX and SVM.
--- arch/x86/include/asm/kvm_host.h | 3 +- arch/x86/kvm/cpuid.c | 5 +-- arch/x86/kvm/vmx/capabilities.h | 5 +++ arch/x86/kvm/vmx/vmx.c | 55 +++++++++++++++++++++++++++++++-- arch/x86/kvm/x86.c | 8 +++++ 5 files changed, 70 insertions(+), 6 deletions(-)
arch/x86/include/asm/kvm_host.h +2 -1
@@ -100,7 +100,8 @@ | X86_CR4_PGE | X86_CR4_PCE | X86_CR4_OSFXSR | X86_CR4_PCIDE \ | X86_CR4_OSXSAVE | X86_CR4_SMEP | X86_CR4_FSGSBASE \ | X86_CR4_OSXMMEXCPT | X86_CR4_LA57 | X86_CR4_VMXE \ - | X86_CR4_SMAP | X86_CR4_PKE | X86_CR4_UMIP)) + | X86_CR4_SMAP | X86_CR4_PKE | X86_CR4_UMIP \ + | X86_CR4_CET))#define CR8_RESERVED_BITS (~(unsigned long)X86_CR8_TPR)
arch/x86/kvm/cpuid.c +3 -2
@@ -417,7 +417,8 @@ void kvm_set_cpu_caps(void)F (AVX512VBMI ) |F (LA57 ) |F (PKU ) |0 /*OSPKE*/ |F (RDPID ) |F (AVX512_VPOPCNTDQ ) |F (UMIP ) |F (AVX512_VBMI2 ) |F (GFNI ) |F (VAES ) |F (VPCLMULQDQ ) |F (AVX512_VNNI ) |F (AVX512_BITALG ) | -F (CLDEMOTE ) |F (MOVDIRI ) |F (MOVDIR64B ) |0 /*WAITPKG*/ +F (CLDEMOTE ) |F (MOVDIRI ) |F (MOVDIR64B ) |0 /*WAITPKG*/ | +F (SHSTK ) );/* Set LA57 based on hardware capability. */ if (cpuid_ecx (7 ) &F (LA57 ))
@@ -434,7 +435,7 @@ void kvm_set_cpu_caps(void)F (AVX512_4VNNIW ) |F (AVX512_4FMAPS ) |F (SPEC_CTRL ) |F (SPEC_CTRL_SSBD ) |F (ARCH_CAPABILITIES ) |F (INTEL_STIBP ) |F (MD_CLEAR ) |F (AVX512_VP2INTERSECT ) |F (FSRM ) | -F (SERIALIZE ) |F (TSXLDTRK ) |F (AVX512_FP16 ) +F (SERIALIZE ) |F (TSXLDTRK ) |F (AVX512_FP16 ) |F (IBT ) );/* TSC_ADJUST and ARCH_CAPABILITIES are emulated in software. */
arch/x86/kvm/vmx/capabilities.h +5 -0
@@ -103,6 +103,11 @@ static inline bool cpu_has_load_perf_global_ctrl(void) (vmcs_config.vmexit_ctrl &VM_EXIT_LOAD_IA32_PERF_GLOBAL_CTRL ); } +static inline bool cpu_has_load_cet_ctrl (void ) +{ +return (vmcs_config.vmentry_ctrl &VM_ENTRY_LOAD_CET_STATE ) && + (vmcs_config.vmexit_ctrl &VM_EXIT_LOAD_CET_STATE ); +}static inline bool cpu_has_vmx_mpx (void ) { return (vmcs_config.vmexit_ctrl & VM_EXIT_CLEAR_BNDCFGS) &&
arch/x86/kvm/vmx/vmx.c +52 -3
109 lines not on this page · raw message
arch/x86/kvm/x86.c +8 -0
@@ -10329,6 +10329,14 @@ int kvm_arch_hardware_setup(void *opaque)if (!kvm_cpu_cap_has (X86_FEATURE_XSAVES )) supported_xss =0 ; +else + supported_xss &= host_xss; + +/* Update CET features now that supported_xss is finalized. */ +if (!kvm_cet_supported ()) { +kvm_cpu_cap_clear (X86_FEATURE_SHSTK ); +kvm_cpu_cap_clear (X86_FEATURE_IBT ); + }#define __kvm_cpu_cap_has (UNUSED_ , f) kvm_cpu_cap_has(f) cr4_reserved_bits =__cr4_reserved_bits (__kvm_cpu_cap_has,UNUSED_ );
Signature · 1 line
2.26.2
PATCH v15 11/14 KVM: VMX: Pass through CET MSRs to the guest when supported
In reply to Yang WeijiangPass through all CET MSRs when the associated CET component (kernel vs. user) is enabled to improve guest performance. All CET MSRs are context switched, either via dedicated VMCS fields or XSAVES.
--- arch/x86/kvm/vmx/vmx.c | 33 +++++++++++++++++++++++++++++++++ 1 file changed, 33 insertions(+)
arch/x86/kvm/vmx/vmx.c +33 -0
@@ -659,6 +659,10 @@ static bool is_valid_passthrough_msr(u32 msr) case MSR_IA32_RTIT_ADDR0_A ... MSR_IA32_RTIT_ADDR3_B:/* PT MSRs. These are handled in pt_update_intercept_for_msr() */ return true; +case MSR_IA32_U_CET : +case MSR_IA32_S_CET : + case MSR_IA32_PL0_SSP ... MSR_IA32_INT_SSP_TAB: +return true; } r =possible_passthrough_msr_slot (msr) != -ENOENT ;
@@ -7343,6 +7347,32 @@ static void update_intel_pt_cfg(struct kvm_vcpu *vcpu) vmx->pt_desc.ctl_bitmask &= ~(0xfULL << (32 + i *4 )); } +static bool is_cet_state_supported (struct kvm_vcpu *vcpu,u32 xss_state) +{ +return (vcpu->arch.guest_supported_xss & xss_state) && + (guest_cpuid_has (vcpu,X86_FEATURE_SHSTK ) || +guest_cpuid_has (vcpu,X86_FEATURE_IBT )); +} + +static void vmx_update_intercept_for_cet_msr (struct kvm_vcpu *vcpu) +{ +bool incpt = !is_cet_state_supported (vcpu,XFEATURE_MASK_CET_USER ); + +vmx_set_intercept_for_msr (vcpu,MSR_IA32_U_CET ,MSR_TYPE_RW , incpt); + + incpt |= !guest_cpuid_has (vcpu,X86_FEATURE_SHSTK ); +vmx_set_intercept_for_msr (vcpu,MSR_IA32_PL3_SSP ,MSR_TYPE_RW , incpt); + + incpt = !is_cet_state_supported (vcpu,XFEATURE_MASK_CET_KERNEL ); +vmx_set_intercept_for_msr (vcpu,MSR_IA32_S_CET ,MSR_TYPE_RW , incpt); + + incpt |= !guest_cpuid_has (vcpu,X86_FEATURE_SHSTK ); +vmx_set_intercept_for_msr (vcpu,MSR_IA32_INT_SSP_TAB ,MSR_TYPE_RW , incpt); +vmx_set_intercept_for_msr (vcpu,MSR_IA32_PL0_SSP ,MSR_TYPE_RW , incpt); +vmx_set_intercept_for_msr (vcpu,MSR_IA32_PL1_SSP ,MSR_TYPE_RW , incpt); +vmx_set_intercept_for_msr (vcpu,MSR_IA32_PL2_SSP ,MSR_TYPE_RW , incpt); +} +static void vmx_vcpu_after_set_cpuid (struct kvm_vcpu *vcpu) {struct vcpu_vmx *vmx =to_vmx (vcpu);
@@ -7386,6 +7416,9 @@ static void vmx_vcpu_after_set_cpuid(struct kvm_vcpu *vcpu)/* Refresh #PF interception to account for MAXPHYADDR changes. */ update_exception_bitmap (vcpu); + +if (kvm_cet_supported ()) +vmx_update_intercept_for_cet_msr (vcpu); }static __init void vmx_set_cpu_caps (void )
Signature · 1 line
2.26.2
PATCH v15 12/14 KVM: nVMX: Add helper to check the vmcs01 MSR bitmap for MSR pass-through
In reply to Yang WeijiangAdd a helper to perform the check on the vmcs01/l01 MSR bitmap when disabling interception of an MSR for L2. This reduces the boilerplate for the existing cases, and will be used heavily in a future patch for CET MSRs.
--- arch/x86/kvm/vmx/nested.c | 27 +++++++++++++++++---------- 1 file changed, 17 insertions(+), 10 deletions(-)
arch/x86/kvm/vmx/nested.c +17 -10
@@ -544,6 +544,17 @@ static void nested_vmx_disable_intercept_for_msr(unsigned long *msr_bitmap_l1, } } +static void nested_vmx_cond_disable_intercept_for_msr (struct kvm_vcpu *vcpu,u32 msr, +unsigned long *bitmap_12, +unsigned long *bitmap_02, +int type) +{ +if (msr_write_intercepted_l01 (vcpu, msr)) +return ; + +nested_vmx_disable_intercept_for_msr (bitmap_12, bitmap_02, msr, type); +} +static inline void enable_x2apic_msr_intercepts (unsigned long *msr_bitmap) {int msr;
@@ -640,17 +651,13 @@ static inline bool nested_vmx_prepare_msr_bitmap(struct kvm_vcpu *vcpu,* updated to reflect this when L1 (or its L2s) actually write to * the MSR. */ -if (!msr_write_intercepted_l01 (vcpu,MSR_IA32_SPEC_CTRL )) -nested_vmx_disable_intercept_for_msr ( - msr_bitmap_l1, msr_bitmap_l0, -MSR_IA32_SPEC_CTRL , -MSR_TYPE_R |MSR_TYPE_W ); +nested_vmx_cond_disable_intercept_for_msr (vcpu,MSR_IA32_SPEC_CTRL , + msr_bitmap_l1, msr_bitmap_l0, +MSR_TYPE_R |MSR_TYPE_W ); -if (!msr_write_intercepted_l01 (vcpu,MSR_IA32_PRED_CMD )) -nested_vmx_disable_intercept_for_msr ( - msr_bitmap_l1, msr_bitmap_l0, -MSR_IA32_PRED_CMD , -MSR_TYPE_W ); +nested_vmx_cond_disable_intercept_for_msr (vcpu,MSR_IA32_PRED_CMD , + msr_bitmap_l1, msr_bitmap_l0, +MSR_TYPE_W );kvm_vcpu_unmap (vcpu, &to_vmx (vcpu)->nested.msr_bitmap_map, false);
Signature · 1 line
2.26.2
PATCH v15 13/14 KVM: nVMX: Enable CET support for nested VMX
In reply to Yang WeijiangAdd vmcs12 fields for all CET fields, pass-through CET MSRs to L2 when possible, and enumerate the VMCS controls and CR4 bit as supported.
--- arch/x86/kvm/vmx/nested.c | 30 ++++++++++++++++++++++++++++-- arch/x86/kvm/vmx/vmcs12.c | 6 ++++++ arch/x86/kvm/vmx/vmcs12.h | 14 +++++++++++++- arch/x86/kvm/vmx/vmx.c | 1 + 4 files changed, 48 insertions(+), 3 deletions(-)
arch/x86/kvm/vmx/nested.c +28 -2
@@ -638,6 +638,29 @@ static inline bool nested_vmx_prepare_msr_bitmap(struct kvm_vcpu *vcpu,nested_vmx_disable_intercept_for_msr (msr_bitmap_l1, msr_bitmap_l0,MSR_KERNEL_GS_BASE ,MSR_TYPE_RW ); +/* Pass CET MSRs to nested VM if L0 and L1 are set to pass-through. */ +nested_vmx_cond_disable_intercept_for_msr (vcpu,MSR_IA32_U_CET , + msr_bitmap_l1, msr_bitmap_l0, +MSR_TYPE_RW ); +nested_vmx_cond_disable_intercept_for_msr (vcpu,MSR_IA32_PL3_SSP , + msr_bitmap_l1, msr_bitmap_l0, +MSR_TYPE_RW ); +nested_vmx_cond_disable_intercept_for_msr (vcpu,MSR_IA32_S_CET , + msr_bitmap_l1, msr_bitmap_l0, +MSR_TYPE_RW ); +nested_vmx_cond_disable_intercept_for_msr (vcpu,MSR_IA32_PL0_SSP , + msr_bitmap_l1, msr_bitmap_l0, +MSR_TYPE_RW ); +nested_vmx_cond_disable_intercept_for_msr (vcpu,MSR_IA32_PL1_SSP , + msr_bitmap_l1, msr_bitmap_l0, +MSR_TYPE_RW ); +nested_vmx_cond_disable_intercept_for_msr (vcpu,MSR_IA32_PL2_SSP , + msr_bitmap_l1, msr_bitmap_l0, +MSR_TYPE_RW ); +nested_vmx_cond_disable_intercept_for_msr (vcpu,MSR_IA32_INT_SSP_TAB , + msr_bitmap_l1, msr_bitmap_l0, +MSR_TYPE_RW ); +/* * Checking the L0->L1 bitmap is trying to verify two things: *
@@ -6386,7 +6409,9 @@ void nested_vmx_setup_ctls_msrs(struct nested_vmx_msrs *msrs, u32 ept_caps)VM_EXIT_HOST_ADDR_SPACE_SIZE | #endifVM_EXIT_LOAD_IA32_PAT |VM_EXIT_SAVE_IA32_PAT | -VM_EXIT_CLEAR_BNDCFGS |VM_EXIT_LOAD_IA32_PERF_GLOBAL_CTRL ; +VM_EXIT_CLEAR_BNDCFGS |VM_EXIT_LOAD_IA32_PERF_GLOBAL_CTRL | +VM_EXIT_LOAD_CET_STATE ; + msrs->exit_ctls_high |=VM_EXIT_ALWAYSON_WITHOUT_TRUE_MSR | VM_EXIT_LOAD_IA32_EFER | VM_EXIT_SAVE_IA32_EFER |
@@ -6406,7 +6431,8 @@ void nested_vmx_setup_ctls_msrs(struct nested_vmx_msrs *msrs, u32 ept_caps)VM_ENTRY_IA32E_MODE | #endifVM_ENTRY_LOAD_IA32_PAT |VM_ENTRY_LOAD_BNDCFGS | -VM_ENTRY_LOAD_IA32_PERF_GLOBAL_CTRL ; +VM_ENTRY_LOAD_IA32_PERF_GLOBAL_CTRL |VM_ENTRY_LOAD_CET_STATE ; + msrs->entry_ctls_high |= (VM_ENTRY_ALWAYSON_WITHOUT_TRUE_MSR |VM_ENTRY_LOAD_IA32_EFER );
arch/x86/kvm/vmx/vmcs12.c +6 -0
@@ -137,6 +137,9 @@ const unsigned short vmcs_field_to_offset_table[] = {FIELD (GUEST_PENDING_DBG_EXCEPTIONS , guest_pending_dbg_exceptions),FIELD (GUEST_SYSENTER_ESP , guest_sysenter_esp),FIELD (GUEST_SYSENTER_EIP , guest_sysenter_eip), +FIELD (GUEST_S_CET , guest_s_cet), +FIELD (GUEST_SSP , guest_ssp), +FIELD (GUEST_INTR_SSP_TABLE , guest_ssp_tbl),FIELD (HOST_CR0 , host_cr0),FIELD (HOST_CR3 , host_cr3), FIELD(HOST_CR4, host_cr4),
@@ -149,5 +152,8 @@ const unsigned short vmcs_field_to_offset_table[] = {FIELD (HOST_IA32_SYSENTER_EIP , host_ia32_sysenter_eip),FIELD (HOST_RSP , host_rsp),FIELD (HOST_RIP , host_rip), +FIELD (HOST_S_CET , host_s_cet), +FIELD (HOST_SSP , host_ssp), + FIELD(HOST_INTR_SSP_TABLE, host_ssp_tbl), };const unsigned int nr_vmcs12_fields =ARRAY_SIZE (vmcs_field_to_offset_table);
arch/x86/kvm/vmx/vmcs12.h +13 -1
@@ -115,7 +115,13 @@ struct __packed vmcs12 {natural_width host_ia32_sysenter_eip;natural_width host_rsp;natural_width host_rip; -natural_width paddingl[8 ];/* room for future expansion */ +natural_width host_s_cet; +natural_width host_ssp; +natural_width host_ssp_tbl; +natural_width guest_s_cet; +natural_width guest_ssp; +natural_width guest_ssp_tbl; +natural_width paddingl[2 ];/* room for future expansion */ u32 pin_based_vm_exec_control;u32 cpu_based_vm_exec_control;u32 exception_bitmap;
@@ -295,6 +301,12 @@ static inline void vmx_check_vmcs12_offsets(void)CHECK_OFFSET (host_ia32_sysenter_eip,656 );CHECK_OFFSET (host_rsp,664 );CHECK_OFFSET (host_rip,672 ); +CHECK_OFFSET (host_s_cet,680 ); +CHECK_OFFSET (host_ssp,688 ); +CHECK_OFFSET (host_ssp_tbl,696 ); +CHECK_OFFSET (guest_s_cet,704 ); +CHECK_OFFSET (guest_ssp,712 ); +CHECK_OFFSET (guest_ssp_tbl,720 );CHECK_OFFSET (pin_based_vm_exec_control,744 );CHECK_OFFSET (cpu_based_vm_exec_control,748 );CHECK_OFFSET (exception_bitmap,752 );
arch/x86/kvm/vmx/vmx.c +1 -0
@@ -7257,6 +7257,7 @@ static void nested_vmx_cr_fixed1_bits_update(struct kvm_vcpu *vcpu)cr4_fixed1_update (X86_CR4_PKE , ecx,feature_bit (PKU ));cr4_fixed1_update (X86_CR4_UMIP , ecx,feature_bit (UMIP ));cr4_fixed1_update (X86_CR4_LA57 , ecx,feature_bit (LA57 )); +cr4_fixed1_update (X86_CR4_CET , ecx,feature_bit (SHSTK ));#undef cr4_fixed1_update }
Signature · 1 line
2.26.2
PATCH v15 14/14 KVM: x86: Save/Restore GUEST_SSP to/from SMRAM
In reply to Yang WeijiangSave GUEST_SSP to SMRAM when guest exits to SMM due to SMI and restore it when guest exits SMM to interrupted normal non-root mode.
--- arch/x86/kvm/emulate.c | 11 +++++++++++ arch/x86/kvm/x86.c | 10 ++++++++++ 2 files changed, 21 insertions(+)
arch/x86/kvm/emulate.c +11 -0
@@ -2615,6 +2615,17 @@ static int rsm_load_state_64(struct x86_emulate_ctxt *ctxt, return r; } +if (kvm_cet_supported ()) { +struct msr_data msr; + + val =GET_SMSTATE (u64, smstate,0x7ec8 ); + msr.index =MSR_KVM_GUEST_SSP ; + msr.host_initiated = true; + msr.data = val; +/* Mimic host_initiated access to bypass ssp access check. */ + kvm_x86_ops.set_msr (ctxt->vcpu, &msr); + } +return X86EMUL_CONTINUE ; }#endif
arch/x86/kvm/x86.c +10 -0
@@ -8592,6 +8592,16 @@ static void enter_smm_save_state_64(struct kvm_vcpu *vcpu, char *buf)for (i =0 ; i <6 ; i++)enter_smm_save_seg_64 (vcpu, buf, i); + +if (kvm_cet_supported ()) { +struct msr_data msr; + + msr.index =MSR_KVM_GUEST_SSP ; + msr.host_initiated = true; +/* GUEST_SSP is stored in VMCS at vm-exit. */ + kvm_x86_ops.get_msr (vcpu, &msr); +put_smstate (u64, buf,0x7ec8 , msr.data); + } }#endif
Signature · 1 line
2.26.2
Paolo Bonzini
maintainerRe: [PATCH v15 14/14] KVM: x86: Save/Restore GUEST_SSP to/from SMRAM
Quoted 12 lines · Yang Weijiang
arch/x86/kvm/x86.c +3
-0@@ -8592,6 +8592,16 @@ static void enter_smm_save_state_64(struct kvm_vcpu *vcpu, char *buf)for (i =0 ; i <6 ; i++)enter_smm_save_seg_64 (vcpu, buf, i); + +if (kvm_cet_supported ()) { +struct msr_data msr;
arch/x86/kvm/x86.c static void enter_smm_save_state_64(struct kvm_vcpu *vcpu, char *buf) · line 8607
Quoted 10 lines
arch/x86/kvm/x86.c +7
-0+ + msr.index =MSR_KVM_GUEST_SSP ; + msr.host_initiated = true; +/* GUEST_SSP is stored in VMCS at vm-exit. */ + kvm_x86_ops.get_msr (vcpu, &msr); + put_smstate(u64, buf, 0x7ec8, msr.data); + } }#endif
0x7ec8 is used for I/O instruction restart and auto-halt restart. 0x7f08 is a free spot. We should really document the KVM state save area format.
Paolo
Re: [PATCH v15 14/14] KVM: x86: Save/Restore GUEST_SSP to/from SMRAM
Quoted 16 lines · Paolo Bonzini
Quoted 15 lines · Yang Weijiang
arch/x86/kvm/x86.c +8
-0@@ -8592,6 +8592,16 @@ static void enter_smm_save_state_64(struct kvm_vcpu *vcpu, char *buf)for (i =0 ; i <6 ; i++)enter_smm_save_seg_64 (vcpu, buf, i); + +if (kvm_cet_supported ()) { +struct msr_data msr; + + msr.index =MSR_KVM_GUEST_SSP ; + msr.host_initiated = true; +/* GUEST_SSP is stored in VMCS at vm-exit. */ + kvm_x86_ops.get_msr (vcpu, &msr);
Quoted 8 lines
arch/x86/kvm/x86.c static void enter_smm_save_state_64(struct kvm_vcpu *vcpu, char *buf) · line 8607
Quoted 5 lines
arch/x86/kvm/x86.c +2
-0+ put_smstate(u64, buf, 0x7ec8, msr.data); + } }#endif
0x7ec8is used for I/O instruction restart and auto-halt restart.0x7f08is a free spot. We should really document the KVM state save area format.
Thanks for catching the documentation error!
Quoted 2 lines
Paolo
Paolo Bonzini
maintainerQuoted 64 lines · Yang Weijiang
Control-flow Enforcement Technology (CET) provides protection against Return/Jump-Oriented Programming (ROP/JOP) attack. There're two CET
subfeatures: Shadow Stack (SHSTK) and Indirect Branch Tracking (IBT). SHSTK is to prevent ROP and IBT is to prevent JOP.Several parts in KVM have been updated to provide guest CET support, including:
CPUID/XSAVES settings, MSR passthrough, user-space MSR access interface, vmentry/vmexit config, nested VM etc. These patches are dependent on CET kernel patches for XSAVES support and CET definitions, e.g., MSR and related feature flags.CET kernel patches: refer to [1], [2].
Previous CET KVM patches: refer to [3].
CET QEMU patches: refer to [4].
CET KVM unit-test patch: refer to [5].
[1]: CET Shadow Stack patches v18:
https://lkml.kernel.org/linux-api/[email protected]/[2]: Indirect Branch Tracking patches v18:
https://lkml.kernel.org/linux-api/[email protected]/[3]: CET KVM patches v14:
https://lkml.kernel.org/kvm/[email protected]/[4]: CET QEMU patches:
https://patchwork.ozlabs.org/project/qemu-devel/patch/[email protected]/[5]: CET KVM unit-test patch:
https://patchwork.kernel.org/project/kvm/patch/[email protected]/Changes in v15:
- Changed patches per Paolo's review feedback on v14.
- Added a new patch forGUEST_SSPsave/restore in guest SMM case.
- Fixed guest call-trace issue due to CET MSR interception.
- Removed unnecessary guest CET state cleanup in VMCS.
- Rebased patches to 5.11-rc6.Sean Christopherson (2):
KVM: x86: Report XSS as an MSR to be saved if there are supported
features
KVM: x86: Load guest fpu state when accessing MSRs managed by XSAVESYang Weijiang (12):
KVM: x86: Refresh CPUID on writes toMSR_IA32_XSS
KVM: x86: Add #CP support in guest exception dispatch
KVM: VMX: Introduce CET VMCS fields and flags
KVM: x86: Add fault checks for CR4.CET
KVM: VMX: Emulate reads and writes to CET MSRs
KVM: VMX: Add a synthetic MSR to allow userspace VMM to access
GUEST_SSP
KVM: x86: Report CET MSRs as to-be-saved if CET is supported
KVM: x86: Enable CET virtualization for VMX and advertise CET to
userspace
KVM: VMX: Pass through CET MSRs to the guest when supported
KVM: nVMX: Add helper to check the vmcs01 MSR bitmap for MSR
pass-through
KVM: nVMX: Enable CET support for nested VMX
KVM: x86: Save/RestoreGUEST_SSPto/from SMRAM
Quoted 15 lines
arch/x86/include/asm/kvm_host.h | 4 +- arch/x86/include/asm/vmx.h | 8 ++ arch/x86/include/uapi/asm/kvm.h | 1 + arch/x86/include/uapi/asm/kvm_para.h | 1 + arch/x86/kvm/cpuid.c | 26 +++- arch/x86/kvm/emulate.c | 11 ++ arch/x86/kvm/vmx/capabilities.h | 5 + arch/x86/kvm/vmx/nested.c | 57 ++++++-- arch/x86/kvm/vmx/vmcs12.c | 6 + arch/x86/kvm/vmx/vmcs12.h | 14 +- arch/x86/kvm/vmx/vmx.c | 202 ++++++++++++++++++++++++++- arch/x86/kvm/x86.c | 67 ++++++++- arch/x86/kvm/x86.h | 10 +- 13 files changed, 387 insertions(+), 25 deletions(-)
Queued, though not for 5.12 unless the bare metal support is there too.
Paolo