@@ -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 bool svm_can_emulate_instruction (struct kvm_vcpu * vcpu , int emul_type ,
368- void * insn , int insn_len );
369367
370368static 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_can_emulate_instruction (vcpu , EMULTYPE_SKIP , NULL , 0 ))
395- return 0 ;
396-
397387 if (unlikely (!commit_side_effects ))
398388 old_rflags = svm -> vmcb -> save .rflags ;
399389
@@ -2202,12 +2192,6 @@ static int shutdown_interception(struct kvm_vcpu *vcpu)
22022192 struct kvm_run * kvm_run = vcpu -> run ;
22032193 struct vcpu_svm * svm = to_svm (vcpu );
22042194
2205- /*
2206- * The VM save area has already been encrypted so it
2207- * cannot be reinitialized - just terminate.
2208- */
2209- if (sev_es_guest (vcpu -> kvm ))
2210- return - EINVAL ;
22112195
22122196 /*
22132197 * VMCB is undefined after a SHUTDOWN intercept. INIT the vCPU to put
@@ -2216,9 +2200,14 @@ static int shutdown_interception(struct kvm_vcpu *vcpu)
22162200 * userspace. At a platform view, INIT is acceptable behavior as
22172201 * there exist bare metal platforms that automatically INIT the CPU
22182202 * in response to shutdown.
2203+ *
2204+ * The VM save area for SEV-ES guests has already been encrypted so it
2205+ * cannot be reinitialized, i.e. synthesizing INIT is futile.
22192206 */
2220- clear_page (svm -> vmcb );
2221- kvm_vcpu_reset (vcpu , true);
2207+ if (!sev_es_guest (vcpu -> kvm )) {
2208+ clear_page (svm -> vmcb );
2209+ kvm_vcpu_reset (vcpu , true);
2210+ }
22222211
22232212 kvm_run -> exit_reason = KVM_EXIT_SHUTDOWN ;
22242213 return 0 ;
@@ -4727,15 +4716,15 @@ static void svm_enable_smi_window(struct kvm_vcpu *vcpu)
47274716}
47284717#endif
47294718
4730- static bool svm_can_emulate_instruction (struct kvm_vcpu * vcpu , int emul_type ,
4731- void * insn , int insn_len )
4719+ static int svm_check_emulate_instruction (struct kvm_vcpu * vcpu , int emul_type ,
4720+ void * insn , int insn_len )
47324721{
47334722 bool smep , smap , is_user ;
47344723 u64 error_code ;
47354724
47364725 /* Emulation is always possible when KVM has access to all guest state. */
47374726 if (!sev_guest (vcpu -> kvm ))
4738- return true ;
4727+ return X86EMUL_CONTINUE ;
47394728
47404729 /* #UD and #GP should never be intercepted for SEV guests. */
47414730 WARN_ON_ONCE (emul_type & (EMULTYPE_TRAP_UD |
@@ -4747,14 +4736,14 @@ static bool svm_can_emulate_instruction(struct kvm_vcpu *vcpu, int emul_type,
47474736 * to guest register state.
47484737 */
47494738 if (sev_es_guest (vcpu -> kvm ))
4750- return false ;
4739+ return X86EMUL_RETRY_INSTR ;
47514740
47524741 /*
47534742 * Emulation is possible if the instruction is already decoded, e.g.
47544743 * when completing I/O after returning from userspace.
47554744 */
47564745 if (emul_type & EMULTYPE_NO_DECODE )
4757- return true ;
4746+ return X86EMUL_CONTINUE ;
47584747
47594748 /*
47604749 * Emulation is possible for SEV guests if and only if a prefilled
@@ -4780,9 +4769,11 @@ static bool svm_can_emulate_instruction(struct kvm_vcpu *vcpu, int emul_type,
47804769 * success (and in practice it will work the vast majority of the time).
47814770 */
47824771 if (unlikely (!insn )) {
4783- if (!(emul_type & EMULTYPE_SKIP ))
4784- kvm_queue_exception (vcpu , UD_VECTOR );
4785- return false;
4772+ if (emul_type & EMULTYPE_SKIP )
4773+ return X86EMUL_UNHANDLEABLE ;
4774+
4775+ kvm_queue_exception (vcpu , UD_VECTOR );
4776+ return X86EMUL_PROPAGATE_FAULT ;
47864777 }
47874778
47884779 /*
@@ -4793,7 +4784,7 @@ static bool svm_can_emulate_instruction(struct kvm_vcpu *vcpu, int emul_type,
47934784 * table used to translate CS:RIP resides in emulated MMIO.
47944785 */
47954786 if (likely (insn_len ))
4796- return true ;
4787+ return X86EMUL_CONTINUE ;
47974788
47984789 /*
47994790 * Detect and workaround Errata 1096 Fam_17h_00_0Fh.
@@ -4851,6 +4842,7 @@ static bool svm_can_emulate_instruction(struct kvm_vcpu *vcpu, int emul_type,
48514842 kvm_inject_gp (vcpu , 0 );
48524843 else
48534844 kvm_make_request (KVM_REQ_TRIPLE_FAULT , vcpu );
4845+ return X86EMUL_PROPAGATE_FAULT ;
48544846 }
48554847
48564848resume_guest :
@@ -4868,7 +4860,7 @@ static bool svm_can_emulate_instruction(struct kvm_vcpu *vcpu, int emul_type,
48684860 * doesn't explicitly define "ignored", i.e. doing nothing and letting
48694861 * the guest spin is technically "ignoring" the access.
48704862 */
4871- return false ;
4863+ return X86EMUL_RETRY_INSTR ;
48724864}
48734865
48744866static bool svm_apic_init_signal_blocked (struct kvm_vcpu * vcpu )
@@ -5028,7 +5020,7 @@ static struct kvm_x86_ops svm_x86_ops __initdata = {
50285020 .vm_copy_enc_context_from = sev_vm_copy_enc_context_from ,
50295021 .vm_move_enc_context_from = sev_vm_move_enc_context_from ,
50305022
5031- .can_emulate_instruction = svm_can_emulate_instruction ,
5023+ .check_emulate_instruction = svm_check_emulate_instruction ,
50325024
50335025 .apic_init_signal_blocked = svm_apic_init_signal_blocked ,
50345026
0 commit comments