RFC: mem_event: use wait queue when ring is full
PATCH 1/1 RFC: mem_event: use wait queue when ring is full
# HG changeset patch
# User Olaf Hering <[email protected]>
# Date 1320786230 -3600
# Node ID 601d9ee4f1364e5e05b69f24be5e6c3b33e428ca # Parent 455f064fe54eeb57a43aa0c45a56cc4c4847d7a0
RFC: mem_event: use wait queue when ring is full
CAUTION: while the patch by itself is supposed to be complete, the added usage of waitqueues will lead to guest hangs and even sudden host reboots!
This change is based on an idea/patch from Adin Scannell.
If the ring is full, put the current vcpu to sleep if it belongs to the target domain. The wakeup happens in the p2m_*_resume functions. A request from another domain will use the existing ->req_producers functionality because sleeping is not possible if the vcpu does not belong to the target domain.
This change fixes also a bug in p2m_mem_paging_drop_page(). Up to now a full ring will lead to harmless inconsistency in the pager,
xen/arch/x86/hvm/hvm.c +1 -1
@@ -4026,7 +4026,7 @@ static int hvm_memory_event_traps(long preturn 1 ; rc =mem_event_check_ring (d, &d->mem_access); -if ( rc ) +if ( rc <0 )return rc;memset (&req,0 ,sizeof (req));
xen/arch/x86/mm/mem_event.c +62 -11
159 lines not on this page · raw message
xen/arch/x86/mm/mem_sharing.c +9 -17
@@ -253,19 +253,11 @@ static void mem_sharing_audit(void)#endif -static struct page_info *mem_sharing_alloc_page (struct domain *d, -unsigned long gfn) +static void mem_sharing_notify_helper (struct domain *d,unsigned long gfn) { -struct page_info * page;struct vcpu *v = current;mem_event_request_t req; - page =alloc_domheap_page (d,0 ); -if (page !=NULL )return page; - -memset (&req,0 ,sizeof (req)); - req.type =MEM_EVENT_TYPE_SHARED ; -if ( v->domain != d ) {/* XXX This path needs some attention. For now, just fail foreign
@@ -275,20 +267,19 @@ static struct page_info* mem_sharing_allgdprintk (XENLOG_ERR ,"Failed alloc on unshare path for foreign (%d) lookup\n" , d->domain_id); -return page; +return ; } -vcpu_pause_nosync (v); - req.flags |=MEM_EVENT_FLAG_VCPU_PAUSED ; +if (mem_event_check_ring (d, &d->mem_share) <0 ) +return ; -if (mem_event_check_ring (d, &d->mem_share))return page; - +memset (&req,0 ,sizeof (req)); + req.type =MEM_EVENT_TYPE_SHARED ; + req.flags =MEM_EVENT_FLAG_VCPU_PAUSED ; req.gfn = gfn; req.p2mt = p2m_ram_shared; req.vcpu_id = v->vcpu_id;mem_event_put_request (d, &d->mem_share, &req); - -return page; }unsigned int mem_sharing_get_nr_saved_mfns (void )
@@ -647,13 +638,14 @@ gfn_found:if (ret ==0 ) goto private_page_found; old_page = page; - page =mem_sharing_alloc_page (d, gfn); + page =alloc_domheap_page (d,0 );if (!page) {/* We've failed to obtain memory for private page. Need to re-add the * gfn_info to relevant list */ list_add (&gfn_info->list, &hash_entry->gfns);shr_unlock (); +mem_sharing_notify_helper (d, gfn);return -ENOMEM ; }
xen/arch/x86/mm/p2m.c +14 -16
@@ -840,17 +840,13 @@ void p2m_mem_paging_drop_page(struct domstruct vcpu *v = current;mem_event_request_t req; -/* Check that there's space on the ring for this request */ -if (mem_event_check_ring (d, &d->mem_paging) ==0 ) - { -/* Send release notification to pager */ -memset (&req,0 ,sizeof (req)); - req.flags |=MEM_EVENT_FLAG_DROP_PAGE ; - req.gfn = gfn; - req.vcpu_id = v->vcpu_id; +/* Send release notification to pager */ +memset (&req,0 ,sizeof (req)); + req.flags |=MEM_EVENT_FLAG_DROP_PAGE ; + req.gfn = gfn; + req.vcpu_id = v->vcpu_id; -mem_event_put_request (d, &d->mem_paging, &req); - } +mem_event_put_request (d, &d->mem_paging, &req); }/**
@@ -1027,8 +1023,8 @@ void p2m_mem_paging_resume(struct domainif ( rsp.flags &MEM_EVENT_FLAG_VCPU_PAUSED )vcpu_unpause (d->vcpu[rsp.vcpu_id]); -/* Unpause any domains that were paused because the ring was full */ -mem_event_unpause_vcpus (d); +/* Unpause all vcpus that were paused because the ring was full */ +wake_up (&d->mem_paging.wq); } void p2m_mem_access_check(unsigned long gpa, bool_t gla_valid, unsigned long gla,
@@ -1067,7 +1063,7 @@ void p2m_mem_access_check(unsigned long"Memory access permissions failure, no mem_event listener: pausing VCPU %d, dom %d\n" , v->vcpu_id, d->domain_id); -mem_event_mark_and_pause (v); +mem_event_mark_and_pause (v, &d->mem_access); }else {
@@ -1117,9 +1113,11 @@ void p2m_mem_access_resume(struct p2m_doif ( rsp.flags &MEM_EVENT_FLAG_VCPU_PAUSED )vcpu_unpause (d->vcpu[rsp.vcpu_id]); -/* Unpause any domains that were paused because the ring was full or no listener -* was available */ -mem_event_unpause_vcpus (d); +/* Wakeup all vcpus waiting because the ring was full */ +wake_up (&d->mem_access.wq); + +/* Unpause all vcpus that were paused because no listener was available */ +mem_event_unpause_vcpus (d, &d->mem_access); }
xen/include/asm-x86/mem_event.h +2 -2
@@ -25,12 +25,12 @@#define __MEM_EVENT_H__/* Pauses VCPU while marking pause flag for mem event */ -void mem_event_mark_and_pause (struct vcpu *v); +void mem_event_mark_and_pause (struct vcpu *v,struct mem_event_domain *med);int mem_event_check_ring (struct domain *d,struct mem_event_domain *med);void mem_event_put_req_producers (struct mem_event_domain *med);void mem_event_put_request (struct domain *d,struct mem_event_domain *med,mem_event_request_t *req);void mem_event_get_response (struct mem_event_domain *med,mem_event_response_t *rsp); -void mem_event_unpause_vcpus (struct domain *d); +void mem_event_unpause_vcpus (struct domain *d,struct mem_event_domain *med);int mem_event_domctl (struct domain *d,xen_domctl_mem_event_op_t *mec,XEN_GUEST_HANDLE (void ) u_domctl);
xen/include/xen/sched.h +11 -3
@@ -14,6 +14,7 @@#include <xen/nodemask.h> #include <xen/radix-tree.h> #include <xen/multicall.h> +#include <xen/wait.h> #include <public/xen.h> #include <public/domctl.h> #include <public/sysctl.h>
@@ -192,6 +193,10 @@ struct mem_event_domainmem_event_front_ring_t front_ring;/* event channel port (vcpu0 only) */ int xen_port; +/* mem_event bit for vcpu->pause_flags */ +int mem_event_bit; +/* list of vcpus waiting for room in the ring */ +struct waitqueue_head wq; };struct domain
@@ -588,9 +593,12 @@ extern struct domain *domain_list;/* VCPU affinity has changed: migrating to a new CPU. */ #define _VPF_migrating 3#define VPF_migrating (1UL<<_VPF_migrating) -/* VCPU is blocked on memory-event ring. */ -#define _VPF_mem_event 4 -#define VPF_mem_event (1UL<<_VPF_mem_event) +/* VCPU is blocked on mem_paging ring. */ +#define _VPF_me_mem_paging 4 +#define VPF_me_mem_paging (1UL<<_VPF_me_mem_paging) +/* VCPU is blocked on mem_access ring. */ +#define _VPF_me_mem_access 5 +#define VPF_me_mem_access (1UL<<_VPF_me_mem_access)static inline int vcpu_runnable (struct vcpu *v) {