KVM x86: Extend AMD specific guest behavior to Hygon virtual CPUs
authorSean Christopherson <sean.j.christopherson@intel.com>
Thu, 5 Mar 2020 01:34:33 +0000 (17:34 -0800)
committerPaolo Bonzini <pbonzini@redhat.com>
Mon, 16 Mar 2020 16:58:48 +0000 (17:58 +0100)
Extend guest_cpuid_is_amd() to cover Hygon virtual CPUs and rename it
accordingly.  Hygon CPUs use an AMD-based core and so have the same
basic behavior as AMD CPUs.

Fixes: b8f4abb652146 ("x86/kvm: Add Hygon Dhyana support to KVM")
Cc: Pu Wen <puwen@hygon.cn>
Signed-off-by: Sean Christopherson <sean.j.christopherson@intel.com>
Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
arch/x86/kvm/cpuid.c
arch/x86/kvm/cpuid.h
arch/x86/kvm/mmu/mmu.c
arch/x86/kvm/x86.c

index a25b520d26c9d2884d9a3b63b0442e55de1482fd..ec91b9b127faeb2d4ad30a782e8ff42efda2c5d8 100644 (file)
@@ -946,7 +946,7 @@ bool kvm_cpuid(struct kvm_vcpu *vcpu, u32 *eax, u32 *ebx,
         * requested. AMD CPUID semantics returns all zeroes for any
         * undefined leaf, whether or not the leaf is in range.
         */
-       if (!entry && check_limit && !guest_cpuid_is_amd(vcpu) &&
+       if (!entry && check_limit && !guest_cpuid_is_amd_or_hygon(vcpu) &&
            !cpuid_function_in_range(vcpu, function)) {
                max = kvm_find_cpuid_entry(vcpu, 0, 0);
                if (max) {
index cccfd854aacf6e5414ab5d6387b62ab7060eaa74..a0988609f620760e8180600c2d40c1a08d517476 100644 (file)
@@ -214,12 +214,14 @@ static __always_inline void guest_cpuid_clear(struct kvm_vcpu *vcpu,
                *reg &= ~__feature_bit(x86_feature);
 }
 
-static inline bool guest_cpuid_is_amd(struct kvm_vcpu *vcpu)
+static inline bool guest_cpuid_is_amd_or_hygon(struct kvm_vcpu *vcpu)
 {
        struct kvm_cpuid_entry2 *best;
 
        best = kvm_find_cpuid_entry(vcpu, 0, 0);
-       return best && is_guest_vendor_amd(best->ebx, best->ecx, best->edx);
+       return best &&
+              (is_guest_vendor_amd(best->ebx, best->ecx, best->edx) ||
+               is_guest_vendor_hygon(best->ebx, best->ecx, best->edx));
 }
 
 static inline int guest_cpuid_family(struct kvm_vcpu *vcpu)
index 554546948e8791ceabd3b4882986a9c0b6880f37..f1eb2d3e1f40eaba2c4099e473df66bb0739a258 100644 (file)
@@ -4510,7 +4510,8 @@ static void reset_rsvds_bits_mask(struct kvm_vcpu *vcpu,
                                cpuid_maxphyaddr(vcpu), context->root_level,
                                context->nx,
                                guest_cpuid_has(vcpu, X86_FEATURE_GBPAGES),
-                               is_pse(vcpu), guest_cpuid_is_amd(vcpu));
+                               is_pse(vcpu),
+                               guest_cpuid_is_amd_or_hygon(vcpu));
 }
 
 static void
index 96e897d38a63bddcf27cc1af5e9294a0a8afc3e6..cda0b787b2e3e30b6ea1a55e47caa6c45381a459 100644 (file)
@@ -2550,7 +2550,7 @@ static void kvmclock_sync_fn(struct work_struct *work)
 static bool can_set_mci_status(struct kvm_vcpu *vcpu)
 {
        /* McStatusWrEn enabled? */
-       if (guest_cpuid_is_amd(vcpu))
+       if (guest_cpuid_is_amd_or_hygon(vcpu))
                return !!(vcpu->arch.msr_hwcr & BIT_ULL(18));
 
        return false;