KVM: X86: Introduce handle_ud()
authorWanpeng Li <wanpengli@tencent.com>
Tue, 3 Apr 2018 23:28:48 +0000 (16:28 -0700)
committerPaolo Bonzini <pbonzini@redhat.com>
Wed, 4 Apr 2018 17:03:58 +0000 (19:03 +0200)
Introduce handle_ud() to handle invalid opcode, this function will be
used by later patches.

Reviewed-by: Konrad Rzeszutek Wilk <konrad.wilk@oracle.com>
Reviewed-by: Liran Alon <liran.alon@oracle.com>
Cc: Paolo Bonzini <pbonzini@redhat.com>
Cc: Radim KrÄmář <rkrcmar@redhat.com>
Cc: Andrew Cooper <andrew.cooper3@citrix.com>
Cc: Konrad Rzeszutek Wilk <konrad.wilk@oracle.com>
Cc: Liran Alon <liran.alon@oracle.com>
Signed-off-by: Wanpeng Li <wanpengli@tencent.com>
Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
arch/x86/kvm/svm.c
arch/x86/kvm/vmx.c
arch/x86/kvm/x86.c
arch/x86/kvm/x86.h

index f66fc2ee9058c32f048a038a3e1ba58e15bd20d7..e0a3f56a791d579da61fe325f0515d02b8c2348a 100644 (file)
@@ -2676,14 +2676,7 @@ static int bp_interception(struct vcpu_svm *svm)
 
 static int ud_interception(struct vcpu_svm *svm)
 {
-       int er;
-
-       er = emulate_instruction(&svm->vcpu, EMULTYPE_TRAP_UD);
-       if (er == EMULATE_USER_EXIT)
-               return 0;
-       if (er != EMULATE_DONE)
-               kvm_queue_exception(&svm->vcpu, UD_VECTOR);
-       return 1;
+       return handle_ud(&svm->vcpu);
 }
 
 static int ac_interception(struct vcpu_svm *svm)
index a1572461786e660b6d56d2e4b7381c32268dd814..59d91516a622cba15abe06451ee7a56b90837359 100644 (file)
@@ -6434,14 +6434,8 @@ static int handle_exception(struct kvm_vcpu *vcpu)
        if (is_nmi(intr_info))
                return 1;  /* already handled by vmx_vcpu_run() */
 
-       if (is_invalid_opcode(intr_info)) {
-               er = emulate_instruction(vcpu, EMULTYPE_TRAP_UD);
-               if (er == EMULATE_USER_EXIT)
-                       return 0;
-               if (er != EMULATE_DONE)
-                       kvm_queue_exception(vcpu, UD_VECTOR);
-               return 1;
-       }
+       if (is_invalid_opcode(intr_info))
+               return handle_ud(vcpu);
 
        error_code = 0;
        if (intr_info & INTR_INFO_DELIVER_CODE_MASK)
index 7d9a444f2f24f5c4d7517889e478274e47d32eb2..1eb495e04fd35736a416aa90d7ed5cd3a08c0a7b 100644 (file)
@@ -4840,6 +4840,19 @@ out:
 }
 EXPORT_SYMBOL_GPL(kvm_write_guest_virt_system);
 
+int handle_ud(struct kvm_vcpu *vcpu)
+{
+       enum emulation_result er;
+
+       er = emulate_instruction(vcpu, EMULTYPE_TRAP_UD);
+       if (er == EMULATE_USER_EXIT)
+               return 0;
+       if (er != EMULATE_DONE)
+               kvm_queue_exception(vcpu, UD_VECTOR);
+       return 1;
+}
+EXPORT_SYMBOL_GPL(handle_ud);
+
 static int vcpu_is_mmio_gpa(struct kvm_vcpu *vcpu, unsigned long gva,
                            gpa_t gpa, bool write)
 {
index 1e8617414ee4b920678f661c09228eac31ecce4a..7d35ce672989ddcbc719db96081d37607c79734f 100644 (file)
@@ -255,6 +255,8 @@ int kvm_write_guest_virt_system(struct x86_emulate_ctxt *ctxt,
        gva_t addr, void *val, unsigned int bytes,
        struct x86_exception *exception);
 
+int handle_ud(struct kvm_vcpu *vcpu);
+
 void kvm_vcpu_mtrr_init(struct kvm_vcpu *vcpu);
 u8 kvm_mtrr_get_guest_memory_type(struct kvm_vcpu *vcpu, gfn_t gfn);
 bool kvm_mtrr_valid(struct kvm_vcpu *vcpu, u32 msr, u64 data);