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

c461a1
From 178a63f8515a461a6625b856d25f4d4154ada960 Mon Sep 17 00:00:00 2001
c461a1
From: "plai@redhat.com" <plai@redhat.com>
c461a1
Date: Mon, 23 Sep 2019 20:40:26 +0200
c461a1
Subject: [PATCH 10/12] i386: kvm: Disable arch_capabilities if MSR can't be
2ec96d
 set
2ec96d
c461a1
RH-Author: plai@redhat.com
c461a1
Message-id: <1569271227-28026-10-git-send-email-plai@redhat.com>
c461a1
Patchwork-id: 90858
c461a1
O-Subject: [RHEL7.8 qemu-kvm PATCH v6 09/10] i386: kvm: Disable arch_capabilities if MSR can't be set
c461a1
Bugzilla: 1709971
c461a1
RH-Acked-by: Eduardo Habkost <ehabkost@redhat.com>
2ec96d
RH-Acked-by: Bandan Das <bsd@redhat.com>
c461a1
RH-Acked-by: Miroslav Rezanina <mrezanin@redhat.com>
c461a1
c461a1
From: Eduardo Habkost <ehabkost@redhat.com>
2ec96d
2ec96d
KVM has two bugs in the handling of MSR_IA32_ARCH_CAPABILITIES:
2ec96d
2ec96d
1) Linux commit commit 1eaafe91a0df ("kvm: x86: IA32_ARCH_CAPABILITIES
2ec96d
   is always supported") makes GET_SUPPORTED_CPUID return
2ec96d
   arch_capabilities even if running on SVM.  This makes "-cpu
2ec96d
   host,migratable=off" incorrectly expose arch_capabilities on CPUID on
2ec96d
   AMD hosts (where the MSR is not emulated by KVM).
2ec96d
2ec96d
2) KVM_GET_MSR_INDEX_LIST does not return MSR_IA32_ARCH_CAPABILITIES if
2ec96d
   the MSR is not supported by the host CPU.  This makes QEMU not
2ec96d
   initialize the MSR properly at kvm_put_msrs() on those hosts.
2ec96d
2ec96d
Work around both bugs on the QEMU side, by checking if the MSR
2ec96d
was returned by KVM_GET_MSR_INDEX_LIST before returning the
2ec96d
feature flag on kvm_arch_get_supported_cpuid().
2ec96d
2ec96d
This has the unfortunate side effect of making arch_capabilities
2ec96d
unavailable on hosts without hardware support for the MSR until bug #2
2ec96d
is fixed on KVM, but I can't see another way to work around bug #1
2ec96d
without that side effect.
2ec96d
2ec96d
Signed-off-by: Eduardo Habkost <ehabkost@redhat.com>
2ec96d
Message-Id: <20190125220606.4864-2-ehabkost@redhat.com>
2ec96d
Signed-off-by: Eduardo Habkost <ehabkost@redhat.com>
2ec96d
(cherry picked from commit 485b1d256bcb0874bcde0223727c159b6837e6f8)
2ec96d
Signed-off-by: Paul Lai <plai@redhat.com>
2ec96d
Signed-off-by: Miroslav Rezanina <mrezanin@redhat.com>
c461a1
c461a1
Conflicts:
c461a1
	target/i386/kvm.c changes to target-i386/kvm.c
2ec96d
---
2ec96d
 target-i386/kvm.c | 9 +++++++++
2ec96d
 1 file changed, 9 insertions(+)
2ec96d
2ec96d
diff --git a/target-i386/kvm.c b/target-i386/kvm.c
c461a1
index 12781a8..c79b0ea 100644
2ec96d
--- a/target-i386/kvm.c
2ec96d
+++ b/target-i386/kvm.c
c461a1
@@ -235,6 +235,15 @@ uint32_t kvm_arch_get_supported_cpuid(KVMState *s, uint32_t function,
2ec96d
         if (!kvm_irqchip_in_kernel()) {
2ec96d
             ret &= ~CPUID_EXT_X2APIC;
2ec96d
         }
2ec96d
+    } else if (function == 7 && index == 0 && reg == R_EDX) {
2ec96d
+        /*
2ec96d
+         * Linux v4.17-v4.20 incorrectly return ARCH_CAPABILITIES on SVM hosts.
2ec96d
+         * We can detect the bug by checking if MSR_IA32_ARCH_CAPABILITIES is
2ec96d
+         * returned by KVM_GET_MSR_INDEX_LIST.
2ec96d
+         */
2ec96d
+        if (!has_msr_arch_capabs) {
2ec96d
+            ret &= ~CPUID_7_0_EDX_ARCH_CAPABILITIES;
2ec96d
+        }
2ec96d
     } else if (function == 0x80000001 && reg == R_EDX) {
2ec96d
         /* On Intel, kvm returns cpuid according to the Intel spec,
2ec96d
          * so add missing bits according to the AMD spec:
2ec96d
-- 
2ec96d
1.8.3.1
2ec96d