Skip to content

Commit 0068299

Browse files
committed
KVM: SVM: Treat all "skip" emulation for SEV guests as outright failures
Treat EMULTYPE_SKIP failures on SEV guests as unhandleable emulation instead of simply resuming the guest, and drop the hack-a-fix which effects that behavior for the INT3/INTO injection path. If KVM can't skip an instruction for which KVM has already done partial emulation, resuming the guest is undesirable as doing so may corrupt guest state. Link: https://lore.kernel.org/r/20230825013621.2845700-5-seanjc@google.com Signed-off-by: Sean Christopherson <seanjc@google.com>
1 parent aeb904f commit 0068299

File tree

2 files changed

+8
-13
lines changed

2 files changed

+8
-13
lines changed

arch/x86/kvm/svm/svm.c

Lines changed: 1 addition & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -364,8 +364,6 @@ static void svm_set_interrupt_shadow(struct kvm_vcpu *vcpu, int mask)
364364
svm->vmcb->control.int_state |= SVM_INTERRUPT_SHADOW_MASK;
365365

366366
}
367-
static int svm_check_emulate_instruction(struct kvm_vcpu *vcpu, int emul_type,
368-
void *insn, int insn_len);
369367

370368
static int __svm_skip_emulated_instruction(struct kvm_vcpu *vcpu,
371369
bool commit_side_effects)
@@ -386,14 +384,6 @@ static int __svm_skip_emulated_instruction(struct kvm_vcpu *vcpu,
386384
}
387385

388386
if (!svm->next_rip) {
389-
/*
390-
* FIXME: Drop this when kvm_emulate_instruction() does the
391-
* right thing and treats "can't emulate" as outright failure
392-
* for EMULTYPE_SKIP.
393-
*/
394-
if (svm_check_emulate_instruction(vcpu, EMULTYPE_SKIP, NULL, 0) != X86EMUL_CONTINUE)
395-
return 0;
396-
397387
if (unlikely(!commit_side_effects))
398388
old_rflags = svm->vmcb->save.rflags;
399389

@@ -4781,7 +4771,7 @@ static int svm_check_emulate_instruction(struct kvm_vcpu *vcpu, int emul_type,
47814771
*/
47824772
if (unlikely(!insn)) {
47834773
if (emul_type & EMULTYPE_SKIP)
4784-
return X86EMUL_RETRY_INSTR;
4774+
return X86EMUL_UNHANDLEABLE;
47854775

47864776
kvm_queue_exception(vcpu, UD_VECTOR);
47874777
return X86EMUL_PROPAGATE_FAULT;

arch/x86/kvm/x86.c

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8874,8 +8874,13 @@ int x86_emulate_instruction(struct kvm_vcpu *vcpu, gpa_t cr2_or_gpa,
88748874
bool writeback = true;
88758875

88768876
r = kvm_check_emulate_insn(vcpu, emulation_type, insn, insn_len);
8877-
if (r != X86EMUL_CONTINUE)
8878-
return 1;
8877+
if (r != X86EMUL_CONTINUE) {
8878+
if (r == X86EMUL_RETRY_INSTR || r == X86EMUL_PROPAGATE_FAULT)
8879+
return 1;
8880+
8881+
WARN_ON_ONCE(r != X86EMUL_UNHANDLEABLE);
8882+
return handle_emulation_failure(vcpu, emulation_type);
8883+
}
88798884

88808885
vcpu->arch.l1tf_flush_l1d = true;
88818886

0 commit comments

Comments
 (0)