Skip to content

Commit da5b48a

Browse files
bonzinigregkh
authored andcommitted
KVM: nSVM: fix running nested guests when npt=0
commit a04aead upstream. In case of npt=0 on host, nSVM needs the same .inject_page_fault tweak as VMX has, to make sure that shadow mmu faults are injected as vmexits. It is not clear why this is needed at all, but for now keep the same code as VMX and we'll fix it for both. Based on a patch by Maxim Levitsky <mlevitsk@redhat.com>. Fixes: 7c86663 ("KVM: nSVM: inject exceptions via svm_check_nested_events") Cc: stable@vger.kernel.org Signed-off-by: Paolo Bonzini <pbonzini@redhat.com> Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
1 parent 25b0eb2 commit da5b48a

1 file changed

Lines changed: 20 additions & 0 deletions

File tree

arch/x86/kvm/svm/nested.c

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,23 @@ static void nested_svm_inject_npf_exit(struct kvm_vcpu *vcpu,
5151
nested_svm_vmexit(svm);
5252
}
5353

54+
static void svm_inject_page_fault_nested(struct kvm_vcpu *vcpu, struct x86_exception *fault)
55+
{
56+
struct vcpu_svm *svm = to_svm(vcpu);
57+
WARN_ON(!is_guest_mode(vcpu));
58+
59+
if (vmcb_is_intercept(&svm->nested.ctl, INTERCEPT_EXCEPTION_OFFSET + PF_VECTOR) &&
60+
!svm->nested.nested_run_pending) {
61+
svm->vmcb->control.exit_code = SVM_EXIT_EXCP_BASE + PF_VECTOR;
62+
svm->vmcb->control.exit_code_hi = 0;
63+
svm->vmcb->control.exit_info_1 = fault->error_code;
64+
svm->vmcb->control.exit_info_2 = fault->address;
65+
nested_svm_vmexit(svm);
66+
} else {
67+
kvm_inject_page_fault(vcpu, fault);
68+
}
69+
}
70+
5471
static u64 nested_svm_get_tdp_pdptr(struct kvm_vcpu *vcpu, int index)
5572
{
5673
struct vcpu_svm *svm = to_svm(vcpu);
@@ -446,6 +463,9 @@ int enter_svm_guest_mode(struct vcpu_svm *svm, u64 vmcb12_gpa,
446463
if (ret)
447464
return ret;
448465

466+
if (!npt_enabled)
467+
svm->vcpu.arch.mmu->inject_page_fault = svm_inject_page_fault_nested;
468+
449469
svm_set_gif(svm, true);
450470

451471
return 0;

0 commit comments

Comments
 (0)