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