Skip to content

Commit cdf85e0

Browse files
sean-jcbonzini
authored andcommitted
KVM: SVM: Don't kill SEV guest if SMAP erratum triggers in usermode
Inject a #GP instead of synthesizing triple fault to try to avoid killing the guest if emulation of an SEV guest fails due to encountering the SMAP erratum. The injected #GP may still be fatal to the guest, e.g. if the userspace process is providing critical functionality, but KVM should make every attempt to keep the guest alive. Signed-off-by: Sean Christopherson <[email protected]> Reviewed-by: Liam Merwick <[email protected]> Message-Id: <[email protected]> Signed-off-by: Paolo Bonzini <[email protected]>
1 parent 3280cc2 commit cdf85e0

File tree

1 file changed

+15
-1
lines changed

1 file changed

+15
-1
lines changed

arch/x86/kvm/svm/svm.c

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4360,7 +4360,21 @@ static bool svm_can_emulate_instruction(struct kvm_vcpu *vcpu, int emul_type,
43604360
is_user = svm_get_cpl(vcpu) == 3;
43614361
if (smap && (!smep || is_user)) {
43624362
pr_err_ratelimited("KVM: SEV Guest triggered AMD Erratum 1096\n");
4363-
kvm_make_request(KVM_REQ_TRIPLE_FAULT, vcpu);
4363+
4364+
/*
4365+
* If the fault occurred in userspace, arbitrarily inject #GP
4366+
* to avoid killing the guest and to hopefully avoid confusing
4367+
* the guest kernel too much, e.g. injecting #PF would not be
4368+
* coherent with respect to the guest's page tables. Request
4369+
* triple fault if the fault occurred in the kernel as there's
4370+
* no fault that KVM can inject without confusing the guest.
4371+
* In practice, the triple fault is moot as no sane SEV kernel
4372+
* will execute from user memory while also running with SMAP=1.
4373+
*/
4374+
if (is_user)
4375+
kvm_inject_gp(vcpu, 0);
4376+
else
4377+
kvm_make_request(KVM_REQ_TRIPLE_FAULT, vcpu);
43644378
}
43654379

43664380
resume_guest:

0 commit comments

Comments
 (0)