qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
From: Paolo Bonzini <pbonzini@redhat.com>
To: Liran Alon <liran.alon@oracle.com>, qemu-devel@nongnu.org
Cc: mtosatti@redhat.com, ehabkost@redhat.com, rth@twiddle.net
Subject: Re: [PATCH] i386/kvm: Add CPU property to expose VMware CPUID signature
Date: Tue, 17 Mar 2020 19:02:35 +0100	[thread overview]
Message-ID: <6cd902ba-c90b-b600-c460-a9b8fba2ebc7@redhat.com> (raw)
In-Reply-To: <20200310004017.100484-1-liran.alon@oracle.com>

On 10/03/20 01:40, Liran Alon wrote:
> Some guests are only familiar with VMware PV interface. Therefore, in
> order for these guests to run properly on KVM, we need to be able to
> expose VMware main CPUID leaf. i.e. leaf 0x40000000.
> 
> E.g. Without exposing this VMware CPUID leaf, some guests will fail to boot.
> For example, because of guest attempt to calibrate TSC.
> 
> Signed-off-by: Liran Alon <liran.alon@oracle.com>

Looks good, thanks.  It was submitted quite close to soft freeze so I
couldn't get to it quickly.  But I've queued it now, either for 5.0 or 5.1.

Paolo

> ---
>  target/i386/cpu.c |  1 +
>  target/i386/cpu.h |  1 +
>  target/i386/kvm.c | 35 +++++++++++++++++++++++++++++------
>  3 files changed, 31 insertions(+), 6 deletions(-)
> 
> diff --git a/target/i386/cpu.c b/target/i386/cpu.c
> index 92fafa265914..694766d45a9b 100644
> --- a/target/i386/cpu.c
> +++ b/target/i386/cpu.c
> @@ -7127,6 +7127,7 @@ static Property x86_cpu_properties[] = {
>      DEFINE_PROP_BOOL("l3-cache", X86CPU, enable_l3_cache, true),
>      DEFINE_PROP_BOOL("kvm-no-smi-migration", X86CPU, kvm_no_smi_migration,
>                       false),
> +    DEFINE_PROP_BOOL("vmware-cpuid", X86CPU, expose_vmware, false),
>      DEFINE_PROP_BOOL("vmware-cpuid-freq", X86CPU, vmware_cpuid_freq, true),
>      DEFINE_PROP_BOOL("tcg-cpuid", X86CPU, expose_tcg, true),
>      DEFINE_PROP_BOOL("x-migrate-smi-count", X86CPU, migrate_smi_count,
> diff --git a/target/i386/cpu.h b/target/i386/cpu.h
> index 9c7cd7cde107..bca626963e25 100644
> --- a/target/i386/cpu.h
> +++ b/target/i386/cpu.h
> @@ -1647,6 +1647,7 @@ struct X86CPU {
>       */
>      bool force_features;
>      bool expose_kvm;
> +    bool expose_vmware;
>      bool expose_tcg;
>      bool migratable;
>      bool migrate_smi_count;
> diff --git a/target/i386/kvm.c b/target/i386/kvm.c
> index 00917196dffb..2656258b96b3 100644
> --- a/target/i386/kvm.c
> +++ b/target/i386/kvm.c
> @@ -1187,6 +1187,15 @@ static int hyperv_handle_properties(CPUState *cs,
>      if (!hyperv_enabled(cpu))
>          return 0;
>  
> +    /*
> +     * VMware & Hyper-V conflicts in CPUID leafs.
> +     * Therefore, they cannot exists together.
> +     */
> +    if (cpu->expose_vmware) {
> +        error_report("vmware-cpuid not compatible with hyperv options");
> +        return -ENOTSUP;
> +    }
> +
>      if (hyperv_feat_enabled(cpu, HYPERV_FEAT_EVMCS) ||
>          cpu->hyperv_passthrough) {
>          uint16_t evmcs_version;
> @@ -1508,6 +1517,18 @@ int kvm_arch_init_vcpu(CPUState *cs)
>          has_msr_hv_hypercall = true;
>      }
>  
> +    if (cpu->expose_vmware) {
> +        c = &cpuid_data.entries[cpuid_i++];
> +        c->function = KVM_CPUID_SIGNATURE;
> +        memcpy(signature, "VMwareVMware", 12);
> +        c->eax = KVM_CPUID_SIGNATURE;
> +        c->ebx = signature[0];
> +        c->ecx = signature[1];
> +        c->edx = signature[2];
> +
> +        kvm_base = KVM_CPUID_SIGNATURE_NEXT;
> +    }
> +
>      if (cpu->expose_kvm) {
>          memcpy(signature, "KVMKVMKVM\0\0\0", 12);
>          c = &cpuid_data.entries[cpuid_i++];
> @@ -1791,11 +1812,13 @@ int kvm_arch_init_vcpu(CPUState *cs)
>          }
>      }
>  
> -    if (cpu->vmware_cpuid_freq
> -        /* Guests depend on 0x40000000 to detect this feature, so only expose
> -         * it if KVM exposes leaf 0x40000000. (Conflicts with Hyper-V) */
> -        && cpu->expose_kvm
> -        && kvm_base == KVM_CPUID_SIGNATURE
> +    if (cpu->vmware_cpuid_freq &&
> +        (cpu->expose_vmware ||
> +         /*
> +          * Guests depend on 0x40000000 to detect this feature, so only expose
> +          * it if KVM exposes leaf 0x40000000. (Conflicts with Hyper-V)
> +          */
> +          (cpu->expose_kvm && kvm_base == KVM_CPUID_SIGNATURE))
>          /* TSC clock must be stable and known for this feature. */
>          && tsc_is_stable_and_known(env)) {
>  
> @@ -1805,7 +1828,7 @@ int kvm_arch_init_vcpu(CPUState *cs)
>          c->ebx = env->apic_bus_freq / 1000; /* Hz to KHz */
>          c->ecx = c->edx = 0;
>  
> -        c = cpuid_find_entry(&cpuid_data.cpuid, kvm_base, 0);
> +        c = cpuid_find_entry(&cpuid_data.cpuid, KVM_CPUID_SIGNATURE, 0);
>          c->eax = MAX(c->eax, KVM_CPUID_SIGNATURE | 0x10);
>      }
>  
> 



      parent reply	other threads:[~2020-03-17 18:15 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-03-10  0:40 [PATCH] i386/kvm: Add CPU property to expose VMware CPUID signature Liran Alon
2020-03-17 17:43 ` Liran Alon
2020-03-17 18:02 ` Paolo Bonzini [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=6cd902ba-c90b-b600-c460-a9b8fba2ebc7@redhat.com \
    --to=pbonzini@redhat.com \
    --cc=ehabkost@redhat.com \
    --cc=liran.alon@oracle.com \
    --cc=mtosatti@redhat.com \
    --cc=qemu-devel@nongnu.org \
    --cc=rth@twiddle.net \
    /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).