From: Maxim Levitsky <mlevitsk@redhat.com>
To: "Yang, Weijiang" <weijiang.yang@intel.com>
Cc: seanjc@google.com, pbonzini@redhat.com, dave.hansen@intel.com,
linux-kernel@vger.kernel.org, peterz@infradead.org,
chao.gao@intel.com, rick.p.edgecombe@intel.com,
john.allen@amd.com, kvm@vger.kernel.org
Subject: Re: [PATCH v7 24/26] KVM: x86: Enable CET virtualization for VMX and advertise to userspace
Date: Tue, 05 Dec 2023 12:07:46 +0200 [thread overview]
Message-ID: <6b508ee1ed3a121f2c4842c6a912bc5bd12ed469.camel@redhat.com> (raw)
In-Reply-To: <8b68d17c-9b65-4d01-8d3d-fccdb50306ac@intel.com>
On Sat, 2023-12-02 at 00:15 +0800, Yang, Weijiang wrote:
> On 12/1/2023 1:46 AM, Maxim Levitsky wrote:
>
> [...]
>
> > >
> > > +static inline bool cpu_has_vmx_basic_no_hw_errcode(void)
> > > +{
> > > + return ((u64)vmcs_config.basic_cap << 32) &
> > > + VMX_BASIC_NO_HW_ERROR_CODE_CC;
> > > +}
> > I still think that we should add a comment explaining why this check is needed,
> > as I said in the previous review.
>
> OK, I'll add some comments above the function. Thanks!
>
> > > +
> > > static inline bool cpu_has_virtual_nmis(void)
> > > {
> > > return vmcs_config.pin_based_exec_ctrl & PIN_BASED_VIRTUAL_NMIS &&
> > > diff --git a/arch/x86/kvm/vmx/vmx.c b/arch/x86/kvm/vmx/vmx.c
> > > index c658f2f230df..a1aae8709939 100644
> > > --- a/arch/x86/kvm/vmx/vmx.c
> > > +++ b/arch/x86/kvm/vmx/vmx.c
> > > @@ -2614,6 +2614,7 @@ static int setup_vmcs_config(struct vmcs_config *vmcs_conf,
> > > { VM_ENTRY_LOAD_IA32_EFER, VM_EXIT_LOAD_IA32_EFER },
> > > { VM_ENTRY_LOAD_BNDCFGS, VM_EXIT_CLEAR_BNDCFGS },
> > > { VM_ENTRY_LOAD_IA32_RTIT_CTL, VM_EXIT_CLEAR_IA32_RTIT_CTL },
> > > + { VM_ENTRY_LOAD_CET_STATE, VM_EXIT_LOAD_CET_STATE },
> > > };
> > >
> > > memset(vmcs_conf, 0, sizeof(*vmcs_conf));
> > > @@ -4935,6 +4936,15 @@ static void vmx_vcpu_reset(struct kvm_vcpu *vcpu, bool init_event)
> > >
> > > vmcs_write32(VM_ENTRY_INTR_INFO_FIELD, 0); /* 22.2.1 */
> > >
> > > + if (kvm_cpu_cap_has(X86_FEATURE_SHSTK))
> > > + vmcs_writel(GUEST_SSP, 0);
> > > + if (kvm_cpu_cap_has(X86_FEATURE_SHSTK) ||
> > > + kvm_cpu_cap_has(X86_FEATURE_IBT))
> > > + vmcs_writel(GUEST_S_CET, 0);
> > > + if (kvm_cpu_cap_has(X86_FEATURE_SHSTK) &&
> > > + IS_ENABLED(CONFIG_X86_64))
> > > + vmcs_writel(GUEST_INTR_SSP_TABLE, 0);
> > Looks reasonable now.
> > > +
> > > kvm_make_request(KVM_REQ_APIC_PAGE_RELOAD, vcpu);
> > >
> > > vpid_sync_context(vmx->vpid);
> > > @@ -6354,6 +6364,12 @@ void dump_vmcs(struct kvm_vcpu *vcpu)
> > > if (vmcs_read32(VM_EXIT_MSR_STORE_COUNT) > 0)
> > > vmx_dump_msrs("guest autostore", &vmx->msr_autostore.guest);
> > >
> > > + if (vmentry_ctl & VM_ENTRY_LOAD_CET_STATE) {
> > > + pr_err("S_CET = 0x%016lx\n", vmcs_readl(GUEST_S_CET));
> > > + pr_err("SSP = 0x%016lx\n", vmcs_readl(GUEST_SSP));
> > > + pr_err("INTR SSP TABLE = 0x%016lx\n",
> > > + vmcs_readl(GUEST_INTR_SSP_TABLE));
> > > + }
> > > pr_err("*** Host State ***\n");
> > > pr_err("RIP = 0x%016lx RSP = 0x%016lx\n",
> > > vmcs_readl(HOST_RIP), vmcs_readl(HOST_RSP));
> > > @@ -6431,6 +6447,12 @@ void dump_vmcs(struct kvm_vcpu *vcpu)
> > > if (secondary_exec_control & SECONDARY_EXEC_ENABLE_VPID)
> > > pr_err("Virtual processor ID = 0x%04x\n",
> > > vmcs_read16(VIRTUAL_PROCESSOR_ID));
> > > + if (vmexit_ctl & VM_EXIT_LOAD_CET_STATE) {
> > > + pr_err("S_CET = 0x%016lx\n", vmcs_readl(HOST_S_CET));
> > > + pr_err("SSP = 0x%016lx\n", vmcs_readl(HOST_SSP));
> > > + pr_err("INTR SSP TABLE = 0x%016lx\n",
> > > + vmcs_readl(HOST_INTR_SSP_TABLE));
> > > + }
> > > }
> > >
> > > /*
> > > @@ -7964,7 +7986,6 @@ static __init void vmx_set_cpu_caps(void)
> > > kvm_cpu_cap_set(X86_FEATURE_UMIP);
> > >
> > > /* CPUID 0xD.1 */
> > > - kvm_caps.supported_xss = 0;
> > > if (!cpu_has_vmx_xsaves())
> > > kvm_cpu_cap_clear(X86_FEATURE_XSAVES);
> > >
> > > @@ -7976,6 +7997,12 @@ static __init void vmx_set_cpu_caps(void)
> > >
> > > if (cpu_has_vmx_waitpkg())
> > > kvm_cpu_cap_check_and_set(X86_FEATURE_WAITPKG);
> > > +
> > > + if (!cpu_has_load_cet_ctrl() || !enable_unrestricted_guest ||
> > > + !cpu_has_vmx_basic_no_hw_errcode()) {
> > > + kvm_cpu_cap_clear(X86_FEATURE_SHSTK);
> > > + kvm_cpu_cap_clear(X86_FEATURE_IBT);
> > > + }
> > My review feedback from previous version still applies here, I don't have an
> > idea why this was not addressed....
> >
> > "I think that here we also need to clear kvm_caps.supported_xss,
> > or even better, lets set the CET bits in kvm_caps.supported_xss only
> > once CET is fully enabled (both this check and check in __kvm_x86_vendor_init pass)."
>
> Ah, previously I had a helper to check whether CET bits were enabled in kvm_caps.supported_xss,
> so need to set the bits earlier before vmx's hardware_setup. I still want to keep the code as-is
> in case other features need to check the their related bits set before configure something in
> vmx hardware_setup.
As long as the code is correct I won't object.
Best regards,
Maxim Levitsky
>
> > In addition to that I just checked and unless I am mistaken:
> >
> > vmx_set_cpu_caps() is called from vmx's hardware_setup(), which is called
> > from __kvm_x86_vendor_init.
> >
> > After this call, __kvm_x86_vendor_init does clear kvm_caps.supported_xss,
> > but doesn't do this if the above code cleared X86_FEATURE_SHSTK/X86_FEATURE_IBT.
> >
> Yeah, I checked the history, the similar logic was there until v6, I can pick it up, thanks!
>
> > > }
> > >
> > > static void vmx_request_immediate_exit(struct kvm_vcpu *vcpu)
> > > diff --git a/arch/x86/kvm/vmx/vmx.h b/arch/x86/kvm/vmx/vmx.h
> > > index c2130d2c8e24..fb72819fbb41 100644
> > > --- a/arch/x86/kvm/vmx/vmx.h
> > > +++ b/arch/x86/kvm/vmx/vmx.h
> > > @@ -480,7 +480,8 @@ static inline u8 vmx_get_rvi(void)
> > > VM_ENTRY_LOAD_IA32_EFER | \
> > > VM_ENTRY_LOAD_BNDCFGS | \
> > > VM_ENTRY_PT_CONCEAL_PIP | \
> > > - VM_ENTRY_LOAD_IA32_RTIT_CTL)
> > > + VM_ENTRY_LOAD_IA32_RTIT_CTL | \
> > > + VM_ENTRY_LOAD_CET_STATE)
> > >
> > > #define __KVM_REQUIRED_VMX_VM_EXIT_CONTROLS \
> > > (VM_EXIT_SAVE_DEBUG_CONTROLS | \
> > > @@ -502,7 +503,8 @@ static inline u8 vmx_get_rvi(void)
> > > VM_EXIT_LOAD_IA32_EFER | \
> > > VM_EXIT_CLEAR_BNDCFGS | \
> > > VM_EXIT_PT_CONCEAL_PIP | \
> > > - VM_EXIT_CLEAR_IA32_RTIT_CTL)
> > > + VM_EXIT_CLEAR_IA32_RTIT_CTL | \
> > > + VM_EXIT_LOAD_CET_STATE)
> > >
> > > #define KVM_REQUIRED_VMX_PIN_BASED_VM_EXEC_CONTROL \
> > > (PIN_BASED_EXT_INTR_MASK | \
> > > diff --git a/arch/x86/kvm/x86.c b/arch/x86/kvm/x86.c
> > > index c6b57ede0f57..2bcf3c7923bf 100644
> > > --- a/arch/x86/kvm/x86.c
> > > +++ b/arch/x86/kvm/x86.c
> > > @@ -231,7 +231,8 @@ static struct kvm_user_return_msrs __percpu *user_return_msrs;
> > > | XFEATURE_MASK_BNDCSR | XFEATURE_MASK_AVX512 \
> > > | XFEATURE_MASK_PKRU | XFEATURE_MASK_XTILE)
> > >
> > > -#define KVM_SUPPORTED_XSS 0
> > > +#define KVM_SUPPORTED_XSS (XFEATURE_MASK_CET_USER | \
> > > + XFEATURE_MASK_CET_KERNEL)
> > >
> > > u64 __read_mostly host_efer;
> > > EXPORT_SYMBOL_GPL(host_efer);
> > > @@ -9854,6 +9855,15 @@ static int __kvm_x86_vendor_init(struct kvm_x86_init_ops *ops)
> > > if (!kvm_cpu_cap_has(X86_FEATURE_XSAVES))
> > > kvm_caps.supported_xss = 0;
> > >
> > > + if ((kvm_caps.supported_xss & (XFEATURE_MASK_CET_USER |
> > > + XFEATURE_MASK_CET_KERNEL)) !=
> > > + (XFEATURE_MASK_CET_USER | XFEATURE_MASK_CET_KERNEL)) {
> > > + kvm_cpu_cap_clear(X86_FEATURE_SHSTK);
> > > + kvm_cpu_cap_clear(X86_FEATURE_IBT);
> > > + kvm_caps.supported_xss &= ~XFEATURE_CET_USER;
> > > + kvm_caps.supported_xss &= ~XFEATURE_CET_KERNEL;
> > > + }
> > > +
> > > #define __kvm_cpu_cap_has(UNUSED_, f) kvm_cpu_cap_has(f)
> > > cr4_reserved_bits = __cr4_reserved_bits(__kvm_cpu_cap_has, UNUSED_);
> > > #undef __kvm_cpu_cap_has
> > > @@ -12319,7 +12329,9 @@ void kvm_arch_vcpu_destroy(struct kvm_vcpu *vcpu)
> > >
> > > static inline bool is_xstate_reset_needed(void)
> > > {
> > > - return kvm_cpu_cap_has(X86_FEATURE_MPX);
> > > + return kvm_cpu_cap_has(X86_FEATURE_MPX) ||
> > > + kvm_cpu_cap_has(X86_FEATURE_SHSTK) ||
> > > + kvm_cpu_cap_has(X86_FEATURE_IBT);
> > > }
> > >
> > > void kvm_vcpu_reset(struct kvm_vcpu *vcpu, bool init_event)
> > > @@ -12396,6 +12408,16 @@ void kvm_vcpu_reset(struct kvm_vcpu *vcpu, bool init_event)
> > > XFEATURE_BNDCSR);
> > > }
> > >
> > > + if (kvm_cpu_cap_has(X86_FEATURE_SHSTK)) {
> > > + fpstate_clear_xstate_component(fpstate,
> > > + XFEATURE_CET_USER);
> > > + fpstate_clear_xstate_component(fpstate,
> > > + XFEATURE_CET_KERNEL);
> > > + } else if (kvm_cpu_cap_has(X86_FEATURE_IBT)) {
> > > + fpstate_clear_xstate_component(fpstate,
> > > + XFEATURE_CET_USER);
> > > + }
> > > +
> > > if (init_event)
> > > kvm_load_guest_fpu(vcpu);
> > > }
> > > diff --git a/arch/x86/kvm/x86.h b/arch/x86/kvm/x86.h
> > > index d9cc352cf421..dc79dcd733ac 100644
> > > --- a/arch/x86/kvm/x86.h
> > > +++ b/arch/x86/kvm/x86.h
> > > @@ -531,6 +531,9 @@ bool kvm_msr_allowed(struct kvm_vcpu *vcpu, u32 index, u32 type);
> > > __reserved_bits |= X86_CR4_VMXE; \
> > > if (!__cpu_has(__c, X86_FEATURE_PCID)) \
> > > __reserved_bits |= X86_CR4_PCIDE; \
> > > + if (!__cpu_has(__c, X86_FEATURE_SHSTK) && \
> > > + !__cpu_has(__c, X86_FEATURE_IBT)) \
> > > + __reserved_bits |= X86_CR4_CET; \
> > > __reserved_bits; \
> > > })
> > >
> >
> > Best regards,
> > Maxim Levitsky
> >
> >
> >
next prev parent reply other threads:[~2023-12-05 10:07 UTC|newest]
Thread overview: 104+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-11-24 5:53 [PATCH v7 00/26] Enable CET Virtualization Yang Weijiang
2023-11-24 5:53 ` [PATCH v7 01/26] x86/fpu/xstate: Always preserve non-user xfeatures/flags in __state_perm Yang Weijiang
2023-11-30 17:24 ` Maxim Levitsky
2023-11-24 5:53 ` [PATCH v7 02/26] x86/fpu/xstate: Refine CET user xstate bit enabling Yang Weijiang
2023-11-24 9:40 ` Peter Zijlstra
2023-11-27 2:55 ` Yang, Weijiang
2023-11-28 1:31 ` Edgecombe, Rick P
2023-11-28 8:50 ` Peter Zijlstra
2023-11-28 1:31 ` Edgecombe, Rick P
2023-11-28 7:52 ` Yang, Weijiang
2023-11-30 17:26 ` Maxim Levitsky
2023-12-01 6:51 ` Yang, Weijiang
2023-12-05 9:53 ` Maxim Levitsky
2023-12-06 1:03 ` Yang, Weijiang
2023-12-06 15:57 ` Maxim Levitsky
2023-12-08 14:57 ` Yang, Weijiang
2023-12-08 15:15 ` Maxim Levitsky
2023-12-13 9:30 ` Yang, Weijiang
2023-12-13 13:31 ` Maxim Levitsky
2023-12-13 17:01 ` Chang S. Bae
2023-12-14 3:12 ` Yang, Weijiang
2023-11-24 5:53 ` [PATCH v7 03/26] x86/fpu/xstate: Add CET supervisor mode state support Yang Weijiang
2023-11-24 9:45 ` Peter Zijlstra
2023-11-27 4:06 ` Yang, Weijiang
2023-11-28 1:34 ` Edgecombe, Rick P
2023-11-30 17:27 ` Maxim Levitsky
2023-12-01 7:01 ` Yang, Weijiang
2023-12-05 9:53 ` Maxim Levitsky
2023-11-24 5:53 ` [PATCH v7 04/26] x86/fpu/xstate: Introduce XFEATURE_MASK_KERNEL_DYNAMIC xfeature set Yang Weijiang
2023-11-28 1:46 ` Edgecombe, Rick P
2023-11-28 8:00 ` Yang, Weijiang
2023-11-30 17:33 ` Maxim Levitsky
2023-12-01 7:49 ` Yang, Weijiang
2023-12-05 9:55 ` Maxim Levitsky
2023-12-06 3:00 ` Yang, Weijiang
2023-12-06 16:11 ` Maxim Levitsky
2023-12-08 15:57 ` Yang, Weijiang
2023-11-24 5:53 ` [PATCH v7 05/26] x86/fpu/xstate: Introduce fpu_guest_cfg for guest FPU configuration Yang Weijiang
2023-11-28 14:58 ` Edgecombe, Rick P
2023-11-29 14:12 ` Yang, Weijiang
2023-11-29 17:08 ` Edgecombe, Rick P
2023-11-30 13:28 ` Yang, Weijiang
2023-11-30 17:29 ` Maxim Levitsky
2023-11-30 18:02 ` Edgecombe, Rick P
2023-11-30 17:29 ` Maxim Levitsky
2023-11-24 5:53 ` [PATCH v7 06/26] x86/fpu/xstate: Create guest fpstate with guest specific config Yang Weijiang
2023-11-28 15:19 ` Edgecombe, Rick P
2023-11-29 14:16 ` Yang, Weijiang
2023-11-30 17:36 ` Maxim Levitsky
2023-12-01 8:36 ` Yang, Weijiang
2023-12-05 9:57 ` Maxim Levitsky
2023-11-24 5:53 ` [PATCH v7 07/26] x86/fpu/xstate: Warn if kernel dynamic xfeatures detected in normal fpstate Yang Weijiang
2023-11-28 15:25 ` Edgecombe, Rick P
2023-11-29 14:18 ` Yang, Weijiang
2023-11-24 5:53 ` [PATCH v7 08/26] KVM: x86: Rework cpuid_get_supported_xcr0() to operate on vCPU data Yang Weijiang
2023-11-24 5:53 ` [PATCH v7 09/26] KVM: x86: Rename kvm_{g,s}et_msr() to menifest emulation operations Yang Weijiang
2023-11-30 17:36 ` Maxim Levitsky
2023-11-24 5:53 ` [PATCH v7 10/26] KVM: x86: Refine xsave-managed guest register/MSR reset handling Yang Weijiang
2023-11-30 17:36 ` Maxim Levitsky
2023-11-24 5:53 ` [PATCH v7 11/26] KVM: x86: Add kvm_msr_{read,write}() helpers Yang Weijiang
2023-11-30 17:37 ` Maxim Levitsky
2023-11-24 5:53 ` [PATCH v7 12/26] KVM: x86: Report XSS as to-be-saved if there are supported features Yang Weijiang
2023-11-24 5:53 ` [PATCH v7 13/26] KVM: x86: Refresh CPUID on write to guest MSR_IA32_XSS Yang Weijiang
2023-11-30 17:37 ` Maxim Levitsky
2023-11-24 5:53 ` [PATCH v7 14/26] KVM: x86: Initialize kvm_caps.supported_xss Yang Weijiang
2023-11-24 5:53 ` [PATCH v7 15/26] KVM: x86: Load guest FPU state when access XSAVE-managed MSRs Yang Weijiang
2023-11-30 17:38 ` Maxim Levitsky
2023-11-24 5:53 ` [PATCH v7 16/26] KVM: x86: Add fault checks for guest CR4.CET setting Yang Weijiang
2023-11-24 5:53 ` [PATCH v7 17/26] KVM: x86: Report KVM supported CET MSRs as to-be-saved Yang Weijiang
2023-11-30 17:40 ` Maxim Levitsky
2023-11-24 5:53 ` [PATCH v7 18/26] KVM: VMX: Introduce CET VMCS fields and control bits Yang Weijiang
2023-11-24 5:53 ` [PATCH v7 19/26] KVM: x86: Use KVM-governed feature framework to track "SHSTK/IBT enabled" Yang Weijiang
2023-11-30 17:40 ` Maxim Levitsky
2023-11-24 5:53 ` [PATCH v7 20/26] KVM: VMX: Emulate read and write to CET MSRs Yang Weijiang
2023-11-30 17:41 ` Maxim Levitsky
2023-11-24 5:53 ` [PATCH v7 21/26] KVM: x86: Save and reload SSP to/from SMRAM Yang Weijiang
2023-11-30 17:42 ` Maxim Levitsky
2023-12-01 2:23 ` Chao Gao
2023-12-04 0:45 ` Yang, Weijiang
2023-12-05 10:02 ` Maxim Levitsky
2023-12-01 8:55 ` Yang, Weijiang
2023-11-24 5:53 ` [PATCH v7 22/26] KVM: VMX: Set up interception for CET MSRs Yang Weijiang
2023-11-30 17:44 ` Maxim Levitsky
2023-12-01 6:33 ` Chao Gao
2023-12-05 10:04 ` Maxim Levitsky
2023-12-01 9:45 ` Yang, Weijiang
2023-12-05 10:07 ` Maxim Levitsky
2023-11-24 5:53 ` [PATCH v7 23/26] KVM: VMX: Set host constant supervisor states to VMCS fields Yang Weijiang
2023-11-24 5:53 ` [PATCH v7 24/26] KVM: x86: Enable CET virtualization for VMX and advertise to userspace Yang Weijiang
2023-11-30 17:46 ` Maxim Levitsky
2023-12-01 16:15 ` Yang, Weijiang
2023-12-05 10:07 ` Maxim Levitsky [this message]
2023-11-24 5:53 ` [PATCH v7 25/26] KVM: nVMX: Introduce new VMX_BASIC bit for event error_code delivery to L1 Yang Weijiang
2023-11-24 5:53 ` [PATCH v7 26/26] KVM: nVMX: Enable CET support for nested guest Yang Weijiang
2023-11-30 17:53 ` Maxim Levitsky
2023-12-04 8:50 ` Yang, Weijiang
2023-12-05 10:12 ` Maxim Levitsky
2023-12-06 9:22 ` Yang, Weijiang
2023-12-06 17:24 ` Maxim Levitsky
2023-12-08 15:15 ` Yang, Weijiang
2023-12-08 15:22 ` Maxim Levitsky
2023-12-12 8:56 ` Yang, Weijiang
2023-12-12 11:09 ` Maxim Levitsky
2023-12-15 2:29 ` [PATCH v7 00/26] Enable CET Virtualization Yang, Weijiang
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=6b508ee1ed3a121f2c4842c6a912bc5bd12ed469.camel@redhat.com \
--to=mlevitsk@redhat.com \
--cc=chao.gao@intel.com \
--cc=dave.hansen@intel.com \
--cc=john.allen@amd.com \
--cc=kvm@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=pbonzini@redhat.com \
--cc=peterz@infradead.org \
--cc=rick.p.edgecombe@intel.com \
--cc=seanjc@google.com \
--cc=weijiang.yang@intel.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).