From: Jan Kiszka <jan.kiszka@siemens.com>
To: Paolo Bonzini <pbonzini@redhat.com>,
Sean Christopherson <sean.j.christopherson@intel.com>
Cc: Vitaly Kuznetsov <vkuznets@redhat.com>,
Wanpeng Li <wanpengli@tencent.com>,
Jim Mattson <jmattson@google.com>, Joerg Roedel <joro@8bytes.org>,
kvm@vger.kernel.org, linux-kernel@vger.kernel.org,
Xiaoyao Li <xiaoyao.li@intel.com>
Subject: Re: [PATCH 3/6] KVM: x86: Add dedicated emulator helper for grabbing CPUID.maxphyaddr
Date: Tue, 3 Mar 2020 10:48:42 +0100 [thread overview]
Message-ID: <617748ab-0edd-2ccc-e86b-b86b0adf9d3b@siemens.com> (raw)
In-Reply-To: <de2ed4e9-409a-6cb1-e295-ea946be11e82@redhat.com>
On 03.03.20 09:48, Paolo Bonzini wrote:
> On 02/03/20 20:57, Sean Christopherson wrote:
>> Add a helper to retrieve cpuid_maxphyaddr() instead of manually
>> calculating the value in the emulator via raw CPUID output. In addition
>> to consolidating logic, this also paves the way toward simplifying
>> kvm_cpuid(), whose somewhat confusing return value exists purely to
>> support the emulator's maxphyaddr calculation.
>>
>> No functional change intended.
>
> I don't think this is a particularly useful change. Yes, it's not
> intuitive but is it more than a matter of documentation (and possibly
> moving the check_cr_write snippet into a separate function)?
Besides the non obvious return value of the current function, this
approach also avoids leaving cpuid traces for querying maxphyaddr, which
is also not very intuitive IMHO.
Jan
>
> Paolo
>
>> Signed-off-by: Sean Christopherson <sean.j.christopherson@intel.com>
>> ---
>> arch/x86/include/asm/kvm_emulate.h | 1 +
>> arch/x86/kvm/emulate.c | 10 +---------
>> arch/x86/kvm/x86.c | 6 ++++++
>> 3 files changed, 8 insertions(+), 9 deletions(-)
>>
>> diff --git a/arch/x86/include/asm/kvm_emulate.h b/arch/x86/include/asm/kvm_emulate.h
>> index bf5f5e476f65..ded06515d30f 100644
>> --- a/arch/x86/include/asm/kvm_emulate.h
>> +++ b/arch/x86/include/asm/kvm_emulate.h
>> @@ -222,6 +222,7 @@ struct x86_emulate_ops {
>>
>> bool (*get_cpuid)(struct x86_emulate_ctxt *ctxt, u32 *eax, u32 *ebx,
>> u32 *ecx, u32 *edx, bool check_limit);
>> + int (*get_cpuid_maxphyaddr)(struct x86_emulate_ctxt *ctxt);
>> bool (*guest_has_long_mode)(struct x86_emulate_ctxt *ctxt);
>> bool (*guest_has_movbe)(struct x86_emulate_ctxt *ctxt);
>> bool (*guest_has_fxsr)(struct x86_emulate_ctxt *ctxt);
>> diff --git a/arch/x86/kvm/emulate.c b/arch/x86/kvm/emulate.c
>> index dd19fb3539e0..bf02ed51e90f 100644
>> --- a/arch/x86/kvm/emulate.c
>> +++ b/arch/x86/kvm/emulate.c
>> @@ -4244,16 +4244,8 @@ static int check_cr_write(struct x86_emulate_ctxt *ctxt)
>>
>> ctxt->ops->get_msr(ctxt, MSR_EFER, &efer);
>> if (efer & EFER_LMA) {
>> - u64 maxphyaddr;
>> - u32 eax, ebx, ecx, edx;
>> + int maxphyaddr = ctxt->ops->get_cpuid_maxphyaddr(ctxt);
>>
>> - eax = 0x80000008;
>> - ecx = 0;
>> - if (ctxt->ops->get_cpuid(ctxt, &eax, &ebx, &ecx,
>> - &edx, false))
>> - maxphyaddr = eax & 0xff;
>> - else
>> - maxphyaddr = 36;
>> rsvd = rsvd_bits(maxphyaddr, 63);
>> if (ctxt->ops->get_cr(ctxt, 4) & X86_CR4_PCIDE)
>> rsvd &= ~X86_CR3_PCID_NOFLUSH;
>> diff --git a/arch/x86/kvm/x86.c b/arch/x86/kvm/x86.c
>> index ddd1d296bd20..5467ee71c25b 100644
>> --- a/arch/x86/kvm/x86.c
>> +++ b/arch/x86/kvm/x86.c
>> @@ -6209,6 +6209,11 @@ static bool emulator_get_cpuid(struct x86_emulate_ctxt *ctxt,
>> return kvm_cpuid(emul_to_vcpu(ctxt), eax, ebx, ecx, edx, check_limit);
>> }
>>
>> +static int emulator_get_cpuid_maxphyaddr(struct x86_emulate_ctxt *ctxt)
>> +{
>> + return cpuid_maxphyaddr(emul_to_vcpu(ctxt));
>> +}
>> +
>> static bool emulator_guest_has_long_mode(struct x86_emulate_ctxt *ctxt)
>> {
>> return guest_cpuid_has(emul_to_vcpu(ctxt), X86_FEATURE_LM);
>> @@ -6301,6 +6306,7 @@ static const struct x86_emulate_ops emulate_ops = {
>> .fix_hypercall = emulator_fix_hypercall,
>> .intercept = emulator_intercept,
>> .get_cpuid = emulator_get_cpuid,
>> + .get_cpuid_maxphyaddr= emulator_get_cpuid_maxphyaddr,
>> .guest_has_long_mode = emulator_guest_has_long_mode,
>> .guest_has_movbe = emulator_guest_has_movbe,
>> .guest_has_fxsr = emulator_guest_has_fxsr,
>>
>
--
Siemens AG, Corporate Technology, CT RDA IOT SES-DE
Corporate Competence Center Embedded Linux
next prev parent reply other threads:[~2020-03-03 9:49 UTC|newest]
Thread overview: 40+ messages / expand[flat|nested] mbox.gz Atom feed top
2020-03-02 19:57 [PATCH 0/6] KVM: x86: CPUID emulation and tracing fixes Sean Christopherson
2020-03-02 19:57 ` [PATCH 1/6] KVM: x86: Fix tracing of CPUID.function when function is out-of-range Sean Christopherson
2020-03-02 20:26 ` Jan Kiszka
2020-03-02 20:49 ` Sean Christopherson
2020-03-02 20:59 ` Jan Kiszka
2020-03-03 2:27 ` Xiaoyao Li
2020-03-03 3:45 ` Sean Christopherson
2020-03-03 4:02 ` Xiaoyao Li
2020-03-03 4:12 ` Sean Christopherson
2020-03-03 4:30 ` Xiaoyao Li
2020-03-03 2:50 ` Xiaoyao Li
2020-03-03 4:08 ` Sean Christopherson
2020-03-03 4:16 ` Xiaoyao Li
2020-03-02 19:57 ` [PATCH 2/6] KVM: x86: Fix CPUID range check for Centaur and Hypervisor ranges Sean Christopherson
2020-03-02 21:59 ` Jim Mattson
2020-03-03 0:57 ` Sean Christopherson
2020-03-03 3:25 ` Jim Mattson
2020-03-03 4:25 ` Jim Mattson
2020-03-03 4:58 ` Sean Christopherson
2020-03-03 17:42 ` Jim Mattson
2020-03-03 18:01 ` Sean Christopherson
2020-03-03 18:08 ` Jim Mattson
2020-03-04 11:18 ` Paolo Bonzini
2020-03-02 19:57 ` [PATCH 3/6] KVM: x86: Add dedicated emulator helper for grabbing CPUID.maxphyaddr Sean Christopherson
2020-03-03 8:48 ` Paolo Bonzini
2020-03-03 9:48 ` Jan Kiszka [this message]
2020-03-03 10:14 ` Paolo Bonzini
2020-03-04 20:47 ` Sean Christopherson
2020-03-03 16:28 ` Sean Christopherson
2020-03-03 17:21 ` Paolo Bonzini
2020-03-02 19:57 ` [PATCH 4/6] KVM: x86: Drop return value from kvm_cpuid() Sean Christopherson
2020-03-02 19:57 ` [PATCH 5/6] KVM: x86: Rename "found" variable in kvm_cpuid() to "exact_entry_exists" Sean Christopherson
2020-03-02 20:20 ` Jan Kiszka
2020-03-02 20:35 ` Sean Christopherson
2020-03-02 20:48 ` Jan Kiszka
2020-03-02 19:57 ` [PATCH 6/6] KVM: x86: Add requested index to the CPUID tracepoint Sean Christopherson
2020-03-07 9:48 ` Jan Kiszka
2020-03-10 4:00 ` Sean Christopherson
2020-03-03 8:48 ` [PATCH 0/6] KVM: x86: CPUID emulation and tracing fixes Paolo Bonzini
2020-03-03 16:38 ` Sean Christopherson
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=617748ab-0edd-2ccc-e86b-b86b0adf9d3b@siemens.com \
--to=jan.kiszka@siemens.com \
--cc=jmattson@google.com \
--cc=joro@8bytes.org \
--cc=kvm@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=pbonzini@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).