xen: Introduce VM_EVENT_FLAG_SET_REGISTERS
PATCH v4 1/1 xen: Introduce VM_EVENT_FLAG_SET_REGISTERS
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. The registers that can now be set are EAX-EDX, ESP, EBP, ESI, EDI, R8-R15, EFLAGS, and EIP. CR0, CR3 and CR4 are not set, as at the time of vm_event_resume() we can't call hvm_set_cr{0,3,4}() and simply setting v->arch.hvm_vcpu.guest_cr[{0,3,4}] is unlikely to have the desired effect. The rest of the vm_event registers are not set because they're not being filled by hvm_event_fill_regs(), but only by p2m_vm_event_fill_regs(). Currently x86-only.
The VCPU needs to be paused for this flag to take effect.
---
Changes since V3:
- Added Reviewed-by and Acked-by tags.
- Updated the header comment and patch description to explicitly state that support is only being added for x86 registers.
--- xen/arch/x86/vm_event.c | 24 ++++++++++++++++++++++++ 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 | 7 +++++++ 5 files changed, 42 insertions(+)
xen/arch/x86/vm_event.c +24 -0
@@ -97,6 +97,30 @@ 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.eax = rsp->data.regs.x86.rax; + v->arch.user_regs.ebx = rsp->data.regs.x86.rbx; + v->arch.user_regs.ecx = rsp->data.regs.x86.rcx; + v->arch.user_regs.edx = rsp->data.regs.x86.rdx; + v->arch.user_regs.esp = rsp->data.regs.x86.rsp; + v->arch.user_regs.ebp = rsp->data.regs.x86.rbp; + v->arch.user_regs.esi = rsp->data.regs.x86.rsi; + v->arch.user_regs.edi = rsp->data.regs.x86.rdi; + + v->arch.user_regs.r8 = rsp->data.regs.x86.r8; + v->arch.user_regs.r9 = rsp->data.regs.x86.r9; + v->arch.user_regs.r10 = rsp->data.regs.x86.r10; + v->arch.user_regs.r11 = rsp->data.regs.x86.r11; + v->arch.user_regs.r12 = rsp->data.regs.x86.r12; + v->arch.user_regs.r13 = rsp->data.regs.x86.r13; + v->arch.user_regs.r14 = rsp->data.regs.x86.r14; + v->arch.user_regs.r15 = rsp->data.regs.x86.r15; + + v->arch.user_regs.eflags = rsp->data.regs.x86.rflags; + v->arch.user_regs.eip = rsp->data.regs.x86.rip; +} +/* * Local variables: * mode: C
xen/common/vm_event.c +3 -0
@@ -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);
xen/include/asm-arm/vm_event.h +6 -0
@@ -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__ */
xen/include/asm-x86/vm_event.h +2 -0
@@ -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__ */
xen/include/public/vm_event.h +7 -0
@@ -89,6 +89,13 @@* 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. +* At the moment x86-only, applies to EAX-EDX, ESP, EBP, ESI, EDI, R8-R15, +* EFLAGS, and 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
Signature · 1 line
1.7.9.5