Call x86_decode_insn() only when needed
PATCH 5/5 Call x86_decode_insn() only when needed
move emulate_ctxt to kvm_vcpu to keep emulate context when we exit from kvm module. Call x86_decode_insn() only when needed. Modify x86_emulate_insn() to not modify the context if it must be re-entered.
drivers/kvm/kvm.h +7 -1
@@ -206,6 +206,8 @@ enum { VCPU_SREG_LDTR, }; +#include "x86_emulate.h" +struct kvm_pio_request {unsigned long count;int cur_count;
@@ -372,6 +374,10 @@ struct kvm_vcpu {int cpuid_nent;struct kvm_cpuid_entry cpuid_entries[KVM_MAX_CPUID_ENTRIES ]; + +/* emulate context */ + +struct x86_emulate_ctxt emulate_ctxt; };struct kvm_mem_alias {
@@ -525,7 +531,7 @@ enum emulation_result { };int emulate_instruction (struct kvm_vcpu *vcpu,struct kvm_run *run, -unsigned long cr2,u16 error_code); +unsigned long cr2,u16 error_code,int no_decode);void realmode_lgdt (struct kvm_vcpu *vcpu,u16 size,unsigned long address);void realmode_lidt (struct kvm_vcpu *vcpu,u16 size,unsigned long address); void realmode_lmsw(struct kvm_vcpu *vcpu, unsigned long msw,
drivers/kvm/kvm_main.c +42 -33
110 lines not on this page · raw message
drivers/kvm/svm.c +4 -3
@@ -938,7 +938,7 @@ static int pf_interception(struct vcpu_sreturn 1 ; } er =emulate_instruction (&svm->vcpu, kvm_run, fault_address, - error_code); + error_code,0 );mutex_unlock (&kvm->lock);switch (er) {
@@ -994,7 +994,8 @@ static int io_interception(struct vcpu_s string = (io_info &SVM_IOIO_STR_MASK ) !=0 ;if (string) { -if (emulate_instruction (&svm->vcpu, kvm_run,0 ,0 ) ==EMULATE_DO_MMIO ) +if (emulate_instruction (&svm->vcpu, + kvm_run,0 ,0 ,0 ) ==EMULATE_DO_MMIO )return 0 ;return 1 ; }
@@ -1052,7 +1053,7 @@ static int cpuid_interception(struct vcpstatic int emulate_on_interception (struct vcpu_svm *svm,struct kvm_run *kvm_run) { -if (emulate_instruction (&svm->vcpu,NULL ,0 ,0 ) !=EMULATE_DONE ) +if (emulate_instruction (&svm->vcpu,NULL ,0 ,0 ,0 ) !=EMULATE_DONE )pr_unimpl (&svm->vcpu,"%s: failed\n" , __FUNCTION__);return 1 ; }
drivers/kvm/vmx.c +4 -3
@@ -1659,7 +1659,7 @@ static int handle_rmode_exception(struct* Cause the #SS fault with 0 error code in VM86 mode. */ if (((vec ==GP_VECTOR ) || (vec ==SS_VECTOR )) && err_code ==0 ) -if (emulate_instruction (vcpu,NULL ,0 ,0 ) ==EMULATE_DONE ) +if (emulate_instruction (vcpu,NULL ,0 ,0 ,0 ) ==EMULATE_DONE )return 1 ;return 0 ; }
@@ -1715,7 +1715,7 @@ static int handle_exception(struct kvm_vreturn 1 ; } - er =emulate_instruction (vcpu, kvm_run, cr2, error_code); + er =emulate_instruction (vcpu, kvm_run, cr2, error_code,0 );mutex_unlock (&vcpu->kvm->lock);switch (er) {
@@ -1776,7 +1776,8 @@ static int handle_io(struct kvm_vcpu *vc string = (exit_qualification &16 ) !=0 ;if (string) { -if (emulate_instruction (vcpu, kvm_run,0 ,0 ) ==EMULATE_DO_MMIO ) +if (emulate_instruction (vcpu, + kvm_run,0 ,0 ,0 ) ==EMULATE_DO_MMIO )return 0 ;return 1 ; }
drivers/kvm/x86_emulate.c +24 -3
@@ -888,8 +888,12 @@ x86_emulate_insn(struct x86_emulate_ctxtint mode = ctxt->mode;int no_wb =0 ;u64 msr_data; +unsigned long saved_rcx =0 , saved_eip =0 ;unsigned long _eflags = ctxt->eflags; +if ((decode->d & ModRM) && (decode->modrm_mod !=3 )) + ctxt->cr2 = decode->modrm_ea; + if (decode->src.type == OP_MEM) { decode->src.ptr = (unsigned long *)ctxt->cr2; if ((rc = ops->read_emulated((unsigned long)decode->src.ptr,
@@ -1274,6 +1278,8 @@ special_insn: ctxt->vcpu->rip = decode->eip; goto done; } + saved_rcx = ctxt->decode.regs[VCPU_REGS_RCX ]; + saved_eip = ctxt->decode.eip; decode->regs[VCPU_REGS_RCX ]--; decode->eip = ctxt->vcpu->rip; }
@@ -1289,8 +1295,13 @@ special_insn: ctxt->ds_base, decode->regs[VCPU_REGS_RSI]), &decode->dst.val, - decode->dst.bytes, ctxt->vcpu)) != 0) + decode->dst.bytes, ctxt->vcpu)) != 0) { +if (ctxt->decode.rep_prefix) { + ctxt->decode.regs[VCPU_REGS_RCX ] = saved_rcx; + ctxt->decode.eip = saved_eip; + } goto done; + }register_address_increment (decode->regs[VCPU_REGS_RSI ], (_eflags &EFLG_DF ) ? -decode->dst.bytes : decode->dst.bytes);
@@ -1316,8 +1327,13 @@ special_insn: decode->dst.ptr = (unsigned long *)&decode->regs[VCPU_REGS_RAX ];if ((rc = ops->read_emulated (ctxt->cr2, &decode->dst.val, decode->dst.bytes, - ctxt->vcpu)) !=0 ) + ctxt->vcpu)) !=0 ) { +if (ctxt->decode.rep_prefix) { + ctxt->decode.regs[VCPU_REGS_RCX ] = saved_rcx; + ctxt->decode.eip = saved_eip; + } goto done; + }register_address_increment (decode->regs[VCPU_REGS_RSI ], (_eflags &EFLG_DF ) ? -decode->dst.bytes : decode->dst.bytes);
@@ -1338,8 +1354,13 @@ special_insn: pop_instruction:if ((rc = ops->read_std (register_address (ctxt->ss_base, decode->regs[VCPU_REGS_RSP ]), decode->dst.ptr, - decode->op_bytes, ctxt->vcpu)) !=0 ) + decode->op_bytes, ctxt->vcpu)) !=0 ) { +if (ctxt->decode.rep_prefix) { + ctxt->decode.regs[VCPU_REGS_RCX ] = saved_rcx; + ctxt->decode.eip = saved_eip; + } goto done; + }register_address_increment (decode->regs[VCPU_REGS_RSP ], decode->op_bytes);
-------------------------------------------------------------------------
This SF.net email is sponsored by: Splunk Inc.
Still grepping through log files to find problems? Stop. Now Search log events and configuration files using AJAX and a browser. Download your FREE copy of Splunk now >> http://get.splunk.com/
_______________________________________________
kvm-devel mailing list [email protected]
https://lists.sourceforge.net/lists/listinfo/kvm-devel
A message that is not in the archive (sent off-list or not yet received): 46D5A2B0.7050802-6ktuUTfB/[email protected]
Review static int kvm_vcpu_ioctl_run(struct kvm · line 1875
Quoted 10 lines · Laurent Vivier
Index:
kvm/drivers/kvm/kvm.h(quoted diff) +1
-1@@ -1860,7 +1869,7 @@ static int kvm_vcpu_ioctl_run(struct kvm vcpu->mmio_read_completed = 1; vcpu->mmio_needed = 0; r = emulate_instruction(vcpu, kvm_run, - vcpu->mmio_fault_cr2, 0); + vcpu->mmio_fault_cr2, 0, 0); if (r == EMULATE_DO_MMIO) { /* * Read-modify-write. Back to userspace.
Sorry this one is wrong, we must have here:
+ vcpu->mmio_fault_cr2, 0, 1);
(good patch attached)
Laurent
Signature · 2 lines
------------- Laurent.Vivier-6ktuUTfB/[email protected] -------------- "Software is hard" - Donald Knuth
drivers/kvm/kvm.h +7 -1
@@ -206,6 +206,8 @@ enum { VCPU_SREG_LDTR, }; +#include "x86_emulate.h" +struct kvm_pio_request {unsigned long count;int cur_count;
@@ -372,6 +374,10 @@ struct kvm_vcpu {int cpuid_nent;struct kvm_cpuid_entry cpuid_entries[KVM_MAX_CPUID_ENTRIES ]; + +/* emulate context */ + +struct x86_emulate_ctxt emulate_ctxt; };struct kvm_mem_alias {
@@ -525,7 +531,7 @@ enum emulation_result { };int emulate_instruction (struct kvm_vcpu *vcpu,struct kvm_run *run, -unsigned long cr2,u16 error_code); +unsigned long cr2,u16 error_code,int no_decode);void realmode_lgdt (struct kvm_vcpu *vcpu,u16 size,unsigned long address);void realmode_lidt (struct kvm_vcpu *vcpu,u16 size,unsigned long address); void realmode_lmsw(struct kvm_vcpu *vcpu, unsigned long msw,
drivers/kvm/kvm_main.c +42 -33
110 lines not on this page · raw message
drivers/kvm/svm.c +4 -3
@@ -938,7 +938,7 @@ static int pf_interception(struct vcpu_sreturn 1 ; } er =emulate_instruction (&svm->vcpu, kvm_run, fault_address, - error_code); + error_code,0 );mutex_unlock (&kvm->lock);switch (er) {
@@ -994,7 +994,8 @@ static int io_interception(struct vcpu_s string = (io_info &SVM_IOIO_STR_MASK ) !=0 ;if (string) { -if (emulate_instruction (&svm->vcpu, kvm_run,0 ,0 ) ==EMULATE_DO_MMIO ) +if (emulate_instruction (&svm->vcpu, + kvm_run,0 ,0 ,0 ) ==EMULATE_DO_MMIO )return 0 ;return 1 ; }
@@ -1052,7 +1053,7 @@ static int cpuid_interception(struct vcpstatic int emulate_on_interception (struct vcpu_svm *svm,struct kvm_run *kvm_run) { -if (emulate_instruction (&svm->vcpu,NULL ,0 ,0 ) !=EMULATE_DONE ) +if (emulate_instruction (&svm->vcpu,NULL ,0 ,0 ,0 ) !=EMULATE_DONE )pr_unimpl (&svm->vcpu,"%s: failed\n" , __FUNCTION__);return 1 ; }
drivers/kvm/vmx.c +4 -3
@@ -1659,7 +1659,7 @@ static int handle_rmode_exception(struct* Cause the #SS fault with 0 error code in VM86 mode. */ if (((vec ==GP_VECTOR ) || (vec ==SS_VECTOR )) && err_code ==0 ) -if (emulate_instruction (vcpu,NULL ,0 ,0 ) ==EMULATE_DONE ) +if (emulate_instruction (vcpu,NULL ,0 ,0 ,0 ) ==EMULATE_DONE )return 1 ;return 0 ; }
@@ -1715,7 +1715,7 @@ static int handle_exception(struct kvm_vreturn 1 ; } - er =emulate_instruction (vcpu, kvm_run, cr2, error_code); + er =emulate_instruction (vcpu, kvm_run, cr2, error_code,0 );mutex_unlock (&vcpu->kvm->lock);switch (er) {
@@ -1776,7 +1776,8 @@ static int handle_io(struct kvm_vcpu *vc string = (exit_qualification &16 ) !=0 ;if (string) { -if (emulate_instruction (vcpu, kvm_run,0 ,0 ) ==EMULATE_DO_MMIO ) +if (emulate_instruction (vcpu, + kvm_run,0 ,0 ,0 ) ==EMULATE_DO_MMIO )return 0 ;return 1 ; }
drivers/kvm/x86_emulate.c +24 -3
@@ -888,8 +888,12 @@ x86_emulate_insn(struct x86_emulate_ctxtint mode = ctxt->mode;int no_wb =0 ;u64 msr_data; +unsigned long saved_rcx =0 , saved_eip =0 ;unsigned long _eflags = ctxt->eflags; +if ((decode->d & ModRM) && (decode->modrm_mod !=3 )) + ctxt->cr2 = decode->modrm_ea; + if (decode->src.type == OP_MEM) { decode->src.ptr = (unsigned long *)ctxt->cr2; if ((rc = ops->read_emulated((unsigned long)decode->src.ptr,
@@ -1274,6 +1278,8 @@ special_insn: ctxt->vcpu->rip = decode->eip; goto done; } + saved_rcx = ctxt->decode.regs[VCPU_REGS_RCX ]; + saved_eip = ctxt->decode.eip; decode->regs[VCPU_REGS_RCX ]--; decode->eip = ctxt->vcpu->rip; }
@@ -1289,8 +1295,13 @@ special_insn: ctxt->ds_base, decode->regs[VCPU_REGS_RSI]), &decode->dst.val, - decode->dst.bytes, ctxt->vcpu)) != 0) + decode->dst.bytes, ctxt->vcpu)) != 0) { +if (ctxt->decode.rep_prefix) { + ctxt->decode.regs[VCPU_REGS_RCX ] = saved_rcx; + ctxt->decode.eip = saved_eip; + } goto done; + }register_address_increment (decode->regs[VCPU_REGS_RSI ], (_eflags &EFLG_DF ) ? -decode->dst.bytes : decode->dst.bytes);
@@ -1316,8 +1327,13 @@ special_insn: decode->dst.ptr = (unsigned long *)&decode->regs[VCPU_REGS_RAX ];if ((rc = ops->read_emulated (ctxt->cr2, &decode->dst.val, decode->dst.bytes, - ctxt->vcpu)) !=0 ) + ctxt->vcpu)) !=0 ) { +if (ctxt->decode.rep_prefix) { + ctxt->decode.regs[VCPU_REGS_RCX ] = saved_rcx; + ctxt->decode.eip = saved_eip; + } goto done; + }register_address_increment (decode->regs[VCPU_REGS_RSI ], (_eflags &EFLG_DF ) ? -decode->dst.bytes : decode->dst.bytes);
@@ -1338,8 +1354,13 @@ special_insn: pop_instruction:if ((rc = ops->read_std (register_address (ctxt->ss_base, decode->regs[VCPU_REGS_RSP ]), decode->dst.ptr, - decode->op_bytes, ctxt->vcpu)) !=0 ) + decode->op_bytes, ctxt->vcpu)) !=0 ) { +if (ctxt->decode.rep_prefix) { + ctxt->decode.regs[VCPU_REGS_RCX ] = saved_rcx; + ctxt->decode.eip = saved_eip; + } goto done; + }register_address_increment (decode->regs[VCPU_REGS_RSP ], decode->op_bytes);
-------------------------------------------------------------------------
This SF.net email is sponsored by: Splunk Inc.
Still grepping through log files to find problems? Stop. Now Search log events and configuration files using AJAX and a browser. Download your FREE copy of Splunk now >> http://get.splunk.com/
_______________________________________________
kvm-devel mailing list [email protected]
https://lists.sourceforge.net/lists/listinfo/kvm-devel