yeahuh / rpms / qemu-kvm

Forked from rpms/qemu-kvm 2 years ago
Clone

Blame SOURCES/kvm-target-i386-kvm-kvm_get_supported_msrs-cleanup.patch

4ec855
From 07cb338d84e4f439b0a62fbdcbe2162936e3728a Mon Sep 17 00:00:00 2001
4ec855
From: Paolo Bonzini <pbonzini@redhat.com>
4ec855
Date: Fri, 22 Nov 2019 11:53:38 +0000
4ec855
Subject: [PATCH 05/16] target-i386: kvm: 'kvm_get_supported_msrs' cleanup
4ec855
4ec855
RH-Author: Paolo Bonzini <pbonzini@redhat.com>
4ec855
Message-id: <20191122115348.25000-6-pbonzini@redhat.com>
4ec855
Patchwork-id: 92606
4ec855
O-Subject: [RHEL8.2/rhel qemu-kvm PATCH 05/15] target-i386: kvm: 'kvm_get_supported_msrs' cleanup
4ec855
Bugzilla: 1689270
4ec855
RH-Acked-by: Dr. David Alan Gilbert <dgilbert@redhat.com>
4ec855
RH-Acked-by: Eduardo Habkost <ehabkost@redhat.com>
4ec855
RH-Acked-by: Maxim Levitsky <mlevitsk@redhat.com>
4ec855
4ec855
From: Li Qiang <liq3ea@163.com>
4ec855
4ec855
Function 'kvm_get_supported_msrs' is only called once
4ec855
now, get rid of the static variable 'kvm_supported_msrs'.
4ec855
4ec855
Signed-off-by: Li Qiang <liq3ea@163.com>
4ec855
Message-Id: <20190725151639.21693-1-liq3ea@163.com>
4ec855
Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
4ec855
(cherry picked from commit de428cead63a958137ee63efcc3cceaf75f6c125)
4ec855
4ec855
RHEL: no HV_X64_MSR_REENLIGHTENMENT_CONTROL
4ec855
Signed-off-by: Danilo C. L. de Paula <ddepaula@redhat.com>
4ec855
---
4ec855
 target/i386/kvm.c | 179 +++++++++++++++++++++++++++---------------------------
4ec855
 1 file changed, 88 insertions(+), 91 deletions(-)
4ec855
4ec855
diff --git a/target/i386/kvm.c b/target/i386/kvm.c
4ec855
index 849a11a..2290c5d 100644
4ec855
--- a/target/i386/kvm.c
4ec855
+++ b/target/i386/kvm.c
4ec855
@@ -1340,105 +1340,102 @@ static int kvm_get_supported_feature_msrs(KVMState *s)
4ec855
 
4ec855
 static int kvm_get_supported_msrs(KVMState *s)
