Skip to content

Commit 0204750

Browse files
jsmattsonjrbonzini
authored andcommitted
KVM: x86: Mask off unsupported and unknown bits of IA32_ARCH_CAPABILITIES
KVM should not claim to virtualize unknown IA32_ARCH_CAPABILITIES bits. When kvm_get_arch_capabilities() was originally written, there were only a few bits defined in this MSR, and KVM could virtualize all of them. However, over the years, several bits have been defined that KVM cannot just blindly pass through to the guest without additional work (such as virtualizing an MSR promised by the IA32_ARCH_CAPABILITES feature bit). Define a mask of supported IA32_ARCH_CAPABILITIES bits, and mask off any other bits that are set in the hardware MSR. Cc: Paolo Bonzini <pbonzini@redhat.com> Fixes: 5b76a3c ("KVM: VMX: Tell the nested hypervisor to skip L1D flush on vmentry") Signed-off-by: Jim Mattson <jmattson@google.com> Reviewed-by: Vipin Sharma <vipinsh@google.com> Reviewed-by: Xiaoyao Li <xiaoyao.li@intel.com> Message-Id: <20220830174947.2182144-1-jmattson@google.com> Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
1 parent 372d070 commit 0204750

File tree

1 file changed

+21
-4
lines changed

1 file changed

+21
-4
lines changed

arch/x86/kvm/x86.c

Lines changed: 21 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1557,12 +1557,32 @@ static const u32 msr_based_features_all[] = {
15571557
static u32 msr_based_features[ARRAY_SIZE(msr_based_features_all)];
15581558
static unsigned int num_msr_based_features;
15591559

1560+
/*
1561+
* Some IA32_ARCH_CAPABILITIES bits have dependencies on MSRs that KVM
1562+
* does not yet virtualize. These include:
1563+
* 10 - MISC_PACKAGE_CTRLS
1564+
* 11 - ENERGY_FILTERING_CTL
1565+
* 12 - DOITM
1566+
* 18 - FB_CLEAR_CTRL
1567+
* 21 - XAPIC_DISABLE_STATUS
1568+
* 23 - OVERCLOCKING_STATUS
1569+
*/
1570+
1571+
#define KVM_SUPPORTED_ARCH_CAP \
1572+
(ARCH_CAP_RDCL_NO | ARCH_CAP_IBRS_ALL | ARCH_CAP_RSBA | \
1573+
ARCH_CAP_SKIP_VMENTRY_L1DFLUSH | ARCH_CAP_SSB_NO | ARCH_CAP_MDS_NO | \
1574+
ARCH_CAP_PSCHANGE_MC_NO | ARCH_CAP_TSX_CTRL_MSR | ARCH_CAP_TAA_NO | \
1575+
ARCH_CAP_SBDR_SSDP_NO | ARCH_CAP_FBSDP_NO | ARCH_CAP_PSDP_NO | \
1576+
ARCH_CAP_FB_CLEAR | ARCH_CAP_RRSBA | ARCH_CAP_PBRSB_NO)
1577+
15601578
static u64 kvm_get_arch_capabilities(void)
15611579
{
15621580
u64 data = 0;
15631581

1564-
if (boot_cpu_has(X86_FEATURE_ARCH_CAPABILITIES))
1582+
if (boot_cpu_has(X86_FEATURE_ARCH_CAPABILITIES)) {
15651583
rdmsrl(MSR_IA32_ARCH_CAPABILITIES, data);
1584+
data &= KVM_SUPPORTED_ARCH_CAP;
1585+
}
15661586

15671587
/*
15681588
* If nx_huge_pages is enabled, KVM's shadow paging will ensure that
@@ -1610,9 +1630,6 @@ static u64 kvm_get_arch_capabilities(void)
16101630
*/
16111631
}
16121632

1613-
/* Guests don't need to know "Fill buffer clear control" exists */
1614-
data &= ~ARCH_CAP_FB_CLEAR_CTRL;
1615-
16161633
return data;
16171634
}
16181635

0 commit comments

Comments
 (0)