Skip to content

Commit 59cd9bc

Browse files
vittyvkbonzini
authored andcommitted
KVM: nSVM: prepare to handle errors from enter_svm_guest_mode()
Some operations in enter_svm_guest_mode() may fail, e.g. currently we suppress kvm_set_cr3() return value. Prepare the code to proparate errors. No functional change intended. Signed-off-by: Vitaly Kuznetsov <[email protected]> Message-Id: <[email protected]> Signed-off-by: Paolo Bonzini <[email protected]>
1 parent ebdb3db commit 59cd9bc

File tree

3 files changed

+22
-14
lines changed

3 files changed

+22
-14
lines changed

arch/x86/kvm/svm/nested.c

Lines changed: 16 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -404,7 +404,7 @@ static void nested_prepare_vmcb_control(struct vcpu_svm *svm)
404404
vmcb_mark_all_dirty(svm->vmcb);
405405
}
406406

407-
void enter_svm_guest_mode(struct vcpu_svm *svm, u64 vmcb_gpa,
407+
int enter_svm_guest_mode(struct vcpu_svm *svm, u64 vmcb_gpa,
408408
struct vmcb *nested_vmcb)
409409
{
410410
svm->nested.vmcb = vmcb_gpa;
@@ -413,6 +413,8 @@ void enter_svm_guest_mode(struct vcpu_svm *svm, u64 vmcb_gpa,
413413
nested_prepare_vmcb_control(svm);
414414

415415
svm_set_gif(svm, true);
416+
417+
return 0;
416418
}
417419

418420
int nested_svm_vmrun(struct vcpu_svm *svm)
@@ -490,18 +492,22 @@ int nested_svm_vmrun(struct vcpu_svm *svm)
490492
copy_vmcb_control_area(&hsave->control, &vmcb->control);
491493

492494
svm->nested.nested_run_pending = 1;
493-
enter_svm_guest_mode(svm, vmcb_gpa, nested_vmcb);
494495

495-
if (!nested_svm_vmrun_msrpm(svm)) {
496-
svm->nested.nested_run_pending = 0;
496+
if (enter_svm_guest_mode(svm, vmcb_gpa, nested_vmcb))
497+
goto out_exit_err;
497498

498-
svm->vmcb->control.exit_code = SVM_EXIT_ERR;
499-
svm->vmcb->control.exit_code_hi = 0;
500-
svm->vmcb->control.exit_info_1 = 0;
501-
svm->vmcb->control.exit_info_2 = 0;
499+
if (nested_svm_vmrun_msrpm(svm))
500+
goto out;
502501

503-
nested_svm_vmexit(svm);
504-
}
502+
out_exit_err:
503+
svm->nested.nested_run_pending = 0;
504+
505+
svm->vmcb->control.exit_code = SVM_EXIT_ERR;
506+
svm->vmcb->control.exit_code_hi = 0;
507+
svm->vmcb->control.exit_info_1 = 0;
508+
svm->vmcb->control.exit_info_2 = 0;
509+
510+
nested_svm_vmexit(svm);
505511

506512
out:
507513
kvm_vcpu_unmap(&svm->vcpu, &map, true);

arch/x86/kvm/svm/svm.c

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3889,6 +3889,7 @@ static int svm_pre_leave_smm(struct kvm_vcpu *vcpu, const char *smstate)
38893889
struct kvm_host_map map;
38903890
u64 guest;
38913891
u64 vmcb;
3892+
int ret = 0;
38923893

38933894
guest = GET_SMSTATE(u64, smstate, 0x7ed8);
38943895
vmcb = GET_SMSTATE(u64, smstate, 0x7ee0);
@@ -3897,10 +3898,11 @@ static int svm_pre_leave_smm(struct kvm_vcpu *vcpu, const char *smstate)
38973898
if (kvm_vcpu_map(&svm->vcpu, gpa_to_gfn(vmcb), &map) == -EINVAL)
38983899
return 1;
38993900
nested_vmcb = map.hva;
3900-
enter_svm_guest_mode(svm, vmcb, nested_vmcb);
3901+
ret = enter_svm_guest_mode(svm, vmcb, nested_vmcb);
39013902
kvm_vcpu_unmap(&svm->vcpu, &map, true);
39023903
}
3903-
return 0;
3904+
3905+
return ret;
39043906
}
39053907

39063908
static void enable_smi_window(struct kvm_vcpu *vcpu)

arch/x86/kvm/svm/svm.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -387,8 +387,8 @@ static inline bool nested_exit_on_nmi(struct vcpu_svm *svm)
387387
return (svm->nested.ctl.intercept & (1ULL << INTERCEPT_NMI));
388388
}
389389

390-
void enter_svm_guest_mode(struct vcpu_svm *svm, u64 vmcb_gpa,
391-
struct vmcb *nested_vmcb);
390+
int enter_svm_guest_mode(struct vcpu_svm *svm, u64 vmcb_gpa,
391+
struct vmcb *nested_vmcb);
392392
void svm_leave_nested(struct vcpu_svm *svm);
393393
int nested_svm_vmrun(struct vcpu_svm *svm);
394394
void nested_svm_vmloadsave(struct vmcb *from_vmcb, struct vmcb *to_vmcb);

0 commit comments

Comments
 (0)