KVM: SVM: Treat all "skip" emulation for SEV guests as outright failures
authorSean Christopherson <seanjc@google.com>
Fri, 25 Aug 2023 01:36:21 +0000 (18:36 -0700)
committerSean Christopherson <seanjc@google.com>
Wed, 4 Oct 2023 22:08:53 +0000 (15:08 -0700)
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>
arch/x86/kvm/svm/svm.c
arch/x86/kvm/x86.c

index c4e700f945f828c73308c33564ce313aaac068fb..b7472ad183b9d361128cc76dd2d81c221394652b 100644 (file)
@@ -364,8 +364,6 @@ static void svm_set_interrupt_shadow(struct kvm_vcpu *vcpu, int mask)
                svm->vmcb->control.int_state |= SVM_INTERRUPT_SHADOW_MASK;
 
 }
-static int svm_check_emulate_instruction(struct kvm_vcpu *vcpu, int emul_type,
-                                        void *insn, int insn_len);
 
 static int __svm_skip_emulated_instruction(struct kvm_vcpu *vcpu,
                                           bool commit_side_effects)
@@ -386,14 +384,6 @@ static int __svm_skip_emulated_instruction(struct kvm_vcpu *vcpu,
        }
 
        if (!svm->next_rip) {
-               /*
-                * FIXME: Drop this when kvm_emulate_instruction() does the
-                * right thing and treats "can't emulate" as outright failure
-                * for EMULTYPE_SKIP.
-                */
-               if (svm_check_emulate_instruction(vcpu, EMULTYPE_SKIP, NULL, 0) != X86EMUL_CONTINUE)
-                       return 0;
-
                if (unlikely(!commit_side_effects))
                        old_rflags = svm->vmcb->save.rflags;
 
@@ -4781,7 +4771,7 @@ static int svm_check_emulate_instruction(struct kvm_vcpu *vcpu, int emul_type,
         */
        if (unlikely(!insn)) {
                if (emul_type & EMULTYPE_SKIP)
-                       return X86EMUL_RETRY_INSTR;
+                       return X86EMUL_UNHANDLEABLE;
 
                kvm_queue_exception(vcpu, UD_VECTOR);
                return X86EMUL_PROPAGATE_FAULT;
index 104e6b4520a9c3ad9d61bf79fd318b295897b182..cc7d29e9104ba5d42c8559ea930f1b7ba3c089ee 100644 (file)
@@ -8874,8 +8874,13 @@ int x86_emulate_instruction(struct kvm_vcpu *vcpu, gpa_t cr2_or_gpa,
        bool writeback = true;
 
        r = kvm_check_emulate_insn(vcpu, emulation_type, insn, insn_len);
-       if (r != X86EMUL_CONTINUE)
-               return 1;
+       if (r != X86EMUL_CONTINUE) {
+               if (r == X86EMUL_RETRY_INSTR || r == X86EMUL_PROPAGATE_FAULT)
+                       return 1;
+
+               WARN_ON_ONCE(r != X86EMUL_UNHANDLEABLE);
+               return handle_emulation_failure(vcpu, emulation_type);
+       }
 
        vcpu->arch.l1tf_flush_l1d = true;