[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] Re: [Xen-devel] [PATCH 1/5] xen/vm_event: Added support for XSETBV events
On 06/05/15 18:12, Razvan Cojocaru wrote: > This patch adds XSETBV (XCR) vm_events. > > Signed-off-by: Razvan Cojocaru <rcojocaru@xxxxxxxxxxxxxxx> > --- > tools/libxc/include/xenctrl.h | 2 ++ > tools/libxc/xc_monitor.c | 15 +++++++++++++++ > xen/arch/x86/hvm/event.c | 16 ++++++++++++++++ > xen/arch/x86/hvm/hvm.c | 2 ++ > xen/arch/x86/monitor.c | 16 ++++++++++++++++ > xen/include/asm-x86/domain.h | 2 ++ > xen/include/asm-x86/hvm/event.h | 1 + > xen/include/public/domctl.h | 6 ++++++ > xen/include/public/vm_event.h | 8 ++++++++ > 9 files changed, 68 insertions(+) > > diff --git a/tools/libxc/include/xenctrl.h b/tools/libxc/include/xenctrl.h > index 6994c51..1aa4f87 100644 > --- a/tools/libxc/include/xenctrl.h > +++ b/tools/libxc/include/xenctrl.h > @@ -2337,6 +2337,8 @@ int xc_monitor_mov_to_msr(xc_interface *xch, domid_t > domain_id, bool enable, > int xc_monitor_singlestep(xc_interface *xch, domid_t domain_id, bool enable); > int xc_monitor_software_breakpoint(xc_interface *xch, domid_t domain_id, > bool enable); > +int xc_monitor_xsetbv(xc_interface *xch, domid_t domain_id, bool enable, > + bool sync); > > /*** > * Memory sharing operations. > diff --git a/tools/libxc/xc_monitor.c b/tools/libxc/xc_monitor.c > index 87ad968..aec2f4a 100644 > --- a/tools/libxc/xc_monitor.c > +++ b/tools/libxc/xc_monitor.c > @@ -135,3 +135,18 @@ int xc_monitor_singlestep(xc_interface *xch, domid_t > domain_id, > > return do_domctl(xch, &domctl); > } > + > +int xc_monitor_xsetbv(xc_interface *xch, domid_t domain_id, bool enable, > + bool sync) > +{ > + DECLARE_DOMCTL; > + > + domctl.cmd = XEN_DOMCTL_monitor_op; > + domctl.domain = domain_id; > + domctl.u.monitor_op.op = enable ? XEN_DOMCTL_MONITOR_OP_ENABLE > + : XEN_DOMCTL_MONITOR_OP_DISABLE; > + domctl.u.monitor_op.event = XEN_DOMCTL_MONITOR_EVENT_XSETBV; > + domctl.u.monitor_op.u.xsetbv.sync = sync; > + > + return do_domctl(xch, &domctl); > +} > diff --git a/xen/arch/x86/hvm/event.c b/xen/arch/x86/hvm/event.c > index 9d5f9f3..5b869c8 100644 > --- a/xen/arch/x86/hvm/event.c > +++ b/xen/arch/x86/hvm/event.c > @@ -151,6 +151,22 @@ void hvm_event_msr(unsigned int msr, uint64_t value) > hvm_event_traps(1, &req); > } > > +void hvm_event_xsetbv(unsigned long xcr, uint64_t value) Architecturally, the XCR index is specified in ecx, making it only 32 bits wide. > +{ > + struct vcpu *curr = current; > + struct arch_domain *currad = ¤t->domain->arch; > + > + vm_event_request_t req = { > + .reason = VM_EVENT_REASON_XSETBV, > + .vcpu_id = curr->vcpu_id, > + .u.xsetbv.xcr = xcr, > + .u.xsetbv.value = value, > + }; > + > + if ( currad->monitor.xsetbv_enabled ) > + hvm_event_traps(currad->monitor.xsetbv_sync, &req); > +} > + > int hvm_event_int3(unsigned long gla) > { > int rc = 0; > diff --git a/xen/arch/x86/hvm/hvm.c b/xen/arch/x86/hvm/hvm.c > index 3a09439..86f9885 100644 > --- a/xen/arch/x86/hvm/hvm.c > +++ b/xen/arch/x86/hvm/hvm.c > @@ -2966,6 +2966,8 @@ int hvm_handle_xsetbv(u32 index, u64 new_bv) > { > struct segment_register sreg; > > + hvm_event_xsetbv(index, new_bv); > + > hvm_get_segment_register(current, x86_seg_ss, &sreg); > if ( sreg.attr.fields.dpl != 0 ) > goto err; > diff --git a/xen/arch/x86/monitor.c b/xen/arch/x86/monitor.c > index d7b1c18..6823a84 100644 > --- a/xen/arch/x86/monitor.c > +++ b/xen/arch/x86/monitor.c > @@ -178,6 +178,22 @@ int monitor_domctl(struct domain *d, struct > xen_domctl_monitor_op *mop) > break; > } > > + case XEN_DOMCTL_MONITOR_EVENT_XSETBV: > + { > + bool_t status = ad->monitor.xsetbv_enabled; > + > + rc = status_check(mop, status); > + if ( rc ) > + return rc; > + > + ad->monitor.xsetbv_sync = mop->u.xsetbv.sync; > + > + domain_pause(d); > + ad->monitor.xsetbv_enabled = !status; > + domain_unpause(d); > + break; > + } > + > default: > return -EOPNOTSUPP; > > diff --git a/xen/include/asm-x86/domain.h b/xen/include/asm-x86/domain.h > index 3f83e8b..452a9b3 100644 > --- a/xen/include/asm-x86/domain.h > +++ b/xen/include/asm-x86/domain.h > @@ -354,6 +354,8 @@ struct arch_domain > uint16_t mov_to_msr_extended : 1; > uint16_t singlestep_enabled : 1; > uint16_t software_breakpoint_enabled : 1; > + uint16_t xsetbv_enabled : 1; > + uint16_t xsetbv_sync : 1; > } monitor; > > /* Mem_access emulation control */ > diff --git a/xen/include/asm-x86/hvm/event.h b/xen/include/asm-x86/hvm/event.h > index bb757a1..b2cf3bc 100644 > --- a/xen/include/asm-x86/hvm/event.h > +++ b/xen/include/asm-x86/hvm/event.h > @@ -23,6 +23,7 @@ void hvm_event_cr0(unsigned long value, unsigned long old); > void hvm_event_cr3(unsigned long value, unsigned long old); > void hvm_event_cr4(unsigned long value, unsigned long old); > void hvm_event_msr(unsigned int msr, uint64_t value); > +void hvm_event_xsetbv(unsigned long xcr, uint64_t value); > /* Called for current VCPU: returns -1 if no listener */ > int hvm_event_int3(unsigned long gla); > int hvm_event_single_step(unsigned long gla); > diff --git a/xen/include/public/domctl.h b/xen/include/public/domctl.h > index 10b51ef..b866e33 100644 > --- a/xen/include/public/domctl.h > +++ b/xen/include/public/domctl.h > @@ -1018,6 +1018,7 @@ DEFINE_XEN_GUEST_HANDLE(xen_domctl_psr_cmt_op_t); > #define XEN_DOMCTL_MONITOR_EVENT_MOV_TO_MSR 3 > #define XEN_DOMCTL_MONITOR_EVENT_SINGLESTEP 4 > #define XEN_DOMCTL_MONITOR_EVENT_SOFTWARE_BREAKPOINT 5 > +#define XEN_DOMCTL_MONITOR_EVENT_XSETBV 6 > > struct xen_domctl_monitor_op { > uint32_t op; /* XEN_DOMCTL_MONITOR_OP_* */ > @@ -1038,6 +1039,11 @@ struct xen_domctl_monitor_op { > /* Enable the capture of an extended set of MSRs */ > uint8_t extended_capture; > } mov_to_msr; > + > + struct { > + /* Pause vCPU until response */ > + uint8_t sync; > + } xsetbv; > } u; > }; > typedef struct xen_domctl__op xen_domctl_monitor_op_t; > diff --git a/xen/include/public/vm_event.h b/xen/include/public/vm_event.h > index c7426de..71fe9ba 100644 > --- a/xen/include/public/vm_event.h > +++ b/xen/include/public/vm_event.h > @@ -72,6 +72,8 @@ > #define VM_EVENT_REASON_SOFTWARE_BREAKPOINT 8 > /* Single-step (e.g. MTF) */ > #define VM_EVENT_REASON_SINGLESTEP 9 > +/* An XCR was updated. */ > +#define VM_EVENT_REASON_XSETBV 10 > > /* > * Using a custom struct (not hvm_hw_cpu) so as to not fill > @@ -186,6 +188,11 @@ struct vm_event_sharing { > uint32_t _pad; > }; > > +struct vm_event_xsetbv { > + uint64_t xcr; > + uint64_t value; > +}; > + In an effort to be architecture neutral, it might be an idea to have something like struct vm_event_write_cr { uint64_t index; uint64_t old_val, new_val; }; And have a per-arch index of control registers, such as X86_CR0 X86_CR3 X86_CR4 X86_XCR0 ... ARM32_$foo (See also my reply to Tim on this thread) ~Andrew > typedef struct vm_event_st { > uint32_t version; /* VM_EVENT_INTERFACE_VERSION */ > uint32_t flags; /* VM_EVENT_FLAG_* */ > @@ -200,6 +207,7 @@ typedef struct vm_event_st { > struct vm_event_mov_to_msr mov_to_msr; > struct vm_event_debug software_breakpoint; > struct vm_event_debug singlestep; > + struct vm_event_xsetbv xsetbv; > } u; > > union { _______________________________________________ Xen-devel mailing list Xen-devel@xxxxxxxxxxxxx http://lists.xen.org/xen-devel
|
Lists.xenproject.org is hosted with RackSpace, monitoring our |