From: Kouya Shimura Subject: Re: [PATCH] vmx: Fix single step on debugger Date: Thu, 25 Dec 2008 11:53:34 +0900 Message-ID: <7kwsdpklsh.fsf@pingu.sky.yk.fujitsu.co.jp> References: <7kzlipkkf1.fsf@pingu.sky.yk.fujitsu.co.jp> Mime-Version: 1.0 Content-Type: multipart/mixed; boundary="xJIVs4unA0" Content-Transfer-Encoding: 7bit Return-path: In-Reply-To: List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Sender: xen-devel-bounces@lists.xensource.com Errors-To: xen-devel-bounces@lists.xensource.com To: Keir Fraser Cc: xen-devel@lists.xensource.com List-Id: xen-devel@lists.xenproject.org --xJIVs4unA0 Content-Type: text/plain; charset=us-ascii Content-Description: message body text Content-Transfer-Encoding: 7bit Keir Fraser writes: > On 22/12/2008 02:34, "Kouya Shimura" wrote: > > > Indeed, this fix is hacky but it works well for me. > > > > At first, I tried setting GUEST_PENDING_DBG_EXCEPTIONS.BS > > according to the SDM. As a result, the guest doesn't be killed > > but never go progress after the STI instruction > > (i.e. VM exit immediately after VM entry) as long as RFLAGS.TF=1. > > That is inconvenient for debugging. > > > > Is there any other way? > > If you make it conditional on debugger_attached then I guess you can do what > you like. I strongly dislike it though. > > -- Keir > I read the SDM carefully, however, I can't find any solution for this. Although the monitor trap flag might help, my machine doesn't have such a feature. At least, crashing the guest should be avoided. Attached is the updated patch. I think it might become a little better. Thanks, Kouya Signed-off-by: Kouya Shimura --xJIVs4unA0 Content-Type: text/x-patch Content-Disposition: inline; filename="STI_single_step2.patch" Content-Transfer-Encoding: 7bit diff -r e2f36d066b7b xen/arch/x86/hvm/vmx/vmx.c --- a/xen/arch/x86/hvm/vmx/vmx.c Mon Dec 22 13:48:40 2008 +0000 +++ b/xen/arch/x86/hvm/vmx/vmx.c Thu Dec 25 11:50:56 2008 +0900 @@ -1314,8 +1314,29 @@ static void vmx_set_info_guest(struct vcpu *v) { + unsigned long intr_shadow; + vmx_vmcs_enter(v); + __vmwrite(GUEST_DR7, v->arch.guest_context.debugreg[7]); + + /* + * If the interruptibility-state field indicates blocking by STI, + * setting the TF flag in the EFLAGS may cause VM entry to fail + * and crash the guest. See SDM 3B 22.3.1.5. + * Resetting the VMX_INTR_SHADOW_STI flag looks hackish but + * to set the GUEST_PENDING_DBG_EXCEPTIONS.BS here incurs + * immediately vmexit and hence make no progress. + */ + intr_shadow = __vmread(GUEST_INTERRUPTIBILITY_INFO); + if ( v->domain->debugger_attached && + (v->arch.guest_context.user_regs.eflags & X86_EFLAGS_TF) && + (intr_shadow & VMX_INTR_SHADOW_STI) ) + { + intr_shadow &= ~VMX_INTR_SHADOW_STI; + __vmwrite(GUEST_INTERRUPTIBILITY_INFO, intr_shadow); + } + vmx_vmcs_exit(v); } --xJIVs4unA0 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 --xJIVs4unA0--