diff options
author | Wanpeng Li <wanpengli@tencent.com> | 2018-04-03 19:28:48 -0400 |
---|---|---|
committer | Paolo Bonzini <pbonzini@redhat.com> | 2018-04-04 13:03:58 -0400 |
commit | 082d06edab49f302eb96b7a9d029f52713156354 (patch) | |
tree | 18f6005208f65fbfa2a13f52ae47aeb18ee3bd77 | |
parent | 4fde8d57cfa8236818459adfc4f8bd7d353c153e (diff) |
KVM: X86: Introduce handle_ud()
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>
-rw-r--r-- | arch/x86/kvm/svm.c | 9 | ||||
-rw-r--r-- | arch/x86/kvm/vmx.c | 10 | ||||
-rw-r--r-- | arch/x86/kvm/x86.c | 13 | ||||
-rw-r--r-- | arch/x86/kvm/x86.h | 2 |
4 files changed, 18 insertions, 16 deletions
diff --git a/arch/x86/kvm/svm.c b/arch/x86/kvm/svm.c index f66fc2ee9058..e0a3f56a791d 100644 --- a/arch/x86/kvm/svm.c +++ b/arch/x86/kvm/svm.c | |||
@@ -2676,14 +2676,7 @@ static int bp_interception(struct vcpu_svm *svm) | |||
2676 | 2676 | ||
2677 | static int ud_interception(struct vcpu_svm *svm) | 2677 | static int ud_interception(struct vcpu_svm *svm) |
2678 | { | 2678 | { |
2679 | int er; | 2679 | return handle_ud(&svm->vcpu); |
2680 | |||
2681 | er = emulate_instruction(&svm->vcpu, EMULTYPE_TRAP_UD); | ||
2682 | if (er == EMULATE_USER_EXIT) | ||
2683 | return 0; | ||
2684 | if (er != EMULATE_DONE) | ||
2685 | kvm_queue_exception(&svm->vcpu, UD_VECTOR); | ||
2686 | return 1; | ||
2687 | } | 2680 | } |
2688 | 2681 | ||
2689 | static int ac_interception(struct vcpu_svm *svm) | 2682 | static int ac_interception(struct vcpu_svm *svm) |
diff --git a/arch/x86/kvm/vmx.c b/arch/x86/kvm/vmx.c index a1572461786e..59d91516a622 100644 --- a/arch/x86/kvm/vmx.c +++ b/arch/x86/kvm/vmx.c | |||
@@ -6434,14 +6434,8 @@ static int handle_exception(struct kvm_vcpu *vcpu) | |||
6434 | if (is_nmi(intr_info)) | 6434 | if (is_nmi(intr_info)) |
6435 | return 1; /* already handled by vmx_vcpu_run() */ | 6435 | return 1; /* already handled by vmx_vcpu_run() */ |
6436 | 6436 | ||
6437 | if (is_invalid_opcode(intr_info)) { | 6437 | if (is_invalid_opcode(intr_info)) |
6438 | er = emulate_instruction(vcpu, EMULTYPE_TRAP_UD); | 6438 | return handle_ud(vcpu); |
6439 | if (er == EMULATE_USER_EXIT) | ||
6440 | return 0; | ||
6441 | if (er != EMULATE_DONE) | ||
6442 | kvm_queue_exception(vcpu, UD_VECTOR); | ||
6443 | return 1; | ||
6444 | } | ||
6445 | 6439 | ||
6446 | error_code = 0; | 6440 | error_code = 0; |
6447 | if (intr_info & INTR_INFO_DELIVER_CODE_MASK) | 6441 | if (intr_info & INTR_INFO_DELIVER_CODE_MASK) |
diff --git a/arch/x86/kvm/x86.c b/arch/x86/kvm/x86.c index 7d9a444f2f24..1eb495e04fd3 100644 --- a/arch/x86/kvm/x86.c +++ b/arch/x86/kvm/x86.c | |||
@@ -4840,6 +4840,19 @@ out: | |||
4840 | } | 4840 | } |
4841 | EXPORT_SYMBOL_GPL(kvm_write_guest_virt_system); | 4841 | EXPORT_SYMBOL_GPL(kvm_write_guest_virt_system); |
4842 | 4842 | ||
4843 | int handle_ud(struct kvm_vcpu *vcpu) | ||
4844 | { | ||
4845 | enum emulation_result er; | ||
4846 | |||
4847 | er = emulate_instruction(vcpu, EMULTYPE_TRAP_UD); | ||
4848 | if (er == EMULATE_USER_EXIT) | ||
4849 | return 0; | ||
4850 | if (er != EMULATE_DONE) | ||
4851 | kvm_queue_exception(vcpu, UD_VECTOR); | ||
4852 | return 1; | ||
4853 | } | ||
4854 | EXPORT_SYMBOL_GPL(handle_ud); | ||
4855 | |||
4843 | static int vcpu_is_mmio_gpa(struct kvm_vcpu *vcpu, unsigned long gva, | 4856 | static int vcpu_is_mmio_gpa(struct kvm_vcpu *vcpu, unsigned long gva, |
4844 | gpa_t gpa, bool write) | 4857 | gpa_t gpa, bool write) |
4845 | { | 4858 | { |
diff --git a/arch/x86/kvm/x86.h b/arch/x86/kvm/x86.h index 1e8617414ee4..7d35ce672989 100644 --- a/arch/x86/kvm/x86.h +++ b/arch/x86/kvm/x86.h | |||
@@ -255,6 +255,8 @@ int kvm_write_guest_virt_system(struct x86_emulate_ctxt *ctxt, | |||
255 | gva_t addr, void *val, unsigned int bytes, | 255 | gva_t addr, void *val, unsigned int bytes, |
256 | struct x86_exception *exception); | 256 | struct x86_exception *exception); |
257 | 257 | ||
258 | int handle_ud(struct kvm_vcpu *vcpu); | ||
259 | |||
258 | void kvm_vcpu_mtrr_init(struct kvm_vcpu *vcpu); | 260 | void kvm_vcpu_mtrr_init(struct kvm_vcpu *vcpu); |
259 | u8 kvm_mtrr_get_guest_memory_type(struct kvm_vcpu *vcpu, gfn_t gfn); | 261 | u8 kvm_mtrr_get_guest_memory_type(struct kvm_vcpu *vcpu, gfn_t gfn); |
260 | bool kvm_mtrr_valid(struct kvm_vcpu *vcpu, u32 msr, u64 data); | 262 | bool kvm_mtrr_valid(struct kvm_vcpu *vcpu, u32 msr, u64 data); |