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