yeahuh / rpms / qemu-kvm

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