From: Jing Liu <jing2.liu@linux.intel.com>
To: Paolo Bonzini <pbonzini@redhat.com>,
linux-kernel@vger.kernel.org, kvm@vger.kernel.org
Subject: Re: [PATCH 2/5] KVM: cpuid: extract do_cpuid_7_mask and support multiple subleafs
Date: Mon, 8 Jul 2019 15:07:15 +0800 [thread overview]
Message-ID: <5af77de6-3a18-a3b9-b492-c280ac4310a1@linux.intel.com> (raw)
In-Reply-To: <20190704140715.31181-3-pbonzini@redhat.com>
Hi Paolo,
Thank you for refining the cpuid codes especially for case 7! It looks
much clear now!
On 7/4/2019 10:07 PM, Paolo Bonzini wrote:
> CPUID function 7 has multiple subleafs. Instead of having nested
> switch statements, move the logic to filter supported features to
> a separate function, and call it for each subleaf.
>
> Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
> ---
> Here you would have something like entry->eax = min(entry->eax, 1)
> when adding subleaf 1.
>
> arch/x86/kvm/cpuid.c | 128 +++++++++++++++++++++++++++----------------
> 1 file changed, 81 insertions(+), 47 deletions(-)
>
[...]
> +
> + switch (index) {
> + case 0:
> + entry->eax = 0;
Here, mark: when adding subleaf 1, change to
entry->eax = min(entry->eax, 1).
> + entry->ebx &= kvm_cpuid_7_0_ebx_x86_features;
> + cpuid_mask(&entry->ebx, CPUID_7_0_EBX);
> + /* TSC_ADJUST is emulated */
> + entry->ebx |= F(TSC_ADJUST);
> +
> + entry->ecx &= kvm_cpuid_7_0_ecx_x86_features;
> + f_la57 = entry->ecx & F(LA57);
> + cpuid_mask(&entry->ecx, CPUID_7_ECX);
> + /* Set LA57 based on hardware capability. */
> + entry->ecx |= f_la57;
> + entry->ecx |= f_umip;
> + /* PKU is not yet implemented for shadow paging. */
> + if (!tdp_enabled || !boot_cpu_has(X86_FEATURE_OSPKE))
> + entry->ecx &= ~F(PKU);
> +
> + entry->edx &= kvm_cpuid_7_0_edx_x86_features;
> + cpuid_mask(&entry->edx, CPUID_7_EDX);
> + /*
> + * We emulate ARCH_CAPABILITIES in software even
> + * if the host doesn't support it.
> + */
> + entry->edx |= F(ARCH_CAPABILITIES);
> + break;
And when adding subleaf 1, plan to add codes,
case 1:
entry->eax |= kvm_cpuid_7_1_eax_x86_features;
entry->ebx = entry->ecx = entry->edx =0;
break;
What do you think?
> + default:
> + WARN_ON_ONCE(1);
> + entry->eax = 0;
> + entry->ebx = 0;
> + entry->ecx = 0;
> + entry->edx = 0;
> + break;
> + }
> +}
> +
> static inline int __do_cpuid_func(struct kvm_cpuid_entry2 *entry, u32 function,
> int *nent, int maxnent)
[...]
> + /* function 7 has additional index. */
> case 7: {
> + int i;
> +
> entry->flags |= KVM_CPUID_FLAG_SIGNIFCANT_INDEX;
> - entry->eax = 0;
> - /* Mask ebx against host capability word 9 */
> - entry->ebx &= kvm_cpuid_7_0_ebx_x86_features;
> - cpuid_mask(&entry->ebx, CPUID_7_0_EBX);
> - // TSC_ADJUST is emulated
> - entry->ebx |= F(TSC_ADJUST);
> - entry->ecx &= kvm_cpuid_7_0_ecx_x86_features;
> - f_la57 = entry->ecx & F(LA57);
> - cpuid_mask(&entry->ecx, CPUID_7_ECX);
> - /* Set LA57 based on hardware capability. */
> - entry->ecx |= f_la57;
> - entry->ecx |= f_umip;
> - /* PKU is not yet implemented for shadow paging. */
> - if (!tdp_enabled || !boot_cpu_has(X86_FEATURE_OSPKE))
> - entry->ecx &= ~F(PKU);
> - entry->edx &= kvm_cpuid_7_0_edx_x86_features;
> - cpuid_mask(&entry->edx, CPUID_7_EDX);
> - /*
> - * We emulate ARCH_CAPABILITIES in software even
> - * if the host doesn't support it.
> - */
> - entry->edx |= F(ARCH_CAPABILITIES);
> + for (i = 0; ; ) {
> + do_cpuid_7_mask(&entry[i], i);
> + if (i == entry->eax)
> + break;
> + if (*nent >= maxnent)
> + goto out;
> +
> + ++i;
> + do_cpuid_1_ent(&entry[i], function, i);
> + entry[i].flags |=
> + KVM_CPUID_FLAG_SIGNIFCANT_INDEX;
> + ++*nent;
> + }
The new logic is great and adding subleaf support would be much easier!
> break;
> }
> case 9:
>
Thanks,
Jing
next prev parent reply other threads:[~2019-07-08 7:07 UTC|newest]
Thread overview: 13+ messages / expand[flat|nested] mbox.gz Atom feed top
2019-07-04 14:07 [PATCH 0/5] KVM: cpuid: cleanups, simplify multi-index CPUID leaves Paolo Bonzini
2019-07-04 14:07 ` [PATCH 1/5] KVM: cpuid: do_cpuid_ent works on a whole CPUID function Paolo Bonzini
2019-07-08 7:05 ` Jing Liu
2019-07-04 14:07 ` [PATCH 2/5] KVM: cpuid: extract do_cpuid_7_mask and support multiple subleafs Paolo Bonzini
2019-07-08 7:07 ` Jing Liu [this message]
2019-07-10 6:30 ` Paolo Bonzini
2019-07-10 7:32 ` Jing Liu
2019-07-10 7:48 ` Paolo Bonzini
2019-07-04 14:07 ` [PATCH 3/5] KVM: cpuid: set struct kvm_cpuid_entry2 flags in do_cpuid_1_ent Paolo Bonzini
2019-07-04 14:07 ` [PATCH 4/5] KVM: cpuid: rename do_cpuid_1_ent Paolo Bonzini
2019-07-04 14:07 ` [PATCH 5/5] KVM: cpuid: remove has_leaf_count from struct kvm_cpuid_param Paolo Bonzini
2019-07-08 7:09 ` Jing Liu
2019-07-10 6:34 ` 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=5af77de6-3a18-a3b9-b492-c280ac4310a1@linux.intel.com \
--to=jing2.liu@linux.intel.com \
--cc=kvm@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=pbonzini@redhat.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
all inboxes | Powered by JetHome®