From: Jim Mattson <jmattson@google.com>
To: Xiaoyao Li <xiaoyao.li@intel.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 2/2] KVM: CPUID: Put maxphyaddr updating together with virtual address width checking
Date: Tue, 10 Sep 2019 16:26:02 -0700 [thread overview]
Message-ID: <CALMp9eQCwSOJDSMHkqhsYyEZjaRo0B5yt+Y7i+fsA-GZ9xfFRA@mail.gmail.com> (raw)
In-Reply-To: <6ce6567e286b4432d62a730dd1697a3592c36a82.camel@intel.com>
On Tue, Sep 10, 2019 at 3:52 PM Xiaoyao Li <xiaoyao.li@intel.com> wrote:
>
> On Tue, 2019-09-10 at 10:13 -0700, Jim Mattson wrote:
> > On Tue, Sep 10, 2019 at 3:42 AM Xiaoyao Li <xiaoyao.li@intel.com> wrote:
> > >
> > > Since both of maxphyaddr updating and virtual address width checking
> > > need to query the cpuid leaf 0x80000008. We can put them together.
> > >
> > > Signed-off-by: Xiaoyao Li <xiaoyao.li@intel.com>
> > > ---
> > > arch/x86/kvm/cpuid.c | 6 ++++--
> > > 1 file changed, 4 insertions(+), 2 deletions(-)
> > >
> > > diff --git a/arch/x86/kvm/cpuid.c b/arch/x86/kvm/cpuid.c
> > > index 67fa44ab87af..fd0a66079001 100644
> > > --- a/arch/x86/kvm/cpuid.c
> > > +++ b/arch/x86/kvm/cpuid.c
> > > @@ -118,6 +118,7 @@ int kvm_update_cpuid(struct kvm_vcpu *vcpu)
> > > best->ebx = xstate_required_size(vcpu->arch.xcr0, true);
> > >
> > > /*
> > > + * Update physical address width and check virtual address width.
> > > * The existing code assumes virtual address is 48-bit or 57-bit in
> > > the
> > > * canonical address checks; exit if it is ever changed.
> > > */
> > > @@ -127,7 +128,10 @@ int kvm_update_cpuid(struct kvm_vcpu *vcpu)
> > >
> > > if (vaddr_bits != 48 && vaddr_bits != 57 && vaddr_bits != 0)
> > > return -EINVAL;
> > > +
> > > + vcpu->arch.maxphyaddr = best->eax & 0xff;
> > > }
> > > + vcpu->arch.maxphyaddr = 36;
> >
> > Perhaps I'm missing something, but it looks to me like you always set
> > vcpu->arch.maxphyaddr to 36, regardless of what may be enumerated by
> > leaf 0x80000008.
>
> Oh, I made a stupid mistake. It should be included in the else case.
>
> >
> > Is there really much of an advantage to open-coding
> > cpuid_query_maxphyaddr() here?
>
> Indeed not so much.
> It can avoid two more kvm_find_cpuid_entry() calling that we don't handle leaf
> 0x80000008 twice in two place.
I'm inclined to leave things as they are. As your previous attempt
demonstrates, having the same logic replicated in multiple places is
prone to error. I can't imagine that this would be a
performance-sensitive path.
> > > best = kvm_find_cpuid_entry(vcpu, KVM_CPUID_FEATURES, 0);
> > > if (kvm_hlt_in_guest(vcpu->kvm) && best &&
> > > @@ -144,8 +148,6 @@ int kvm_update_cpuid(struct kvm_vcpu *vcpu)
> > > }
> > > }
> > >
> > > - /* Update physical-address width */
> > > - vcpu->arch.maxphyaddr = cpuid_query_maxphyaddr(vcpu);
> > > kvm_mmu_reset_context(vcpu);
> > >
> > > kvm_pmu_refresh(vcpu);
> > > --
> > > 2.19.1
> > >
>
prev parent reply other threads:[~2019-09-10 23:26 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
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 [this message]
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=CALMp9eQCwSOJDSMHkqhsYyEZjaRo0B5yt+Y7i+fsA-GZ9xfFRA@mail.gmail.com \
--to=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 \
--cc=xiaoyao.li@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).