On Mon, Jul 25, 2022, Paolo Bonzini wrote: > On 7/21/22 23:58, Sean Christopherson wrote: > > > > diff --git a/arch/x86/kvm/vmx/evmcs.c b/arch/x86/kvm/vmx/evmcs.c > > index b5cfbf7d487b..7b348a03e096 100644 > > --- a/arch/x86/kvm/vmx/evmcs.c > > +++ b/arch/x86/kvm/vmx/evmcs.c > > @@ -355,11 +355,6 @@ uint16_t nested_get_evmcs_version(struct kvm_vcpu *vcpu) > > return 0; > > } > > > > -enum evmcs_v1_revision { > > - EVMCSv1_2016, > > - EVMCSv1_2022, > > -}; > > - > > enum evmcs_unsupported_ctrl_type { > > EVMCS_EXIT_CTLS, > > EVMCS_ENTRY_CTLS, > > @@ -372,29 +367,29 @@ static u32 evmcs_get_unsupported_ctls(struct kvm_vcpu *vcpu, > > enum evmcs_unsupported_ctrl_type ctrl_type) > > { > > struct kvm_vcpu_hv *hv_vcpu = to_hv_vcpu(vcpu); > > - enum evmcs_v1_revision evmcs_rev = EVMCSv1_2016; > > + bool has_evmcs_2022_features; > > > > if (!hv_vcpu) > > return 0; > > > > - if (hv_vcpu->cpuid_cache.nested_ebx & HV_X64_NESTED_EVMCS1_2022_UPDATE) > > - evmcs_rev = EVMCSv1_2022; > > + has_evmcs_2022_features = hv_vcpu->cpuid_cache.nested_ebx & > > + HV_X64_NESTED_EVMCS1_2022_UPDATE; > > > > switch (ctrl_type) { > > case EVMCS_EXIT_CTLS: > > - if (evmcs_rev == EVMCSv1_2016) > > + if (!has_evmcs_2022_features) > > return EVMCS1_UNSUPPORTED_VMEXIT_CTRL | > > VM_EXIT_LOAD_IA32_PERF_GLOBAL_CTRL; > > else > > return EVMCS1_UNSUPPORTED_VMEXIT_CTRL; > > case EVMCS_ENTRY_CTLS: > > - if (evmcs_rev == EVMCSv1_2016) > > + if (!has_evmcs_2022_features) > > return EVMCS1_UNSUPPORTED_VMENTRY_CTRL | > > VM_ENTRY_LOAD_IA32_PERF_GLOBAL_CTRL; > > else > > return EVMCS1_UNSUPPORTED_VMENTRY_CTRL; > > case EVMCS_2NDEXEC: > > - if (evmcs_rev == EVMCSv1_2016) > > + if (!has_evmcs_2022_features) > > return EVMCS1_UNSUPPORTED_2NDEXEC | > > SECONDARY_EXEC_TSC_SCALING; > > else > > > > I kind of like the idea of having a two-dimensional array based on the enums > instead of switch statements, so for now I'll keep Vitaly's enums. I don't have a strong opinion on using a 2d array, but unless I'm missing something, that's nowhere to be found in this patch. IMO, having the enums without them providing any unique value is silly and obfuscates the code.