Skip to content

Commit 3fa5e8f

Browse files
committed
KVM: SVM: delay svm_vcpu_init_msrpm after svm->vmcb is initialized
Right now, svm_hv_vmcb_dirty_nested_enlightenments has an incorrect dereference of vmcb->control.reserved_sw before the vmcb is checked for being non-NULL. The compiler is usually sinking the dereference after the check; instead of doing this ourselves in the source, ensure that svm_hv_vmcb_dirty_nested_enlightenments is only called with a non-NULL VMCB. Reported-by: Dan Carpenter <[email protected]> Cc: Vineeth Pillai <[email protected]> Signed-off-by: Paolo Bonzini <[email protected]> [Untested for now due to issues with my AMD machine. - Paolo]
1 parent c33e05d commit 3fa5e8f

File tree

2 files changed

+3
-3
lines changed

2 files changed

+3
-3
lines changed

arch/x86/kvm/svm/svm.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1406,8 +1406,6 @@ static int svm_create_vcpu(struct kvm_vcpu *vcpu)
14061406
goto error_free_vmsa_page;
14071407
}
14081408

1409-
svm_vcpu_init_msrpm(vcpu, svm->msrpm);
1410-
14111409
svm->vmcb01.ptr = page_address(vmcb01_page);
14121410
svm->vmcb01.pa = __sme_set(page_to_pfn(vmcb01_page) << PAGE_SHIFT);
14131411

@@ -1419,6 +1417,8 @@ static int svm_create_vcpu(struct kvm_vcpu *vcpu)
14191417
svm_switch_vmcb(svm, &svm->vmcb01);
14201418
init_vmcb(vcpu);
14211419

1420+
svm_vcpu_init_msrpm(vcpu, svm->msrpm);
1421+
14221422
svm_init_osvw(vcpu);
14231423
vcpu->arch.microcode_version = 0x01000065;
14241424

arch/x86/kvm/svm/svm_onhyperv.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,7 @@ static inline void svm_hv_vmcb_dirty_nested_enlightenments(
8989
* as we mark it dirty unconditionally towards end of vcpu
9090
* init phase.
9191
*/
92-
if (vmcb && vmcb_is_clean(vmcb, VMCB_HV_NESTED_ENLIGHTENMENTS) &&
92+
if (vmcb_is_clean(vmcb, VMCB_HV_NESTED_ENLIGHTENMENTS) &&
9393
hve->hv_enlightenments_control.msr_bitmap)
9494
vmcb_mark_dirty(vmcb, VMCB_HV_NESTED_ENLIGHTENMENTS);
9595
}

0 commit comments

Comments
 (0)