qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] i386/kvm: Add CPU property to expose VMware CPUID signature
@ 2020-03-10  0:40 Liran Alon
  2020-03-17 17:43 ` Liran Alon
  2020-03-17 18:02 ` Paolo Bonzini
  0 siblings, 2 replies; 3+ messages in thread
From: Liran Alon @ 2020-03-10  0:40 UTC (permalink / raw)
  To: qemu-devel; +Cc: pbonzini, mtosatti, Liran Alon, ehabkost, rth

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>
---
 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);
     }
 
-- 
2.20.1



^ permalink raw reply related	[flat|nested] 3+ messages in thread

* Re: [PATCH] i386/kvm: Add CPU property to expose VMware CPUID signature
  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
  1 sibling, 0 replies; 3+ messages in thread
From: Liran Alon @ 2020-03-17 17:43 UTC (permalink / raw)
  To: qemu-devel; +Cc: pbonzini, mtosatti, ehabkost, rth

Gentle ping (A week have passed since submission).

Thanks,
-Liran

On 10/03/2020 2: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>
> ---
>   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);
>       }
>   


^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [PATCH] i386/kvm: Add CPU property to expose VMware CPUID signature
  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
  1 sibling, 0 replies; 3+ messages in thread
From: Paolo Bonzini @ 2020-03-17 18:02 UTC (permalink / raw)
  To: Liran Alon, qemu-devel; +Cc: mtosatti, ehabkost, rth

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);
>      }
>  
> 



^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2020-03-17 18:15 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
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 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).