Skip to contentSkip to conversation

i386: arch_capabilities fixes + migratability

PATCH In review Eduardo Habkost 1 participant 4 messages Jan 25, 2019 – Mar 20, 2019 KVM

lore
Share & tools
lore
#0 lore raw

cover i386: arch_capabilities fixes + migratability

This series works around KVM bugs that affect the arch_capabilities feature. One bug made the feature be enabled incorrect on AMD hosts, and another one made the feature unsafe to enable on most Intel hosts. With the work around, we can finally make arch_capabilities a migratable feature.

Unfortunately, the work around has the side effect of making arch_capabilities unavailable on hosts without hardware support for the feature until one of the KVM bugs is fixed.

Eduardo Habkost (2):
i386: kvm: Disable arch_capabilities if MSR can't be set
i386: Make arch_capabilities migratable

 target/i386/cpu.c | 1 -
 target/i386/kvm.c | 9 +++++++++
 2 files changed, 9 insertions(+), 1 deletion(-)
Signature · 1 line
2.18.0.rc1.1.g3f1ff2140
#1 lore raw

PATCH 1/2 i386: kvm: Disable arch_capabilities if MSR can't be set

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.

---
Cc: Konrad Rzeszutek Wilk <[email protected]>
Cc: Jim Mattson <[email protected]>
Cc: KarimAllah Ahmed <[email protected]>
Cc: David Woodhouse <[email protected]>
Cc: Darren Kenny <[email protected]>

---
 target/i386/kvm.c | 9 +++++++++
 1 file changed, 9 insertions(+)
target/i386/kvm.c +9 -0
index 9af4542fb8..4fa3e3806a 100644
@@ -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 incorrectly v4.17-v4.20 return ARCH_CAPABILITIES on SVM.
+         * 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
Signature · 1 line
2.18.0.rc1.1.g3f1ff2140
#2 lore raw

PATCH 2/2 i386: Make arch_capabilities migratable

In reply to Eduardo Habkost

Now that kvm_arch_get_supported_cpuid() will only return arch_capabilities if QEMU is able to initialize the MSR properly, we know that the feature is safely migratable.

---
 target/i386/cpu.c | 1 -
 1 file changed, 1 deletion(-)
target/i386/cpu.c +0 -1
index 2f5412592d..3ff91d794d 100644
@@ -1088,7 +1088,6 @@ static FeatureWordInfo feature_word_info[FEATURE_WORDS] = {
             .reg = R_EDX,
         },
         .tcg_features = TCG_7_0_EDX_FEATURES,
-        .unmigratable_flags = CPUID_7_0_EDX_ARCH_CAPABILITIES,
     },
     [FEAT_8000_0007_EDX] = {
         .type = CPUID_FEATURE_WORD,
Signature · 1 line
2.18.0.rc1.1.g3f1ff2140
#3 lore raw
In reply to Eduardo Habkost

It looks like this has slipped through the cracks. I'm queueing this series for -rc1.

Quoted 21 lines · Eduardo Habkost

This series works around KVM bugs that affect the arch_capabilities feature. One bug made the feature be enabled incorrect on AMD hosts, and another one made the feature unsafe to enable on most Intel hosts. With the work around, we can finally make arch_capabilities a migratable feature.

Unfortunately, the work around has the side effect of making arch_capabilities unavailable on hosts without hardware support for the feature until one of the KVM bugs is fixed.

Eduardo Habkost (2):
i386: kvm: Disable arch_capabilities if MSR can't be set
i386: Make arch_capabilities migratable

 target/i386/cpu.c | 1 -
 target/i386/kvm.c | 9 +++++++++
 2 files changed, 9 insertions(+), 1 deletion(-)
Signature · 1 line
2.18.0.rc1.1.g3f1ff2140
Signature · 1 line
Eduardo