From: Sean Christopherson <sean.j.christopherson@intel.com>
To: Yang Weijiang <weijiang.yang@intel.com>
Cc: pbonzini@redhat.com, rkrcmar@redhat.com,
linux-kernel@vger.kernel.org, kvm@vger.kernel.org,
mst@redhat.com, yu-cheng.yu@intel.com, yi.z.zhang@intel.com,
hjl.tools@gmail.com, Zhang Yi Z <yi.z.zhang@linux.intel.com>
Subject: Re: [PATCH v1 6/8] kvm:cpuid Add CPUID support for CET xsaves component query.
Date: Wed, 2 Jan 2019 10:49:30 -0800 [thread overview]
Message-ID: <20190102184930.GD7460@linux.intel.com> (raw)
In-Reply-To: <20181226081532.30698-7-weijiang.yang@intel.com>
On Wed, Dec 26, 2018 at 04:15:30PM +0800, Yang Weijiang wrote:
> CET xsaves component size is queried through CPUID.(EAX=0xD, ECX=11)
> and CPUID.(EAX=0xD, ECX=12).
>
> Signed-off-by: Zhang Yi Z <yi.z.zhang@linux.intel.com>
> Signed-off-by: Yang Weijiang <weijiang.yang@intel.com>
> ---
> arch/x86/kvm/cpuid.c | 14 ++++++++++----
> 1 file changed, 10 insertions(+), 4 deletions(-)
>
> diff --git a/arch/x86/kvm/cpuid.c b/arch/x86/kvm/cpuid.c
> index 7bcfa61375c0..5bac31e58955 100644
> --- a/arch/x86/kvm/cpuid.c
> +++ b/arch/x86/kvm/cpuid.c
> @@ -565,6 +565,7 @@ static inline int __do_cpuid_ent(struct kvm_cpuid_entry2 *entry, u32 function,
> case 0xd: {
> int idx, i;
> u64 supported = kvm_supported_xcr0();
> + u64 sv_supported;
What about u_supported and s_supported? sv_supported doesn't make me
think "supervisor"e.
> entry->eax &= supported;
> entry->ebx = xstate_required_size(supported, false);
> @@ -584,18 +585,23 @@ static inline int __do_cpuid_ent(struct kvm_cpuid_entry2 *entry, u32 function,
> entry[i].eax &= kvm_cpuid_D_1_eax_x86_features;
> cpuid_mask(&entry[i].eax, CPUID_D_1_EAX);
> entry[i].ebx = 0;
> + sv_supported = entry[i].ecx +
> + ((u64)entry[i].edx << 32);
Use '|' instead of '+' to smush ECX and EDX together, as is it looks
like the code is calculating a size or something.
> if (entry[i].eax & (F(XSAVES)|F(XSAVEC)))
> entry[i].ebx =
> xstate_required_size(supported,
> true);
> - } else {
> + } else if (!(entry[i].ecx & 1)) {
Now that we're actually consuming bit 0, it'd be nice to formally define
it as referring to supervisor state.
What about styling the code like this? Might make it more obvious that
the logic for user vs. supervisor is identical, i.e. ECX bit 0 only
determines which mask is applied.
if (idx == 1) {
...
} else {
supported = (entry[i].ecx & 1) ? s_supported :
u_supported;
if (entry[i].eax == 0 || !(supported & mask))
continue;
entry[i].ecx &= 1;
entry[i].edx = 0;
}
> if (entry[i].eax == 0 || !(supported & mask))
> continue;
> - if (WARN_ON_ONCE(entry[i].ecx & 1))
> + entry[i].ecx = 0;
> + entry[i].edx = 0;
> + } else {
> + if (entry[i].eax == 0 || !(sv_supported & mask))
> continue;
> + entry[i].ecx = 1;
> + entry[i].edx = 0;
> }
> - entry[i].ecx = 0;
> - entry[i].edx = 0;
Removing this entirely isn't correct for CPUID.0xD.0x1, KVM should still
zero out the bits it doesn't handle, e.g. KVM will signal a fault if the
guest attempts to set any bits in IA32_XSS other than the CET bits.
> entry[i].flags |=
> KVM_CPUID_FLAG_SIGNIFCANT_INDEX;
> ++*nent;
> --
> 2.17.1
>
next prev parent reply other threads:[~2019-01-02 18:49 UTC|newest]
Thread overview: 21+ messages / expand[flat|nested] mbox.gz Atom feed top
2018-12-26 8:15 [PATCH v1 0/8] This patch-set is to enable kvm Guest OS CET support Yang Weijiang
2018-12-26 8:15 ` [PATCH v1 1/8] kvm:vmx Introduce CET related VMCS field definitions Yang Weijiang
2019-01-02 18:09 ` Sean Christopherson
2018-12-26 8:15 ` [PATCH v1 2/8] kvm: Define CR4.CET[bit 23] (master enable bit) for guest OS Yang Weijiang
2018-12-26 8:15 ` [PATCH v1 3/8] kvm:vmx Enable loading CET state bit while guest CR4.CET is being set Yang Weijiang
2018-12-26 8:52 ` Liran Alon
2018-12-27 6:07 ` Yang,Weijiang
2018-12-26 8:15 ` [PATCH v1 4/8] kvm:vmx Pass through host CET related MSRs to Guest Yang Weijiang
2019-01-02 18:18 ` Sean Christopherson
2019-01-02 19:12 ` Jim Mattson
2018-12-26 8:15 ` [PATCH v1 5/8] kvm:x86 Enable MSR_IA32_XSS bit 11 and 12 for CET xsaves/xrstors Yang Weijiang
2019-01-02 18:24 ` Sean Christopherson
2019-01-02 19:19 ` Jim Mattson
2019-01-06 21:17 ` Yang Weijiang
2018-12-26 8:15 ` [PATCH v1 6/8] kvm:cpuid Add CPUID support for CET xsaves component query Yang Weijiang
2019-01-02 18:49 ` Sean Christopherson [this message]
2018-12-26 8:15 ` [PATCH v1 7/8] kvm:cpuid Fix xsaves area size calculation for CPUID.(EAX=0xD,ECX=1) Yang Weijiang
2019-01-02 18:54 ` Sean Christopherson
2018-12-26 8:15 ` [PATCH v1 8/8] kvm:cpuid Report CET SHSTK and IBT support in CPUID.(EAX=0x7,ECX=0) Yang Weijiang
2019-01-02 19:00 ` Sean Christopherson
2019-01-07 16:03 ` Paolo Bonzini
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=20190102184930.GD7460@linux.intel.com \
--to=sean.j.christopherson@intel.com \
--cc=hjl.tools@gmail.com \
--cc=kvm@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=mst@redhat.com \
--cc=pbonzini@redhat.com \
--cc=rkrcmar@redhat.com \
--cc=weijiang.yang@intel.com \
--cc=yi.z.zhang@intel.com \
--cc=yi.z.zhang@linux.intel.com \
--cc=yu-cheng.yu@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