Per vcpu vm_event channels
cover Per vcpu vm_event channels
This patchset adds a new mechanism of sending synchronous vm_event requests and handling vm_event responses without using a ring. As each synchronous request pauses the vcpu until the corresponding response is handled, it can be stored in a slotted memory buffer (one per vcpu) shared between the hypervisor and the controlling domain.
The main advantages of this approach are:
- the ability to dynamicaly allocate the necessary memory used to hold the requests/responses (the size of vm_event_request_t/vm_event_response_t can grow unrestricted by the ring's one page limitation)
- the ring's waitqueue logic is unnecessary in this case because the vcpu sending the request is blocked until a response is received.
Petre Pircalabu (9):
tools/libxc: Consistent usage of xc_vm_event_* interface
vm_event: Define VM_EVENT type
vm_event: Make ‘local’ functions ‘static’
vm_event: Remove "ring" suffix from vm_event_check_ring
vm_event: Simplify vm_event interface
vm_event: Move struct vm_event_domain to vm_event.c
vm_event: Decouple implementation details from interface.
vm_event: Add vm_event_ng interface
xen-access: Add support for vm_event_ng interface
tools/libxc/include/xenctrl.h | 56 +--- tools/libxc/xc_mem_paging.c | 23 +- tools/libxc/xc_memshr.c | 34 --- tools/libxc/xc_monitor.c | 46 ++- tools/libxc/xc_private.h | 16 +- tools/libxc/xc_vm_event.c | 175 +++++++----- tools/tests/xen-access/Makefile | 7 +- tools/tests/xen-access/vm-event-ng.c | 210 ++++++++++++++ tools/tests/xen-access/vm-event.c | 193 +++++++++++++ tools/tests/xen-access/xen-access.c | 408 ++++++++++----------------- tools/tests/xen-access/xen-access.h | 91 ++++++ tools/xenpaging/xenpaging.c | 42 +-- xen/arch/arm/mem_access.c | 2 +- xen/arch/x86/mm.c | 5 + xen/arch/x86/mm/mem_access.c | 4 +- xen/arch/x86/mm/mem_paging.c | 2 +- xen/arch/x86/mm/mem_sharing.c | 5 +- xen/arch/x86/mm/p2m.c | 11 +- xen/common/Makefile | 1 + xen/common/domctl.c | 7 + xen/common/mem_access.c | 2 +- xen/common/monitor.c | 4 +- xen/common/vm_event.c | 527 ++++++++++++++++++----------------- xen/common/vm_event_ng.c | 449 +++++++++++++++++++++++++++++ xen/drivers/passthrough/pci.c | 2 +- xen/include/public/domctl.h | 101 +++---- xen/include/public/memory.h | 2 + xen/include/public/vm_event.h | 47 ++++ xen/include/xen/sched.h | 25 +- xen/include/xen/vm_event.h | 80 +++++- 30 files changed, 1720 insertions(+), 857 deletions(-) create mode 100644 tools/tests/xen-access/vm-event-ng.c create mode 100644 tools/tests/xen-access/vm-event.c create mode 100644 tools/tests/xen-access/xen-access.h create mode 100644 xen/common/vm_event_ng.c
Signature · 7 lines
2.7.4 _______________________________________________ Xen-devel mailing list [email protected] https://lists.xenproject.org/mailman/listinfo/xen-devel
PATCH 3/9 vm_event: Make ‘local’ functions ‘static’
vm_event_get_response, vm_event_resume, and vm_event_mark_and_pause are used only in xen/common/vm_event.c.
--- xen/common/vm_event.c | 6 +++--- xen/include/xen/vm_event.h | 3 --- 2 files changed, 3 insertions(+), 6 deletions(-)
xen/common/vm_event.c +3 -3
@@ -252,7 +252,7 @@ static inline void vm_event_release_slot(struct domain *d,* vm_event_mark_and_pause() tags vcpu and put it to sleep. * The vcpu will resume execution in vm_event_wake_blocked(). */ -void vm_event_mark_and_pause (struct vcpu *v,struct vm_event_domain *ved) +static void vm_event_mark_and_pause (struct vcpu *v,struct vm_event_domain *ved) {if ( !test_and_set_bit (ved->pause_flag, &v->pause_flags) ) {
@@ -324,8 +324,8 @@ void vm_event_put_request(struct domain *d,notify_via_xen_event_channel (d, ved->xen_port); } -int vm_event_get_response (struct domain *d,struct vm_event_domain *ved, -vm_event_response_t *rsp) +static int vm_event_get_response (struct domain *d,struct vm_event_domain *ved, +vm_event_response_t *rsp) {vm_event_front_ring_t *front_ring;RING_IDX rsp_cons;
xen/include/xen/vm_event.h +0 -3
@@ -64,9 +64,6 @@ void vm_event_cancel_slot(struct domain *d, struct vm_event_domain *ved);void vm_event_put_request (struct domain *d,struct vm_event_domain *ved,vm_event_request_t *req); -int vm_event_get_response (struct domain *d,struct vm_event_domain *ved, -vm_event_response_t *rsp); -int vm_event_domctl (struct domain *d,struct xen_domctl_vm_event_op *vec,XEN_GUEST_HANDLE_PARAM (void ) u_domctl);
Signature · 7 lines
2.7.4 _______________________________________________ Xen-devel mailing list [email protected] https://lists.xenproject.org/mailman/listinfo/xen-devel
PATCH 4/9 vm_event: Remove "ring" suffix from vm_event_check_ring
In reply to Petre PircalabuDecouple implementation from interface to allow vm_event_check to be used regardless of the vm_event underlying implementation.
--- xen/arch/arm/mem_access.c | 2 +- xen/arch/x86/mm/mem_access.c | 4 ++-- xen/arch/x86/mm/mem_paging.c | 2 +- xen/common/mem_access.c | 2 +- xen/common/vm_event.c | 24 ++++++++++++------------ xen/drivers/passthrough/pci.c | 2 +- xen/include/xen/vm_event.h | 4 ++-- 7 files changed, 20 insertions(+), 20 deletions(-)
xen/arch/arm/mem_access.c +1 -1
@@ -290,7 +290,7 @@ bool p2m_mem_access_check(paddr_t gpa, vaddr_t gla, const struct npfec npfec) }/* Otherwise, check if there is a vm_event monitor subscriber */ -if ( !vm_event_check_ring (v->domain->vm_event_monitor) ) +if ( !vm_event_check (v->domain->vm_event_monitor) ) {/* No listener */ if ( p2m->access_required )
xen/arch/x86/mm/mem_access.c +2 -2
@@ -182,7 +182,7 @@ bool p2m_mem_access_check(paddr_t gpa, unsigned long gla,gfn_unlock (p2m, gfn,0 );/* Otherwise, check if there is a memory event listener, and send the message along */ -if ( !vm_event_check_ring (d->vm_event_monitor) || !req_ptr ) +if ( !vm_event_check (d->vm_event_monitor) || !req_ptr ) {/* No listener */ if ( p2m->access_required )
@@ -210,7 +210,7 @@ bool p2m_mem_access_check(paddr_t gpa, unsigned long gla,return true; } } -if (vm_event_check_ring (d->vm_event_monitor) && +if (vm_event_check (d->vm_event_monitor) && d->arch.monitor.inguest_pagefault_disabled && npfec.kind != npfec_kind_with_gla )/* don't send a mem_event */ {
xen/arch/x86/mm/mem_paging.c +1 -1
@@ -44,7 +44,7 @@ int mem_paging_memop(XEN_GUEST_HANDLE_PARAM(xen_mem_paging_op_t) arg) goto out; rc = -ENODEV ; -if (unlikely (!vm_event_check_ring (d->vm_event_paging)) ) +if (unlikely (!vm_event_check (d->vm_event_paging)) ) goto out; switch( mpo.op )
xen/common/mem_access.c +1 -1
@@ -52,7 +52,7 @@ int mem_access_memop(unsigned long cmd, goto out; rc = -ENODEV ; -if (unlikely (!vm_event_check_ring (d->vm_event_monitor)) ) +if (unlikely (!vm_event_check (d->vm_event_monitor)) ) goto out; switch ( mao.op )
xen/common/vm_event.c +12 -12
@@ -196,7 +196,7 @@ void vm_event_wake(struct domain *d, struct vm_event_domain *ved)static int vm_event_disable (struct domain *d,struct vm_event_domain **ved) { -if (vm_event_check_ring (*ved) ) +if (vm_event_check (*ved) ) {struct vcpu *v;
@@ -277,7 +277,7 @@ void vm_event_put_request(struct domain *d,RING_IDX req_prod;struct vcpu *curr = current; -if ( !vm_event_check_ring (ved)) +if ( !vm_event_check (ved))return ;if ( curr->domain != d )
@@ -380,7 +380,7 @@ static int vm_event_resume(struct domain *d, struct vm_event_domain *ved)*/ ASSERT (d != current->domain); -if (unlikely (!vm_event_check_ring (ved)) ) +if (unlikely (!vm_event_check (ved)) )return -ENODEV ;/* Pull all responses off the ring. */
@@ -452,7 +452,7 @@ static int vm_event_resume(struct domain *d, struct vm_event_domain *ved)void vm_event_cancel_slot (struct domain *d,struct vm_event_domain *ved) { -if ( !vm_event_check_ring (ved) ) +if ( !vm_event_check (ved) )return ;vm_event_ring_lock (ved);
@@ -501,7 +501,7 @@ static int vm_event_wait_slot(struct vm_event_domain *ved)return rc; } -bool vm_event_check_ring (struct vm_event_domain *ved) +bool vm_event_check (struct vm_event_domain *ved) {return (ved && ved->ring_page); }
@@ -521,7 +521,7 @@ bool vm_event_check_ring(struct vm_event_domain *ved)int __vm_event_claim_slot (struct domain *d,struct vm_event_domain *ved,bool allow_sleep) { -if ( !vm_event_check_ring (ved) ) +if ( !vm_event_check (ved) )return -EOPNOTSUPP ;if ( (current->domain == d) && allow_sleep )
@@ -556,7 +556,7 @@ static void mem_sharing_notification(struct vcpu *v, unsigned int port)void vm_event_cleanup (struct domain *d) {#ifdef CONFIG_HAS_MEM_PAGING -if (vm_event_check_ring (d->vm_event_paging) ) +if (vm_event_check (d->vm_event_paging) ) {/* Destroying the wait queue head means waking up all * queued vcpus. This will drain the list, allowing
@@ -569,13 +569,13 @@ void vm_event_cleanup(struct domain *d) (void )vm_event_disable (d, &d->vm_event_paging); }#endif -if (vm_event_check_ring (d->vm_event_monitor) ) +if (vm_event_check (d->vm_event_monitor) ) {destroy_waitqueue_head (&d->vm_event_monitor->wq); (void )vm_event_disable (d, &d->vm_event_monitor); }#ifdef CONFIG_HAS_MEM_SHARING -if (vm_event_check_ring (d->vm_event_share) ) +if (vm_event_check (d->vm_event_share) ) {destroy_waitqueue_head (&d->vm_event_share->wq); (void )vm_event_disable (d, &d->vm_event_share);
@@ -663,7 +663,7 @@ int vm_event_domctl(struct domain *d, struct xen_domctl_vm_event_op *vec,break ;case XEN_VM_EVENT_DISABLE : -if (vm_event_check_ring (d->vm_event_paging) ) +if (vm_event_check (d->vm_event_paging) ) {domain_pause (d); rc =vm_event_disable (d, &d->vm_event_paging);
@@ -700,7 +700,7 @@ int vm_event_domctl(struct domain *d, struct xen_domctl_vm_event_op *vec,break ;case XEN_VM_EVENT_DISABLE : -if (vm_event_check_ring (d->vm_event_monitor) ) +if (vm_event_check (d->vm_event_monitor) ) {domain_pause (d); rc =vm_event_disable (d, &d->vm_event_monitor);
@@ -745,7 +745,7 @@ int vm_event_domctl(struct domain *d, struct xen_domctl_vm_event_op *vec,break ;case XEN_VM_EVENT_DISABLE : -if (vm_event_check_ring (d->vm_event_share) ) +if (vm_event_check (d->vm_event_share) ) {domain_pause (d); rc =vm_event_disable (d, &d->vm_event_share);
xen/drivers/passthrough/pci.c +1 -1
@@ -1453,7 +1453,7 @@ static int assign_device(struct domain *d, u16 seg, u8 bus, u8 devfn, u32 flag)/* Prevent device assign if mem paging or mem sharing have been * enabled for this domain */ if (unlikely (d->arch.hvm.mem_sharing_enabled || -vm_event_check_ring (d->vm_event_paging) || +vm_event_check (d->vm_event_paging) ||p2m_get_hostp2m (d)->global_logdirty) )return -EXDEV ;
xen/include/xen/vm_event.h +2 -2
@@ -29,8 +29,8 @@/* Clean up on domain destruction */ void vm_event_cleanup (struct domain *d); -/* Returns whether a ring has been set up */ -bool vm_event_check_ring (struct vm_event_domain *ved); +/* Returns whether the VM event domain has been set up */ +bool vm_event_check (struct vm_event_domain *ved);/* Returns 0 on success, -ENOSYS if there is no ring, -EBUSY if there is no * available space and the caller is a foreign domain. If the guest itself
Signature · 7 lines
2.7.4 _______________________________________________ Xen-devel mailing list [email protected] https://lists.xenproject.org/mailman/listinfo/xen-devel
PATCH 1/9 tools/libxc: Consistent usage of xc_vm_event_* interface
In reply to Petre PircalabuModified xc_mem_paging_enable to use directly xc_vm_event_enable and moved the ring_page handling from client to libxc (xenpaging).
Restricted vm_event_control usage only to simplest domctls which do not expect any return values and change xc_vm_event_enable to call do_domctl directly.
Removed xc_memshr_ring_enable/disable and xc_memshr_domain_resume.
--- tools/libxc/include/xenctrl.h | 49 +-------------------------------- tools/libxc/xc_mem_paging.c | 23 +++++----------- tools/libxc/xc_memshr.c | 34 ----------------------- tools/libxc/xc_monitor.c | 31 +++++++++++++++++---- tools/libxc/xc_private.h | 2 +- tools/libxc/xc_vm_event.c | 64 ++++++++++++++++--------------------------- tools/xenpaging/xenpaging.c | 42 +++------------------------- 7 files changed, 62 insertions(+), 183 deletions(-)
tools/libxc/include/xenctrl.h +1 -48
@@ -1949,7 +1949,7 @@ int xc_altp2m_change_gfn(xc_interface *handle, uint32_t domid,* Hardware-Assisted Paging (i.e. Intel EPT, AMD NPT). Moreover, AMD NPT * support is considered experimental. */ -int xc_mem_paging_enable (xc_interface *xch,uint32_t domain_id,uint32_t *port); +void *xc_mem_paging_enable (xc_interface *xch,uint32_t domain_id,uint32_t *port);int xc_mem_paging_disable (xc_interface *xch,uint32_t domain_id);int xc_mem_paging_resume (xc_interface *xch,uint32_t domain_id); int xc_mem_paging_nominate(xc_interface *xch, uint32_t domain_id,
@@ -2082,53 +2082,6 @@ int xc_memshr_control(xc_interface *xch,uint32_t domid, int enable); -/* Create a communication ring in which the hypervisor will place ENOMEM -* notifications. -* -* ENOMEM happens when unsharing pages: a Copy-on-Write duplicate needs to be -* allocated, and thus the out-of-memory error occurr. -* -* For complete examples on how to plumb a notification ring, look into -* xenpaging or xen-access. -* -* On receipt of a notification, the helper should ensure there is memory -* available to the domain before retrying. -* -* If a domain encounters an ENOMEM condition when sharing and this ring -* has not been set up, the hypervisor will crash the domain. -* -* Fails with: -* EINVAL if port is NULL -* EINVAL if the sharing ring has already been enabled -* ENOSYS if no guest gfn has been specified to host the ring via an hvm param -* EINVAL if the gfn for the ring has not been populated -* ENOENT if the gfn for the ring is paged out, or cannot be unshared -* EINVAL if the gfn for the ring cannot be written to -* EINVAL if the domain is dying -* ENOSPC if an event channel cannot be allocated for the ring -* ENOMEM if memory cannot be allocated for internal data structures -* EINVAL or EACCESS if the request is denied by the security policy -*/ - -int xc_memshr_ring_enable (xc_interface *xch, -uint32_t domid, -uint32_t *port); -/* Disable the ring for ENOMEM communication. -* May fail with EINVAL if the ring was not enabled in the first place. -*/ -int xc_memshr_ring_disable (xc_interface *xch, -uint32_t domid); - -/* -* Calls below return EINVAL if sharing has not been enabled for the domain -* Calls below return EINVAL if the domain is dying -*/ -/* Once a reponse to an ENOMEM notification is prepared, the tool can -* notify the hypervisor to re-schedule the faulting vcpu of the domain with an -* event channel kick and/or this call. */ -int xc_memshr_domain_resume (xc_interface *xch, -uint32_t domid); -/* Select a page for sharing. * * A 64 bit opaque handle will be stored in handle. The hypervisor ensures
tools/libxc/xc_mem_paging.c +7 -16
@@ -37,35 +37,26 @@ static int xc_mem_paging_memop(xc_interface *xch, uint32_t domain_id,return do_memory_op (xch, XENMEM_paging_op, &mpo,sizeof (mpo)); } -int xc_mem_paging_enable (xc_interface *xch,uint32_t domain_id, -uint32_t *port) +void *xc_mem_paging_enable (xc_interface *xch,uint32_t domain_id, +uint32_t *port) { -if ( !port ) - { - errno =EINVAL ; -return -1 ; - } - -return xc_vm_event_control (xch, domain_id, -XEN_VM_EVENT_ENABLE , -XEN_DOMCTL_VM_EVENT_OP_PAGING , - port); +return xc_vm_event_enable (xch, domain_id, +XEN_DOMCTL_VM_EVENT_OP_PAGING , + port); }int xc_mem_paging_disable (xc_interface *xch,uint32_t domain_id) {return xc_vm_event_control (xch, domain_id,XEN_VM_EVENT_DISABLE , -XEN_DOMCTL_VM_EVENT_OP_PAGING , -NULL ); +XEN_DOMCTL_VM_EVENT_OP_PAGING ); }int xc_mem_paging_resume (xc_interface *xch,uint32_t domain_id) {return xc_vm_event_control (xch, domain_id,XEN_VM_EVENT_RESUME , -XEN_DOMCTL_VM_EVENT_OP_PAGING , -NULL ); +XEN_DOMCTL_VM_EVENT_OP_PAGING ); }int xc_mem_paging_nominate (xc_interface *xch,uint32_t domain_id,uint64_t gfn)
tools/libxc/xc_memshr.c +0 -34
@@ -41,31 +41,6 @@ int xc_memshr_control(xc_interface *xch,return do_domctl (xch, &domctl); } -int xc_memshr_ring_enable (xc_interface *xch, -uint32_t domid, -uint32_t *port) -{ -if ( !port ) - { - errno =EINVAL ; -return -1 ; - } - -return xc_vm_event_control (xch, domid, -XEN_VM_EVENT_ENABLE , -XEN_DOMCTL_VM_EVENT_OP_SHARING , - port); -} - -int xc_memshr_ring_disable (xc_interface *xch, -uint32_t domid) -{ -return xc_vm_event_control (xch, domid, -XEN_VM_EVENT_DISABLE , -XEN_DOMCTL_VM_EVENT_OP_SHARING , -NULL ); -} -static int xc_memshr_memop (xc_interface *xch,uint32_t domid,xen_mem_sharing_op_t *mso) {
@@ -200,15 +175,6 @@ int xc_memshr_range_share(xc_interface *xch,return xc_memshr_memop (xch, source_domain, &mso); } -int xc_memshr_domain_resume (xc_interface *xch, -uint32_t domid) -{ -return xc_vm_event_control (xch, domid, -XEN_VM_EVENT_RESUME , -XEN_DOMCTL_VM_EVENT_OP_SHARING , -NULL ); -} -int xc_memshr_debug_gfn (xc_interface *xch,uint32_t domid,unsigned long gfn)
tools/libxc/xc_monitor.c +25 -6
@@ -24,24 +24,43 @@void *xc_monitor_enable (xc_interface *xch,uint32_t domain_id,uint32_t *port) { -return xc_vm_event_enable (xch, domain_id,HVM_PARAM_MONITOR_RING_PFN , - port); +void *buffer; +int saved_errno; + +/* Pause the domain for ring page setup */ +if (xc_domain_pause (xch, domain_id) ) + { +PERROR ("Unable to pause domain\n" ); +return NULL ; + } + + buffer =xc_vm_event_enable (xch, domain_id, +HVM_PARAM_MONITOR_RING_PFN , + port); + saved_errno = errno; +if (xc_domain_unpause (xch, domain_id) ) + { +if ( buffer ) + saved_errno = errno; +PERROR ("Unable to unpause domain" ); + } + + errno = saved_errno; +return buffer; }int xc_monitor_disable (xc_interface *xch,uint32_t domain_id) {return xc_vm_event_control (xch, domain_id,XEN_VM_EVENT_DISABLE , -XEN_DOMCTL_VM_EVENT_OP_MONITOR , -NULL ); +XEN_DOMCTL_VM_EVENT_OP_MONITOR ); }int xc_monitor_resume (xc_interface *xch,uint32_t domain_id) {return xc_vm_event_control (xch, domain_id,XEN_VM_EVENT_RESUME , -XEN_DOMCTL_VM_EVENT_OP_MONITOR , -NULL ); +XEN_DOMCTL_VM_EVENT_OP_MONITOR ); } int xc_monitor_get_capabilities(xc_interface *xch, uint32_t domain_id,
tools/libxc/xc_private.h +1 -1
@@ -412,7 +412,7 @@ int xc_ffs64(uint64_t x);* vm_event operations. Internal use only. */ int xc_vm_event_control (xc_interface *xch,uint32_t domain_id,unsigned int op, -unsigned int mode,uint32_t *port); +unsigned int mode);/* * Enables vm_event and returns the mapped ring page indicated by param. * param can be HVM_PARAM_PAGING/ACCESS/SHARING_RING_PFN
tools/libxc/xc_vm_event.c +24 -40
128 lines not on this page · raw message
tools/xenpaging/xenpaging.c +4 -38
55 lines not on this page · raw message
Signature · 7 lines
2.7.4 _______________________________________________ Xen-devel mailing list [email protected] https://lists.xenproject.org/mailman/listinfo/xen-devel
PATCH 2/9 vm_event: Define VM_EVENT type
In reply to Petre PircalabuDefine the type for each of the supported vm_event rings (paging, monitor and sharing) and replace the ring param field with this type.
Replace XEN_DOMCTL_VM_EVENT_OP_ occurrences with their corresponding XEN_VM_EVENT_TYPE_ counterpart.
--- tools/libxc/include/xenctrl.h | 1 + tools/libxc/xc_mem_paging.c | 6 ++-- tools/libxc/xc_monitor.c | 6 ++-- tools/libxc/xc_private.h | 8 ++--- tools/libxc/xc_vm_event.c | 70 ++++++++++++++++++------------------- xen/common/vm_event.c | 12 +++---- xen/include/public/domctl.h | 81 ++++++------------------------------------- xen/include/public/vm_event.h | 31 +++++++++++++++++ 8 files changed, 93 insertions(+), 122 deletions(-)
tools/libxc/include/xenctrl.h +1 -0
@@ -46,6 +46,7 @@#include <xen/xsm/flask_op.h> #include <xen/kexec.h> #include <xen/platform.h> +#include <xen/vm_event.h> #include "xentoollog.h"
tools/libxc/xc_mem_paging.c +3 -3
@@ -41,7 +41,7 @@ void *xc_mem_paging_enable(xc_interface *xch, uint32_t domain_id, uint32_t *port) {return xc_vm_event_enable (xch, domain_id, -XEN_DOMCTL_VM_EVENT_OP_PAGING , +XEN_VM_EVENT_TYPE_PAGING , port); }
@@ -49,14 +49,14 @@ int xc_mem_paging_disable(xc_interface *xch, uint32_t domain_id) {return xc_vm_event_control (xch, domain_id,XEN_VM_EVENT_DISABLE , -XEN_DOMCTL_VM_EVENT_OP_PAGING ); +XEN_VM_EVENT_TYPE_PAGING ); }int xc_mem_paging_resume (xc_interface *xch,uint32_t domain_id) {return xc_vm_event_control (xch, domain_id,XEN_VM_EVENT_RESUME , -XEN_DOMCTL_VM_EVENT_OP_PAGING ); +XEN_VM_EVENT_TYPE_PAGING ); }int xc_mem_paging_nominate (xc_interface *xch,uint32_t domain_id,uint64_t gfn)
tools/libxc/xc_monitor.c +3 -3
@@ -35,7 +35,7 @@ void *xc_monitor_enable(xc_interface *xch, uint32_t domain_id, uint32_t *port) } buffer =xc_vm_event_enable (xch, domain_id, -HVM_PARAM_MONITOR_RING_PFN , +XEN_VM_EVENT_TYPE_MONITOR , port); saved_errno = errno;if (xc_domain_unpause (xch, domain_id) )
@@ -53,14 +53,14 @@ int xc_monitor_disable(xc_interface *xch, uint32_t domain_id) {return xc_vm_event_control (xch, domain_id,XEN_VM_EVENT_DISABLE , -XEN_DOMCTL_VM_EVENT_OP_MONITOR ); +XEN_VM_EVENT_TYPE_MONITOR ); }int xc_monitor_resume (xc_interface *xch,uint32_t domain_id) {return xc_vm_event_control (xch, domain_id,XEN_VM_EVENT_RESUME , -XEN_DOMCTL_VM_EVENT_OP_MONITOR ); +XEN_VM_EVENT_TYPE_MONITOR ); } int xc_monitor_get_capabilities(xc_interface *xch, uint32_t domain_id,
tools/libxc/xc_private.h +4 -4
@@ -412,12 +412,12 @@ int xc_ffs64(uint64_t x);* vm_event operations. Internal use only. */ int xc_vm_event_control (xc_interface *xch,uint32_t domain_id,unsigned int op, -unsigned int mode); +unsigned int type);/* -* Enables vm_event and returns the mapped ring page indicated by param. -* param can be HVM_PARAM_PAGING/ACCESS/SHARING_RING_PFN +* Enables vm_event and returns the mapped ring page indicated by type. +* type can be XEN_VM_EVENT_TYPE_(PAGING/MONITOR/SHARING) */ -void *xc_vm_event_enable (xc_interface *xch,uint32_t domain_id,int param, +void *xc_vm_event_enable (xc_interface *xch,uint32_t domain_id,int type,uint32_t *port);int do_dm_op (xc_interface *xch,uint32_t domid,unsigned int nr_bufs, ...);
tools/libxc/xc_vm_event.c +34 -36
107 lines not on this page · raw message
xen/common/vm_event.c +6 -6
@@ -371,7 +371,7 @@ static int vm_event_resume(struct domain *d, struct vm_event_domain *ved)vm_event_response_t rsp;/* -* vm_event_resume() runs in either XEN_DOMCTL_VM_EVENT_OP_*, or +* vm_event_resume() runs in either XEN_VM_EVENT_* domctls, or * EVTCHN_send context from the introspection consumer. Both contexts * are guaranteed not to be the subject of vm_event responses. * While we could ASSERT(v != current) for each VCPU in d in the loop
@@ -597,7 +597,7 @@ int vm_event_domctl(struct domain *d, struct xen_domctl_vm_event_op *vec,if (unlikely (d ==NULL ) )return -ESRCH ; - rc =xsm_vm_event_control (XSM_PRIV , d, vec->mode, vec->op); + rc =xsm_vm_event_control (XSM_PRIV , d, vec->type, vec->op);if ( rc )return rc;
@@ -624,10 +624,10 @@ int vm_event_domctl(struct domain *d, struct xen_domctl_vm_event_op *vec, rc = -ENOSYS ; -switch ( vec->mode ) +switch ( vec->type ) {#ifdef CONFIG_HAS_MEM_PAGING -case XEN_DOMCTL_VM_EVENT_OP_PAGING : +case XEN_VM_EVENT_TYPE_PAGING : { rc = -EINVAL ;
@@ -683,7 +683,7 @@ int vm_event_domctl(struct domain *d, struct xen_domctl_vm_event_op *vec,break ;#endif -case XEN_DOMCTL_VM_EVENT_OP_MONITOR : +case XEN_VM_EVENT_TYPE_MONITOR : { rc = -EINVAL ;
@@ -721,7 +721,7 @@ int vm_event_domctl(struct domain *d, struct xen_domctl_vm_event_op *vec,break ;#ifdef CONFIG_HAS_MEM_SHARING -case XEN_DOMCTL_VM_EVENT_OP_SHARING : +case XEN_VM_EVENT_TYPE_SHARING : { rc = -EINVAL ;
xen/include/public/domctl.h +11 -70
112 lines not on this page · raw message
xen/include/public/vm_event.h +31 -0
@@ -36,6 +36,37 @@#include "io/ring.h" /* +* There are currently three types of VM events. +*/ + +/* +* Domain memory paging +* +* Page memory in and out. +*/ +#define XEN_VM_EVENT_TYPE_PAGING 1 + +/* +* Monitor. +* +* The monitor interface can be used to register for various VM events. For +* example, there are HVM hypercalls to set the per-page access permissions +* of every page in a domain. When one of these permissions--independent, +* read, write, and execute--is violated, the VCPU is paused and a memory event +* is sent with what happened. The memory event handler can then resume the +* VCPU and redo the access with a XEN_VM_EVENT_RESUME option. +*/ +#define XEN_VM_EVENT_TYPE_MONITOR 2 + +/* +* Sharing ENOMEM. +* +* Used to communicate failed allocations in the unshare path. +* XENMEM_sharing_op_resume is used to wake up vcpus that could not unshare. +*/ +#define XEN_VM_EVENT_TYPE_SHARING 3 + +/* * Memory event flags */
Signature · 7 lines
2.7.4 _______________________________________________ Xen-devel mailing list [email protected] https://lists.xenproject.org/mailman/listinfo/xen-devel
PATCH 5/9 vm_event: Simplify vm_event interface
In reply to Petre PircalabuThe domain reference can be part of the vm_event_domain structure because for every call to a vm_event interface function both the latter and it's corresponding domain are passed as parameters.
Affected functions:
- __vm_event_claim_slot / vm_event_claim_slot / vm_event_claim_slot_nosleep
- vm_event_cancel_slot
- vm_event_put_request
--- xen/arch/x86/mm/mem_sharing.c | 5 ++--- xen/arch/x86/mm/p2m.c | 11 +++++------ xen/common/monitor.c | 4 ++-- xen/common/vm_event.c | 37 ++++++++++++++++++------------------- xen/include/xen/sched.h | 2 ++ xen/include/xen/vm_event.h | 17 +++++++---------- 6 files changed, 36 insertions(+), 40 deletions(-)
xen/arch/x86/mm/mem_sharing.c +2 -3
@@ -557,8 +557,7 @@ int mem_sharing_notify_enomem(struct domain *d, unsigned long gfn, .u.mem_sharing.p2mt = p2m_ram_shared }; -if ( (rc =__vm_event_claim_slot (d, - d->vm_event_share, allow_sleep)) <0 ) +if ( (rc =__vm_event_claim_slot (d->vm_event_share, allow_sleep)) <0 )return rc;if ( v->domain == d )
@@ -567,7 +566,7 @@ int mem_sharing_notify_enomem(struct domain *d, unsigned long gfn,vm_event_vcpu_pause (v); } -vm_event_put_request (d, d->vm_event_share, &req); +vm_event_put_request (d->vm_event_share, &req);return 0 ; }
xen/arch/x86/mm/p2m.c +5 -6
@@ -1652,7 +1652,7 @@ void p2m_mem_paging_drop_page(struct domain *d, unsigned long gfn,* correctness of the guest execution at this point. If this is the only * page that happens to be paged-out, we'll be okay.. but it's likely the * guest will crash shortly anyways. */ -int rc =vm_event_claim_slot (d, d->vm_event_paging); +int rc =vm_event_claim_slot (d->vm_event_paging);if ( rc <0 )return ;
@@ -1666,7 +1666,7 @@ void p2m_mem_paging_drop_page(struct domain *d, unsigned long gfn,/* Evict will fail now, tag this request for pager */ req.u.mem_paging.flags |=MEM_PAGING_EVICT_FAIL ; -vm_event_put_request (d, d->vm_event_paging, &req); +vm_event_put_request (d->vm_event_paging, &req); }/**
@@ -1704,8 +1704,7 @@ void p2m_mem_paging_populate(struct domain *d, unsigned long gfn_l)struct p2m_domain *p2m =p2m_get_hostp2m (d);/* We're paging. There should be a ring */ -int rc =vm_event_claim_slot (d, d->vm_event_paging); - +int rc =vm_event_claim_slot (d->vm_event_paging);if ( rc == -EOPNOTSUPP ) { gdprintk(XENLOG_ERR, "Domain %hu paging gfn %lx yet no ring "
@@ -1746,7 +1745,7 @@ void p2m_mem_paging_populate(struct domain *d, unsigned long gfn_l) {/* gfn is already on its way back and vcpu is not paused */ out_cancel: -vm_event_cancel_slot (d, d->vm_event_paging); +vm_event_cancel_slot (d->vm_event_paging);return ; }
@@ -1754,7 +1753,7 @@ void p2m_mem_paging_populate(struct domain *d, unsigned long gfn_l) req.u.mem_paging.p2mt = p2mt; req.vcpu_id = v->vcpu_id; -vm_event_put_request (d, d->vm_event_paging, &req); +vm_event_put_request (d->vm_event_paging, &req); }/**
xen/common/monitor.c +2 -2
@@ -93,7 +93,7 @@ int monitor_traps(struct vcpu *v, bool sync, vm_event_request_t *req)int rc;struct domain *d = v->domain; - rc =vm_event_claim_slot (d, d->vm_event_monitor); + rc =vm_event_claim_slot (d->vm_event_monitor);switch ( rc ) {case 0 :
@@ -125,7 +125,7 @@ int monitor_traps(struct vcpu *v, bool sync, vm_event_request_t *req) }vm_event_fill_regs (req); -vm_event_put_request (d, d->vm_event_monitor, req); +vm_event_put_request (d->vm_event_monitor, req);return rc; }
xen/common/vm_event.c +18 -19
@@ -131,10 +131,11 @@ static unsigned int vm_event_ring_available(struct vm_event_domain *ved)* but need to be resumed where the ring is capable of processing at least * one event from them. */ -static void vm_event_wake_blocked (struct domain *d,struct vm_event_domain *ved) +static void vm_event_wake_blocked (struct vm_event_domain *ved) {struct vcpu *v;unsigned int avail_req =vm_event_ring_available (ved); +struct domain *d = ved->d;if ( avail_req ==0 || ved->blocked ==0 )return ;
@@ -171,7 +172,7 @@ static void vm_event_wake_blocked(struct domain *d, struct vm_event_domain *ved)* was unable to do so, it is queued on a wait queue. These are woken as * needed, and take precedence over the blocked vCPUs. */ -static void vm_event_wake_queued (struct domain *d,struct vm_event_domain *ved) +static void vm_event_wake_queued (struct vm_event_domain *ved) {unsigned int avail_req =vm_event_ring_available (ved);
@@ -186,12 +187,12 @@ static void vm_event_wake_queued(struct domain *d, struct vm_event_domain *ved)* call vm_event_wake() again, ensuring that any blocked vCPUs will get * unpaused once all the queued vCPUs have made it through. */ -void vm_event_wake (struct domain *d,struct vm_event_domain *ved) +void vm_event_wake (struct vm_event_domain *ved) {if (!list_empty (&ved->wq.list)) -vm_event_wake_queued (d, ved); +vm_event_wake_queued (ved);else -vm_event_wake_blocked (d, ved); +vm_event_wake_blocked (ved); }static int vm_event_disable (struct domain *d,struct vm_event_domain **ved)
@@ -235,17 +236,16 @@ static int vm_event_disable(struct domain *d, struct vm_event_domain **ved)return 0 ; } -static inline void vm_event_release_slot (struct domain *d, -struct vm_event_domain *ved) +static inline void vm_event_release_slot (struct vm_event_domain *ved) {/* Update the accounting */ -if ( current->domain == d ) +if ( current->domain == ved->d ) ved->target_producers--;else ved->foreign_producers--;/* Kick any waiters */ -vm_event_wake (d, ved); +vm_event_wake (ved); }/*
@@ -267,8 +267,7 @@ static void vm_event_mark_and_pause(struct vcpu *v, struct vm_event_domain *ved)* overly full and its continued execution would cause stalling and excessive * waiting. The vCPU will be automatically unpaused when the ring clears. */ -void vm_event_put_request (struct domain *d, -struct vm_event_domain *ved, +void vm_event_put_request (struct vm_event_domain *ved,vm_event_request_t *req) {vm_event_front_ring_t *front_ring;
@@ -276,6 +275,7 @@ void vm_event_put_request(struct domain *d,unsigned int avail_req;RING_IDX req_prod;struct vcpu *curr = current; +struct domain *d = ved->d;if ( !vm_event_check (ved))return ;
@@ -309,7 +309,7 @@ void vm_event_put_request(struct domain *d,RING_PUSH_REQUESTS (front_ring);/* We've actually *used* our reservation, so release the slot. */ -vm_event_release_slot (d, ved); +vm_event_release_slot (ved);/* Give this vCPU a black eye if necessary, on the way out. * See the comments above wake_blocked() for more information
@@ -351,7 +351,7 @@ static int vm_event_get_response(struct domain *d, struct vm_event_domain *ved,/* Kick any waiters -- since we've just consumed an event, * there may be additional space available in the ring. */ -vm_event_wake (d, ved); +vm_event_wake (ved);vm_event_ring_unlock (ved);
@@ -450,13 +450,13 @@ static int vm_event_resume(struct domain *d, struct vm_event_domain *ved)return 0 ; } -void vm_event_cancel_slot (struct domain *d,struct vm_event_domain *ved) +void vm_event_cancel_slot (struct vm_event_domain *ved) {if ( !vm_event_check (ved) )return ;vm_event_ring_lock (ved); -vm_event_release_slot (d, ved); +vm_event_release_slot (ved);vm_event_ring_unlock (ved); }
@@ -518,16 +518,15 @@ bool vm_event_check(struct vm_event_domain *ved)* 0: a spot has been reserved * */ -int __vm_event_claim_slot (struct domain *d,struct vm_event_domain *ved, -bool allow_sleep) +int __vm_event_claim_slot (struct vm_event_domain *ved,bool allow_sleep) {if ( !vm_event_check (ved) )return -EOPNOTSUPP ; -if ( (current->domain == d) && allow_sleep ) +if ( (current->domain == ved->d) && allow_sleep )return vm_event_wait_slot (ved);else -return vm_event_grab_slot (ved, (current->domain != d)); +return vm_event_grab_slot (ved, (current->domain != ved->d)); }#ifdef CONFIG_HAS_MEM_PAGING
xen/include/xen/sched.h +2 -0
@@ -282,6 +282,8 @@ struct vcpu/* VM event */ struct vm_event_domain { +/* Domain reference */ +struct domain *d;/* ring lock */ spinlock_t ring_lock;/* The ring has 64 entries */
xen/include/xen/vm_event.h +7 -10
@@ -45,23 +45,20 @@ bool vm_event_check(struct vm_event_domain *ved);* cancel_slot(), both of which are guaranteed to * succeed. */ -int __vm_event_claim_slot (struct domain *d,struct vm_event_domain *ved, -bool allow_sleep); -static inline int vm_event_claim_slot (struct domain *d, -struct vm_event_domain *ved) +int __vm_event_claim_slot (struct vm_event_domain *ved,bool allow_sleep); +static inline int vm_event_claim_slot (struct vm_event_domain *ved) { -return __vm_event_claim_slot (d, ved, true); +return __vm_event_claim_slot (ved, true); } -static inline int vm_event_claim_slot_nosleep (struct domain *d, -struct vm_event_domain *ved) +static inline int vm_event_claim_slot_nosleep (struct vm_event_domain *ved) { -return __vm_event_claim_slot (d, ved, false); +return __vm_event_claim_slot (ved, false); } -void vm_event_cancel_slot (struct domain *d,struct vm_event_domain *ved); +void vm_event_cancel_slot (struct vm_event_domain *ved); -void vm_event_put_request (struct domain *d,struct vm_event_domain *ved, +void vm_event_put_request (struct vm_event_domain *ved,vm_event_request_t *req); int vm_event_domctl(struct domain *d, struct xen_domctl_vm_event_op *vec,
Signature · 7 lines
2.7.4 _______________________________________________ Xen-devel mailing list [email protected] https://lists.xenproject.org/mailman/listinfo/xen-devel
PATCH 6/9 vm_event: Move struct vm_event_domain to vm_event.c
In reply to Petre PircalabuThe vm_event_domain members are not accessed outside vm_event.c so it's better to hide de implementation details.
--- xen/common/vm_event.c | 27 +++++++++++++++++++++++++++ xen/include/xen/sched.h | 27 +-------------------------- 2 files changed, 28 insertions(+), 26 deletions(-)
xen/common/vm_event.c +27 -0
@@ -39,6 +39,33 @@#define vm_event_ring_lock (_ved) spin_lock(&(_ved)->ring_lock)#define vm_event_ring_unlock (_ved) spin_unlock(&(_ved)->ring_lock) +/* VM event */ +struct vm_event_domain +{ +/* Domain reference */ +struct domain *d; +/* ring lock */ +spinlock_t ring_lock; +/* The ring has 64 entries */ +unsigned char foreign_producers; +unsigned char target_producers; +/* shared ring page */ +void *ring_page; +struct page_info *ring_pg_struct; +/* front-end ring */ +vm_event_front_ring_t front_ring; +/* event channel port (vcpu0 only) */ +int xen_port; +/* vm_event bit for vcpu->pause_flags */ +int pause_flag; +/* list of vcpus waiting for room in the ring */ +struct waitqueue_head wq; +/* the number of vCPUs blocked */ +unsigned int blocked; +/* The last vcpu woken up */ +unsigned int last_vcpu_wake_up; +}; + static int vm_event_enable( struct domain *d, struct xen_domctl_vm_event_op *vec,
xen/include/xen/sched.h +1 -26
@@ -279,32 +279,7 @@ struct vcpu#define domain_lock (d) spin_lock_recursive(&(d)->domain_lock)#define domain_unlock (d) spin_unlock_recursive(&(d)->domain_lock) -/* VM event */ -struct vm_event_domain -{ -/* Domain reference */ -struct domain *d; -/* ring lock */ -spinlock_t ring_lock; -/* The ring has 64 entries */ -unsigned char foreign_producers; -unsigned char target_producers; -/* shared ring page */ -void *ring_page; -struct page_info *ring_pg_struct; -/* front-end ring */ -vm_event_front_ring_t front_ring; -/* event channel port (vcpu0 only) */ -int xen_port; -/* vm_event bit for vcpu->pause_flags */ -int pause_flag; -/* list of vcpus waiting for room in the ring */ -struct waitqueue_head wq; -/* the number of vCPUs blocked */ -unsigned int blocked; -/* The last vcpu woken up */ -unsigned int last_vcpu_wake_up; -}; +struct vm_event_domain ;struct evtchn_port_ops ;
Signature · 7 lines
2.7.4 _______________________________________________ Xen-devel mailing list [email protected] https://lists.xenproject.org/mailman/listinfo/xen-devel
PATCH 7/9 vm_event: Decouple implementation details from interface.
In reply to Petre PircalabuTo accommodate a second implementation of the vm_event subsystem, the current one (ring) should be decoupled from the xen/vm_event.h interface.
--- xen/common/vm_event.c | 407 ++++++++++++++++++++++----------------------- xen/include/xen/vm_event.h | 56 ++++++- 2 files changed, 252 insertions(+), 211 deletions(-)
xen/common/vm_event.c +201 -206
@@ -35,17 +35,13 @@#define xen_rmb () smp_rmb()#define xen_wmb () smp_wmb() -#define vm_event_ring_lock_init (_ved) spin_lock_init(&(_ved)->ring_lock) -#define vm_event_ring_lock (_ved) spin_lock(&(_ved)->ring_lock) -#define vm_event_ring_unlock (_ved) spin_unlock(&(_ved)->ring_lock) +#define to_ring (_ved) container_of((_ved), struct vm_event_ring_domain, ved) -/* VM event */ -struct vm_event_domain +/* VM event ring implementation */ +struct vm_event_ring_domain { -/* Domain reference */ -struct domain *d; -/* ring lock */ -spinlock_t ring_lock; +/* VM event domain */ +struct vm_event_domain ved;/* The ring has 64 entries */ unsigned char foreign_producers;unsigned char target_producers;
@@ -56,8 +52,6 @@ struct vm_event_domainvm_event_front_ring_t front_ring;/* event channel port (vcpu0 only) */ int xen_port; -/* vm_event bit for vcpu->pause_flags */ -int pause_flag;/* list of vcpus waiting for room in the ring */ struct waitqueue_head wq;/* the number of vCPUs blocked */
@@ -66,48 +60,54 @@ struct vm_event_domainunsigned int last_vcpu_wake_up; }; -static int vm_event_enable ( +static const struct vm_event_ops vm_event_ring_ops; + +static int vm_event_ring_enable (struct domain *d,struct xen_domctl_vm_event_op *vec, -struct vm_event_domain **ved, +struct vm_event_domain **_ved,int pause_flag,int param,xen_event_channel_notification_t notification_fn) {int rc;unsigned long ring_gfn = d->arch.hvm.params[param]; +struct vm_event_ring_domain *impl; -if ( !*ved ) - *ved = xzalloc(struct vm_event_domain); -if ( !*ved ) + impl = (*_ved) ?to_ring (*_ved) : + xzalloc(struct vm_event_ring_domain); +if ( !impl )return -ENOMEM ;/* Only one helper at a time. If the helper crashed, * the ring is in an undefined state and so is the guest. */ -if ( (*ved)->ring_page ) -return -EBUSY ;; +if ( impl->ring_page ) +return -EBUSY ;/* The parameter defaults to zero, and it should be * set to something */ if ( ring_gfn ==0 )return -EOPNOTSUPP ; -vm_event_ring_lock_init (*ved); -vm_event_ring_lock (*ved); +spin_lock_init (&impl->ved.lock); +spin_lock (&impl->ved.lock); rc =vm_event_init_domain (d);if ( rc <0 ) goto err; - rc =prepare_ring_for_helper (d, ring_gfn, &(*ved)->ring_pg_struct, - &(*ved)->ring_page); + impl->ved.d = d; + impl->ved.ops = &vm_event_ring_ops; + + rc =prepare_ring_for_helper (d, ring_gfn, &impl->ring_pg_struct, + &impl->ring_page);if ( rc <0 ) goto err;/* Set the number of currently blocked vCPUs to 0. */ - (*ved)->blocked =0 ; + impl->blocked =0 ;/* Allocate event channel */ rc = alloc_unbound_xen_event_channel(d, 0, current->domain->domain_id,
@@ -115,37 +115,37 @@ static int vm_event_enable(if ( rc <0 ) goto err; - (*ved)->xen_port = vec->u.enable.port = rc; + impl->xen_port = vec->u.enable.port = rc;/* Prepare ring buffer */ -FRONT_RING_INIT (&(*ved)->front_ring, - (vm_event_sring_t *)(*ved)->ring_page, +FRONT_RING_INIT (&impl->front_ring, + (vm_event_sring_t *)impl->ring_page,PAGE_SIZE );/* Save the pause flag for this particular ring. */ - (*ved)->pause_flag = pause_flag; + impl->ved.pause_flag = pause_flag;/* Initialize the last-chance wait queue. */ -init_waitqueue_head (&(*ved)->wq); +init_waitqueue_head (&impl->wq); -vm_event_ring_unlock (*ved); +spin_unlock (&impl->ved.lock); + *_ved = &impl->ved;return 0 ; err: -destroy_ring_for_helper (&(*ved)->ring_page, - (*ved)->ring_pg_struct); -vm_event_ring_unlock (*ved); -xfree (*ved); - *ved =NULL ; +destroy_ring_for_helper (&impl->ring_page, + impl->ring_pg_struct); +spin_unlock (&impl->ved.lock); +XFREE (impl);return rc; } -static unsigned int vm_event_ring_available (struct vm_event_domain *ved) +static unsigned int vm_event_ring_available (struct vm_event_ring_domain *impl) { -int avail_req =RING_FREE_REQUESTS (&ved->front_ring); - avail_req -= ved->target_producers; - avail_req -= ved->foreign_producers; +int avail_req =RING_FREE_REQUESTS (&impl->front_ring); + avail_req -= impl->target_producers; + avail_req -= impl->foreign_producers;BUG_ON (avail_req <0 );
@@ -153,42 +153,42 @@ static unsigned int vm_event_ring_available(struct vm_event_domain *ved) }/* -* vm_event_wake_blocked() will wakeup vcpus waiting for room in the +* vm_event_ring_wake_blocked() will wakeup vcpus waiting for room in the * ring. These vCPUs were paused on their way out after placing an event, * but need to be resumed where the ring is capable of processing at least * one event from them. */ -static void vm_event_wake_blocked (struct vm_event_domain *ved) +static void vm_event_ring_wake_blocked (struct vm_event_ring_domain *impl) {struct vcpu *v; -unsigned int avail_req =vm_event_ring_available (ved); -struct domain *d = ved->d; +unsigned int avail_req =vm_event_ring_available (impl); -if ( avail_req ==0 || ved->blocked ==0 ) +if ( avail_req ==0 || impl->blocked ==0 )return ;/* We remember which vcpu last woke up to avoid scanning always linearly * from zero and starving higher-numbered vcpus under high load */ -if ( d->vcpu ) +if ( impl->ved.d->vcpu ) {int i, j, k; -for (i = ved->last_vcpu_wake_up +1 , j =0 ; j < d->max_vcpus; i++, j++) +for ( i = impl->last_vcpu_wake_up +1 , j =0 ; + j < impl->ved.d->max_vcpus; i++, j++) { - k = i % d->max_vcpus; - v = d->vcpu[k]; + k = i % impl->ved.d->max_vcpus; + v = impl->ved.d->vcpu[k];if ( !v )continue ; -if ( !(ved->blocked) || avail_req ==0 ) +if ( !(impl->blocked) || avail_req ==0 )break ; -if (test_and_clear_bit (ved->pause_flag, &v->pause_flags) ) +if (test_and_clear_bit (impl->ved.pause_flag, &v->pause_flags) ) {vcpu_unpause (v); avail_req--; - ved->blocked--; - ved->last_vcpu_wake_up = k; + impl->blocked--; + impl->last_vcpu_wake_up = k; } } }
@@ -199,92 +199,90 @@ static void vm_event_wake_blocked(struct vm_event_domain *ved)* was unable to do so, it is queued on a wait queue. These are woken as * needed, and take precedence over the blocked vCPUs. */ -static void vm_event_wake_queued (struct vm_event_domain *ved) +static void vm_event_ring_wake_queued (struct vm_event_ring_domain *impl) { -unsigned int avail_req =vm_event_ring_available (ved); +unsigned int avail_req =vm_event_ring_available (impl);if ( avail_req >0 ) -wake_up_nr (&ved->wq, avail_req); +wake_up_nr (&impl->wq, avail_req); }/* -* vm_event_wake() will wakeup all vcpus waiting for the ring to +* vm_event_ring_wake() will wakeup all vcpus waiting for the ring to * become available. If we have queued vCPUs, they get top priority. We * are guaranteed that they will go through code paths that will eventually -* call vm_event_wake() again, ensuring that any blocked vCPUs will get +* call vm_event_ring_wake() again, ensuring that any blocked vCPUs will get * unpaused once all the queued vCPUs have made it through. */ -void vm_event_wake (struct vm_event_domain *ved) +static void vm_event_ring_wake (struct vm_event_ring_domain *impl) { -if (!list_empty (&ved->wq.list)) -vm_event_wake_queued (ved); +if ( !list_empty (&impl->wq.list) ) +vm_event_ring_wake_queued (impl);else -vm_event_wake_blocked (ved); +vm_event_ring_wake_blocked (impl); } -static int vm_event_disable (struct domain *d,struct vm_event_domain **ved) +static int vm_event_ring_disable (struct vm_event_domain **_ved) { -if (vm_event_check (*ved) ) - { -struct vcpu *v; +struct vcpu *v; +struct domain *d = (*_ved)->d; +struct vm_event_ring_domain *impl =to_ring (*_ved); -vm_event_ring_lock (*ved); +spin_lock (&(*_ved)->lock); -if ( !list_empty (&(*ved)->wq.list) ) - { -vm_event_ring_unlock (*ved); -return -EBUSY ; - } +if ( !list_empty (&impl->wq.list) ) + { +spin_unlock (&(*_ved)->lock); +return -EBUSY ; + } -/* Free domU's event channel and leave the other one unbound */ -free_xen_event_channel (d, (*ved)->xen_port); +/* Free domU's event channel and leave the other one unbound */ +free_xen_event_channel (d, impl->xen_port); -/* Unblock all vCPUs */ - for_each_vcpu ( d, v ) +/* Unblock all vCPUs */ + for_each_vcpu ( d, v ) + { +if (test_and_clear_bit ((*_ved)->pause_flag, &v->pause_flags) ) { -if (test_and_clear_bit ((*ved)->pause_flag, &v->pause_flags) ) - { -vcpu_unpause (v); - (*ved)->blocked--; - } +vcpu_unpause (v); + impl->blocked--; } + } -destroy_ring_for_helper (&(*ved)->ring_page, - (*ved)->ring_pg_struct); - -vm_event_cleanup_domain (d); +destroy_ring_for_helper (&impl->ring_page, + impl->ring_pg_struct); -vm_event_ring_unlock (*ved); - } +vm_event_cleanup_domain (d); -xfree (*ved); - *ved =NULL ; +spin_unlock (&(*_ved)->lock); +XFREE (*_ved);return 0 ; } -static inline void vm_event_release_slot (struct vm_event_domain *ved) +static inline void vm_event_ring_release_slot (struct vm_event_ring_domain *impl) {/* Update the accounting */ -if ( current->domain == ved->d ) - ved->target_producers--; +if ( current->domain == impl->ved.d ) + impl->target_producers--;else - ved->foreign_producers--; + impl->foreign_producers--;/* Kick any waiters */ -vm_event_wake (ved); +vm_event_ring_wake (impl); }/* -* vm_event_mark_and_pause() tags vcpu and put it to sleep. -* The vcpu will resume execution in vm_event_wake_blocked(). +* vm_event_ring_mark_and_pause() tags vcpu and put it to sleep. +* The vcpu will resume execution in vm_event_ring_wake_blocked(). */ -static void vm_event_mark_and_pause (struct vcpu *v,struct vm_event_domain *ved) +static void vm_event_ring_mark_and_pause (struct vcpu *v, +struct vm_event_ring_domain *impl) { -if ( !test_and_set_bit (ved->pause_flag, &v->pause_flags) ) +if ( !test_and_set_bit (impl->ved.pause_flag, &v->pause_flags) ) {vcpu_pause_nosync (v); - ved->blocked++; + impl->blocked++; } }
@@ -294,35 +292,32 @@ static void vm_event_mark_and_pause(struct vcpu *v, struct vm_event_domain *ved)* overly full and its continued execution would cause stalling and excessive * waiting. The vCPU will be automatically unpaused when the ring clears. */ -void vm_event_put_request (struct vm_event_domain *ved, -vm_event_request_t *req) +static void vm_event_ring_put_request (struct vm_event_domain *ved, +vm_event_request_t *req) {vm_event_front_ring_t *front_ring;int free_req;unsigned int avail_req;RING_IDX req_prod;struct vcpu *curr = current; -struct domain *d = ved->d; - -if ( !vm_event_check (ved)) -return ; +struct vm_event_ring_domain *impl =to_ring (ved); -if ( curr->domain != d ) +if ( curr->domain != ved->d ) { req->flags |=VM_EVENT_FLAG_FOREIGN ;#ifndef NDEBUG if ( !(req->flags &VM_EVENT_FLAG_VCPU_PAUSED ) )gdprintk (XENLOG_G_WARNING ,"d%dv%d was not paused.\n" , - d->domain_id, req->vcpu_id); + ved->d->domain_id, req->vcpu_id);#endif } req->version =VM_EVENT_INTERFACE_VERSION ; -vm_event_ring_lock (ved); +spin_lock (&impl->ved.lock);/* Due to the reservations, this step must succeed. */ - front_ring = &ved->front_ring; + front_ring = &impl->front_ring; free_req =RING_FREE_REQUESTS (front_ring);ASSERT (free_req >0 );
@@ -336,35 +331,35 @@ void vm_event_put_request(struct vm_event_domain *ved,RING_PUSH_REQUESTS (front_ring);/* We've actually *used* our reservation, so release the slot. */ -vm_event_release_slot (ved); +vm_event_ring_release_slot (impl);/* Give this vCPU a black eye if necessary, on the way out. * See the comments above wake_blocked() for more information * on how this mechanism works to avoid waiting. */ - avail_req =vm_event_ring_available (ved); -if ( curr->domain == d && avail_req < d->max_vcpus && + avail_req =vm_event_ring_available (impl); +if ( curr->domain == ved->d && avail_req < ved->d->max_vcpus && !atomic_read (&curr->vm_event_pause_count) ) -vm_event_mark_and_pause (curr, ved); +vm_event_ring_mark_and_pause (curr, impl); -vm_event_ring_unlock (ved); +spin_unlock (&impl->ved.lock); -notify_via_xen_event_channel (d, ved->xen_port); +notify_via_xen_event_channel (ved->d, impl->xen_port); } -static int vm_event_get_response (struct domain *d,struct vm_event_domain *ved, -vm_event_response_t *rsp) +static int vm_event_ring_get_response (struct vm_event_ring_domain *impl, +vm_event_response_t *rsp) {vm_event_front_ring_t *front_ring;RING_IDX rsp_cons; -vm_event_ring_lock (ved); +spin_lock (&impl->ved.lock); - front_ring = &ved->front_ring; + front_ring = &impl->front_ring; rsp_cons = front_ring->rsp_cons;if ( !RING_HAS_UNCONSUMED_RESPONSES (front_ring) ) { -vm_event_ring_unlock (ved); +spin_unlock (&impl->ved.lock);return 0 ; }
@@ -378,9 +373,9 @@ static int vm_event_get_response(struct domain *d, struct vm_event_domain *ved,/* Kick any waiters -- since we've just consumed an event, * there may be additional space available in the ring. */ -vm_event_wake (ved); +vm_event_ring_wake (impl); -vm_event_ring_unlock (ved); +spin_unlock (&impl->ved.lock);return 1 ; }
@@ -393,10 +388,13 @@ static int vm_event_get_response(struct domain *d, struct vm_event_domain *ved,* Note: responses are handled the same way regardless of which ring they * arrive on. */ -static int vm_event_resume (struct domain *d,struct vm_event_domain *ved) +static int vm_event_ring_resume (struct vm_event_ring_domain *impl) {vm_event_response_t rsp; +if (unlikely (!impl || !vm_event_check (&impl->ved)) ) +return -ENODEV ; +/* * vm_event_resume() runs in either XEN_VM_EVENT_* domctls, or * EVTCHN_send context from the introspection consumer. Both contexts
@@ -405,13 +403,10 @@ static int vm_event_resume(struct domain *d, struct vm_event_domain *ved)* below, this covers the case where we would need to iterate over all * of them more succintly. */ -ASSERT (d != current->domain); - -if (unlikely (!vm_event_check (ved)) ) -return -ENODEV ; +ASSERT (impl->ved.d != current->domain);/* Pull all responses off the ring. */ -while (vm_event_get_response (d, ved, &rsp) ) +while (vm_event_ring_get_response (impl, &rsp) ) {struct vcpu *v;
@@ -422,10 +417,11 @@ static int vm_event_resume(struct domain *d, struct vm_event_domain *ved) }/* Validate the vcpu_id in the response. */ -if ( (rsp.vcpu_id >= d->max_vcpus) || !d->vcpu[rsp.vcpu_id] ) +if ( (rsp.vcpu_id >= impl->ved.d->max_vcpus) || + !impl->ved.d->vcpu[rsp.vcpu_id] )continue ; - v = d->vcpu[rsp.vcpu_id]; + v = impl->ved.d->vcpu[rsp.vcpu_id];/* * In some cases the response type needs extra handling, so here
@@ -437,7 +433,7 @@ static int vm_event_resume(struct domain *d, struct vm_event_domain *ved) {#ifdef CONFIG_HAS_MEM_PAGING if ( rsp.reason ==VM_EVENT_REASON_MEM_PAGING ) -p2m_mem_paging_resume (d, &rsp); +p2m_mem_paging_resume (impl->ved.d, &rsp);#endif /*
@@ -457,7 +453,7 @@ static int vm_event_resume(struct domain *d, struct vm_event_domain *ved)* Check in arch-specific handler to avoid bitmask overhead when * not supported. */ -vm_event_toggle_singlestep (d, v, &rsp); +vm_event_toggle_singlestep (impl->ved.d, v, &rsp);/* Check for altp2m switch */ if ( rsp.flags &VM_EVENT_FLAG_ALTERNATE_P2M )
@@ -477,66 +473,63 @@ static int vm_event_resume(struct domain *d, struct vm_event_domain *ved)return 0 ; } -void vm_event_cancel_slot (struct vm_event_domain *ved) +static void vm_event_ring_cancel_slot (struct vm_event_domain *ved) { -if ( !vm_event_check (ved) ) -return ; - -vm_event_ring_lock (ved); -vm_event_release_slot (ved); -vm_event_ring_unlock (ved); +spin_lock (&ved->lock); +vm_event_ring_release_slot (to_ring (ved)); +spin_unlock (&ved->lock); } -static int vm_event_grab_slot (struct vm_event_domain *ved,int foreign) +static int vm_event_ring_grab_slot (struct vm_event_ring_domain *impl,int foreign) {unsigned int avail_req; -if ( !ved->ring_page ) +if ( !impl->ring_page )return -EOPNOTSUPP ; -vm_event_ring_lock (ved); +spin_lock (&impl->ved.lock); - avail_req =vm_event_ring_available (ved); + avail_req =vm_event_ring_available (impl);if ( avail_req ==0 ) { -vm_event_ring_unlock (ved); +spin_unlock (&impl->ved.lock);return -EBUSY ; }if ( !foreign ) - ved->target_producers++; + impl->target_producers++;else - ved->foreign_producers++; + impl->foreign_producers++; -vm_event_ring_unlock (ved); +spin_unlock (&impl->ved.lock);return 0 ; }/* Simple try_grab wrapper for use in the wait_event() macro. */ -static int vm_event_wait_try_grab (struct vm_event_domain *ved,int *rc) +static int vm_event_ring_wait_try_grab (struct vm_event_ring_domain *impl,int *rc) { - *rc =vm_event_grab_slot (ved,0 ); + *rc =vm_event_ring_grab_slot (impl,0 );return *rc; } -/* Call vm_event_grab_slot() until the ring doesn't exist, or is available. */ -static int vm_event_wait_slot (struct vm_event_domain *ved) +/* Call vm_event_ring_grab_slot() until the ring doesn't exist, or is available. */ +static int vm_event_ring_wait_slot (struct vm_event_ring_domain *impl) {int rc = -EBUSY ; -wait_event (ved->wq,vm_event_wait_try_grab (ved, &rc) != -EBUSY ); +wait_event (impl->wq,vm_event_ring_wait_try_grab (impl, &rc) != -EBUSY );return rc; } -bool vm_event_check (struct vm_event_domain *ved) +static bool vm_event_ring_check (struct vm_event_domain *ved) { -return (ved && ved->ring_page); +return (to_ring (ved)->ring_page !=NULL ); }/* * Determines whether or not the current vCPU belongs to the target domain, * and calls the appropriate wait function. If it is a guest vCPU, then we -* use vm_event_wait_slot() to reserve a slot. As long as there is a ring, +* use vm_event_ring_wait_slot() to reserve a slot. As long as there is a ring, * this function will always return 0 for a guest. For a non-guest, we check * for space and return -EBUSY if the ring is not available. *
@@ -545,36 +538,33 @@ bool vm_event_check(struct vm_event_domain *ved)* 0: a spot has been reserved * */ -int __vm_event_claim_slot (struct vm_event_domain *ved,bool allow_sleep) +static int vm_event_ring_claim_slot (struct vm_event_domain *ved,bool allow_sleep) { -if ( !vm_event_check (ved) ) -return -EOPNOTSUPP ; -if ( (current->domain == ved->d) && allow_sleep ) -return vm_event_wait_slot (ved); +return vm_event_ring_wait_slot (to_ring (ved));else -return vm_event_grab_slot (ved, (current->domain != ved->d)); +return vm_event_ring_grab_slot (to_ring (ved), (current->domain != ved->d)); }#ifdef CONFIG_HAS_MEM_PAGING /* Registered with Xen-bound event channel for incoming notifications. */ static void mem_paging_notification (struct vcpu *v,unsigned int port) { -vm_event_resume (v->domain, v->domain->vm_event_paging); +vm_event_ring_resume (to_ring (v->domain->vm_event_paging)); }#endif /* Registered with Xen-bound event channel for incoming notifications. */ static void monitor_notification (struct vcpu *v,unsigned int port) { -vm_event_resume (v->domain, v->domain->vm_event_monitor); +vm_event_ring_resume (to_ring (v->domain->vm_event_monitor)); }#ifdef CONFIG_HAS_MEM_SHARING /* Registered with Xen-bound event channel for incoming notifications. */ static void mem_sharing_notification (struct vcpu *v,unsigned int port) { -vm_event_resume (v->domain, v->domain->vm_event_share); +vm_event_ring_resume (to_ring (v->domain->vm_event_share)); }#endif
@@ -583,32 +573,32 @@ void vm_event_cleanup(struct domain *d) {#ifdef CONFIG_HAS_MEM_PAGING if (vm_event_check (d->vm_event_paging) ) - { -/* Destroying the wait queue head means waking up all -* queued vcpus. This will drain the list, allowing -* the disable routine to complete. It will also drop -* all domain refs the wait-queued vcpus are holding. -* Finally, because this code path involves previously -* pausing the domain (domain_kill), unpausing the -* vcpus causes no harm. */ -destroy_waitqueue_head (&d->vm_event_paging->wq); - (void )vm_event_disable (d, &d->vm_event_paging); - } + d->vm_event_paging->ops->cleanup (&d->vm_event_paging);#endif +if (vm_event_check (d->vm_event_monitor) ) - { -destroy_waitqueue_head (&d->vm_event_monitor->wq); - (void )vm_event_disable (d, &d->vm_event_monitor); - } + d->vm_event_monitor->ops->cleanup (&d->vm_event_monitor); +#ifdef CONFIG_HAS_MEM_SHARING if (vm_event_check (d->vm_event_share) ) - { -destroy_waitqueue_head (&d->vm_event_share->wq); - (void )vm_event_disable (d, &d->vm_event_share); - } + d->vm_event_share->ops->cleanup (&d->vm_event_share);#endif } +static void vm_event_ring_cleanup (struct vm_event_domain **_ved) +{ +struct vm_event_ring_domain *impl =to_ring (*_ved); +/* Destroying the wait queue head means waking up all +* queued vcpus. This will drain the list, allowing +* the disable routine to complete. It will also drop +* all domain refs the wait-queued vcpus are holding. +* Finally, because this code path involves previously +* pausing the domain (domain_kill), unpausing the +* vcpus causes no harm. */ +destroy_waitqueue_head (&impl->wq); + (void )vm_event_ring_disable (_ved); +} +int vm_event_domctl (struct domain *d,struct xen_domctl_vm_event_op *vec,XEN_GUEST_HANDLE_PARAM (void ) u_domctl) {
@@ -682,23 +672,22 @@ int vm_event_domctl(struct domain *d, struct xen_domctl_vm_event_op *vec,break ;/* domain_pause() not required here, see XSA-99 */ - rc =vm_event_enable (d, vec, &d->vm_event_paging, _VPF_mem_paging, + rc =vm_event_ring_enable (d, vec, &d->vm_event_paging, _VPF_mem_paging,HVM_PARAM_PAGING_RING_PFN , mem_paging_notification); }break ;case XEN_VM_EVENT_DISABLE : -if (vm_event_check (d->vm_event_paging) ) - { -domain_pause (d); - rc =vm_event_disable (d, &d->vm_event_paging); -domain_unpause (d); - } +if ( !vm_event_check (d->vm_event_paging) ) +break ; +domain_pause (d); + rc =vm_event_ring_disable (&d->vm_event_paging); +domain_unpause (d);break ;case XEN_VM_EVENT_RESUME : - rc =vm_event_resume (d, d->vm_event_paging); + rc =vm_event_ring_resume (to_ring (d->vm_event_paging));break ;default :
@@ -720,23 +709,22 @@ int vm_event_domctl(struct domain *d, struct xen_domctl_vm_event_op *vec, rc =arch_monitor_init_domain (d);if ( rc )break ; - rc =vm_event_enable (d, vec, &d->vm_event_monitor, _VPF_mem_access, + rc =vm_event_ring_enable (d, vec, &d->vm_event_monitor, _VPF_mem_access,HVM_PARAM_MONITOR_RING_PFN , monitor_notification);break ;case XEN_VM_EVENT_DISABLE : -if (vm_event_check (d->vm_event_monitor) ) - { -domain_pause (d); - rc =vm_event_disable (d, &d->vm_event_monitor); -arch_monitor_cleanup_domain (d); -domain_unpause (d); - } +if ( !vm_event_check (d->vm_event_monitor) ) +break ; +domain_pause (d); + rc =vm_event_ring_disable (&d->vm_event_monitor); +arch_monitor_cleanup_domain (d); +domain_unpause (d);break ;case XEN_VM_EVENT_RESUME : - rc =vm_event_resume (d, d->vm_event_monitor); + rc =vm_event_ring_resume (to_ring (d->vm_event_monitor));break ;default :
@@ -765,22 +753,21 @@ int vm_event_domctl(struct domain *d, struct xen_domctl_vm_event_op *vec,break ;/* domain_pause() not required here, see XSA-99 */ - rc =vm_event_enable (d, vec, &d->vm_event_share, _VPF_mem_sharing, + rc =vm_event_ring_enable (d, vec, &d->vm_event_share, _VPF_mem_sharing,HVM_PARAM_SHARING_RING_PFN , mem_sharing_notification);break ;case XEN_VM_EVENT_DISABLE : -if (vm_event_check (d->vm_event_share) ) - { -domain_pause (d); - rc =vm_event_disable (d, &d->vm_event_share); -domain_unpause (d); - } +if ( !vm_event_check (d->vm_event_share) ) +break ; +domain_pause (d); + rc =vm_event_ring_disable (&d->vm_event_share); +domain_unpause (d);break ;case XEN_VM_EVENT_RESUME : - rc =vm_event_resume (d, d->vm_event_share); + rc =vm_event_ring_resume (to_ring (d->vm_event_share));break ;default :
@@ -832,6 +819,14 @@ void vm_event_vcpu_unpause(struct vcpu *v)vcpu_unpause (v); } +static const struct vm_event_ops vm_event_ring_ops = { + .check = vm_event_ring_check, + .cleanup = vm_event_ring_cleanup, + .claim_slot = vm_event_ring_claim_slot, + .cancel_slot = vm_event_ring_cancel_slot, + .put_request = vm_event_ring_put_request +}; +/* * Local variables: * mode: C
xen/include/xen/vm_event.h +51 -5
79 lines not on this page · raw message
Signature · 7 lines
2.7.4 _______________________________________________ Xen-devel mailing list [email protected] https://lists.xenproject.org/mailman/listinfo/xen-devel
PATCH 8/9 vm_event: Add vm_event_ng interface
In reply to Petre PircalabuIn high throughput introspection scenarios where lots of monitor vm_events are generated, the ring buffer can fill up before the monitor application gets a chance to handle all the requests thus blocking other vcpus which will have to wait for a slot to become available.
This patch adds support for a different mechanism to handle synchronous vm_event requests / responses. As each synchronous request pauses the vcpu until the corresponding response is handled, it can be stored in a slotted memory buffer (one per vcpu) shared between the hypervisor and the controlling domain.
--- tools/libxc/include/xenctrl.h | 6 + tools/libxc/xc_monitor.c | 15 ++ tools/libxc/xc_private.h | 8 + tools/libxc/xc_vm_event.c | 53 +++++ xen/arch/x86/mm.c | 5 + xen/common/Makefile | 1 + xen/common/domctl.c | 7 + xen/common/vm_event.c | 94 ++++----- xen/common/vm_event_ng.c | 449 ++++++++++++++++++++++++++++++++++++++++++ xen/include/public/domctl.h | 20 ++ xen/include/public/memory.h | 2 + xen/include/public/vm_event.h | 16 ++ xen/include/xen/vm_event.h | 10 + 13 files changed, 642 insertions(+), 44 deletions(-) create mode 100644 xen/common/vm_event_ng.c
tools/libxc/include/xenctrl.h +6 -0
@@ -1993,6 +1993,7 @@ int xc_get_mem_access(xc_interface *xch, uint32_t domain_id,* Returns the VM_EVENT_INTERFACE version. */ int xc_vm_event_get_version (xc_interface *xch); +int xc_vm_event_ng_get_version (xc_interface *xch);/*** * Monitor control operations.
@@ -2007,6 +2008,11 @@ int xc_vm_event_get_version(xc_interface *xch);void *xc_monitor_enable (xc_interface *xch,uint32_t domain_id,uint32_t *port);int xc_monitor_disable (xc_interface *xch,uint32_t domain_id);int xc_monitor_resume (xc_interface *xch,uint32_t domain_id); + +/* Monitor NG interface */ +int xc_monitor_ng_create (xc_interface *xch,uint32_t domain_id); +int xc_monitor_ng_destroy (xc_interface *xch,uint32_t domain_id); +int xc_monitor_ng_set_state (xc_interface *xch,uint32_t domain_id,bool enabled);/* * Get a bitmap of supported monitor events in the form * (1 << XEN_DOMCTL_MONITOR_EVENT_*).
tools/libxc/xc_monitor.c +15 -0
@@ -265,6 +265,21 @@ int xc_monitor_emul_unimplemented(xc_interface *xch, uint32_t domain_id,return do_domctl (xch, &domctl); } +int xc_monitor_ng_create (xc_interface *xch,uint32_t domain_id) +{ +return xc_vm_event_ng_create (xch, domain_id,XEN_VM_EVENT_TYPE_MONITOR ); +} + +int xc_monitor_ng_destroy (xc_interface *xch,uint32_t domain_id) +{ +return xc_vm_event_ng_destroy (xch, domain_id,XEN_VM_EVENT_TYPE_MONITOR ); +} + +int xc_monitor_ng_set_state (xc_interface *xch,uint32_t domain_id,bool enabled) +{ +return xc_vm_event_ng_set_state (xch, domain_id,XEN_VM_EVENT_TYPE_MONITOR , enabled); +} +/* * Local variables: * mode: C
tools/libxc/xc_private.h +8 -0
@@ -420,6 +420,14 @@ int xc_vm_event_control(xc_interface *xch, uint32_t domain_id, unsigned int op,void *xc_vm_event_enable (xc_interface *xch,uint32_t domain_id,int type,uint32_t *port); +/** +* VM_EVENT NG operations. Internal use only. +*/ +int xc_vm_event_ng_create (xc_interface *xch,uint32_t domain_id,int type); +int xc_vm_event_ng_destroy (xc_interface *xch,uint32_t domain_id,int type); +int xc_vm_event_ng_set_state (xc_interface *xch,uint32_t domain_id,int type,bool enabled); + +int do_dm_op (xc_interface *xch,uint32_t domid,unsigned int nr_bufs, ...);#endif /* __XC_PRIVATE_H__ */
tools/libxc/xc_vm_event.c +53 -0
59 lines not on this page · raw message
xen/arch/x86/mm.c +5 -0
@@ -119,6 +119,7 @@#include <xen/efi.h> #include <xen/grant_table.h> #include <xen/hypercall.h> +#include <xen/vm_event.h> #include <asm/paging.h> #include <asm/shadow.h> #include <asm/page.h>
@@ -4584,6 +4585,10 @@ int arch_acquire_resource(struct domain *d, unsigned int type, }#endif +case XENMEM_resource_vm_event: + rc =vm_event_ng_get_frames (d, id, frame, nr_frames, mfn_list); +break ; +default : rc = -EOPNOTSUPP ;break ;
xen/common/Makefile +1 -0
@@ -59,6 +59,7 @@ obj-y += trace.o obj-y += version.o obj-y += virtual_region.o obj-y += vm_event.o +obj-y += vm_event_ng.o obj-y += vmap.o obj-y += vsprintf.o obj-y += wait.o
xen/common/domctl.c +7 -0
@@ -393,6 +393,7 @@ long do_domctl(XEN_GUEST_HANDLE_PARAM(xen_domctl_t) u_domctl) {case XEN_DOMCTL_test_assign_device:case XEN_DOMCTL_vm_event_op: +case XEN_DOMCTL_vm_event_ng_op:if ( op->domain ==DOMID_INVALID ) {case XEN_DOMCTL_createdomain:
@@ -1023,6 +1024,12 @@ long do_domctl(XEN_GUEST_HANDLE_PARAM(xen_domctl_t) u_domctl) copyback =1 ;break ; +case XEN_DOMCTL_vm_event_ng_op: + ret =vm_event_ng_domctl (d, &op->u.vm_event_ng_op, +guest_handle_cast (u_domctl, void)); + copyback =1 ; +break ; +#ifdef CONFIG_MEM_ACCESS case XEN_DOMCTL_set_access_required:if (unlikely (current->domain == d) )/* no domain_pause() */
xen/common/vm_event.c +50 -44
112 lines not on this page · raw message
xen/common/vm_event_ng.c new file +449 -0
449 lines not on this page · raw message
xen/include/public/domctl.h +20 -0
@@ -792,6 +792,24 @@ struct xen_domctl_vm_event_op { };/* +* XEN_DOMCTL_vm_event_ng_op. +* Next Generation vm_event operations. +*/ +#define XEN_VM_EVENT_NG_CREATE 0 +#define XEN_VM_EVENT_NG_DESTROY 1 +#define XEN_VM_EVENT_NG_SET_STATE 2 +#define XEN_VM_EVENT_NG_GET_VERSION 3 + +struct xen_domctl_vm_event_ng_op { +uint32_t op;/* XEN_VM_EVENT_NG_* */ +uint32_t type;/* XEN_VM_EVENT_TYPE_* */ +union { +uint32_t version;/* OUT: version number */ +uint8_t enabled;/* IN: state */ + } u; +}; + +/* * Memory sharing operations */ /* XEN_DOMCTL_mem_sharing_op.
@@ -1142,6 +1160,7 @@ struct xen_domctl {/* #define XEN_DOMCTL_set_gnttab_limits 80 - Moved into XEN_DOMCTL_createdomain */ #define XEN_DOMCTL_vuart_op 81#define XEN_DOMCTL_get_cpu_policy 82 +#define XEN_DOMCTL_vm_event_ng_op 83#define XEN_DOMCTL_gdbsx_guestmemio 1000#define XEN_DOMCTL_gdbsx_pausevcpu 1001#define XEN_DOMCTL_gdbsx_unpausevcpu 1002
@@ -1183,6 +1202,7 @@ struct xen_domctl {struct xen_domctl_subscribe subscribe;struct xen_domctl_debug_op debug_op;struct xen_domctl_vm_event_op vm_event_op; +struct xen_domctl_vm_event_ng_op vm_event_ng_op;struct xen_domctl_mem_sharing_op mem_sharing_op;#if defined(__i386__) || defined(__x86_64__)struct xen_domctl_cpuid cpuid;
xen/include/public/memory.h +2 -0
@@ -612,6 +612,7 @@ struct xen_mem_acquire_resource {#define XENMEM_resource_ioreq_server 0#define XENMEM_resource_grant_table 1 +#define XENMEM_resource_vm_event 2/* * IN - a type-specific resource identifier, which must be zero
@@ -619,6 +620,7 @@ struct xen_mem_acquire_resource {* * type == XENMEM_resource_ioreq_server -> id == ioreq server id * type == XENMEM_resource_grant_table -> id defined below +* type == XENMEM_resource_vm_event -> id == vm_event type */ uint32_t id;
xen/include/public/vm_event.h +16 -0
@@ -421,6 +421,22 @@ typedef struct vm_event_st {DEFINE_RING_TYPES (vm_event, vm_event_request_t, vm_event_response_t); +/* VM Event slot state */ +#define STATE_VM_EVENT_SLOT_IDLE 0/* the slot data is invalid */ +#define STATE_VM_EVENT_SLOT_SUBMIT 1/* a request was submitted */ +#define STATE_VM_EVENT_SLOT_FINISH 2/* a response was issued */ + +struct vm_event_slot +{ +uint32_t port;/* evtchn for notifications to/from helper */ +uint32_t state:4 ; +uint32_t pad:28 ; +union { +vm_event_request_t req; +vm_event_response_t rsp; + } u; +}; +#endif /* defined(__XEN__) || defined(__XEN_TOOLS__) */ #endif /* _XEN_PUBLIC_VM_EVENT_H */
xen/include/xen/vm_event.h +10 -0
@@ -110,6 +110,13 @@ static inline void vm_event_put_request(struct vm_event_domain *ved,int vm_event_domctl (struct domain *d,struct xen_domctl_vm_event_op *vec,XEN_GUEST_HANDLE_PARAM (void ) u_domctl); +int vm_event_ng_domctl (struct domain *d,struct xen_domctl_vm_event_ng_op *vec, +XEN_GUEST_HANDLE_PARAM (void ) u_domctl); + +int vm_event_ng_get_frames (struct domain *d,unsigned int id, +unsigned long frame,unsigned int nr_frames, +xen_pfn_t mfn_list[]); +void vm_event_vcpu_pause (struct vcpu *v);void vm_event_vcpu_unpause (struct vcpu *v);
@@ -118,6 +125,9 @@ void vm_event_set_registers(struct vcpu *v, vm_event_response_t *rsp);void vm_event_monitor_next_interrupt (struct vcpu *v); +void vm_event_handle_response (struct domain *d,struct vcpu *v, +vm_event_response_t *rsp); +#endif /* __VM_EVENT_H__ */ /*
Signature · 7 lines
2.7.4 _______________________________________________ Xen-devel mailing list [email protected] https://lists.xenproject.org/mailman/listinfo/xen-devel
PATCH 9/9 xen-access: Add support for vm_event_ng interface
In reply to Petre PircalabuSplit xen-access in order to accommodate both vm_event interfaces (legacy and NG). By default, the legacy vm_event is selected but this can be changed by adding the '-n' flag in the command line.
--- tools/tests/xen-access/Makefile | 7 +- tools/tests/xen-access/vm-event-ng.c | 210 ++++++++++++++++++ tools/tests/xen-access/vm-event.c | 193 +++++++++++++++++ tools/tests/xen-access/xen-access.c | 408 +++++++++++++---------------------- tools/tests/xen-access/xen-access.h | 91 ++++++++ 5 files changed, 644 insertions(+), 265 deletions(-) create mode 100644 tools/tests/xen-access/vm-event-ng.c create mode 100644 tools/tests/xen-access/vm-event.c create mode 100644 tools/tests/xen-access/xen-access.h
tools/tests/xen-access/Makefile +5 -2
@@ -7,6 +7,7 @@ CFLAGS += -DXC_WANT_COMPAT_DEVICEMODEL_API CFLAGS += $(CFLAGS_libxenctrl) CFLAGS += $(CFLAGS_libxenguest) CFLAGS += $(CFLAGS_libxenevtchn) +CFLAGS += $(CFLAGS_libxenforeignmemory) CFLAGS += $(CFLAGS_xeninclude) TARGETS-y := xen-access
@@ -25,8 +26,10 @@ clean: .PHONY: distclean distclean: clean -xen-access: xen-access.o Makefile - $(CC) -o $@ $< $(LDFLAGS) $(LDLIBS_libxenctrl) $(LDLIBS_libxenguest) $(LDLIBS_libxenevtchn) +OBJS = xen-access.o vm-event.o vm-event-ng.o + +xen-access: $(OBJS) Makefile + $(CC) -o $@ $(OBJS) $(LDFLAGS) $(LDLIBS_libxenctrl) $(LDLIBS_libxenguest) $(LDLIBS_libxenevtchn) $(LDLIBS_libxenforeignmemory) install uninstall:
tools/tests/xen-access/vm-event-ng.c new file +210 -0
210 lines not on this page · raw message
tools/tests/xen-access/vm-event.c new file +193 -0
193 lines not on this page · raw message
tools/tests/xen-access/xen-access.c +145 -263
762 lines not on this page · raw message
tools/tests/xen-access/xen-access.h new file +91 -0
91 lines not on this page · raw message
Signature · 7 lines
2.7.4 _______________________________________________ Xen-devel mailing list [email protected] https://lists.xenproject.org/mailman/listinfo/xen-devel
Quoted 7 lines · Petre Pircalabu
This patchset adds a new mechanism of sending synchronous
vm_eventrequests and handlingvm_eventresponses without using a ring. As each synchronous request pauses the vcpu until the corresponding response is handled, it can be stored in a slotted memory buffer (one per vcpu) shared between the hypervisor and the controlling domain.
Quoted 6 lines
The main advantages of this approach are:
- the ability to dynamicaly allocate the necessary memory used to hold the requests/responses (the size of vm_event_request_t/vm_event_response_t can grow unrestricted by the ring's one page limitation)
- the ring's waitqueue logic is unnecessary in this case because the vcpu sending the request is blocked until a response is received.
Hi Petre,
could you push this series as a git branch somewhere?
Thanks,
Tamas
_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel
Quoted 20 lines · Tamas K Lengyel
Quoted 8 lines · Petre Pircalabu
This patchset adds a new mechanism of sending synchronous
vm_eventrequests and handlingvm_eventresponses without using a ring. As each synchronous request pauses the vcpu until the corresponding response is handled, it can be stored in a slotted memory buffer (one per vcpu) shared between the hypervisor and the controlling domain.Quoted 9 lines
The main advantages of this approach are:
- the ability to dynamicaly allocate the necessary memory used to hold
the requests/responses (the size of vm_event_request_t/vm_event_response_t
can grow unrestricted by the ring's one page limitation)
- the ring's waitqueue logic is unnecessary in this case because the
vcpu sending the request is blocked until a response is received.
Quoted 5 lines
Hi Petre,
could you push this series as a git branch somewhere?Thanks,
Tamas
Hi Tamas,
I've pushed the changes to
https://github.com/petrepircalabu/xen/tree/vm_event_ng/devel
Thank-you very much for your support,
Petre
_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel
Re: [PATCH 1/9] tools/libxc: Consistent usage of xc_vm_event_* interface
In reply to Petre PircalabuQuoted 10 lines · Petre Pircalabu
Modified
xc_mem_paging_enableto use directlyxc_vm_event_enableand moved thering_pagehandling from client to libxc (xenpaging).Restricted
vm_event_controlusage only to simplest domctls which do not expect any return values and changexc_vm_event_enableto calldo_domctldirectly.Removed xc_memshr_ring_enable/disable and
xc_memshr_domain_resume.Signed-off-by Petre Pircalabu <[email protected]>
Quoted 8 lines
--- tools/libxc/include/xenctrl.h | 49 +-------------------------------- tools/libxc/xc_mem_paging.c | 23 +++++----------- tools/libxc/xc_memshr.c | 34 ----------------------- tools/libxc/xc_monitor.c | 31 +++++++++++++++++---- tools/libxc/xc_private.h | 2 +- tools/libxc/xc_vm_event.c | 64 ++++++++++++++++--------------------------- tools/xenpaging/xenpaging.c | 42 +++-------------------------
So, the diffstat here is very impressive, and judging by the delta, its all about not opencoding the use of the HVM_PARAM interface. Overall, this is clearly a good thing.
However, it is quite difficult to follow exactly what is going on.
AFAICT, this wants splitting into $N patches.
One patch should refactor xc_mem_paging_enable() to use xc_vm_event_enable(), with the associated xenpaging cleanup.
One patch should be the deletion of xc_memshr_* on its own, because AFAICT it is an isolated change. It also needs some justification, even if it is "interface is unused and/or redundant with $X".
One patch (alone) should be the repositioning of the domain_pause() calls. This does certainly look like a vast improvement WRT error handling in xc_vm_event_enable(), but you've definitely changed the API (insofar as the expectation that the caller has paused the domain) goes, and its not at all obvious that this change is safe. It may very well be, but you need to convince people as to why in the commit message.
I still haven't figured out what the purpose behind dropping the port parameter from xc_vm_event_control() is.
~Andrew
_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel
Re: [PATCH 2/9] vm_event: Define VM_EVENT type
In reply to Petre PircalabuQuoted 38 lines · Petre Pircalabu
tools/libxc/xc_vm_event.c +17
-3@@ -23,29 +23,54 @@#include "xc_private.h" int xc_vm_event_control (xc_interface *xch,uint32_t domain_id,unsigned int op, -unsigned int mode) +unsigned int type) {DECLARE_DOMCTL ; domctl.cmd = XEN_DOMCTL_vm_event_op; domctl.domain = domain_id; domctl.u.vm_event_op.op = op; - domctl.u.vm_event_op.mode = mode; + domctl.u.vm_event_op.type = type;return do_domctl (xch, &domctl); } -void *xc_vm_event_enable(xc_interface *xch, uint32_t domain_id, int param, +static int xc_vm_event_ring_pfn_param (int type,int *param) +{ +if ( !param ) +return -EINVAL ; + +switch ( type ) + { +case XEN_VM_EVENT_TYPE_PAGING : + *param =HVM_PARAM_PAGING_RING_PFN ; +break ; + +case XEN_VM_EVENT_TYPE_MONITOR : + *param =HVM_PARAM_MONITOR_RING_PFN ; +break ; +
tools/libxc/xc_vm_event.c line 62
Quoted 10 lines
tools/libxc/xc_vm_event.c +10
-0+case XEN_VM_EVENT_TYPE_SHARING : + *param =HVM_PARAM_SHARING_RING_PFN ; +break ; + +default : +return -EINVAL ; + } + +return 0 ; +}
This is an internal helper, so can reasonably be expected to not be called with junk, and can do away with the param pointer.
Something like
static int xc_vm_event_ring_pfn_param(unsigned int type) {
switch ( type )
{
case XEN_VM_EVENT_TYPE_PAGING:
return HVM_PARAM_PAGING_RING_PFN;
...
default:
return -EINVAL;
}
}
will work fine because HVM_PARAM_* are all tiny unsigned integers in practice. It also has a more sensible API for the caller.
Quoted 7 lines
xen/include/public/domctl.h +0
-0@@ -769,80 +769,18 @@ struct xen_domctl_gdbsx_domstatus {* VM event operations */
xen/include/public/domctl.h struct xen_domctl_gdbsx_domstatus { · line 772
Quoted 10 lines
xen/include/public/domctl.h +1
-8-/* XEN_DOMCTL_vm_event_op */ - -/* -* There are currently three rings available for VM events: -* sharing, monitor and paging. This hypercall allows one to -* control these rings (enable/disable), as well as to signal -* to the hypervisor to pull responses (resume) from the given -* ring. +/* XEN_DOMCTL_vm_event_op.
/*
* XEN_DOMCTL_vm_event_op.
*
please, seeing as you're adjusting the comment.
Quoted 60 lines
xen/include/public/domctl.h +2
-52+* Use for teardown/setup of helper<->hypervisor interface for paging, +* access and sharing. */ #define XEN_VM_EVENT_ENABLE 0#define XEN_VM_EVENT_DISABLE 1#define XEN_VM_EVENT_RESUME 2#define XEN_VM_EVENT_GET_VERSION 3 -/* -* Domain memory paging -* Page memory in and out. -* Domctl interface to set up and tear down the -* pager<->hypervisor interface. Use XENMEM_paging_op* -* to perform per-page operations. -* -* The XEN_VM_EVENT_PAGING_ENABLE domctl returns several -* non-standard error codes to indicate why paging could not be enabled: -* ENODEV - host lacks HAP support (EPT/NPT) or HAP is disabled in guest -* EMLINK - guest has iommu passthrough enabled -* EXDEV - guest has PoD enabled -* EBUSY - guest has or had paging enabled, ring buffer still active -*/ -#define XEN_DOMCTL_VM_EVENT_OP_PAGING 1 - -/* -* Monitor helper. -* -* As with paging, use the domctl for teardown/setup of the -* helper<->hypervisor interface. -* -* The monitor interface can be used to register for various VM events. For -* example, there are HVM hypercalls to set the per-page access permissions -* of every page in a domain. When one of these permissions--independent, -* read, write, and execute--is violated, the VCPU is paused and a memory event -* is sent with what happened. The memory event handler can then resume the -* VCPU and redo the access with a XEN_VM_EVENT_RESUME option. -* -* See public/vm_event.h for the list of available events that can be -* subscribed to via the monitor interface. -* -* The XEN_VM_EVENT_MONITOR_* domctls returns -* non-standard error codes to indicate why access could not be enabled: -* ENODEV - host lacks HAP support (EPT/NPT) or HAP is disabled in guest -* EBUSY - guest has or had access enabled, ring buffer still active -* -*/ -#define XEN_DOMCTL_VM_EVENT_OP_MONITOR 2 - -/* -* Sharing ENOMEM helper. -* -* As with paging, use the domctl for teardown/setup of the -* helper<->hypervisor interface. -* -* If setup, this ring is used to communicate failed allocations -* in the unshare path. XENMEM_sharing_op_resume is used to wake up -* vcpus that could not unshare. -* -* Note that shring can be turned on (as per the domctl below) -* *without* this ring being setup.
xen/include/public/domctl.h struct xen_domctl_gdbsx_domstatus { · line 783
Quoted 10 lines
xen/include/public/domctl.h +2
-7-*/ -#define XEN_DOMCTL_VM_EVENT_OP_SHARING 3 - -/* Use for teardown/setup of helper<->hypervisor interface for paging, -* access and sharing.*/ struct xen_domctl_vm_event_op { -uint32_t op;/* XEN_VM_EVENT_* */ -uint32_t mode;/* XEN_DOMCTL_VM_EVENT_OP_* */ +uint32_t op;/* XEN_VM_EVENT_* */ +uint32_t type;/* XEN_VM_EVENT_TYPE_* */
Why did the vertical alignment change?
xen/include/public/domctl.h struct xen_domctl_vm_event_op { · line 801
Quoted 12 lines
xen/include/public/domctl.h +4
-1union { struct {@@ -857,7 +795,10 @@ struct xen_domctl_vm_event_op {* Memory sharing operations */ /* XEN_DOMCTL_mem_sharing_op. -* The CONTROL sub-domctl is used for bringup/teardown. */ +* The CONTROL sub-domctl is used for bringup/teardown. +* Please note that mem sharing can be turned on *without* setting-up the +* correspondin ring +*/
As a tangent, it can? how? (I'm entirely prepared to believe that this is how the code currently works, but I can't see how such a setup would plausibly work.)
~Andrew
_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel
Re: [PATCH 3/9] vm_event: Make ‘local’ functions ‘static’
In reply to Petre PircalabuQuoted 4 lines · Petre Pircalabu
vm_event_get_response,vm_event_resume, andvm_event_mark_and_pauseare used only inxen/common/vm_event.c.Signed-off-by Petre Pircalabu <[email protected]>
_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel
Re: [PATCH 4/9] vm_event: Remove "ring" suffix from vm_event_check_ring
In reply to Petre Pircalabuxen/common/vm_event.c void vm_event_put_request(struct domain *d, · line 280
Quoted 10 lines · Petre Pircalabu
xen/common/vm_event.c +1
-1@@ -277,7 +277,7 @@ void vm_event_put_request(struct domain *d,RING_IDX req_prod;struct vcpu *curr = current; -if ( !vm_event_check_ring (ved)) +if ( !vm_event_check (ved))
Ideally with fixing up this style error, as you're changing the line. This can be fixed on commit.
_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel
Re: [PATCH 5/9] vm_event: Simplify vm_event interface
In reply to Petre PircalabuQuoted 3 lines · Petre Pircalabu
The domain reference can be part of the
vm_event_domainstructure because for every call to avm_eventinterface function both the latter and it's corresponding domain are passed as parameters.
It can, but why is adding a backpointer helpful?
I ask because I see 5 reads of ved->d, and nothing which ever initialises it.
This should be split into two patches. The first which adds the backpointer, with working initialisation, and the second which drops the struct domain parameter from the impacted APIs.
~Andrew
xen/arch/x86/mm/p2m.c void p2m_mem_paging_populate(struct domain *d, unsigned long gfn_l) · line 1707
Quoted 11 lines
xen/arch/x86/mm/p2m.c +1
-2@@ -1704,8 +1704,7 @@ void p2m_mem_paging_populate(struct domain *d, unsigned long gfn_l)struct p2m_domain *p2m =p2m_get_hostp2m (d);/* We're paging. There should be a ring */ -int rc =vm_event_claim_slot (d, d->vm_event_paging); - +int rc =vm_event_claim_slot (d->vm_event_paging);
You've dropped a newline here, which should be retained.
~Andrew
_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel
Re: [PATCH 6/9] vm_event: Move struct vm_event_domain to vm_event.c
In reply to Petre PircalabuQuoted 4 lines · Petre Pircalabu
The
vm_event_domainmembers are not accessed outsidevm_event.cso it's better to hide de implementation details.Signed-off-by Petre Pircalabu <[email protected]>
Are there any files which now no longer need to include sched.h ? (Probably not, but it is worth checking)
_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel
Re: [PATCH 5/9] vm_event: Simplify vm_event interface
In reply to Andrew CooperQuoted 8 lines · Andrew Cooper
Quoted 3 lines · Petre Pircalabu
The domain reference can be part of the
vm_event_domainstructure because for every call to avm_eventinterface function both the latter and it's corresponding domain are passed as parameters.It can, but why is adding a backpointer helpful?
I ask because I see 5 reads of
ved->d, and nothing which ever initialises it.
P.S. I've finally found the initialisation in patch 7.
~Andrew
_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel
Quoted 6 lines · Petre Pircalabu
This patchset adds a new mechanism of sending synchronous
vm_eventrequests and handlingvm_eventresponses without using a ring. As each synchronous request pauses the vcpu until the corresponding response is handled, it can be stored in a slotted memory buffer (one per vcpu) shared between the hypervisor and the controlling domain.
Quoted 7 lines
The main advantages of this approach are:
- the ability to dynamicaly allocate the necessary memory used to hold the requests/responses (the size of vm_event_request_t/vm_event_response_t can grow unrestricted by the ring's one page limitation)
- the ring's waitqueue logic is unnecessary in this case because the vcpu sending the request is blocked until a response is received.
Before I review patches 7-9 for more than stylistic things, can you briefly describe what's next?
AFACT, this introduces a second interface between Xen and the agent, which is limited to synchronous events only, and exclusively uses slotted system per vcpu, with a per-vcpu event channel?
What (if any) are the future development plans, and what are the plans for deprecating the use of the old interface? (The answers to these will affect my review of the new interface).
~Andrew
_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel
Re: [PATCH 3/9] vm_event: Make ‘local’ functions ‘static’
In reply to Petre PircalabuQuoted 5 lines · Petre Pircalabu
vm_event_get_response,vm_event_resume, andvm_event_mark_and_pauseare used only inxen/common/vm_event.c.Signed-off-by Petre Pircalabu <[email protected]>
_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel
Re: [PATCH 6/9] vm_event: Move struct vm_event_domain to vm_event.c
In reply to Andrew CooperQuoted 7 lines · Andrew Cooper
Quoted 5 lines · Petre Pircalabu
The
vm_event_domainmembers are not accessed outsidevm_event.cso it's
better to hide de implementation details.Signed-off-by Petre Pircalabu <[email protected]>
Quoted 7 lines
Acked-by Andrew Cooper <[email protected]>Are there any files which now no longer need to include
sched.h? (Probably not, but it is worth checking)________________________
This email was scanned by Bitdefender
The "xen/sched.h header can be removed from the "xen/vm_event.h" include list by fw declaring "struct domain" and "struct vm_event_domain".
The vm_event clients (monitor, mem_sharing, mem_paging) need to include "sched.h" because they need access to the "struct domain" details.
Many thanks,
Petre
_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel
Quoted 19 lines · Andrew Cooper
Quoted 7 lines · Petre Pircalabu
This patchset adds a new mechanism of sending synchronous
vm_eventrequests and handlingvm_eventresponses without using a ring. As each synchronous request pauses the vcpu until the corresponding response is handled, it can be stored in a slotted memory buffer (one per vcpu) shared between the hypervisor and the controlling domain.Quoted 10 lines
The main advantages of this approach are:
- the ability to dynamicaly allocate the necessary memory used to hold
the requests/responses (the size of vm_event_request_t/vm_event_response_t
can grow unrestricted by the ring's one page limitation)
- the ring's waitqueue logic is unnecessary in this case because the
vcpu sending the request is blocked until a response is received.
Quoted 6 lines
Before I review patches 7-9 for more than stylistic things, can you briefly describe what's next?
AFACT, this introduces a second interface between Xen and the agent, which is limited to synchronous events only, and exclusively uses slotted system per vcpu, with a per-vcpu event channel?
Using a distinct interface was proposed by George in order to allow the existing vm_event clients to run unmodified.
Quoted 8 lines
What (if any) are the future development plans, and what are the plans
for deprecating the use of the old interface? (The answers to these will affect my review of the new interface).~Andrew
At the moment, we're only using sync vm_events, so the "one slot per vcpu" approach suits us. Also, by allocating dynamically the vm_event_requests/responses, we can increase their size without suffering the performance drop incurred when using the ring (+waitqueue).
At this moment, we don't have a schedule to deprecate the legacy (ring based) interface, but we will adapt the new interface based on the feedback we receive from other vm_event users.
Quoted 2 lines
________________________
This email was scanned by Bitdefender
_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel
Re: [PATCH 5/9] vm_event: Simplify vm_event interface
In reply to Andrew CooperQuoted 7 lines · Andrew Cooper
Quoted 6 lines · Andrew Cooper
Quoted 4 lines · Petre Pircalabu
The domain reference can be part of the
vm_event_domainstructure because for every call to avm_eventinterface function both the latter
and it's corresponding domain are passed as parameters.
Quoted 9 lines
Quoted 4 lines
It can, but why is adding a backpointer helpful?
I ask because I see 5 reads of
ved->d, and nothing which ever initialises it.
P.S. I've finally found the initialisation in patch 7.~Andrew
My mistake. I've only check if this patch compiles ok. I will fix it and split the patch according to your suggestions.
Many thanks for noticing,
Petre
_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel
Re: [PATCH 2/9] vm_event: Define VM_EVENT type
In reply to Petre Pircalabuxen/include/public/domctl.h line 41
Quoted 9 lines
Quoted 1 line
Quoted 1 line · On 30.05.19 at 16:18, <[email protected]> wrote:
xen/include/public/domctl.h +1
-1@@ -38,7 +38,7 @@#include "hvm/save.h" #include "memory.h" -#define XEN_DOMCTL_INTERFACE_VERSION 0x00000011 +#define XEN_DOMCTL_INTERFACE_VERSION 0x00000012
I don't think such a bump is needed - afaict the interface remains binary compatible.
Jan
_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel
Re: [PATCH 2/9] vm_event: Define VM_EVENT type
In reply to Andrew CooperQuoted 10 lines
Quoted 6 lines
/*
XEN_DOMCTL_mem_sharing_op.
- * The CONTROL sub-domctl is used for bringup/teardown. */
+ * The CONTROL sub-domctl is used for bringup/teardown.
+ * Please note that mem sharing can be turned on *without* setting-up the
+ * correspondin ring
+ */As a tangent, it can? how? (I'm entirely prepared to believe that this is how the code currently works, but I can't see how such a setup would plausibly work.)
The vm_event ring for mem_sharing is only used to communicate out-of-memory condition to an external listener. I think it's only useful for logging since the listener wouldn't really be in a position to try to "make space" for the faulting domain and it would get destroyed after the message is sent. In any case, there isn't any documentation for how it was intended to be used so this is just my guess.
Tamas
_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel
Re: [PATCH 2/9] vm_event: Define VM_EVENT type
Quoted 12 lines · Tamas K Lengyel
Quoted 11 lines
Quoted 7 lines
/*
XEN_DOMCTL_mem_sharing_op.
- * The CONTROL sub-domctl is used for bringup/teardown. */
+ * The CONTROL sub-domctl is used for bringup/teardown.
+ * Please note that mem sharing can be turned on *without* setting-up the
+ * correspondin ring
+ */As a tangent, it can? how? (I'm entirely prepared to believe that this is how the code currently works, but I can't see how such a setup would plausibly work.)
Quoted 7 lines
The
vm_eventring formem_sharingis only used to communicate out-of-memory condition to an external listener. I think it's only useful for logging since the listener wouldn't really be in a position to try to "make space" for the faulting domain and it would get destroyed after the message is sent. In any case, there isn't any documentation for how it was intended to be used so this is just my guess.
Actually, it seems the listener was intended to be able to try to "make space" for the domain. How exactly is not clear but anyway, the domain would get paused if there is a listener instead of just being destroyed when there is an ENOMEM error while trying to deduplicate shared pages.
Tamas
_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel
Re: [PATCH 2/9] vm_event: Define VM_EVENT type
In reply to Andrew CooperQuoted 20 lines · Andrew Cooper
Quoted 1 line · Petre Pircalabu
This is an internal helper, so can reasonably be expected to not be called with junk, and can do away with the param pointer.
Something like
static int
xc_vm_event_ring_pfn_param(unsigned int type){ switch ( type ) { case XEN_VM_EVENT_TYPE_PAGING: return HVM_PARAM_PAGING_RING_PFN; ... default: return -EINVAL; } }
Quoted 2 lines
will work fine because HVM_PARAM_* are all tiny unsigned integers in practice. It also has a more sensible API for the caller.
I think in the end it's best just to move the helper to xc_vm_event_enable (inline the switch) as it is not use outside it.
Quoted 9 lines
Quoted 9 lines
index 19486d5..19281fa 100644
xen/include/public/domctl.h +0
-0@@ -769,80 +769,18 @@ struct xen_domctl_gdbsx_domstatus {* VM event operations */
Quoted 11 lines
xen/include/public/domctl.h struct xen_domctl_gdbsx_domstatus { · line 783
Quoted 9 lines
xen/include/public/domctl.h +2
-5- -/* Use for teardown/setup of helper<->hypervisor interface for paging, -* access and sharing.*/ struct xen_domctl_vm_event_op { -uint32_t op;/* XEN_VM_EVENT_* */ -uint32_t mode;/* XEN_DOMCTL_VM_EVENT_OP_* */ +uint32_t op;/* XEN_VM_EVENT_* */ +uint32_t type;/* XEN_VM_EVENT_TYPE_* */ Why did the vertical alignment change?
The initial vertical alignment was not 4 spaces (I will revert it back to the way it was in order to simplify the review )
Quoted 1 line
_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel
Re: [Xen-devel] [PATCH 1/9] tools/libxc: Consistent usage of xc_vm_event_* interface
In reply to Andrew CooperQuoted 53 lines · Andrew Cooper
Quoted 12 lines · Petre Pircalabu
Modified
xc_mem_paging_enableto use directlyxc_vm_event_enableand
moved thering_pagehandling from client to libxc (xenpaging).Restricted
vm_event_controlusage only to simplest domctls which do not expect any return values and changexc_vm_event_enableto calldo_domctl
directly.Removed xc_memshr_ring_enable/disable and
xc_memshr_domain_resume.Signed-off-by Petre Pircalabu <[email protected]>Quoted 10 lines
--- tools/libxc/include/xenctrl.h | 49 +---------------------------- ---- tools/libxc/xc_mem_paging.c | 23 +++++----------- tools/libxc/xc_memshr.c | 34 ----------------------- tools/libxc/xc_monitor.c | 31 +++++++++++++++++---- tools/libxc/xc_private.h | 2 +- tools/libxc/xc_vm_event.c | 64 ++++++++++++++++--------------- ------------ tools/xenpaging/xenpaging.c | 42 +++-------------------------So, the diffstat here is very impressive, and judging by the delta, its
all about not opencoding the use of theHVM_PARAMinterface. Overall,
this is clearly a good thing.However, it is quite difficult to follow exactly what is going on.
AFAICT, this wants splitting into $N patches.
One patch should refactor
xc_mem_paging_enable()to usexc_vm_event_enable(), with the associated xenpaging cleanup.One patch should be the deletion of xc_memshr_* on its own, because AFAICT it is an isolated change. It also needs some justification, even
if it is "interface is unused and/or redundant with $X".One patch (alone) should be the repositioning of the
domain_pause()calls. This does certainly look like a vast improvement WRT error handling inxc_vm_event_enable(), but you've definitely changed the API
(insofar as the expectation that the caller has paused the domain) goes,
and its not at all obvious that this change is safe. It may very well
be, but you need to convince people as to why in the commit message.
Quoted 4 lines
I still haven't figured out what the purpose behind dropping the port parameter from
xc_vm_event_control()is.~Andrew
The main reason for this patch was to use an uniform calling convention for all xc_vm_event wrappers.
However, at this stage I think it's best to drop it altogheter as it's not a requirement for the new vm_event interface (new domctls are used along with their own separate wrappers).
Many thanks for your support,
Petre
_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel
Re: [Xen-devel] [PATCH 8/9] vm_event: Add vm_event_ng interface
In reply to Petre PircalabuQuoted 5 lines · Petre Pircalabu
In high throughput introspection scenarios where lots of monitor
vm_eventsare generated, the ring buffer can fill up before the monitor application gets a chance to handle all the requests thus blocking other vcpus which will have to wait for a slot to become available.
Quoted 7 lines
This patch adds support for a different mechanism to handle synchronous
vm_eventrequests / responses. As each synchronous request pauses the vcpu until the corresponding response is handled, it can be stored in a slotted memory buffer (one per vcpu) shared between the hypervisor and the controlling domain.Signed-off-by Petre Pircalabu <[email protected]>
There are a number of concerns here.
First and foremost, why is a new domctl being added? Surely this should just be a "type of ring access" parameter to event_enable? Everything else in the vm_event set of APIs should be unchanged as a result of the interface differences.
Or am I missing something?
Quoted 5 lines
xen/common/vm_event_ng.c new file +0
-0
xen/common/vm_event_ng.c line 57
Quoted 9 lines
xen/common/vm_event_ng.c new file +7
-0+static int vm_event_channels_alloc_buffer (struct vm_event_channels_domain *impl) +{ +int i, rc = -ENOMEM ; + +for ( i =0 ; i < impl->nr_frames; i++ ) + { +struct page_info *page =alloc_domheap_page (impl->ved.d,0 );
This creates pages which are reference-able (in principle) by the guest, and are bounded by d->max_pages.
Both of these are properties of the existing interface which we'd prefer to remove.
xen/common/vm_event_ng.c line 70
Quoted 13 lines
xen/common/vm_event_ng.c new file +13
-0+if ( !page ) + goto err; + +if ( !get_page_and_type (page, impl->ved.d, PGT_writable_page) ) + { + rc = -ENODATA ; + goto err; + } + + impl->mfn[i] =page_to_mfn (page); + } + + impl->slots = (struct vm_event_slot *)vmap (impl->mfn, impl->nr_frames);
You appear to have opencoded vmalloc() here. Is there any reason not to use that?
Quoted 27 lines
xen/common/vm_event_ng.c new file +27
-0+if ( !impl->slots ) + goto err; + +for ( i =0 ; i < impl->nr_frames; i++ ) +clear_page ((void *)impl->slots + i *PAGE_SIZE ); + +return 0 ; + +err: +while ( --i >=0 ) + { +struct page_info *page =mfn_to_page (impl->mfn[i]); + +if (test_and_clear_bit (_PGC_allocated, &page->count_info) ) +put_page (page); +put_page_and_type (page); + } + +return rc; +} + +static void vm_event_channels_free_buffer (struct vm_event_channels_domain *impl) +{ +int i; + +ASSERT (impl); +
xen/common/vm_event_ng.c line 107
Quoted 10 lines
xen/common/vm_event_ng.c new file +10
-0+if ( !impl->slots ) +return ; + +vunmap (impl->slots); + +for ( i =0 ; i < impl->nr_frames; i++ ) + { +struct page_info *page =mfn_to_page (impl->mfn[i]); + +ASSERT (page);
mfn_to_page() is going to explode before this ASSERT() does.
Quoted 51 lines
xen/common/vm_event_ng.c new file +51
-0+if (test_and_clear_bit (_PGC_allocated, &page->count_info) ) +put_page (page); +put_page_and_type (page); + } +} + +static int vm_event_channels_create ( +struct domain *d, +struct xen_domctl_vm_event_ng_op *vec, +struct vm_event_domain **_ved, +int pause_flag, +xen_event_channel_notification_t notification_fn) +{ +int rc, i; +unsigned int nr_frames =PFN_UP (d->max_vcpus *sizeof (struct vm_event_slot )); +struct vm_event_channels_domain *impl; + +if ( *_ved ) +return -EBUSY ; + + impl =_xzalloc (sizeof (struct vm_event_channels_domain ) + + nr_frames *sizeof (mfn_t), + __alignof__(struct vm_event_channels_domain )); +if (unlikely (!impl) ) +return -ENOMEM ; + +spin_lock_init (&impl->ved.lock); +spin_lock (&impl->ved.lock); + + impl->nr_frames = nr_frames; + impl->ved.d = d; + impl->ved.ops = &vm_event_channels_ops; + + rc =vm_event_init_domain (d); +if ( rc <0 ) + goto err; + + rc =vm_event_channels_alloc_buffer (impl); +if ( rc ) + goto err; + +for ( i =0 ; i < d->max_vcpus; i++ ) + { + rc =alloc_unbound_xen_event_channel (d, i, current->domain->domain_id, + notification_fn); +if ( rc <0 ) + goto err; + + impl->slots[i].port = rc; + impl->slots[i].state =STATE_VM_EVENT_SLOT_IDLE ; + }
xen/common/vm_event_ng.c line 168
Quoted 10 lines
xen/common/vm_event_ng.c new file +10
-0+ + impl->enabled = false; + +spin_unlock (&impl->ved.lock); + *_ved = &impl->ved; +return 0 ; + +err: +spin_unlock (&impl->ved.lock); +XFREE (impl);
You don't free the event channels on error.
Please write make the destructor idempotent and call it from here.
Quoted 81 lines
xen/common/vm_event_ng.c new file +80
-0+return rc; +} + +int vm_event_ng_domctl (struct domain *d,struct xen_domctl_vm_event_ng_op *vec, +XEN_GUEST_HANDLE_PARAM (void ) u_domctl) +{ +int rc; + +if ( vec->op ==XEN_VM_EVENT_NG_GET_VERSION ) + { + vec->u.version =VM_EVENT_INTERFACE_VERSION ; +return 0 ; + } + +if (unlikely (d ==NULL ) ) +return -ESRCH ; + + rc =xsm_vm_event_control (XSM_PRIV , d, vec->type, vec->op); +if ( rc ) +return rc; + +if (unlikely (d == current->domain) )/* no domain_pause() */ + { +gdprintk (XENLOG_INFO ,"Tried to do a memory event op on itself.\n" ); +return -EINVAL ; + } + +if (unlikely (d->is_dying) ) + { +gdprintk (XENLOG_INFO ,"Ignoring memory event op on dying domain %u\n" , + d->domain_id); +return 0 ; + } + +if (unlikely (d->vcpu ==NULL ) ||unlikely (d->vcpu[0 ] ==NULL ) ) + { +gdprintk (XENLOG_INFO , +"Memory event op on a domain (%u) with no vcpus\n" , + d->domain_id); +return -EINVAL ; + } + +switch ( vec->type ) + { +case XEN_VM_EVENT_TYPE_MONITOR : + { + rc = -EINVAL ; + +switch ( vec-> op) + { +case XEN_VM_EVENT_NG_CREATE : +/* domain_pause() not required here, see XSA-99 */ + rc =arch_monitor_init_domain (d); +if ( rc ) +break ; + rc =vm_event_channels_create (d, vec, &d->vm_event_monitor, + _VPF_mem_access, monitor_notification); +break ; + +case XEN_VM_EVENT_NG_DESTROY : +if ( !vm_event_check (d->vm_event_monitor) ) +break ; +domain_pause (d); + rc =vm_event_channels_destroy (&d->vm_event_monitor); +arch_monitor_cleanup_domain (d); +domain_unpause (d); +break ; + +case XEN_VM_EVENT_NG_SET_STATE : +if ( !vm_event_check (d->vm_event_monitor) ) +break ; +domain_pause (d); +to_channels (d->vm_event_monitor)->enabled = !!vec->u.enabled; +domain_unpause (d); + rc =0 ; +break ; + +default : + rc = -ENOSYS ; + }
xen/common/vm_event_ng.c line 392
Quoted 10 lines
xen/common/vm_event_ng.c new file +10
-0+break ; + } + +#ifdef CONFIG_HAS_MEM_PAGING +case XEN_VM_EVENT_TYPE_PAGING : +#endif + +#ifdef CONFIG_HAS_MEM_SHARING +case XEN_VM_EVENT_TYPE_SHARING : +#endif
These are unnecessary, as they don't deviate from the default.
~Andrew
xen/common/vm_event_ng.c line 399
Quoted 8 lines
xen/common/vm_event_ng.c new file +7
-0+ +default : + rc = -ENOSYS ; + } + +return rc; +}
_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel
Re: [Xen-devel] [PATCH 9/9] xen-access: Add support for vm_event_ng interface
In reply to Petre PircalabuQuoted 4 lines · Petre Pircalabu
tools/tests/xen-access/vm-event-ng.c new file +4
-0+#define to_channels (_vme) container_of((_vme), vm_event_channels_t, vme) + +static int vm_event_channels_init(xc_interface *xch, xenevtchn_handle *xce, + domid_t domain_id, vm_event_ops_t *ops,
tools/tests/xen-access/vm-event-ng.c line 60
Quoted 10 lines
tools/tests/xen-access/vm-event-ng.c new file +10
-0+ vm_event_t **vm_event) +{ +vm_event_channels_t *impl =NULL ; +int rc, i, num_vcpus; +xc_dominfo_t info; +unsigned long nr_frames; + +/* Get the numbers of vcpus */ + rc =xc_domain_getinfo (xch, domain_id,1 , &info); +if ( rc !=1 )
|| info.domid != domain_id
The API is idiotic. However... (see several below)
tools/tests/xen-access/vm-event-ng.c line 69
Quoted 9 lines
tools/tests/xen-access/vm-event-ng.c new file +9
-0+ { +ERROR ("xc_domain_getinfo failed. rc = %d\n" , rc); +return rc; + } + + num_vcpus = info.max_vcpu_id +1 ; + + impl = (vm_event_channels_t *)calloc (1 ,sizeof (vm_event_channels_t) + + num_vcpus *sizeof (int ));
This is C, not C++
tools/tests/xen-access/vm-event-ng.c line 75
Quoted 6 lines
tools/tests/xen-access/vm-event-ng.c new file +6
-0+if ( !impl ) +return -ENOMEM ; + + impl->num_vcpus = num_vcpus; + + impl->fmem =xenforeignmemory_open (0 ,0 );
Spaces and NULL.
Quoted 10 lines
tools/tests/xen-access/vm-event-ng.c new file +10
-0+if ( !impl->fmem ) + { + rc = -errno; + goto err; + } + + rc =xc_monitor_ng_create (xch, domain_id); +if ( rc ) + { +ERROR ("Failed to enable monitor" );
tools/tests/xen-access/vm-event-ng.c line 95
Quoted 10 lines
tools/tests/xen-access/vm-event-ng.c new file +10
-0+ goto err; + } + + nr_frames =PFN_UP (num_vcpus *sizeof (struct vm_event_slot )); + + impl->fres =xenforeignmemory_map_resource (impl->fmem, domain_id, + XENMEM_resource_vm_event, +XEN_VM_EVENT_TYPE_MONITOR ,0 , + nr_frames, (void *)&impl->slots, +PROT_READ |PROT_WRITE ,0 );
... one big problem with the existing vm_event interface is that it requires domctls.
In particular, I was hoping we could take the opportunity of this new interface to see if we could also remove the use of all unstable interfaces.
Do you happen to know offhand which non-stable hypercalls are currently needed for introspection purposes?
tools/tests/xen-access/vm-event-ng.c line 200
Quoted 6 lines
tools/tests/xen-access/vm-event-ng.c new file +6
-0+vm_event_ops_t channel_ops = { + .get_request = vm_event_channels_get_request, + .put_response = vm_event_channels_put_response, + .notify_port = vm_event_channels_notify_port, + .init = vm_event_channels_init, + .teardown = vm_event_channels_teardown
Here and elsewhere, a trailing comma please. It simplifies future diffs.
Quoted 12 lines
tools/tests/xen-access/vm-event.c new file +6
-0+static int vm_event_ring_init (xc_interface *xch,xenevtchn_handle *xce, +domid_t domain_id,vm_event_ops_t *ops, +vm_event_t **vm_event) +{ +vm_event_ring_t *impl; +int rc;
tools/tests/xen-access/vm-event.c line 57
Quoted 10 lines
tools/tests/xen-access/vm-event.c new file +10
-0+ + impl = (vm_event_ring_t *)calloc (1 ,sizeof (vm_event_ring_t)); +if ( !impl ) +return -ENOMEM ; + +/* Enable mem_access */ + impl->ring_page =xc_monitor_enable (xch, domain_id, &impl->evtchn_port); +if ( impl->ring_page ==NULL ) + { +switch ( errno ) {
Style, seeing as you're moving it anyway.
Quoted 50 lines
tools/tests/xen-access/xen-access.c +2
-25@@ -35,12 +35,8 @@#include <time.h> #include <signal.h> #include <unistd.h> -#include <sys/mman.h> #include <poll.h> - -#include <xenctrl.h> -#include <xenevtchn.h> -#include <xen/vm_event.h> +#include <getopt.h> #include <xen-tools/libs.h> @@ -51,9 +47,7 @@#define START_PFN 0ULL#endif -#define DPRINTF(a, b...) fprintf(stderr, a, ## b) -#define ERROR(a, b...) fprintf(stderr, a "\n", ## b) -#define PERROR(a, b...) fprintf(stderr, a ": %s\n", ## b, strerror(errno)) +#include "xen-access.h" /* From xen/include/asm-x86/processor.h */ #define X86_TRAP_DEBUG 1@@ -62,32 +56,14 @@/* From xen/include/asm-x86/x86-defns.h */ #define X86_CR4_PGE 0x00000080/* enable global pages */ -typedef struct vm_event { -domid_t domain_id; -xenevtchn_handle *xce_handle; -int port; -vm_event_back_ring_t back_ring; -uint32_t evtchn_port; -void *ring_page; -}vm_event_t ; - -typedef struct xenaccess { -xc_interface *xc_handle; - -xen_pfn_t max_gpfn; - -vm_event_t vm_event; -}xenaccess_t ; -
tools/tests/xen-access/xen-access.c line 66
Quoted 10 lines
tools/tests/xen-access/xen-access.c +1
-2static int interrupted; -bool evtchn_bind =0 , evtchn_open =0 , mem_access_enable =0 ;static void close_handler (int sig) { interrupted = sig; } -int xc_wait_for_event_or_timeout (xc_interface *xch,xenevtchn_handle *xce,unsigned long ms) +static int xc_wait_for_event_or_timeout (xc_interface *xch,xenevtchn_handle *xce,unsigned long ms)
This looks like the patch wants at least splitting into two. The first doing cleanup/renaming/etc, and the second doing the interface splitting. Perhaps even a 3rd for the getopt() change.
~Andrew
_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel
Re: [Xen-devel] [PATCH 1/9] tools/libxc: Consistent usage of xc_vm_event_* interface
In reply to Petre Ovidiu PIRCALABUQuoted 53 lines · Petre Ovidiu PIRCALABU
Quoted 52 lines · Andrew Cooper
Quoted 12 lines · Petre Pircalabu
Modified
xc_mem_paging_enableto use directlyxc_vm_event_enableand
moved thering_pagehandling from client to libxc (xenpaging).Restricted
vm_event_controlusage only to simplest domctls which do not expect any return values and changexc_vm_event_enableto calldo_domctl
directly.Removed xc_memshr_ring_enable/disable and
xc_memshr_domain_resume.Signed-off-by Petre Pircalabu <[email protected]>Quoted 10 lines
--- tools/libxc/include/xenctrl.h | 49 +---------------------------- ---- tools/libxc/xc_mem_paging.c | 23 +++++----------- tools/libxc/xc_memshr.c | 34 ----------------------- tools/libxc/xc_monitor.c | 31 +++++++++++++++++---- tools/libxc/xc_private.h | 2 +- tools/libxc/xc_vm_event.c | 64 ++++++++++++++++--------------- ------------ tools/xenpaging/xenpaging.c | 42 +++-------------------------So, the diffstat here is very impressive, and judging by the delta, its
all about not opencoding the use of theHVM_PARAMinterface. Overall,
this is clearly a good thing.However, it is quite difficult to follow exactly what is going on.
AFAICT, this wants splitting into $N patches.
One patch should refactor
xc_mem_paging_enable()to usexc_vm_event_enable(), with the associated xenpaging cleanup.One patch should be the deletion of xc_memshr_* on its own, because AFAICT it is an isolated change. It also needs some justification, even
if it is "interface is unused and/or redundant with $X".One patch (alone) should be the repositioning of the
domain_pause()calls. This does certainly look like a vast improvement WRT error handling inxc_vm_event_enable(), but you've definitely changed the API
(insofar as the expectation that the caller has paused the domain) goes,
and its not at all obvious that this change is safe. It may very well
be, but you need to convince people as to why in the commit message.
Quoted 6 lines
Quoted 4 lines
I still haven't figured out what the purpose behind dropping the port parameter from
xc_vm_event_control()is.~Andrew
The main reason for this patch was to use an uniform calling convention for all
xc_vm_eventwrappers.
The cleanup is a great, but it needs to be in finer grained patches so it can be followed more easily.
Quoted 3 lines
However, at this stage I think it's best to drop it altogheter as it's not a requirement for the new
vm_eventinterface (new domctls are used along with their own separate wrappers).
See patch 8 for the discussion on why a new domctl probably isn't the right course of action.
~Andrew
_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel
Re: [Xen-devel] [PATCH 2/9] vm_event: Define VM_EVENT type
In reply to Tamas K LengyelQuoted 17 lines · Tamas K Lengyel
Quoted 9 lines · Tamas K Lengyel
Quoted 9 lines
Quoted 6 lines
/*
XEN_DOMCTL_mem_sharing_op.
- * The CONTROL sub-domctl is used for bringup/teardown. */
+ * The CONTROL sub-domctl is used for bringup/teardown.
+ * Please note that mem sharing can be turned on *without* setting-up the
+ * correspondin ring
+ */As a tangent, it can? how? (I'm entirely prepared to believe that this is how the code currently works, but I can't see how such a setup would plausibly work.)
Quoted 7 lines
The
vm_eventring formem_sharingis only used to communicate out-of-memory condition to an external listener. I think it's only useful for logging since the listener wouldn't really be in a position to try to "make space" for the faulting domain and it would get destroyed after the message is sent. In any case, there isn't any documentation for how it was intended to be used so this is just my guess.
Quoted 5 lines
Actually, it seems the listener was intended to be able to try to "make space" for the domain. How exactly is not clear but anyway, the domain would get paused if there is a listener instead of just being destroyed when there is an ENOMEM error while trying to deduplicate shared pages.
I can't say I'm surprised by this...
~Andrew
_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel
Re: [Xen-devel] [PATCH 4/9] vm_event: Remove "ring" suffix from vm_event_check_ring
In reply to Petre PircalabuQuoted 5 lines · Petre Pircalabu
Decouple implementation from interface to allow
vm_event_checkto be used regardless of thevm_eventunderlying implementation.Signed-off-by Petre Pircalabu <[email protected]>
_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel
Re: [Xen-devel] [PATCH 6/9] vm_event: Move struct vm_event_domain to vm_event.c
In reply to Petre PircalabuQuoted 5 lines · Petre Pircalabu
The
vm_event_domainmembers are not accessed outsidevm_event.cso it's better to hide de implementation details.Signed-off-by Petre Pircalabu <[email protected]>
_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel
Re: [Xen-devel] [PATCH 8/9] vm_event: Add vm_event_ng interface
In reply to Andrew CooperQuoted 14 lines · Andrew Cooper
Quoted 2 lines · Petre Pircalabu
Signed-off-by Petre Pircalabu <[email protected]>There are a number of concerns here.
First and foremost, why is a new domctl being added? Surely this should
just be a "type of ring access" parameter toevent_enable? Everything
else in thevm_eventset of APIs should be unchanged as a result of the
interface differences.
Quoted 2 lines
Or am I missing something?
I've used different domctls in order to completely separate the new interface from the old one.
One thing I don't really like about the old vm_event interface is that the "create" and "start" operations are handled in the same call (XEN_VM_EVENT_ENABLE).
These calls should separated in the new interface because the client needs to perform its own initalization (mapping the resource and event channel binding) between "create" and "start".
Quoted 21 lines
Quoted 15 lines
xen/common/vm_event_ng.c new file +1
-0+static int vm_event_channels_alloc_buffer(struct
vm_event_channels_domain*impl)xen/common/vm_event_ng.c new file +6
-0+{ +int i, rc = -ENOMEM ; + +for ( i =0 ; i < impl->nr_frames; i++ ) + { + struct page_info *page = alloc_domheap_page(impl->ved.d,Quoted 1 line
0);
This creates pages which are reference-able (in principle) by the guest,
and are bounded byd->max_pages.
Quoted 3 lines
Both of these are properties of the existing interface which we'd prefer
to remove.
The allocation mechanism is similar with the one used by ioreq (the main difference is the number of pages).
Quoted 15 lines
Quoted 15 lines
xen/common/vm_event_ng.c new file +4
-0+if ( !page ) + goto err; + + if ( !get_page_and_type(page, impl->ved.d,
PGT_writable_page) )xen/common/vm_event_ng.c new file +9
-0+ { + rc = -ENODATA ; + goto err; + } + + impl->mfn[i] =page_to_mfn (page); + } + + impl->slots = (struct vm_event_slot *)vmap(impl->mfn, impl-
Quoted 6 lines
Quoted 1 line
Quoted 1 line
nr_frames);You appear to have opencoded
vmalloc()here. Is there any reason not to
use that?
The problem with vmalloc is that if the pages are not assigned to a specific domain the remapping fails in the monitor domain. e.g.:
...
(XEN) mm.c:1015:d0v2 pg_owner d1 l1e_owner d0, but real_pg_owner d-1 (XEN) mm.c:1091:d0v7 Error getting mfn 5fbf53 (pfn ffffffffffffffff) from L1 entry 80000005fbf53227 for l1e_owner d0, pg_owner d1
Quoted 19 lines
xen/common/vm_event_ng.c line 168
Quoted 3 lines
xen/common/vm_event_ng.c new file +3
-0+err: +spin_unlock (&impl->ved.lock); +XFREE (impl);You don't free the event channels on error.
Please write make the destructor idempotent and call it from here.
xen/common/vm_event_ng.c line 392
Quoted 8 lines
xen/common/vm_event_ng.c new file +7
-0+#ifdef CONFIG_HAS_MEM_PAGING +case XEN_VM_EVENT_TYPE_PAGING : +#endif + +#ifdef CONFIG_HAS_MEM_SHARING +case XEN_VM_EVENT_TYPE_SHARING : +#endif These are unnecessary, as they don't deviate from the default.
Quoted 3 lines
~Andrew
Quoted 1 line
I will correct these in the next patchset iteration.
Many thanks for your support,
Petre
_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel
Re: [Xen-devel] [PATCH 8/9] vm_event: Add vm_event_ng interface
Quoted 16 lines
Quoted 1 line
Quoted 1 line · On 05.06.19 at 19:01, <[email protected]> wrote:
Quoted 14 lines · Andrew Cooper
Quoted 9 lines · Petre Pircalabu
+static int vm_event_channels_alloc_buffer(struct
vm_event_channels_domain*impl)xen/common/vm_event_ng.c new file +6
-0+{ +int i, rc = -ENOMEM ; + +for ( i =0 ; i < impl->nr_frames; i++ ) + { + struct page_info *page = alloc_domheap_page(impl->ved.d,0);
This creates pages which are reference-able (in principle) by the guest,
and are bounded byd->max_pages.
Not by a HVM one, because they can't reference pages by MFN. Or else, as Petre implies, the ioreq approach would be wrong, too.
Quoted 5 lines
Quoted 3 lines
Both of these are properties of the existing interface which we'd prefer
to remove.The allocation mechanism is similar with the one used by ioreq (the main difference is the number of pages).
Question is whether here you want to use the "caller owned" variant. I haven't thought through whether this would actually be better, so it's merely a remark.
Quoted 21 lines
Quoted 14 lines
Quoted 14 lines
xen/common/vm_event_ng.c new file +4
-0+if ( !page ) + goto err; + + if ( !get_page_and_type(page, impl->ved.d,
PGT_writable_page) )xen/common/vm_event_ng.c new file +9
-0+ { + rc = -ENODATA ; + goto err; + } + + impl->mfn[i] =page_to_mfn (page); + } + + impl->slots = (struct vm_event_slot *)vmap(impl->mfn, impl-Quoted 6 lines
Quoted 1 line
Quoted 1 line
nr_frames);You appear to have opencoded
vmalloc()here. Is there any reason not to
use that?
Quoted 7 lines
The problem with vmalloc is that if the pages are not assigned to a specific domain the remapping fails in the monitor domain. e.g.:
...
(XEN) mm.c:1015:d0v2pg_ownerd1l1e_ownerd0, butreal_pg_ownerd-1 (XEN) mm.c:1091:d0v7 Error getting mfn 5fbf53 (pfn ffffffffffffffff) from L1 entry80000005fbf53227forl1e_ownerd0,pg_ownerd1
In which case maybe use vmalloc() and then assign_pages()?
Jan
_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel
Re: [Xen-devel] [PATCH 8/9] vm_event: Add vm_event_ng interface
Quoted 26 lines · Jan Beulich
Quoted 12 lines
Quoted 1 line
Quoted 1 line · On 05.06.19 at 19:01, <[email protected]> wrote:
Quoted 9 lines · Andrew Cooper
Quoted 8 lines · Petre Pircalabu
+static int vm_event_channels_alloc_buffer(struct
vm_event_channels_domain*impl)xen/common/vm_event_ng.c new file +6
-0+{ +int i, rc = -ENOMEM ; + +for ( i =0 ; i < impl->nr_frames; i++ ) + { + struct page_info *page = alloc_domheap_page(impl-Quoted 6 lines
Quoted 6 lines
Quoted 2 lines
Quoted 1 line
ved.d,
0);
This creates pages which are reference-able (in principle) by the guest,
and are bounded byd->max_pages.Not by a HVM one, because they can't reference pages by MFN. Or else, as Petre implies, the ioreq approach would be wrong, too.
Quoted 4 lines
Quoted 3 lines
Both of these are properties of the existing interface which we'd prefer
to remove.
Quoted 7 lines
Quoted 2 lines
The allocation mechanism is similar with the one used by ioreq (the main difference is the number of pages).
Question is whether here you want to use the "caller owned" variant. I haven't thought through whether this would actually be better, so it's merely a remark.
XENMEM_rsrc_acq_caller_owned flag can only be used then the calling domain is the hardware domain. Unfortunately for us, this is a severe limitation as we're running the monitor client form a separate DomU.
From xen/common/memory.c :
....
/*
* FIXME: Until foreign pages inserted into the P2M are properly
* reference counted, it is unsafe to allow mapping of
* non-caller-owned resource pages unless the caller is
* the hardware domain.
*/
if ( !(xmar.flags & XENMEM_rsrc_acq_caller_owned) &&
!is_hardware_domain(currd) )
return -EACCES;...
Quoted 33 lines
Quoted 23 lines
Quoted 15 lines
Quoted 15 lines
xen/common/vm_event_ng.c new file +4
-0+if ( !page ) + goto err; + + if ( !get_page_and_type(page, impl->ved.d,
PGT_writable_page) )xen/common/vm_event_ng.c new file +9
-0+ { + rc = -ENODATA ; + goto err; + } + + impl->mfn[i] =page_to_mfn (page); + } + + impl->slots = (struct vm_event_slot *)vmap(impl->mfn,impl-
Quoted 7 lines
Quoted 1 line
Quoted 1 line
nr_frames);You appear to have opencoded
vmalloc()here. Is there any reason not
to
use that?Quoted 9 lines
The problem with vmalloc is that if the pages are not assigned to a specific domain the remapping fails in the monitor domain. e.g.:
...
(XEN) mm.c:1015:d0v2pg_ownerd1l1e_ownerd0, butreal_pg_ownerd- 1
(XEN) mm.c:1091:d0v7 Error getting mfn 5fbf53 (pfn ffffffffffffffff)
from L1 entry80000005fbf53227forl1e_ownerd0,pg_ownerd1
Quoted 2 lines
In which case maybe use
vmalloc()and thenassign_pages()? Jan
Unfortunately I wasn't able to make it work:
I replaced the buffer allocation with this code:
....
impl->slots = vzalloc(impl->nr_frames * PAGE_SIZE);
if ( !impl->slots )
return -ENOMEM;
for ( i = 0; i < impl->nr_frames; i++ )
{
impl->mfn[i] = vmap_to_mfn(impl->slots + i * PAGE_SIZE);
if ( assign_pages(current->domain, mfn_to_page(impl->mfn[i]),
0, 0/*MEMF_no_refcount*/ ) )
{
printk("%s: assign_pages returned error\n", __func__);
}
}...
And the error is similar with the one without assign_pages:
....
(XEN) mm.c:1015:d0v4 pg_owner d1 l1e_owner d0, but real_pg_owner d0 (XEN) mm.c:1091:d0v4 Error getting mfn 60deaf (pfn ffffffffffffffff) from L1 entry 800000060deaf227 for l1e_owner d0, pg_owner d1
Am I missing something?
Many thanks,
Petre
_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel
Re: [Xen-devel] [PATCH 8/9] vm_event: Add vm_event_ng interface
Quoted 15 lines
Quoted 1 line
Quoted 1 line · On 06.06.19 at 15:48, <[email protected]> wrote:
Quoted 2 lines · Jan Beulich
In which case maybe use
vmalloc()and thenassign_pages()? JanUnfortunately I wasn't able to make it work:
I replaced the buffer allocation with this code:
....impl->slots = vzalloc(impl->nr_frames * PAGE_SIZE); if ( !impl->slots ) return -ENOMEM; for ( i = 0; i < impl->nr_frames; i++ ) { impl->mfn[i] = vmap_to_mfn(impl->slots + i * PAGE_SIZE); if ( assign_pages(current->domain, mfn_to_page(impl->mfn[i]),
Quoted 1 line
0, 0/*MEMF_no_refcount*/ ) )
Who is current->domain at this point?
Quoted 10 lines
{ printk("%s: assign_pages returned error\n", __func__); } }...
And the error is similar with the one withoutassign_pages:
....
(XEN) mm.c:1015:d0v4pg_ownerd1l1e_ownerd0, butreal_pg_ownerd0 (XEN) mm.c:1091:d0v4 Error getting mfn 60deaf (pfn ffffffffffffffff) from L1 entry800000060deaf227forl1e_ownerd0,pg_ownerd1
This looks to be an attempt by Dom0 to map a page into its own page tables which it believes to be owned by Dom1. This would imply that current->domain above is also Dom1. I would instead have expected this to be a Dom0-owned page, in which case you shouldn't specify Dom1 to be the supposed owner of it in the mapping request.
Jan
_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel