From: Tim Deegan Subject: [PATCH] SVM: handle page faults in emaulted instruction fetches Date: Mon, 10 Mar 2008 13:36:47 +0000 Message-ID: <20080310133647.GB22422@york.uk.xensource.com> Mime-Version: 1.0 Content-Type: multipart/mixed; boundary="wRRV7LY7NUeQGEoC" Return-path: Content-Disposition: inline List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Sender: xen-devel-bounces@lists.xensource.com Errors-To: xen-devel-bounces@lists.xensource.com To: xen-devel@lists.xensource.com List-Id: xen-devel@lists.xenproject.org --wRRV7LY7NUeQGEoC Content-Type: text/plain; charset=iso-8859-1 Content-Disposition: inline Deal with failures in hvm_copy_from_guest_virt when fetching instructions in the various SVM emulation paths. Since we know that the instruction was fetchable by the hardware, we can usually just return from the VMEXIT and try again; whatever caused us to fail will cause the hardware to fail next time and we'll get the correct exit code. Signed-off-by: Tim Deegan -- Tim Deegan Principal Software Engineer, Citrix Systems (R&D) Ltd. [Company #02300071, SL9 0DZ, UK.] --wRRV7LY7NUeQGEoC Content-Type: text/plain; charset=iso-8859-1 Content-Disposition: attachment; filename="ifetch-unstable.patch" diff -r 59b8768d0d0d xen/arch/x86/hvm/svm/emulate.c --- a/xen/arch/x86/hvm/svm/emulate.c Wed Mar 05 11:18:25 2008 +0000 +++ b/xen/arch/x86/hvm/svm/emulate.c Mon Mar 10 13:05:14 2008 +0000 @@ -117,7 +117,9 @@ int __get_instruction_length_from_list(s } else { - inst_copy_from_guest(buffer, svm_rip2pointer(v), MAX_INST_LEN); + if ( inst_copy_from_guest(buffer, svm_rip2pointer(v), MAX_INST_LEN) + != MAX_INST_LEN ) + return 0; buf = buffer; } diff -r 59b8768d0d0d xen/arch/x86/hvm/svm/svm.c --- a/xen/arch/x86/hvm/svm/svm.c Wed Mar 05 11:18:25 2008 +0000 +++ b/xen/arch/x86/hvm/svm/svm.c Mon Mar 10 13:09:45 2008 +0000 @@ -943,6 +943,10 @@ static void svm_vmexit_do_cpuid(struct c { unsigned int eax, ebx, ecx, edx, inst_len; + inst_len = __get_instruction_length(current, INSTR_CPUID, NULL); + if ( inst_len == 0 ) + return; + eax = regs->eax; ebx = regs->ebx; ecx = regs->ecx; @@ -955,7 +959,6 @@ static void svm_vmexit_do_cpuid(struct c regs->ecx = ecx; regs->edx = edx; - inst_len = __get_instruction_length(current, INSTR_CPUID, NULL); __update_guest_eip(regs, inst_len); } @@ -1166,6 +1169,8 @@ static void svm_vmexit_do_hlt(struct vmc unsigned int inst_len; inst_len = __get_instruction_length(curr, INSTR_HLT, NULL); + if ( inst_len == 0 ) + return 0; __update_guest_eip(regs, inst_len); /* Check for pending exception or new interrupt. */ @@ -1354,6 +1359,8 @@ asmlinkage void svm_vmexit_handler(struc case VMEXIT_VMMCALL: inst_len = __get_instruction_length(v, INSTR_VMCALL, NULL); + if ( inst_len == 0 ) + break; HVMTRACE_1D(VMMCALL, v, regs->eax); rc = hvm_do_hypercall(regs); if ( rc != HVM_HCALL_preempted ) --wRRV7LY7NUeQGEoC Content-Type: text/plain; charset=iso-8859-1 Content-Disposition: attachment; filename="ifetch-3.2.patch" diff -r a1938d7eebb6 xen/arch/x86/hvm/svm/emulate.c --- a/xen/arch/x86/hvm/svm/emulate.c Mon Mar 10 13:01:40 2008 +0000 +++ b/xen/arch/x86/hvm/svm/emulate.c Mon Mar 10 13:01:40 2008 +0000 @@ -435,7 +435,9 @@ int __get_instruction_length_from_list(s } else { - inst_copy_from_guest(buffer, svm_rip2pointer(v), MAX_INST_LEN); + if ( inst_copy_from_guest(buffer, svm_rip2pointer(v), MAX_INST_LEN) + != MAX_INST_LEN ) + return 0; buf = buffer; } diff -r a1938d7eebb6 xen/arch/x86/hvm/svm/svm.c --- a/xen/arch/x86/hvm/svm/svm.c Mon Mar 10 13:01:40 2008 +0000 +++ b/xen/arch/x86/hvm/svm/svm.c Mon Mar 10 13:02:32 2008 +0000 @@ -1128,7 +1128,7 @@ static void svm_dr_access(struct vcpu *v } -static void svm_get_prefix_info(struct vcpu *v, unsigned int dir, +static int svm_get_prefix_info(struct vcpu *v, unsigned int dir, svm_segment_register_t **seg, unsigned int *asize) { @@ -1141,8 +1141,7 @@ static void svm_get_prefix_info(struct v != MAX_INST_LEN) { gdprintk(XENLOG_ERR, "get guest instruction failed\n"); - domain_crash(current->domain); - return; + return 0; } for (i = 0; i < MAX_INST_LEN; i++) @@ -1200,8 +1199,9 @@ static void svm_get_prefix_info(struct v default: break; } - return; - } + break; + } + return 1; } @@ -1236,7 +1236,8 @@ static int svm_get_io_address( isize --; if (isize > 1) - svm_get_prefix_info(v, info.fields.type, &seg, &asize); + if ( !svm_get_prefix_info(v, info.fields.type, &seg, &asize) ) + return 0; if (info.fields.type == IOREQ_WRITE) { @@ -1591,7 +1592,10 @@ static void svm_cr_access( enum instruction_index list_b[] = {INSTR_MOVCR2, INSTR_SMSW}; enum instruction_index match; - inst_copy_from_guest(buffer, svm_rip2pointer(v), sizeof(buffer)); + if ( inst_copy_from_guest(buffer, svm_rip2pointer(v), sizeof(buffer)) + != sizeof buffer ) + /* #PF will have been delivered if appropriate. */ + return; /* get index to first actual instruction byte - as we will need to know where the prefix lives later on */ @@ -1607,6 +1611,9 @@ static void svm_cr_access( inst_len = __get_instruction_length_from_list( v, list_b, ARRAY_SIZE(list_b), &buffer[index], &match); } + + if ( inst_len == 0 ) + return; inst_len += index; @@ -1940,7 +1947,7 @@ void svm_handle_invlpg(const short invlp if ( inst_copy_from_guest(opcode, svm_rip2pointer(v), length) < length ) { gdprintk(XENLOG_ERR, "Error reading memory %d bytes\n", length); - goto crash; + return; } if ( invlpga ) @@ -2055,6 +2062,8 @@ asmlinkage void svm_vmexit_handler(struc goto exit_and_crash; /* AMD Vol2, 15.11: INT3, INTO, BOUND intercepts do not update RIP. */ inst_len = __get_instruction_length(v, INSTR_INT3, NULL); + if ( inst_len == 0 ) + break; __update_guest_eip(regs, inst_len); domain_pause_for_debugger(); break; @@ -2131,6 +2140,8 @@ asmlinkage void svm_vmexit_handler(struc case VMEXIT_VMMCALL: inst_len = __get_instruction_length(v, INSTR_VMCALL, NULL); + if ( inst_len == 0 ) + break; HVMTRACE_1D(VMMCALL, v, regs->eax); rc = hvm_do_hypercall(regs); if ( rc != HVM_HCALL_preempted ) --wRRV7LY7NUeQGEoC Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Content-Disposition: inline _______________________________________________ Xen-devel mailing list Xen-devel@lists.xensource.com http://lists.xensource.com/xen-devel --wRRV7LY7NUeQGEoC--