kvm.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Xiaoyao Li <xiaoyao.li@intel.com>
To: Jim Mattson <jmattson@google.com>
Cc: "Paolo Bonzini" <pbonzini@redhat.com>,
	"Radim Krčmář" <rkrcmar@redhat.com>,
	"Sean Christopherson" <sean.j.christopherson@intel.com>,
	"Vitaly Kuznetsov" <vkuznets@redhat.com>,
	"Wanpeng Li" <wanpengli@tencent.com>,
	"Joerg Roedel" <joro@8bytes.org>,
	"kvm list" <kvm@vger.kernel.org>
Subject: Re: [PATCH v2 1/2] KVM: CPUID: Check limit first when emulating CPUID instruction
Date: Wed, 11 Sep 2019 09:11:39 +0800	[thread overview]
Message-ID: <0c92b31d-ea09-faeb-d032-811b22e73721@intel.com> (raw)
In-Reply-To: <CALMp9eRUW_N8uaJm8Mz-fkmNE=qpd5=FpKyKahQx4RiCKOLZKA@mail.gmail.com>

On 9/11/2019 1:00 AM, Jim Mattson wrote:
> On Tue, Sep 10, 2019 at 3:42 AM Xiaoyao Li <xiaoyao.li@intel.com> wrote:
>>
>> When limit checking is required, it should be executed first, which is
>> consistent with the CPUID specification.
>>
>> Signed-off-by: Xiaoyao Li <xiaoyao.li@intel.com>
>> ---
>> v2:
>>    - correctly set entry_found in no limit checking case.
>>
>> ---
>>   arch/x86/kvm/cpuid.c | 51 ++++++++++++++++++++++++++------------------
>>   1 file changed, 30 insertions(+), 21 deletions(-)
>>
>> diff --git a/arch/x86/kvm/cpuid.c b/arch/x86/kvm/cpuid.c
>> index 22c2720cd948..67fa44ab87af 100644
>> --- a/arch/x86/kvm/cpuid.c
>> +++ b/arch/x86/kvm/cpuid.c
>> @@ -952,23 +952,36 @@ struct kvm_cpuid_entry2 *kvm_find_cpuid_entry(struct kvm_vcpu *vcpu,
>>   EXPORT_SYMBOL_GPL(kvm_find_cpuid_entry);
>>
>>   /*
>> - * If no match is found, check whether we exceed the vCPU's limit
>> - * and return the content of the highest valid _standard_ leaf instead.
>> - * This is to satisfy the CPUID specification.
>> + * Based on CPUID specification, if leaf number exceeds the vCPU's limit,
>> + * it should return the content of the highest valid _standard_ leaf instead.
>> + * Note: *found is set true only means the queried leaf number doesn't exceed
>> + * the maximum leaf number of basic or extented leaf.
> 
> Nit: "extented" should be "extended."
> 
> A more serious problem is that the CPUID specification you quote is
> Intel's specification. AMD CPUs return zeroes in EAX, EBX, ECX, and
> EDX for all undefined leaves, whatever the input value for EAX. This
> code is supposed to be vendor-agnostic, right?
> 

I checked the AMD spec and I didn't find the statement about "AMD CPUs 
return zeroes in EAX, EBX, ECX, and EDX for all undefined leaves". I 
don't have AMD machine at hand so that I can't test it to verify it.

Assume what you said about AMD CPUs is true, then the current codes in 
KVM makes AMD guest act as Intel CPU that returns the highest valid 
standard leaf if input value of EAX exceeds the limit.

Anyway, I find we cannot check the limit first for guest, otherwise the 
leaves 0x4000XXXX will be not readable. So please just ignore this patch.

  reply	other threads:[~2019-09-11  1:11 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-09-10 10:27 [PATCH v2 0/2] KVM: CPUID: emulation flow adjustment and one minor refinement when updating maxphyaddr Xiaoyao Li
2019-09-10 10:27 ` [PATCH v2 1/2] KVM: CPUID: Check limit first when emulating CPUID instruction Xiaoyao Li
2019-09-10 17:00   ` Jim Mattson
2019-09-11  1:11     ` Xiaoyao Li [this message]
2019-09-10 10:27 ` [PATCH v2 2/2] KVM: CPUID: Put maxphyaddr updating together with virtual address width checking Xiaoyao Li
2019-09-10 17:13   ` Jim Mattson
2019-09-10 22:45     ` Xiaoyao Li
2019-09-10 23:26       ` Jim Mattson

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=0c92b31d-ea09-faeb-d032-811b22e73721@intel.com \
    --to=xiaoyao.li@intel.com \
    --cc=jmattson@google.com \
    --cc=joro@8bytes.org \
    --cc=kvm@vger.kernel.org \
    --cc=pbonzini@redhat.com \
    --cc=rkrcmar@redhat.com \
    --cc=sean.j.christopherson@intel.com \
    --cc=vkuznets@redhat.com \
    --cc=wanpengli@tencent.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).