Skip to content

Commit 7bd7ff9

Browse files
iorlov-devsean-jc
authored andcommitted
KVM: SVM: Handle event vectoring error in check_emulate_instruction()
Detect unhandleable vectoring in check_emulate_instruction() to prevent infinite retry loops on SVM, and to eliminate the main differences in how VM-Exits during event vectoring are handled on SVM versus VMX. E.g. if the vCPU puts its IDT in emulated MMIO memory and generates an event, without the check_emulate_instruction() change, SVM will re-inject the event and resume the guest, and effectively put the vCPU into an infinite loop. Signed-off-by: Ivan Orlov <[email protected]> Link: https://lore.kernel.org/r/[email protected] [sean: grab "svm" locally, massage changelog] Signed-off-by: Sean Christopherson <[email protected]>
1 parent 47ef3ef commit 7bd7ff9

File tree

1 file changed

+7
-1
lines changed

1 file changed

+7
-1
lines changed

arch/x86/kvm/svm/svm.c

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4789,9 +4789,15 @@ static void svm_enable_smi_window(struct kvm_vcpu *vcpu)
47894789
static int svm_check_emulate_instruction(struct kvm_vcpu *vcpu, int emul_type,
47904790
void *insn, int insn_len)
47914791
{
4792+
struct vcpu_svm *svm = to_svm(vcpu);
47924793
bool smep, smap, is_user;
47934794
u64 error_code;
47944795

4796+
/* Check that emulation is possible during event vectoring */
4797+
if ((svm->vmcb->control.exit_int_info & SVM_EXITINTINFO_TYPE_MASK) &&
4798+
!kvm_can_emulate_event_vectoring(emul_type))
4799+
return X86EMUL_UNHANDLEABLE_VECTORING;
4800+
47954801
/* Emulation is always possible when KVM has access to all guest state. */
47964802
if (!sev_guest(vcpu->kvm))
47974803
return X86EMUL_CONTINUE;
@@ -4888,7 +4894,7 @@ static int svm_check_emulate_instruction(struct kvm_vcpu *vcpu, int emul_type,
48884894
* In addition, don't apply the erratum workaround if the #NPF occurred
48894895
* while translating guest page tables (see below).
48904896
*/
4891-
error_code = to_svm(vcpu)->vmcb->control.exit_info_1;
4897+
error_code = svm->vmcb->control.exit_info_1;
48924898
if (error_code & (PFERR_GUEST_PAGE_MASK | PFERR_FETCH_MASK))
48934899
goto resume_guest;
48944900

0 commit comments

Comments
 (0)