@@ -364,8 +364,6 @@ static void svm_set_interrupt_shadow(struct kvm_vcpu *vcpu, int mask)
364
364
svm -> vmcb -> control .int_state |= SVM_INTERRUPT_SHADOW_MASK ;
365
365
366
366
}
367
- static bool svm_can_emulate_instruction (struct kvm_vcpu * vcpu , int emul_type ,
368
- void * insn , int insn_len );
369
367
370
368
static int __svm_skip_emulated_instruction (struct kvm_vcpu * vcpu ,
371
369
bool commit_side_effects )
@@ -386,14 +384,6 @@ static int __svm_skip_emulated_instruction(struct kvm_vcpu *vcpu,
386
384
}
387
385
388
386
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
-
397
387
if (unlikely (!commit_side_effects ))
398
388
old_rflags = svm -> vmcb -> save .rflags ;
399
389
@@ -2202,12 +2192,6 @@ static int shutdown_interception(struct kvm_vcpu *vcpu)
2202
2192
struct kvm_run * kvm_run = vcpu -> run ;
2203
2193
struct vcpu_svm * svm = to_svm (vcpu );
2204
2194
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 ;
2211
2195
2212
2196
/*
2213
2197
* VMCB is undefined after a SHUTDOWN intercept. INIT the vCPU to put
@@ -2216,9 +2200,14 @@ static int shutdown_interception(struct kvm_vcpu *vcpu)
2216
2200
* userspace. At a platform view, INIT is acceptable behavior as
2217
2201
* there exist bare metal platforms that automatically INIT the CPU
2218
2202
* 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.
2219
2206
*/
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
+ }
2222
2211
2223
2212
kvm_run -> exit_reason = KVM_EXIT_SHUTDOWN ;
2224
2213
return 0 ;
@@ -4727,15 +4716,15 @@ static void svm_enable_smi_window(struct kvm_vcpu *vcpu)
4727
4716
}
4728
4717
#endif
4729
4718
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 )
4732
4721
{
4733
4722
bool smep , smap , is_user ;
4734
4723
u64 error_code ;
4735
4724
4736
4725
/* Emulation is always possible when KVM has access to all guest state. */
4737
4726
if (!sev_guest (vcpu -> kvm ))
4738
- return true ;
4727
+ return X86EMUL_CONTINUE ;
4739
4728
4740
4729
/* #UD and #GP should never be intercepted for SEV guests. */
4741
4730
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,
4747
4736
* to guest register state.
4748
4737
*/
4749
4738
if (sev_es_guest (vcpu -> kvm ))
4750
- return false ;
4739
+ return X86EMUL_RETRY_INSTR ;
4751
4740
4752
4741
/*
4753
4742
* Emulation is possible if the instruction is already decoded, e.g.
4754
4743
* when completing I/O after returning from userspace.
4755
4744
*/
4756
4745
if (emul_type & EMULTYPE_NO_DECODE )
4757
- return true ;
4746
+ return X86EMUL_CONTINUE ;
4758
4747
4759
4748
/*
4760
4749
* 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,
4780
4769
* success (and in practice it will work the vast majority of the time).
4781
4770
*/
4782
4771
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 ;
4786
4777
}
4787
4778
4788
4779
/*
@@ -4793,7 +4784,7 @@ static bool svm_can_emulate_instruction(struct kvm_vcpu *vcpu, int emul_type,
4793
4784
* table used to translate CS:RIP resides in emulated MMIO.
4794
4785
*/
4795
4786
if (likely (insn_len ))
4796
- return true ;
4787
+ return X86EMUL_CONTINUE ;
4797
4788
4798
4789
/*
4799
4790
* 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,
4851
4842
kvm_inject_gp (vcpu , 0 );
4852
4843
else
4853
4844
kvm_make_request (KVM_REQ_TRIPLE_FAULT , vcpu );
4845
+ return X86EMUL_PROPAGATE_FAULT ;
4854
4846
}
4855
4847
4856
4848
resume_guest :
@@ -4868,7 +4860,7 @@ static bool svm_can_emulate_instruction(struct kvm_vcpu *vcpu, int emul_type,
4868
4860
* doesn't explicitly define "ignored", i.e. doing nothing and letting
4869
4861
* the guest spin is technically "ignoring" the access.
4870
4862
*/
4871
- return false ;
4863
+ return X86EMUL_RETRY_INSTR ;
4872
4864
}
4873
4865
4874
4866
static bool svm_apic_init_signal_blocked (struct kvm_vcpu * vcpu )
@@ -5028,7 +5020,7 @@ static struct kvm_x86_ops svm_x86_ops __initdata = {
5028
5020
.vm_copy_enc_context_from = sev_vm_copy_enc_context_from ,
5029
5021
.vm_move_enc_context_from = sev_vm_move_enc_context_from ,
5030
5022
5031
- .can_emulate_instruction = svm_can_emulate_instruction ,
5023
+ .check_emulate_instruction = svm_check_emulate_instruction ,
5032
5024
5033
5025
.apic_init_signal_blocked = svm_apic_init_signal_blocked ,
5034
5026
0 commit comments