@@ -6421,8 +6421,7 @@ void nested_vmx_set_vmcs_shadowing_bitmap(void)
* that madness to get the encoding for comparison.
*/
#define VMCS12_IDX_TO_ENC(idx) ((u16)(((u16)(idx) >> 6) | ((u16)(idx) << 10)))
-
-static u64 nested_vmx_calc_vmcs_enum_msr(void)
+u64 nested_vmx_calc_vmcs_enum_msr(struct nested_vmx *nvmx)
{
/*
* Note these are the so called "index" of the VMCS field encoding, not
@@ -6442,6 +6441,15 @@ static u64 nested_vmx_calc_vmcs_enum_msr(void)
if (!vmcs_field_to_offset_table[i])
continue;
+ if (unlikely(!nvmx->vmcs12_field_existence_bitmap)) {
+ WARN_ON(1);
+ break;
+ }
+
+ if (!test_bit(vmcs_field_to_offset_table[i] / sizeof(u16),
+ nvmx->vmcs12_field_existence_bitmap))
+ continue;
+
idx = vmcs_field_index(VMCS12_IDX_TO_ENC(i));
if (idx > max_idx)
max_idx = idx;
@@ -6695,7 +6703,8 @@ void nested_vmx_setup_ctls_msrs(struct nested_vmx_msrs *msrs, u32 ept_caps)
rdmsrl(MSR_IA32_VMX_CR0_FIXED1, msrs->cr0_fixed1);
rdmsrl(MSR_IA32_VMX_CR4_FIXED1, msrs->cr4_fixed1);
- msrs->vmcs_enum = nested_vmx_calc_vmcs_enum_msr();
+ /* In initial setup, simply read HW value for reference */
+ rdmsrl(MSR_IA32_VMX_VMCS_ENUM, msrs->vmcs_enum);
}
void nested_vmx_hardware_unsetup(void)
@@ -36,6 +36,7 @@ void nested_vmx_pmu_entry_exit_ctls_update(struct kvm_vcpu *vcpu);
void nested_mark_vmcs12_pages_dirty(struct kvm_vcpu *vcpu);
bool nested_vmx_check_io_bitmaps(struct kvm_vcpu *vcpu, unsigned int port,
int size);
+u64 nested_vmx_calc_vmcs_enum_msr(struct nested_vmx *nvmx);
static inline struct vmcs12 *get_vmcs12(struct kvm_vcpu *vcpu)
{
@@ -7156,10 +7156,13 @@ static void vmx_vcpu_after_set_cpuid(struct kvm_vcpu *vcpu)
vmcs_set_secondary_exec_control(vmx);
}
- if (nested_vmx_allowed(vcpu))
+ if (nested_vmx_allowed(vcpu)) {
to_vmx(vcpu)->msr_ia32_feature_control_valid_bits |=
FEAT_CTL_VMX_ENABLED_INSIDE_SMX |
FEAT_CTL_VMX_ENABLED_OUTSIDE_SMX;
+ to_vmx(vcpu)->nested.msrs.vmcs_enum =
+ nested_vmx_calc_vmcs_enum_msr(&to_vmx(vcpu)->nested);
+ }
else
to_vmx(vcpu)->msr_ia32_feature_control_valid_bits &=
~(FEAT_CTL_VMX_ENABLED_INSIDE_SMX |