Added support for a new class of vm_events: VM_EVENT_REASON_REQUEST, sent via HVMOP_request_vm_event. The guest can request that a generic vm_event (containing only the vm_event-filled guest registers as information) be sent to userspace by setting up the correct registers and doing a VMCALL. For example, for a 32-bit guest, this means: EAX = 34 (hvmop), EBX = 24 (HVMOP_guest_request_vm_event), ECX = 0 (NULL required for the hypercall parameter, reserved).
Signed-off-by: Razvan Cojocaru <rcojoc...@bitdefender.com> Acked-by: Tamas K Lengyel <tleng...@novetta.com> Acked-by: Wei Liu <wei.l...@citrix.com> Acked-by: Jan Beulich <jbeul...@suse.com> Acked-by: George Dunlap <george.dun...@eu.citrix.com> --- Changes since V4: - Added XEN_DOMCTL_MONITOR_EVENT_GUEST_REQUEST to the capabilities in monitor.c (Tamas' patch has hit staging since V4). --- 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 | 8 +++++++- xen/arch/x86/monitor.c | 19 ++++++++++++++++++- xen/include/asm-x86/domain.h | 16 +++++++++------- xen/include/asm-x86/hvm/event.h | 1 + xen/include/public/domctl.h | 6 ++++++ xen/include/public/hvm/hvm_op.h | 2 ++ xen/include/public/vm_event.h | 2 ++ 10 files changed, 78 insertions(+), 9 deletions(-) diff --git a/tools/libxc/include/xenctrl.h b/tools/libxc/include/xenctrl.h index 0bbae2a..ce9029c 100644 --- a/tools/libxc/include/xenctrl.h +++ b/tools/libxc/include/xenctrl.h @@ -2378,6 +2378,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_guest_request(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 b64bce3..d5f87da 100644 --- a/tools/libxc/xc_monitor.c +++ b/tools/libxc/xc_monitor.c @@ -129,3 +129,18 @@ int xc_monitor_singlestep(xc_interface *xch, domid_t domain_id, return do_domctl(xch, &domctl); } + +int xc_monitor_guest_request(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_GUEST_REQUEST; + domctl.u.monitor_op.u.guest_request.sync = sync; + + return do_domctl(xch, &domctl); +} diff --git a/xen/arch/x86/hvm/event.c b/xen/arch/x86/hvm/event.c index 5341937..17638ea 100644 --- a/xen/arch/x86/hvm/event.c +++ b/xen/arch/x86/hvm/event.c @@ -126,6 +126,22 @@ void hvm_event_msr(unsigned int msr, uint64_t value) hvm_event_traps(1, &req); } +void hvm_event_guest_request(void) +{ + struct vcpu *curr = current; + struct arch_domain *currad = &curr->domain->arch; + + if ( currad->monitor.guest_request_enabled ) + { + vm_event_request_t req = { + .reason = VM_EVENT_REASON_GUEST_REQUEST, + .vcpu_id = curr->vcpu_id, + }; + + hvm_event_traps(currad->monitor.guest_request_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 545aa91..18d9621 100644 --- a/xen/arch/x86/hvm/hvm.c +++ b/xen/arch/x86/hvm/hvm.c @@ -6001,7 +6001,6 @@ static int hvmop_get_param( #define HVMOP_op_mask 0xff long do_hvm_op(unsigned long op, XEN_GUEST_HANDLE_PARAM(void) arg) - { unsigned long start_iter, mask; long rc = 0; @@ -6415,6 +6414,13 @@ long do_hvm_op(unsigned long op, XEN_GUEST_HANDLE_PARAM(void) arg) break; } + case HVMOP_guest_request_vm_event: + if ( guest_handle_is_null(arg) ) + hvm_event_guest_request(); + else + rc = -EINVAL; + break; + default: { gdprintk(XENLOG_DEBUG, "Bad HVM op %ld.\n", op); diff --git a/xen/arch/x86/monitor.c b/xen/arch/x86/monitor.c index 0da855e..d35907b 100644 --- a/xen/arch/x86/monitor.c +++ b/xen/arch/x86/monitor.c @@ -55,7 +55,8 @@ static inline uint32_t get_capabilities(struct domain *d) capabilities = (1 << XEN_DOMCTL_MONITOR_EVENT_WRITE_CTRLREG) | (1 << XEN_DOMCTL_MONITOR_EVENT_MOV_TO_MSR) | - (1 << XEN_DOMCTL_MONITOR_EVENT_SOFTWARE_BREAKPOINT); + (1 << XEN_DOMCTL_MONITOR_EVENT_SOFTWARE_BREAKPOINT) | + (1 << XEN_DOMCTL_MONITOR_EVENT_GUEST_REQUEST); /* Since we know this is on VMX, we can just call the hvm func */ if ( hvm_is_singlestep_supported() ) @@ -184,6 +185,22 @@ int monitor_domctl(struct domain *d, struct xen_domctl_monitor_op *mop) break; } + case XEN_DOMCTL_MONITOR_EVENT_GUEST_REQUEST: + { + bool_t status = ad->monitor.guest_request_enabled; + + rc = status_check(mop, status); + if ( rc ) + return rc; + + ad->monitor.guest_request_sync = mop->u.guest_request.sync; + + domain_pause(d); + ad->monitor.guest_request_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 c5ad1cb..9fbbdd9 100644 --- a/xen/include/asm-x86/domain.h +++ b/xen/include/asm-x86/domain.h @@ -347,13 +347,15 @@ struct arch_domain /* Monitor options */ struct { - uint16_t write_ctrlreg_enabled : 4; - uint16_t write_ctrlreg_sync : 4; - uint16_t write_ctrlreg_onchangeonly : 4; - uint16_t mov_to_msr_enabled : 1; - uint16_t mov_to_msr_extended : 1; - uint16_t singlestep_enabled : 1; - uint16_t software_breakpoint_enabled : 1; + unsigned int write_ctrlreg_enabled : 4; + unsigned int write_ctrlreg_sync : 4; + unsigned int write_ctrlreg_onchangeonly : 4; + unsigned int mov_to_msr_enabled : 1; + unsigned int mov_to_msr_extended : 1; + unsigned int singlestep_enabled : 1; + unsigned int software_breakpoint_enabled : 1; + unsigned int guest_request_enabled : 1; + unsigned int guest_request_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 819ef96..ab5abd0 100644 --- a/xen/include/asm-x86/hvm/event.h +++ b/xen/include/asm-x86/hvm/event.h @@ -26,6 +26,7 @@ void hvm_event_msr(unsigned int msr, 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); +void hvm_event_guest_request(void); #endif /* __ASM_X86_HVM_EVENT_H__ */ diff --git a/xen/include/public/domctl.h b/xen/include/public/domctl.h index 8b1d6b4..631935a 100644 --- a/xen/include/public/domctl.h +++ b/xen/include/public/domctl.h @@ -1009,6 +1009,7 @@ DEFINE_XEN_GUEST_HANDLE(xen_domctl_psr_cmt_op_t); #define XEN_DOMCTL_MONITOR_EVENT_MOV_TO_MSR 1 #define XEN_DOMCTL_MONITOR_EVENT_SINGLESTEP 2 #define XEN_DOMCTL_MONITOR_EVENT_SOFTWARE_BREAKPOINT 3 +#define XEN_DOMCTL_MONITOR_EVENT_GUEST_REQUEST 4 struct xen_domctl_monitor_op { uint32_t op; /* XEN_DOMCTL_MONITOR_OP_* */ @@ -1039,6 +1040,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; + } guest_request; } u; }; typedef struct xen_domctl_monitor_op xen_domctl_monitor_op_t; diff --git a/xen/include/public/hvm/hvm_op.h b/xen/include/public/hvm/hvm_op.h index 9b84e84..d053db9 100644 --- a/xen/include/public/hvm/hvm_op.h +++ b/xen/include/public/hvm/hvm_op.h @@ -396,6 +396,8 @@ DEFINE_XEN_GUEST_HANDLE(xen_hvm_evtchn_upcall_vector_t); #endif /* defined(__i386__) || defined(__x86_64__) */ +#define HVMOP_guest_request_vm_event 24 + #endif /* __XEN_PUBLIC_HVM_HVM_OP_H__ */ /* diff --git a/xen/include/public/vm_event.h b/xen/include/public/vm_event.h index 4d89c38..f889139 100644 --- a/xen/include/public/vm_event.h +++ b/xen/include/public/vm_event.h @@ -95,6 +95,8 @@ #define VM_EVENT_REASON_SOFTWARE_BREAKPOINT 6 /* Single-step (e.g. MTF) */ #define VM_EVENT_REASON_SINGLESTEP 7 +/* An event has been requested via HVMOP_guest_request_vm_event. */ +#define VM_EVENT_REASON_GUEST_REQUEST 8 /* Supported values for the vm_event_write_ctrlreg index. */ #define VM_EVENT_X86_CR0 0 -- 1.7.9.5 _______________________________________________ Xen-devel mailing list Xen-devel@lists.xen.org http://lists.xen.org/xen-devel