Aravindh Puthiyaparambil
2011-May-27 03:39 UTC
[Xen-devel] [PATCH] mem_event: Allow memory access listener to perform single step execution
# HG changeset patch # User Aravindh Puthiyaparambil <aravindh@virtuata.com> # Date 1306467255 25200 # Node ID 193b5d38ae4b5f4e6c18c68328d67d5cf0d76bef # Parent 37c77bacb52aa7795978b994f9d371b979b2cb07 mem_event: Allow memory access listener to perform single step execution. Add a new memory event that handles single step. This allows the memory access listener to handle instructions that modify data within the execution page. This can be enabled in the listener by doing: xc_set_hvm_param(xch, domain_id, HVM_PARAM_MEMORY_EVENT_SINGLE_STEP, HVMPME_mode_sync) Now the listener can start single stepping by: xc_domain_debug_control(xch, domain_id, XEN_DOMCTL_DEBUG_OP_SINGLE_STEP_ON, vcpu_id) And stop single stepping by: xc_domain_debug_control(xch, domain_id, XEN_DOMCTL_DEBUG_OP_SINGLE_STEP_OFF, vcpu_id) Signed-off-by: Aravindh Puthiyaparambil <aravindh@virtuata.com> diff -r 37c77bacb52a -r 193b5d38ae4b xen/arch/x86/hvm/hvm.c --- a/xen/arch/x86/hvm/hvm.c Mon May 23 17:38:28 2011 +0100 +++ b/xen/arch/x86/hvm/hvm.c Thu May 26 20:34:15 2011 -0700 @@ -3489,7 +3489,8 @@ rc = -EPERM; break; case HVM_PARAM_MEMORY_EVENT_INT3: - if ( d == current->domain ) + case HVM_PARAM_MEMORY_EVENT_SINGLE_STEP: + if ( d == current->domain ) { rc = -EPERM; break; @@ -3522,6 +3523,7 @@ switch( a.index ) { case HVM_PARAM_MEMORY_EVENT_INT3: + case HVM_PARAM_MEMORY_EVENT_SINGLE_STEP: { domain_pause(d); domain_unpause(d); /* Causes guest to latch new status */ @@ -4040,11 +4042,21 @@ rc = -ENOSYS; if ( !cpu_has_monitor_trap_flag ) break; - rc = 0; - vcpu_pause(v); + + rc = mem_event_check_ring(v->domain); + /* rc ==0 p2m_mem_access_check() has already paused the vcpu */ + if ( rc < 0 ) + vcpu_pause(v); + v->arch.hvm_vcpu.single_step (op == XEN_DOMCTL_DEBUG_OP_SINGLE_STEP_ON); - vcpu_unpause(v); /* guest will latch new state */ + + /* rc ==0 p2m_mem_access_resume() will unpause the vcpu */ + if ( rc < 0 ) + { + vcpu_unpause(v); /* guest will latch new state */ + rc = 0; + } break; default: rc = -ENOSYS; @@ -4133,6 +4145,18 @@ MEM_EVENT_REASON_INT3, gfn, 0, 1, gla); } + +int hvm_memory_event_single_step(unsigned long gla) +{ + uint32_t pfec = PFEC_page_present; + unsigned long gfn; + gfn = paging_gva_to_gfn(current, gla, &pfec); + + return hvm_memory_event_traps(current->domain->arch.hvm_domain + .params[HVM_PARAM_MEMORY_EVENT_SINGLE_STEP], + MEM_EVENT_REASON_SINGLESTEP, + gfn, 0, 1, gla); +} #endif /* __x86_64__ */ int nhvm_vcpu_hostrestore(struct vcpu *v, struct cpu_user_regs *regs) diff -r 37c77bacb52a -r 193b5d38ae4b xen/arch/x86/hvm/vmx/vmcs.c --- a/xen/arch/x86/hvm/vmx/vmcs.c Mon May 23 17:38:28 2011 +0100 +++ b/xen/arch/x86/hvm/vmx/vmcs.c Thu May 26 20:34:15 2011 -0700 @@ -1081,8 +1081,9 @@ hvm_asid_flush_vcpu(v); } - debug_state = v->domain->debugger_attached - || v->domain->arch.hvm_domain.params[HVM_PARAM_MEMORY_EVENT_INT3]; + debug_state = v->domain->debugger_attached + || v->domain->arch.hvm_domain.params[HVM_PARAM_MEMORY_EVENT_INT3] + || v->domain->arch.hvm_domain.params[HVM_PARAM_MEMORY_EVENT_SINGLE_STEP]; if ( unlikely(v->arch.hvm_vcpu.debug_state_latch != debug_state) ) { diff -r 37c77bacb52a -r 193b5d38ae4b xen/arch/x86/hvm/vmx/vmx.c --- a/xen/arch/x86/hvm/vmx/vmx.c Mon May 23 17:38:28 2011 +0100 +++ b/xen/arch/x86/hvm/vmx/vmx.c Thu May 26 20:34:15 2011 -0700 @@ -2494,8 +2494,12 @@ case EXIT_REASON_MONITOR_TRAP_FLAG: v->arch.hvm_vmx.exec_control &= ~CPU_BASED_MONITOR_TRAP_FLAG; vmx_update_cpu_exec_control(v); - if ( v->domain->debugger_attached && v->arch.hvm_vcpu.single_step ) - domain_pause_for_debugger(); + if ( v->arch.hvm_vcpu.single_step ) { + hvm_memory_event_single_step(regs->eip); + if ( v->domain->debugger_attached ) + domain_pause_for_debugger(); + } + break; case EXIT_REASON_PAUSE_INSTRUCTION: diff -r 37c77bacb52a -r 193b5d38ae4b xen/include/asm-x86/hvm/hvm.h --- a/xen/include/asm-x86/hvm/hvm.h Mon May 23 17:38:28 2011 +0100 +++ b/xen/include/asm-x86/hvm/hvm.h Thu May 26 20:34:15 2011 -0700 @@ -405,6 +405,10 @@ void hvm_memory_event_cr4(unsigned long value, unsigned long old); /* Called for current VCPU on int3: returns -1 if no listener */ int hvm_memory_event_int3(unsigned long gla); + +/* Called for current VCPU on single step: returns -1 if no listener */ +int hvm_memory_event_single_step(unsigned long gla); + #else static inline void hvm_memory_event_cr0(unsigned long value, unsigned long old) { } @@ -414,6 +418,8 @@ { } static inline int hvm_memory_event_int3(unsigned long gla) { return 0; } +static inline int hvm_memory_event_single_step(unsigned long gla) +{ return 0; } #endif /* diff -r 37c77bacb52a -r 193b5d38ae4b xen/include/public/hvm/params.h --- a/xen/include/public/hvm/params.h Mon May 23 17:38:28 2011 +0100 +++ b/xen/include/public/hvm/params.h Thu May 26 20:34:15 2011 -0700 @@ -126,10 +126,11 @@ /* Enable blocking memory events, async or sync (pause vcpu until response) * onchangeonly indicates messages only on a change of value */ -#define HVM_PARAM_MEMORY_EVENT_CR0 20 -#define HVM_PARAM_MEMORY_EVENT_CR3 21 -#define HVM_PARAM_MEMORY_EVENT_CR4 22 -#define HVM_PARAM_MEMORY_EVENT_INT3 23 +#define HVM_PARAM_MEMORY_EVENT_CR0 20 +#define HVM_PARAM_MEMORY_EVENT_CR3 21 +#define HVM_PARAM_MEMORY_EVENT_CR4 22 +#define HVM_PARAM_MEMORY_EVENT_INT3 23 +#define HVM_PARAM_MEMORY_EVENT_SINGLE_STEP 25 #define HVMPME_MODE_MASK (3 << 0) #define HVMPME_mode_disabled 0 @@ -140,6 +141,6 @@ /* Boolean: Enable nestedhvm (hvm only) */ #define HVM_PARAM_NESTEDHVM 24 -#define HVM_NR_PARAMS 25 +#define HVM_NR_PARAMS 26 #endif /* __XEN_PUBLIC_HVM_PARAMS_H__ */ diff -r 37c77bacb52a -r 193b5d38ae4b xen/include/public/mem_event.h --- a/xen/include/public/mem_event.h Mon May 23 17:38:28 2011 +0100 +++ b/xen/include/public/mem_event.h Thu May 26 20:34:15 2011 -0700 @@ -46,6 +46,7 @@ #define MEM_EVENT_REASON_CR3 3 /* CR3 was hit: gfn is CR3 value */ #define MEM_EVENT_REASON_CR4 4 /* CR4 was hit: gfn is CR4 value */ #define MEM_EVENT_REASON_INT3 5 /* int3 was hit: gla/gfn are RIP */ +#define MEM_EVENT_REASON_SINGLESTEP 6 /* single step was invoked: gla/gfn are RIP */ typedef struct mem_event_shared_page { uint32_t port; _______________________________________________ Xen-devel mailing list Xen-devel@lists.xensource.com http://lists.xensource.com/xen-devel
Tim Deegan
2011-May-27 08:39 UTC
Re: [Xen-devel] [PATCH] mem_event: Allow memory access listener to perform single step execution
At 04:39 +0100 on 27 May (1306471145), Aravindh Puthiyaparambil wrote:> mem_event: Allow memory access listener to perform single step execution. > Add a new memory event that handles single step. This allows the memory access listener to handle instructions that modify data within the execution page. > This can be enabled in the listener by doing: > xc_set_hvm_param(xch, domain_id, HVM_PARAM_MEMORY_EVENT_SINGLE_STEP, HVMPME_mode_sync) > > Now the listener can start single stepping by: > xc_domain_debug_control(xch, domain_id, XEN_DOMCTL_DEBUG_OP_SINGLE_STEP_ON, vcpu_id) > > And stop single stepping by: > xc_domain_debug_control(xch, domain_id, XEN_DOMCTL_DEBUG_OP_SINGLE_STEP_OFF, vcpu_id) > > Signed-off-by: Aravindh Puthiyaparambil <aravindh@virtuata.com>Acked-by: Tim Deegan <Tim.Deegan@citrix.com> -- Tim Deegan <Tim.Deegan@citrix.com> Principal Software Engineer, Xen Platform Team Citrix Systems UK Ltd. (Company #02937203, SL9 0BG) _______________________________________________ Xen-devel mailing list Xen-devel@lists.xensource.com http://lists.xensource.com/xen-devel
Aravindh Puthiyaparambil
2011-May-27 16:36 UTC
Re: [Xen-devel] [PATCH] mem_event: Allow memory access listener to perform single step execution
Can this be included in xen-4.1-testing.hg too so that it could make the Xen 4.1.1 cut? Thanks, Aravindh On May 27, 2011 1:39 AM, "Tim Deegan" <Tim.Deegan@citrix.com> wrote:> At 04:39 +0100 on 27 May (1306471145), Aravindh Puthiyaparambil wrote: >> mem_event: Allow memory access listener to perform single step execution. >> Add a new memory event that handles single step. This allows the memoryaccess listener to handle instructions that modify data within the execution page.>> This can be enabled in the listener by doing: >> xc_set_hvm_param(xch, domain_id, HVM_PARAM_MEMORY_EVENT_SINGLE_STEP,HVMPME_mode_sync)>> >> Now the listener can start single stepping by: >> xc_domain_debug_control(xch, domain_id,XEN_DOMCTL_DEBUG_OP_SINGLE_STEP_ON, vcpu_id)>> >> And stop single stepping by: >> xc_domain_debug_control(xch, domain_id,XEN_DOMCTL_DEBUG_OP_SINGLE_STEP_OFF, vcpu_id)>> >> Signed-off-by: Aravindh Puthiyaparambil <aravindh@virtuata.com> > > Acked-by: Tim Deegan <Tim.Deegan@citrix.com> > > -- > Tim Deegan <Tim.Deegan@citrix.com> > Principal Software Engineer, Xen Platform Team > Citrix Systems UK Ltd. (Company #02937203, SL9 0BG)_______________________________________________ Xen-devel mailing list Xen-devel@lists.xensource.com http://lists.xensource.com/xen-devel
Keir Fraser
2011-May-28 07:53 UTC
Re: [Xen-devel] [PATCH] mem_event: Allow memory access listener to perform single step execution
I removed and unrelated and pointless change that broke the x86_32 build, as c/s 23435. If that change is okay for you, I could backport the combination of 23434+23435 to 4.1.1. -- Keir On 27/05/2011 17:36, "Aravindh Puthiyaparambil" <aravindh@virtuata.com> wrote:> Can this be included in xen-4.1-testing.hg too so that it could make the Xen > 4.1.1 cut? > > Thanks, > Aravindh > > On May 27, 2011 1:39 AM, "Tim Deegan" <Tim.Deegan@citrix.com> wrote: >> At 04:39 +0100 on 27 May (1306471145), Aravindh Puthiyaparambil wrote: >>> mem_event: Allow memory access listener to perform single step execution. >>> Add a new memory event that handles single step. This allows the memory >>> access listener to handle instructions that modify data within the execution >>> page. >>> This can be enabled in the listener by doing: >>> xc_set_hvm_param(xch, domain_id, HVM_PARAM_MEMORY_EVENT_SINGLE_STEP, >>> HVMPME_mode_sync) >>> >>> Now the listener can start single stepping by: >>> xc_domain_debug_control(xch, domain_id, XEN_DOMCTL_DEBUG_OP_SINGLE_STEP_ON, >>> vcpu_id) >>> >>> And stop single stepping by: >>> xc_domain_debug_control(xch, domain_id, XEN_DOMCTL_DEBUG_OP_SINGLE_STEP_OFF, >>> vcpu_id) >>> >>> Signed-off-by: Aravindh Puthiyaparambil <aravindh@virtuata.com> >> >> Acked-by: Tim Deegan <Tim.Deegan@citrix.com> >> >> -- >> Tim Deegan <Tim.Deegan@citrix.com> >> Principal Software Engineer, Xen Platform Team >> Citrix Systems UK Ltd. (Company #02937203, SL9 0BG) > > > _______________________________________________ > Xen-devel mailing list > Xen-devel@lists.xensource.com > http://lists.xensource.com/xen-devel_______________________________________________ Xen-devel mailing list Xen-devel@lists.xensource.com http://lists.xensource.com/xen-devel
Aravindh Puthiyaparambil
2011-May-28 17:48 UTC
Re: [Xen-devel] [PATCH] mem_event: Allow memory access listener to perform single step execution
On Sat, May 28, 2011 at 12:53 AM, Keir Fraser <keir@xen.org> wrote:> I removed and unrelated and pointless change that broke the x86_32 build, as > c/s 23435. If that change is okay for you, I could backport the combination > of 23434+23435 to 4.1.1.Keir, Sorry about the build breakage. I will test the 32-bit side of things also in the future. I did not realize VCPU pausing was nestable. So even after the vcpu_unpause() in hvm_debug_op(), the VCPU will still be paused because of the vcpu_pause() in p2m_mem_access_check()? If that is the case I am fine with the combination for 4.1.1. Thanks, Aravindh> -- Keir > > On 27/05/2011 17:36, "Aravindh Puthiyaparambil" <aravindh@virtuata.com> > wrote: > >> Can this be included in xen-4.1-testing.hg too so that it could make the Xen >> 4.1.1 cut? >> >> Thanks, >> Aravindh >> >> On May 27, 2011 1:39 AM, "Tim Deegan" <Tim.Deegan@citrix.com> wrote: >>> At 04:39 +0100 on 27 May (1306471145), Aravindh Puthiyaparambil wrote: >>>> mem_event: Allow memory access listener to perform single step execution. >>>> Add a new memory event that handles single step. This allows the memory >>>> access listener to handle instructions that modify data within the execution >>>> page. >>>> This can be enabled in the listener by doing: >>>> xc_set_hvm_param(xch, domain_id, HVM_PARAM_MEMORY_EVENT_SINGLE_STEP, >>>> HVMPME_mode_sync) >>>> >>>> Now the listener can start single stepping by: >>>> xc_domain_debug_control(xch, domain_id, XEN_DOMCTL_DEBUG_OP_SINGLE_STEP_ON, >>>> vcpu_id) >>>> >>>> And stop single stepping by: >>>> xc_domain_debug_control(xch, domain_id, XEN_DOMCTL_DEBUG_OP_SINGLE_STEP_OFF, >>>> vcpu_id) >>>> >>>> Signed-off-by: Aravindh Puthiyaparambil <aravindh@virtuata.com> >>> >>> Acked-by: Tim Deegan <Tim.Deegan@citrix.com> >>> >>> -- >>> Tim Deegan <Tim.Deegan@citrix.com> >>> Principal Software Engineer, Xen Platform Team >>> Citrix Systems UK Ltd. (Company #02937203, SL9 0BG) >> >> >> _______________________________________________ >> Xen-devel mailing list >> Xen-devel@lists.xensource.com >> http://lists.xensource.com/xen-devel > > >_______________________________________________ Xen-devel mailing list Xen-devel@lists.xensource.com http://lists.xensource.com/xen-devel
Keir Fraser
2011-May-28 21:41 UTC
Re: [Xen-devel] [PATCH] mem_event: Allow memory access listener to perform single step execution
On 28/05/2011 18:48, "Aravindh Puthiyaparambil" <aravindh@virtuata.com> wrote:> Sorry about the build breakage. I will test the 32-bit side of things > also in the future. > > I did not realize VCPU pausing was nestable. So even after the > vcpu_unpause() in hvm_debug_op(), the VCPU will still be paused > because of the vcpu_pause() in p2m_mem_access_check()?Yes that''s right. -- Keir> If that is the > case I am fine with the combination for 4.1.1._______________________________________________ Xen-devel mailing list Xen-devel@lists.xensource.com http://lists.xensource.com/xen-devel