Commit 3e8eaccc authored by Sean Christopherson's avatar Sean Christopherson Committed by Paolo Bonzini
Browse files

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: default avatarSean Christopherson <sean.j.christopherson@intel.com>
Signed-off-by: default avatarPaolo Bonzini <pbonzini@redhat.com>
parent e4027cfa
Loading
Loading
Loading
Loading
+8 −8
Original line number Original line Diff line number Diff line
@@ -1759,11 +1759,6 @@ static inline bool nested_vmx_allowed(struct kvm_vcpu *vcpu)
static void nested_vmx_setup_ctls_msrs(struct nested_vmx_msrs *msrs,
static void nested_vmx_setup_ctls_msrs(struct nested_vmx_msrs *msrs,
				       u32 ept_caps, bool apicv)
				       u32 ept_caps, bool apicv)
{
{
	if (!nested) {
		memset(msrs, 0, sizeof(*msrs));
		return;
	}

	/*
	/*
	 * Note that as a general rule, the high half of the MSRs (bits in
	 * Note that as a general rule, the high half of the MSRs (bits in
	 * the control fields which may be 1) should be initialized by the
	 * 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)
		nested_vmx_setup_ctls_msrs(&vmx->nested.msrs,
		nested_vmx_setup_ctls_msrs(&vmx->nested.msrs,
					   vmx_capability.ept,
					   vmx_capability.ept,
					   kvm_vcpu_apicv_active(&vmx->vcpu));
					   kvm_vcpu_apicv_active(&vmx->vcpu));
	else
		memset(&vmx->nested.msrs, 0, sizeof(vmx->nested.msrs));


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


	kvm_set_posted_intr_wakeup_handler(wakeup_handler);
	kvm_set_posted_intr_wakeup_handler(wakeup_handler);
	nested_vmx_setup_ctls_msrs(&vmcs_config.nested, vmx_capability.ept,
				   enable_apicv);


	kvm_mce_cap_supported |= MCG_LMCE_P;
	kvm_mce_cap_supported |= MCG_LMCE_P;


	if (nested) {
	if (nested) {
		nested_vmx_setup_ctls_msrs(&vmcs_config.nested,
					   vmx_capability.ept, enable_apicv);

		r = nested_vmx_hardware_setup(kvm_vmx_exit_handlers);
		r = nested_vmx_hardware_setup(kvm_vmx_exit_handlers);
		if (r)
		if (r)
			return r;
			return r;