[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Qemu-devel] [PULL 1/5] i386: kvm: Disable arch_capabilities if MSR can'
From: |
Eduardo Habkost |
Subject: |
[Qemu-devel] [PULL 1/5] i386: kvm: Disable arch_capabilities if MSR can't be set |
Date: |
Thu, 21 Mar 2019 16:35:56 -0300 |
KVM has two bugs in the handling of MSR_IA32_ARCH_CAPABILITIES:
1) Linux commit commit 1eaafe91a0df ("kvm: x86: IA32_ARCH_CAPABILITIES
is always supported") makes GET_SUPPORTED_CPUID return
arch_capabilities even if running on SVM. This makes "-cpu
host,migratable=off" incorrectly expose arch_capabilities on CPUID on
AMD hosts (where the MSR is not emulated by KVM).
2) KVM_GET_MSR_INDEX_LIST does not return MSR_IA32_ARCH_CAPABILITIES if
the MSR is not supported by the host CPU. This makes QEMU not
initialize the MSR properly at kvm_put_msrs() on those hosts.
Work around both bugs on the QEMU side, by checking if the MSR
was returned by KVM_GET_MSR_INDEX_LIST before returning the
feature flag on kvm_arch_get_supported_cpuid().
This has the unfortunate side effect of making arch_capabilities
unavailable on hosts without hardware support for the MSR until bug #2
is fixed on KVM, but I can't see another way to work around bug #1
without that side effect.
Signed-off-by: Eduardo Habkost <address@hidden>
Message-Id: <address@hidden>
Signed-off-by: Eduardo Habkost <address@hidden>
---
target/i386/kvm.c | 9 +++++++++
1 file changed, 9 insertions(+)
diff --git a/target/i386/kvm.c b/target/i386/kvm.c
index beae1b99da..3b29ce5c0d 100644
--- a/target/i386/kvm.c
+++ b/target/i386/kvm.c
@@ -389,6 +389,15 @@ uint32_t kvm_arch_get_supported_cpuid(KVMState *s,
uint32_t function,
if (host_tsx_blacklisted()) {
ret &= ~(CPUID_7_0_EBX_RTM | CPUID_7_0_EBX_HLE);
}
+ } else if (function == 7 && index == 0 && reg == R_EDX) {
+ /*
+ * Linux v4.17-v4.20 incorrectly return ARCH_CAPABILITIES on SVM hosts.
+ * We can detect the bug by checking if MSR_IA32_ARCH_CAPABILITIES is
+ * returned by KVM_GET_MSR_INDEX_LIST.
+ */
+ if (!has_msr_arch_capabs) {
+ ret &= ~CPUID_7_0_EDX_ARCH_CAPABILITIES;
+ }
} else if (function == 0x80000001 && reg == R_ECX) {
/*
* It's safe to enable TOPOEXT even if it's not returned by
--
2.18.0.rc1.1.g3f1ff2140
- [Qemu-devel] [PULL 0/5] x86 queue for -rc1, Eduardo Habkost, 2019/03/21
- [Qemu-devel] [PULL 1/5] i386: kvm: Disable arch_capabilities if MSR can't be set,
Eduardo Habkost <=
- [Qemu-devel] [PULL 2/5] i386: Make arch_capabilities migratable, Eduardo Habkost, 2019/03/21
- [Qemu-devel] [PULL 3/5] i386: Disable OSPKE on CPU model definitions, Eduardo Habkost, 2019/03/21
- [Qemu-devel] [PULL 4/5] docs: clarify that spec-ctrl is only needed for Spectre v2, Eduardo Habkost, 2019/03/21
- [Qemu-devel] [PULL 5/5] docs: add note about stibp CPU feature for spectre v2, Eduardo Habkost, 2019/03/21
- Re: [Qemu-devel] [PULL 0/5] x86 queue for -rc1, Peter Maydell, 2019/03/22