4ec855
 {
4ec855
-    static int kvm_supported_msrs;
4ec855
     int ret = 0;
4ec855
+    struct kvm_msr_list msr_list, *kvm_msr_list;
4ec855
 
4ec855
-    /* first time */
4ec855
-    if (kvm_supported_msrs == 0) {
4ec855
-        struct kvm_msr_list msr_list, *kvm_msr_list;
4ec855
+    /*
4ec855
+     *  Obtain MSR list from KVM.  These are the MSRs that we must
4ec855
+     *  save/restore.
4ec855
+     */
4ec855
+    msr_list.nmsrs = 0;
4ec855
+    ret = kvm_ioctl(s, KVM_GET_MSR_INDEX_LIST, &msr_list);
4ec855
+    if (ret < 0 && ret != -E2BIG) {
4ec855
+        return ret;
4ec855
+    }
4ec855
+    /*
4ec855
+     * Old kernel modules had a bug and could write beyond the provided
4ec855
+     * memory. Allocate at least a safe amount of 1K.
4ec855
+     */
4ec855
+    kvm_msr_list = g_malloc0(MAX(1024, sizeof(msr_list) +
4ec855
+                                          msr_list.nmsrs *
4ec855
+                                          sizeof(msr_list.indices[0])));
4ec855
 
4ec855
-        kvm_supported_msrs = -1;
4ec855
+    kvm_msr_list->nmsrs = msr_list.nmsrs;
4ec855
+    ret = kvm_ioctl(s, KVM_GET_MSR_INDEX_LIST, kvm_msr_list);
4ec855
+    if (ret >= 0) {
4ec855
+        int i;
4ec855
 
4ec855
-        /* Obtain MSR list from KVM.  These are the MSRs that we must
4ec855
-         * save/restore */
4ec855
-        msr_list.nmsrs = 0;
4ec855
-        ret = kvm_ioctl(s, KVM_GET_MSR_INDEX_LIST, &msr_list);
4ec855
-        if (ret < 0 && ret != -E2BIG) {
4ec855
-            return ret;
4ec855
-        }
4ec855
-        /* Old kernel modules had a bug and could write beyond the provided
4ec855
-           memory. Allocate at least a safe amount of 1K. */
4ec855
-        kvm_msr_list = g_malloc0(MAX(1024, sizeof(msr_list) +
4ec855
-                                              msr_list.nmsrs *
4ec855
-                                              sizeof(msr_list.indices[0])));
4ec855
-
4ec855
-        kvm_msr_list->nmsrs = msr_list.nmsrs;
4ec855
-        ret = kvm_ioctl(s, KVM_GET_MSR_INDEX_LIST, kvm_msr_list);
4ec855
-        if (ret >= 0) {
4ec855
-            int i;
4ec855
-
4ec855
-            for (i = 0; i < kvm_msr_list->nmsrs; i++) {
4ec855
-                switch (kvm_msr_list->indices[i]) {
4ec855
-                case MSR_STAR:
4ec855
-                    has_msr_star = true;
4ec855
-                    break;
4ec855
-                case MSR_VM_HSAVE_PA:
4ec855
-                    has_msr_hsave_pa = true;
4ec855
-                    break;
4ec855
-                case MSR_TSC_AUX:
4ec855
-                    has_msr_tsc_aux = true;
4ec855
-                    break;
4ec855
-                case MSR_TSC_ADJUST:
4ec855
-                    has_msr_tsc_adjust = true;
4ec855
-                    break;
4ec855
-                case MSR_IA32_TSCDEADLINE:
4ec855
-                    has_msr_tsc_deadline = true;
4ec855
-                    break;
4ec855
-                case MSR_IA32_SMBASE:
4ec855
-                    has_msr_smbase = true;
4ec855
-                    break;
4ec855
-                case MSR_SMI_COUNT:
4ec855
-                    has_msr_smi_count = true;
4ec855
-                    break;
4ec855
-                case MSR_IA32_MISC_ENABLE:
4ec855
-                    has_msr_misc_enable = true;
4ec855
-                    break;
4ec855
-                case MSR_IA32_BNDCFGS:
4ec855
-                    has_msr_bndcfgs = true;
4ec855
-                    break;
4ec855
-                case MSR_IA32_XSS:
4ec855
-                    has_msr_xss = true;
4ec855
-                    break;
4ec855
-                case HV_X64_MSR_CRASH_CTL:
4ec855
-                    has_msr_hv_crash = true;
4ec855
-                    break;
4ec855
-                case HV_X64_MSR_RESET:
4ec855
-                    has_msr_hv_reset = true;
4ec855
-                    break;
4ec855
-                case HV_X64_MSR_VP_INDEX:
4ec855
-                    has_msr_hv_vpindex = true;
4ec855
-                    break;
4ec855
-                case HV_X64_MSR_VP_RUNTIME:
4ec855
-                    has_msr_hv_runtime = true;
4ec855
-                    break;
4ec855
-                case HV_X64_MSR_SCONTROL:
4ec855
-                    has_msr_hv_synic = true;
4ec855
-                    break;
4ec855
-                case HV_X64_MSR_STIMER0_CONFIG:
4ec855
-                    has_msr_hv_stimer = true;
4ec855
-                    break;
4ec855
-                case HV_X64_MSR_TSC_FREQUENCY:
4ec855
-                    has_msr_hv_frequencies = true;
4ec855
-                    break;
4ec855
-                case MSR_IA32_SPEC_CTRL:
4ec855
-                    has_msr_spec_ctrl = true;
4ec855
-                    break;
4ec855
-                case MSR_VIRT_SSBD:
4ec855
-                    has_msr_virt_ssbd = true;
4ec855
-                    break;
4ec855
-                case MSR_IA32_ARCH_CAPABILITIES:
4ec855
-                    has_msr_arch_capabs = true;
4ec855
-                    break;
4ec855
-                case MSR_IA32_CORE_CAPABILITY:
4ec855
-                    has_msr_core_capabs = true;
4ec855
-                    break;
4ec855
-                }
4ec855
+        for (i = 0; i < kvm_msr_list->nmsrs; i++) {
4ec855
+            switch (kvm_msr_list->indices[i]) {
4ec855
+            case MSR_STAR:
4ec855
+                has_msr_star = true;
4ec855
+                break;
4ec855
+            case MSR_VM_HSAVE_PA:
4ec855
+                has_msr_hsave_pa = true;
4ec855
+                break;
4ec855
+            case MSR_TSC_AUX:
4ec855
+                has_msr_tsc_aux = true;
4ec855
+                break;
4ec855
+            case MSR_TSC_ADJUST:
4ec855
+                has_msr_tsc_adjust = true;
4ec855
+                break;
4ec855
+            case MSR_IA32_TSCDEADLINE:
4ec855
+                has_msr_tsc_deadline = true;
4ec855
+                break;
4ec855
+            case MSR_IA32_SMBASE:
4ec855
+                has_msr_smbase = true;
4ec855
+                break;
4ec855
+            case MSR_SMI_COUNT:
4ec855
+                has_msr_smi_count = true;
4ec855
+                break;
4ec855
+            case MSR_IA32_MISC_ENABLE:
4ec855
+                has_msr_misc_enable = true;
4ec855
+                break;
4ec855
+            case MSR_IA32_BNDCFGS:
4ec855
+                has_msr_bndcfgs = true;
4ec855
+                break;
4ec855
+            case MSR_IA32_XSS:
4ec855
+                has_msr_xss = true;
4ec855
+                break;
4ec855
+            case HV_X64_MSR_CRASH_CTL:
4ec855
+                has_msr_hv_crash = true;
4ec855
+                break;
4ec855
+            case HV_X64_MSR_RESET:
4ec855
+                has_msr_hv_reset = true;
4ec855
+                break;
4ec855
+            case HV_X64_MSR_VP_INDEX:
4ec855
+                has_msr_hv_vpindex = true;
4ec855
+                break;
4ec855
+            case HV_X64_MSR_VP_RUNTIME:
4ec855
+                has_msr_hv_runtime = true;
4ec855
+                break;
4ec855
+            case HV_X64_MSR_SCONTROL:
4ec855
+                has_msr_hv_synic = true;
4ec855
+                break;
4ec855
+            case HV_X64_MSR_STIMER0_CONFIG:
4ec855
+                has_msr_hv_stimer = true;
4ec855
+                break;
4ec855
+            case HV_X64_MSR_TSC_FREQUENCY:
4ec855
+                has_msr_hv_frequencies = true;
4ec855
+                break;
4ec855
+            case MSR_IA32_SPEC_CTRL:
4ec855
+                has_msr_spec_ctrl = true;
4ec855
+                break;
4ec855
+            case MSR_VIRT_SSBD:
4ec855
+                has_msr_virt_ssbd = true;
4ec855
+                break;
4ec855
+            case MSR_IA32_ARCH_CAPABILITIES:
4ec855
+                has_msr_arch_capabs = true;
4ec855
+                break;
4ec855
+            case MSR_IA32_CORE_CAPABILITY:
4ec855
+                has_msr_core_capabs = true;
4ec855
+                break;
4ec855
             }
4ec855
         }
4ec855
-
4ec855
-        g_free(kvm_msr_list);
4ec855
     }
4ec855
 
4ec855
+    g_free(kvm_msr_list);
4ec855
+
4ec855
     return ret;
4ec855
 }
4ec855
 
4ec855
-- 
4ec855
1.8.3.1
4ec855