[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <30c89021-5b82-c676-bb58-1b572e57436a@linux.intel.com>
Date: Tue, 23 May 2023 16:21:27 +0800
From: Binbin Wu <binbin.wu@...ux.intel.com>
To: Yang Weijiang <weijiang.yang@...el.com>
Cc: seanjc@...gle.com, pbonzini@...hat.com, kvm@...r.kernel.org,
linux-kernel@...r.kernel.org, peterz@...radead.org,
rppt@...nel.org, rick.p.edgecombe@...el.com, john.allen@....com,
Sean Christopherson <sean.j.christopherson@...el.com>
Subject: Re: [PATCH v3 13/21] KVM:VMX: Emulate reads and writes to CET MSRs
On 5/11/2023 12:08 PM, Yang Weijiang wrote:
> 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.
>
> Co-developed-by: Sean Christopherson <sean.j.christopherson@...el.com>
> Signed-off-by: Sean Christopherson <sean.j.christopherson@...el.com>
> Signed-off-by: Yang Weijiang <weijiang.yang@...el.com>
> ---
> arch/x86/kernel/fpu/core.c | 1 +
> arch/x86/kvm/vmx/vmx.c | 18 ++++++++++++++++++
> arch/x86/kvm/x86.c | 20 ++++++++++++++++++++
> arch/x86/kvm/x86.h | 31 +++++++++++++++++++++++++++++++
> 4 files changed, 70 insertions(+)
>
...
> diff --git a/arch/x86/kvm/x86.c b/arch/x86/kvm/x86.c
> index b6eec9143129..2e3a39c9297c 100644
> --- a/arch/x86/kvm/x86.c
> +++ b/arch/x86/kvm/x86.c
> @@ -13630,6 +13630,26 @@ int kvm_sev_es_string_io(struct kvm_vcpu *vcpu, unsigned int size,
> }
> EXPORT_SYMBOL_GPL(kvm_sev_es_string_io);
>
> +bool kvm_cet_is_msr_accessible(struct kvm_vcpu *vcpu, struct msr_data *msr)
> +{
> + if (!kvm_cet_user_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;
> +
> + if (msr->index == MSR_IA32_PL3_SSP &&
> + !guest_cpuid_has(vcpu, X86_FEATURE_SHSTK))
> + return false;
It may be better to merge the two if statements into one to avoid
calling guest_cpuid_has(vcpu, X86_FEATURE_SHSTK) twice.
e.g,
if (!guest_cpuid_has(vcpu, X86_FEATURE_SHSTK) &&
(!guest_cpuid_has(vcpu, X86_FEATURE_IBT) || msr->index ==
MSR_IA32_PL3_SSP))
return false;
> +
> + return true;
> +}
> +EXPORT_SYMBOL_GPL(kvm_cet_is_msr_accessible);
> +
> EXPORT_TRACEPOINT_SYMBOL_GPL(kvm_entry);
> EXPORT_TRACEPOINT_SYMBOL_GPL(kvm_exit);
> EXPORT_TRACEPOINT_SYMBOL_GPL(kvm_fast_mmio);
>
...
Powered by blists - more mailing lists