kvm: Use KVM_GET_MSR_INDEX_LIST for MSR_IA32_ARCH_CAPABILITIES support

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: d86f963694
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>
This commit is contained in:
Bandan Das 2018-11-25 23:17:28 -05:00 committed by Eduardo Habkost
parent d522fba244
commit aec5e9c3a9

View File

@ -95,6 +95,7 @@ static bool has_msr_xss;
static bool has_msr_spec_ctrl; static bool has_msr_spec_ctrl;
static bool has_msr_virt_ssbd; static bool has_msr_virt_ssbd;
static bool has_msr_smi_count; static bool has_msr_smi_count;
static bool has_msr_arch_capabs;
static uint32_t has_architectural_pmu_version; static uint32_t has_architectural_pmu_version;
static uint32_t num_architectural_pmu_gp_counters; static uint32_t num_architectural_pmu_gp_counters;
@ -1481,6 +1482,9 @@ static int kvm_get_supported_msrs(KVMState *s)
case MSR_VIRT_SSBD: case MSR_VIRT_SSBD:
has_msr_virt_ssbd = true; has_msr_virt_ssbd = true;
break; break;
case MSR_IA32_ARCH_CAPABILITIES:
has_msr_arch_capabs = true;
break;
} }
} }
} }
@ -2002,14 +2006,9 @@ static int kvm_put_msrs(X86CPU *cpu, int level)
#endif #endif
/* If host supports feature MSR, write down. */ /* If host supports feature MSR, write down. */
if (kvm_feature_msrs) { if (has_msr_arch_capabs) {
int i; kvm_msr_entry_add(cpu, MSR_IA32_ARCH_CAPABILITIES,
for (i = 0; i < kvm_feature_msrs->nmsrs; i++) env->features[FEAT_ARCH_CAPABILITIES]);
if (kvm_feature_msrs->indices[i] == MSR_IA32_ARCH_CAPABILITIES) {
kvm_msr_entry_add(cpu, MSR_IA32_ARCH_CAPABILITIES,
env->features[FEAT_ARCH_CAPABILITIES]);
break;
}
} }
/* /*