Blob Blame Raw
From aa89186992d427e17118608c9fa02b36be8fab8e Mon Sep 17 00:00:00 2001
From: "plai@redhat.com" <plai@redhat.com>
Date: Mon, 23 Sep 2019 20:40:25 +0200
Subject: [PATCH 09/12] kvm: Use KVM_GET_MSR_INDEX_LIST for
 MSR_IA32_ARCH_CAPABILITIES support

RH-Author: plai@redhat.com
Message-id: <1569271227-28026-9-git-send-email-plai@redhat.com>
Patchwork-id: 90861
O-Subject: [RHEL7.8 qemu-kvm PATCH v6 08/10] kvm: Use KVM_GET_MSR_INDEX_LIST for MSR_IA32_ARCH_CAPABILITIES support
Bugzilla: 1709971
RH-Acked-by: Eduardo Habkost <ehabkost@redhat.com>
RH-Acked-by: Bandan Das <bsd@redhat.com>
RH-Acked-by: Miroslav Rezanina <mrezanin@redhat.com>

From: Bandan Das <bsd@redhat.com>

When writing to guest's MSR_IA32_ARCH_CAPABILITIES, check whether it's
supported in the guest using the KVM_GET_MSR_INDEX_LIST ioctl.

Fixes: d86f963694df27f11b3681ffd225c9362de1b634
Suggested-by: Eduardo Habkost <ehabkost@redhat.com>
Tested-by: balducci@units.it
Signed-off-by: Bandan Das <bsd@redhat.com>
Message-Id: <jpg4lc4iiav.fsf_-_@linux.bootlegged.copy>
Signed-off-by: Eduardo Habkost <ehabkost@redhat.com>
(cherry picked from commit aec5e9c3a94cf8b7920f59bef69a6f426092c4a0)
Signed-off-by: Paul Lai <plai@redhat.com>

Resolved Conflicts:
	target/i386/kvm.c changes to target-i386/kvm.c

Signed-off-by: Miroslav Rezanina <mrezanin@redhat.com>
---
 target-i386/cpu.h |  1 +
 target-i386/kvm.c | 19 +++++++++++--------
 2 files changed, 12 insertions(+), 8 deletions(-)

diff --git a/target-i386/cpu.h b/target-i386/cpu.h
index 5a86b2c..8f73af7 100644
--- a/target-i386/cpu.h
+++ b/target-i386/cpu.h
@@ -1070,6 +1070,7 @@ typedef struct CPUX86State {
 
     uint64_t spec_ctrl;
     uint64_t virt_ssbd;
+    uint64_t virt_arch_capabs;
 
     TPRAccess tpr_access_type;
 } CPUX86State;
diff --git a/target-i386/kvm.c b/target-i386/kvm.c
index 722cfbc..12781a8 100644
--- a/target-i386/kvm.c
+++ b/target-i386/kvm.c
@@ -81,6 +81,7 @@ static bool has_msr_mtrr;
 static bool has_msr_xss;
 static bool has_msr_spec_ctrl;
 static bool has_msr_virt_ssbd;
+static bool has_msr_arch_capabs;
 
 static bool has_msr_architectural_pmu;
 static uint32_t num_architectural_pmu_counters;
@@ -902,6 +903,10 @@ static int kvm_get_supported_msrs(KVMState *s)
                     has_msr_virt_ssbd = true;
                     continue;
                 }
+                if (kvm_msr_list->indices[i] == MSR_IA32_ARCH_CAPABILITIES) {
+                    has_msr_arch_capabs = true;
+                    continue;
+                }
             }
         }
 
@@ -1340,14 +1345,9 @@ static int kvm_put_msrs(X86CPU *cpu, int level)
         }
     }
     /* If host supports feature MSR, write down. */
-    if (kvm_feature_msrs) {
-        int i;
-        for (i = 0; i < kvm_feature_msrs->nmsrs; i++)
-            if (kvm_feature_msrs->indices[i] == MSR_IA32_ARCH_CAPABILITIES) {
-                kvm_msr_entry_set(&msrs[n++], MSR_IA32_ARCH_CAPABILITIES,
-                              env->features[FEAT_ARCH_CAPABILITIES]);
-                break;
-            }
+    if (has_msr_arch_capabs) {
+        kvm_msr_entry_set(&msrs[n++], MSR_IA32_ARCH_CAPABILITIES,
+                          env->features[FEAT_ARCH_CAPABILITIES]);
     }
     /*
      * The following MSRs have side effects on the guest or are too heavy
@@ -1939,6 +1939,9 @@ static int kvm_get_msrs(X86CPU *cpu)
         case MSR_VIRT_SSBD:
             env->virt_ssbd = msrs[i].data;
             break;
+        case MSR_IA32_ARCH_CAPABILITIES:
+            env->features[FEAT_ARCH_CAPABILITIES] = msrs[i].data;
+            break;
         }
     }
 
-- 
1.8.3.1