From: Razvan Cojocaru Subject: [PATCH V2 2/2] xen: Introduce VM_EVENT_FLAG_SET_REGISTERS Date: Mon, 21 Sep 2015 16:31:34 +0300 Message-ID: <1442842294-6123-3-git-send-email-rcojocaru@bitdefender.com> References: <1442842294-6123-1-git-send-email-rcojocaru@bitdefender.com> Mime-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Return-path: In-Reply-To: <1442842294-6123-1-git-send-email-rcojocaru@bitdefender.com> List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Sender: xen-devel-bounces@lists.xen.org Errors-To: xen-devel-bounces@lists.xen.org To: xen-devel@lists.xen.org Cc: tamas@tklengyel.com, keir@xen.org, ian.campbell@citrix.com, Razvan Cojocaru , andrew.cooper3@citrix.com, ian.jackson@eu.citrix.com, stefano.stabellini@eu.citrix.co, stefano.stabellini@citrix.com, jbeulich@suse.com, wei.liu2@citrix.com List-Id: xen-devel@lists.xenproject.org A previous version of this patch dealing with support for skipping the current instruction when a vm_event response requested it computed the instruction length in the hypervisor, adding non-trivial code dependencies. This patch allows a userspace vm_event client to simply request that the guest's EIP is set to an arbitary value, computed by the introspection application. In the future, other registers can also be set via a vm_event reply by using this flag. The VCPU needs to be paused for this flag to take effect. Signed-off-by: Razvan Cojocaru --- Changes since V1: - Renamed the patch (VM_EVENT_FLAG_SET_EIP -> VM_EVENT_FLAG_SET_REGISTERS). - As suggested by Tamas Lengyel, EIP is now being set via a dedicated generic vm_event_set_registers() function that can be extended to set other registers in the future. --- xen/arch/x86/vm_event.c | 5 +++++ xen/common/vm_event.c | 3 +++ xen/include/asm-arm/vm_event.h | 6 ++++++ xen/include/asm-x86/vm_event.h | 2 ++ xen/include/public/vm_event.h | 6 ++++++ 5 files changed, 22 insertions(+) diff --git a/xen/arch/x86/vm_event.c b/xen/arch/x86/vm_event.c index e4e0aa4..a59ba79 100644 --- a/xen/arch/x86/vm_event.c +++ b/xen/arch/x86/vm_event.c @@ -95,6 +95,11 @@ void vm_event_register_write_resume(struct vcpu *v, vm_event_response_t *rsp) } } +void vm_event_set_registers(struct vcpu *v, vm_event_response_t *rsp) +{ + v->arch.user_regs.eip = rsp->data.regs.x86.rip; +} + /* * Local variables: * mode: C diff --git a/xen/common/vm_event.c b/xen/common/vm_event.c index ef84b0f..e1f9580 100644 --- a/xen/common/vm_event.c +++ b/xen/common/vm_event.c @@ -417,6 +417,9 @@ void vm_event_resume(struct domain *d, struct vm_event_domain *ved) if ( rsp.flags & VM_EVENT_FLAG_VCPU_PAUSED ) { + if ( rsp.flags & VM_EVENT_FLAG_SET_REGISTERS ) + vm_event_set_registers(v, &rsp); + if ( rsp.flags & VM_EVENT_FLAG_TOGGLE_SINGLESTEP ) vm_event_toggle_singlestep(d, v); diff --git a/xen/include/asm-arm/vm_event.h b/xen/include/asm-arm/vm_event.h index 976fdf1..4d0fbf7 100644 --- a/xen/include/asm-arm/vm_event.h +++ b/xen/include/asm-arm/vm_event.h @@ -47,4 +47,10 @@ void vm_event_register_write_resume(struct vcpu *v, vm_event_response_t *rsp) /* Not supported on ARM. */ } +static inline +void vm_event_set_registers(struct vcpu *v, vm_event_response_t *rsp) +{ + /* Not supported on ARM. */ +} + #endif /* __ASM_ARM_VM_EVENT_H__ */ diff --git a/xen/include/asm-x86/vm_event.h b/xen/include/asm-x86/vm_event.h index 2ff2cab..5aff834 100644 --- a/xen/include/asm-x86/vm_event.h +++ b/xen/include/asm-x86/vm_event.h @@ -42,4 +42,6 @@ void vm_event_toggle_singlestep(struct domain *d, struct vcpu *v); void vm_event_register_write_resume(struct vcpu *v, vm_event_response_t *rsp); +void vm_event_set_registers(struct vcpu *v, vm_event_response_t *rsp); + #endif /* __ASM_X86_VM_EVENT_H__ */ diff --git a/xen/include/public/vm_event.h b/xen/include/public/vm_event.h index ff2f217..51539af 100644 --- a/xen/include/public/vm_event.h +++ b/xen/include/public/vm_event.h @@ -89,6 +89,12 @@ * by the altp2m_idx response field if possible. */ #define VM_EVENT_FLAG_ALTERNATE_P2M (1 << 7) +/* + * Set the vCPU registers to the values in the vm_event response. + * Currently only applies to EIP. + * Requires the vCPU to be paused already (synchronous events only). + */ +#define VM_EVENT_FLAG_SET_REGISTERS (1 << 8) /* * Reasons for the vm event request -- 1.7.9.5