KVM: x86: handle GBPAGE CPUID adjustment for EPT with generic code
authorPaolo Bonzini <pbonzini@redhat.com>
Tue, 3 Mar 2020 14:54:39 +0000 (15:54 +0100)
committerPaolo Bonzini <pbonzini@redhat.com>
Mon, 16 Mar 2020 16:58:21 +0000 (17:58 +0100)
The clearing of the GBPAGE CPUID bit for VMX is wrong; support for 1GB
pages in EPT has no relationship to whether 1GB pages should be marked as
supported in CPUID.  This has no ill effect because we're only clearing
the bit, but we're not marking 1GB pages as available when EPT is disabled
(even though they are actually supported thanks to shadowing).  Instead,
forcibly enable 1GB pages in the shadow paging case.

This also eliminates an instance of the undesirable "unsigned f_* =
*_supported ? F(*) : 0" pattern in the common CPUID handling code,
and paves the way toward eliminating ->get_lpage_level().

Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
arch/x86/kvm/cpuid.c

index 26955c724571c73644303932baa8a58b9f77b796..aeab6573fe0f29213f55f1f816b088217b3c3890 100644 (file)
@@ -408,8 +408,7 @@ static inline int __do_cpuid_func(struct kvm_cpuid_array *array, u32 function)
        int r, i, max_idx;
        unsigned f_nx = is_efer_nx() ? F(NX) : 0;
 #ifdef CONFIG_X86_64
-       unsigned f_gbpages = (kvm_x86_ops->get_lpage_level() == PT_PDPE_LEVEL)
-                               ? F(GBPAGES) : 0;
+       unsigned f_gbpages = F(GBPAGES);
        unsigned f_lm = F(LM);
 #else
        unsigned f_gbpages = 0;
@@ -683,6 +682,8 @@ static inline int __do_cpuid_func(struct kvm_cpuid_array *array, u32 function)
        case 0x80000001:
                entry->edx &= kvm_cpuid_8000_0001_edx_x86_features;
                cpuid_entry_mask(entry, CPUID_8000_0001_EDX);
+               if (!tdp_enabled)
+                       cpuid_entry_set(entry, X86_FEATURE_GBPAGES);
                entry->ecx &= kvm_cpuid_8000_0001_ecx_x86_features;
                cpuid_entry_mask(entry, CPUID_8000_0001_ECX);
                break;