Skip to content

Commit 3e8eacc

Browse files
Sean Christophersonbonzini
authored andcommitted
KVM: nVMX: Call nested_vmx_setup_ctls_msrs() iff @nested is true
...so that it doesn't need access to @nested. The only case where the provided struct isn't already zeroed is the call from vmx_create_vcpu() as setup_vmcs_config() zeroes the struct in the other use cases. This will allow @nested to be statically defined in vmx.c, i.e. this removes the last direct reference from nested code. Signed-off-by: Sean Christopherson <[email protected]> Signed-off-by: Paolo Bonzini <[email protected]>
1 parent e4027cf commit 3e8eacc

File tree

1 file changed

+8
-8
lines changed

1 file changed

+8
-8
lines changed

arch/x86/kvm/vmx/vmx.c

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1759,11 +1759,6 @@ static inline bool nested_vmx_allowed(struct kvm_vcpu *vcpu)
17591759
static void nested_vmx_setup_ctls_msrs(struct nested_vmx_msrs *msrs,
17601760
u32 ept_caps, bool apicv)
17611761
{
1762-
if (!nested) {
1763-
memset(msrs, 0, sizeof(*msrs));
1764-
return;
1765-
}
1766-
17671762
/*
17681763
* Note that as a general rule, the high half of the MSRs (bits in
17691764
* the control fields which may be 1) should be initialized by the
@@ -9546,6 +9541,8 @@ static struct kvm_vcpu *vmx_create_vcpu(struct kvm *kvm, unsigned int id)
95469541
nested_vmx_setup_ctls_msrs(&vmx->nested.msrs,
95479542
vmx_capability.ept,
95489543
kvm_vcpu_apicv_active(&vmx->vcpu));
9544+
else
9545+
memset(&vmx->nested.msrs, 0, sizeof(vmx->nested.msrs));
95499546

95509547
vmx->nested.posted_intr_nv = -1;
95519548
vmx->nested.current_vmptr = -1ull;
@@ -9619,7 +9616,9 @@ static void __init vmx_check_processor_compat(void *rtn)
96199616
*(int *)rtn = 0;
96209617
if (setup_vmcs_config(&vmcs_conf, &vmx_cap) < 0)
96219618
*(int *)rtn = -EIO;
9622-
nested_vmx_setup_ctls_msrs(&vmcs_conf.nested, vmx_cap.ept, enable_apicv);
9619+
if (nested)
9620+
nested_vmx_setup_ctls_msrs(&vmcs_conf.nested, vmx_cap.ept,
9621+
enable_apicv);
96239622
if (memcmp(&vmcs_config, &vmcs_conf, sizeof(struct vmcs_config)) != 0) {
96249623
printk(KERN_ERR "kvm: CPU %d feature inconsistency!\n",
96259624
smp_processor_id());
@@ -13151,12 +13150,13 @@ static __init int hardware_setup(void)
1315113150
enable_shadow_vmcs = 0;
1315213151

1315313152
kvm_set_posted_intr_wakeup_handler(wakeup_handler);
13154-
nested_vmx_setup_ctls_msrs(&vmcs_config.nested, vmx_capability.ept,
13155-
enable_apicv);
1315613153

1315713154
kvm_mce_cap_supported |= MCG_LMCE_P;
1315813155

1315913156
if (nested) {
13157+
nested_vmx_setup_ctls_msrs(&vmcs_config.nested,
13158+
vmx_capability.ept, enable_apicv);
13159+
1316013160
r = nested_vmx_hardware_setup(kvm_vmx_exit_handlers);
1316113161
if (r)
1316213162
return r;

0 commit comments

Comments
 (0)