yeahuh / rpms / qemu-kvm

Forked from rpms/qemu-kvm 2 years ago
Clone

Blame SOURCES/kvm-i386-kvm-Disable-arch_capabilities-if-MSR-can-t-be-s.patch

b38b0f
From c48019a17552791a63cc143321944ed916de0672 Mon Sep 17 00:00:00 2001
b38b0f
From: Eduardo Habkost <ehabkost@redhat.com>
b38b0f
Date: Thu, 9 May 2019 22:43:18 +0100
b38b0f
Subject: [PATCH 2/2] i386: kvm: Disable arch_capabilities if MSR can't be set
69f3e1
b38b0f
RH-Author: Eduardo Habkost <ehabkost@redhat.com>
b38b0f
Message-id: <20190509224318.23376-3-ehabkost@redhat.com>
b38b0f
Patchwork-id: 87252
b38b0f
O-Subject: [RHEL-8.1.0 qemu-kvm PATCH 2/2] i386: kvm: Disable arch_capabilities if MSR can't be set
b38b0f
Bugzilla: 1707706
b38b0f
RH-Acked-by: Dr. David Alan Gilbert <dgilbert@redhat.com>
b38b0f
RH-Acked-by: Paolo Bonzini <pbonzini@redhat.com>
69f3e1
RH-Acked-by: Igor Mammedov <imammedo@redhat.com>
b38b0f
RH-Acked-by: Bandan Das <bsd@redhat.com>
69f3e1
69f3e1
KVM has two bugs in the handling of MSR_IA32_ARCH_CAPABILITIES:
69f3e1
69f3e1
1) Linux commit commit 1eaafe91a0df ("kvm: x86: IA32_ARCH_CAPABILITIES
69f3e1
   is always supported") makes GET_SUPPORTED_CPUID return
69f3e1
   arch_capabilities even if running on SVM.  This makes "-cpu
69f3e1
   host,migratable=off" incorrectly expose arch_capabilities on CPUID on
69f3e1
   AMD hosts (where the MSR is not emulated by KVM).
69f3e1
69f3e1
2) KVM_GET_MSR_INDEX_LIST does not return MSR_IA32_ARCH_CAPABILITIES if
69f3e1
   the MSR is not supported by the host CPU.  This makes QEMU not
69f3e1
   initialize the MSR properly at kvm_put_msrs() on those hosts.
69f3e1
69f3e1
Work around both bugs on the QEMU side, by checking if the MSR
69f3e1
was returned by KVM_GET_MSR_INDEX_LIST before returning the
69f3e1
feature flag on kvm_arch_get_supported_cpuid().
69f3e1
69f3e1
This has the unfortunate side effect of making arch_capabilities
69f3e1
unavailable on hosts without hardware support for the MSR until bug #2
69f3e1
is fixed on KVM, but I can't see another way to work around bug #1
69f3e1
without that side effect.
69f3e1
69f3e1
Signed-off-by: Eduardo Habkost <ehabkost@redhat.com>
69f3e1
Message-Id: <20190125220606.4864-2-ehabkost@redhat.com>
69f3e1
Signed-off-by: Eduardo Habkost <ehabkost@redhat.com>
69f3e1
(cherry picked from commit 485b1d256bcb0874bcde0223727c159b6837e6f8)
b38b0f
Signed-off-by: Eduardo Habkost <ehabkost@redhat.com>
69f3e1
Signed-off-by: Danilo C. L. de Paula <ddepaula@redhat.com>
69f3e1
---
69f3e1
 target/i386/kvm.c | 9 +++++++++
69f3e1
 1 file changed, 9 insertions(+)
69f3e1
69f3e1
diff --git a/target/i386/kvm.c b/target/i386/kvm.c
b38b0f
index e3e8c78..8a4d31d 100644
69f3e1
--- a/target/i386/kvm.c
69f3e1
+++ b/target/i386/kvm.c
69f3e1
@@ -374,6 +374,15 @@ uint32_t kvm_arch_get_supported_cpuid(KVMState *s, uint32_t function,
69f3e1
         if (host_tsx_blacklisted()) {
69f3e1
             ret &= ~(CPUID_7_0_EBX_RTM | CPUID_7_0_EBX_HLE);
69f3e1
         }
69f3e1
+    } else if (function == 7 && index == 0 && reg == R_EDX) {
69f3e1
+        /*
69f3e1
+         * Linux v4.17-v4.20 incorrectly return ARCH_CAPABILITIES on SVM hosts.
69f3e1
+         * We can detect the bug by checking if MSR_IA32_ARCH_CAPABILITIES is
69f3e1
+         * returned by KVM_GET_MSR_INDEX_LIST.
69f3e1
+         */
69f3e1
+        if (!has_msr_arch_capabs) {
69f3e1
+            ret &= ~CPUID_7_0_EDX_ARCH_CAPABILITIES;
69f3e1
+        }
69f3e1
     } else if (function == 0x80000001 && reg == R_ECX) {
69f3e1
         /*
69f3e1
          * It's safe to enable TOPOEXT even if it's not returned by
69f3e1
-- 
69f3e1
1.8.3.1
69f3e1