RFC: Use memops for mem paging, sharing, and access, instead of domctls
PATCH 1/1 RFC: Use memops for mem paging, sharing, and access, instead of domctls
tools/libxc/xc_mem_access.c | 12 +- tools/libxc/xc_mem_event.c | 23 +++- tools/libxc/xc_mem_paging.c | 44 ++++---- tools/libxc/xc_memshr.c | 192 ++++++++++++++++++------------------- tools/libxc/xc_private.c | 10 - tools/libxc/xenctrl.h | 6 +- tools/memshr/interface.c | 4 +- xen/arch/x86/domctl.c | 1 - xen/arch/x86/mm/mem_access.c | 7 +- xen/arch/x86/mm/mem_event.c | 68 +++++++++++-- xen/arch/x86/mm/mem_paging.c | 13 +- xen/arch/x86/mm/mem_sharing.c | 101 +++++++++++-------- xen/arch/x86/x86_64/compat/mm.c | 23 ++++ xen/arch/x86/x86_64/mm.c | 23 ++++ xen/include/asm-x86/mem_access.h | 3 +- xen/include/asm-x86/mem_event.h | 2 + xen/include/asm-x86/mem_paging.h | 3 +- xen/include/asm-x86/mem_sharing.h | 3 + xen/include/public/domctl.h | 91 +++++------------ xen/include/public/memory.h | 74 ++++++++++++++ 20 files changed, 426 insertions(+), 277 deletions(-)
Per page operations in the paging, sharing, and access tracking subsystems are all implemented with domctls (e.g. a domctl to evict one page, or to share one page).
Under heavy load, the domctl path reveals a lack of scalability. The domctl lock serializes dom0's vcpus in the hypervisor. When performing thousands of per-page operations on dozens of domains, these vcpus will spin in the hypervisor. Beyond the aggressive locking, an added inefficiency of blocking vcpus in the domctl lock is that dom0 is prevented from re-scheduling.
In this proposal we retain the domctl interface for setting up and tearing down paging/sharing/mem access for a domain. But we migrate all the per page operations to use the memory_op hypercalls (e.g XENMEM_*).
While we naturally welcome comments on the correctness of the approach, we are also concerned about the viability of this API change. With 4.2 coming, this is the right time to get an interface right, for the long run.
tools/libxc/xc_mem_access.c +6 -6
@@ -30,7 +30,7 @@ int xc_mem_access_enable(xc_interface *xreturn xc_mem_event_control (xch, domain_id,XEN_DOMCTL_MEM_EVENT_OP_ACCESS_ENABLE ,XEN_DOMCTL_MEM_EVENT_OP_ACCESS , - shared_page, ring_page,INVALID_MFN ); + shared_page, ring_page); }int xc_mem_access_disable (xc_interface *xch,domid_t domain_id)
@@ -38,15 +38,15 @@ int xc_mem_access_disable(xc_interface *return xc_mem_event_control (xch, domain_id,XEN_DOMCTL_MEM_EVENT_OP_ACCESS_DISABLE ,XEN_DOMCTL_MEM_EVENT_OP_ACCESS , -NULL ,NULL ,INVALID_MFN ); +NULL ,NULL ); }int xc_mem_access_resume (xc_interface *xch,domid_t domain_id,unsigned long gfn) { -return xc_mem_event_control (xch, domain_id, -XEN_DOMCTL_MEM_EVENT_OP_ACCESS_RESUME , -XEN_DOMCTL_MEM_EVENT_OP_ACCESS , -NULL ,NULL , gfn); +return xc_mem_event_memop (xch, domain_id, + XENMEM_access_op_resume, + XENMEM_access_op, + gfn,NULL ); }/*
tools/libxc/xc_mem_event.c +18 -5
@@ -24,8 +24,7 @@#include "xc_private.h" int xc_mem_event_control (xc_interface *xch,domid_t domain_id,unsigned int op, -unsigned int mode,void *page, -void *ring_page,unsigned long gfn) +unsigned int mode,void *page,void *ring_page) {DECLARE_DOMCTL ;
@@ -34,11 +33,25 @@ int xc_mem_event_control(xc_interface *x domctl.u.mem_event_op.op = op; domctl.u.mem_event_op.mode = mode; - domctl.u.mem_event_op.u.shared_addr = (unsigned long )page; + domctl.u.mem_event_op.shared_addr = (unsigned long )page; domctl.u.mem_event_op.ring_addr = (unsigned long )ring_page; - - domctl.u.mem_event_op.gfn = gfn;return do_domctl (xch, &domctl); } +int xc_mem_event_memop (xc_interface *xch,domid_t domain_id, +unsigned int op,unsigned int mode, +uint64_t gfn,void *buffer) +{ +xen_mem_event_op_t meo; + +memset (&meo,0 ,sizeof (meo)); + + meo.op = op; + meo.domain = domain_id; + meo.gfn = gfn; + meo.buffer = (unsigned long ) buffer; + +return do_memory_op (xch, mode, &meo,sizeof (meo)); +} +
tools/libxc/xc_mem_paging.c +22 -22
80 lines not on this page · raw message
tools/libxc/xc_memshr.c +94 -98
274 lines not on this page · raw message
tools/libxc/xc_private.c +0 -10
@@ -533,16 +533,6 @@ long xc_maximum_ram_page(xc_interface *xreturn do_memory_op (xch, XENMEM_maximum_ram_page,NULL ,0 ); } -long xc_sharing_freed_pages (xc_interface *xch) -{ -return do_memory_op (xch, XENMEM_get_sharing_freed_pages,NULL ,0 ); -} - -long xc_sharing_used_frames (xc_interface *xch) -{ -return do_memory_op (xch, XENMEM_get_sharing_shared_pages,NULL ,0 ); -} -long long xc_domain_get_cpu_usage (xc_interface *xch,domid_t domid,int vcpu ) {DECLARE_DOMCTL ;
tools/libxc/xenctrl.h +4 -2
@@ -1872,8 +1872,10 @@ int xc_tmem_restore_extra(xc_interface ** mem_event operations */ int xc_mem_event_control (xc_interface *xch,domid_t domain_id,unsigned int op, -unsigned int mode,void *shared_page, -void *ring_page,unsigned long gfn); +unsigned int mode,void *shared_page,void *ring_page); +int xc_mem_event_memop (xc_interface *xch,domid_t domain_id, +unsigned int op,unsigned int mode, +uint64_t gfn,void *buffer);int xc_mem_paging_enable (xc_interface *xch,domid_t domain_id,void *shared_page,void *ring_page);
tools/memshr/interface.c +2 -2
@@ -186,12 +186,12 @@ int memshr_vbd_issue_ro_request(char *buremove the relevant ones from the map */ switch (ret) { -case XEN_DOMCTL_MEM_SHARING_S_HANDLE_INVALID : +case XENMEM_SHARING_OP_S_HANDLE_INVALID : ret =blockshr_shrhnd_remove (memshr.blks, source_st,NULL );if (ret)DPRINTF ("Could not rm invl s_hnd: %u %" PRId64" %" PRId64"\n" , source_st.domain, source_st.frame, source_st.handle);break ; -case XEN_DOMCTL_MEM_SHARING_C_HANDLE_INVALID : +case XENMEM_SHARING_OP_C_HANDLE_INVALID : ret =blockshr_shrhnd_remove (memshr.blks, client_st,NULL );if (ret)DPRINTF ("Could not rm invl c_hnd: %u %" PRId64" %" PRId64"\n" , client_st.domain, client_st.frame, client_st.handle);
xen/arch/x86/domctl.c +0 -1
@@ -1463,7 +1463,6 @@ long arch_do_domctl(if ( !ret ) ret =mem_sharing_domctl (d, &domctl->u.mem_sharing_op);rcu_unlock_domain (d); -copy_to_guest (u_domctl, domctl,1 ); } }break ;
xen/arch/x86/mm/mem_access.c +3 -4
@@ -25,14 +25,13 @@#include <asm/mem_event.h> -int mem_access_domctl (struct domain *d,xen_domctl_mem_event_op_t *mec, -XEN_GUEST_HANDLE (void ) u_domctl) +int mem_access_memop (struct domain *d,xen_mem_event_op_t *meo) {int rc; -switch ( mec->op ) +switch ( meo->op ) { -case XEN_DOMCTL_MEM_EVENT_OP_ACCESS_RESUME : +case XENMEM_access_op_resume: {p2m_mem_access_resume (d); rc =0 ;
xen/arch/x86/mm/mem_event.c +57 -11
101 lines not on this page · raw message
xen/arch/x86/mm/mem_paging.c +6 -7
@@ -25,33 +25,32 @@#include <asm/mem_event.h> -int mem_paging_domctl (struct domain *d,xen_domctl_mem_event_op_t *mec, -XEN_GUEST_HANDLE (void ) u_domctl) +int mem_paging_memop (struct domain *d,xen_mem_event_op_t *mec) {switch ( mec->op ) { -case XEN_DOMCTL_MEM_EVENT_OP_PAGING_NOMINATE : +case XENMEM_paging_op_nominate: {unsigned long gfn = mec->gfn;return p2m_mem_paging_nominate (d, gfn); }break ; -case XEN_DOMCTL_MEM_EVENT_OP_PAGING_EVICT : +case XENMEM_paging_op_evict: {unsigned long gfn = mec->gfn;return p2m_mem_paging_evict (d, gfn); }break ; -case XEN_DOMCTL_MEM_EVENT_OP_PAGING_PREP : +case XENMEM_paging_op_prep: {unsigned long gfn = mec->gfn; -return p2m_mem_paging_prep (d, gfn, mec->u.buffer); +return p2m_mem_paging_prep (d, gfn, mec->buffer); }break ; -case XEN_DOMCTL_MEM_EVENT_OP_PAGING_RESUME : +case XENMEM_paging_op_resume: {p2m_mem_paging_resume (d);return 0 ;
xen/arch/x86/mm/mem_sharing.c +60 -41
260 lines not on this page · raw message
xen/arch/x86/x86_64/compat/mm.c +23 -0
@@ -2,6 +2,7 @@#include <xen/multicall.h> #include <compat/memory.h> #include <compat/xen.h> +#include <asm/mem_event.h> int compat_set_gdt (XEN_GUEST_HANDLE (uint) frame_list,unsigned int entries) {
@@ -211,6 +212,28 @@ int compat_arch_memory_op(int op, XEN_GUcase XENMEM_get_sharing_shared_pages:return mem_sharing_get_nr_shared_mfns (); +case XENMEM_paging_op: +case XENMEM_access_op: + { +xen_mem_event_op_t meo; +if (copy_from_guest (&meo, arg,1 ) ) +return -EFAULT ; + rc =do_mem_event_op (op, meo.domain, (void *) &meo); +if ( !rc &©_to_guest (arg, &meo,1 ) ) +return -EFAULT ; +break ; + } +case XENMEM_sharing_op: + { +xen_mem_sharing_op_t mso; +if (copy_from_guest (&mso, arg,1 ) ) +return -EFAULT ; + rc =do_mem_event_op (op, mso.domain, (void *) &mso); +if ( !rc &©_to_guest (arg, &mso,1 ) ) +return -EFAULT ; +break ; + } +default : rc = -ENOSYS ;break ;
xen/arch/x86/x86_64/mm.c +23 -0
@@ -34,6 +34,7 @@#include <asm/msr.h> #include <asm/setup.h> #include <asm/numa.h> +#include <asm/mem_event.h> #include <asm/mem_sharing.h> #include <public/memory.h>
@@ -1100,6 +1101,28 @@ long subarch_memory_op(int op, XEN_GUESTcase XENMEM_get_sharing_shared_pages:return mem_sharing_get_nr_shared_mfns (); +case XENMEM_paging_op: +case XENMEM_access_op: + { +xen_mem_event_op_t meo; +if (copy_from_guest (&meo, arg,1 ) ) +return -EFAULT ; + rc =do_mem_event_op (op, meo.domain, (void *) &meo); +if ( !rc &©_to_guest (arg, &meo,1 ) ) +return -EFAULT ; +break ; + } +case XENMEM_sharing_op: + { +xen_mem_sharing_op_t mso; +if (copy_from_guest (&mso, arg,1 ) ) +return -EFAULT ; + rc =do_mem_event_op (op, mso.domain, (void *) &mso); +if ( !rc &©_to_guest (arg, &mso,1 ) ) +return -EFAULT ; +break ; + } +default : rc = -ENOSYS ;break ;
xen/include/asm-x86/mem_access.h +1 -2
@@ -21,8 +21,7 @@*/ -int mem_access_domctl (struct domain *d,xen_domctl_mem_event_op_t *mec, -XEN_GUEST_HANDLE (void ) u_domctl); +int mem_access_memop (struct domain *d,xen_mem_event_op_t *meo);/*
xen/include/asm-x86/mem_event.h +2 -0
@@ -39,6 +39,8 @@ void mem_event_put_request(struct domainint mem_event_get_response (struct domain *d,struct mem_event_domain *med,mem_event_response_t *rsp); +struct domain *get_mem_event_op_target (uint32_t domain,int *rc); +int do_mem_event_op (int op,uint32_t domain,void *arg);int mem_event_domctl (struct domain *d,xen_domctl_mem_event_op_t *mec,XEN_GUEST_HANDLE (void ) u_domctl);
xen/include/asm-x86/mem_paging.h +1 -2
@@ -21,8 +21,7 @@*/ -int mem_paging_domctl (struct domain *d,xen_domctl_mem_event_op_t *mec, -XEN_GUEST_HANDLE (void ) u_domctl); +int mem_paging_memop (struct domain *d,xen_mem_event_op_t *meo);/*
xen/include/asm-x86/mem_sharing.h +3 -0
@@ -23,6 +23,7 @@#define __MEM_SHARING_H__#include <public/domctl.h> +#include <public/memory.h> /* Auditing of memory sharing code? */ #define MEM_SHARING_AUDIT 1
@@ -56,6 +57,8 @@ int mem_sharing_unshare_page(struct domaunsigned long gfn, uint16_t flags);int mem_sharing_sharing_resume (struct domain *d); +int mem_sharing_memop (struct domain *d, +xen_mem_sharing_op_t *mec);int mem_sharing_domctl (struct domain *d,xen_domctl_mem_sharing_op_t *mec);void mem_sharing_init (void );
xen/include/public/domctl.h +27 -64
133 lines not on this page · raw message
xen/include/public/memory.h +74 -0
80 lines not on this page · raw message
Quoted 10 lines · Andres Lagar-Cavilla
Per page operations in the paging, sharing, and access tracking subsystems are all implemented with domctls (e.g. a domctl to evict one page, or to share one page).
Under heavy load, the domctl path reveals a lack of scalability. The domctl lock serializes dom0's vcpus in the hypervisor. When performing thousands of per-page operations on dozens of domains, these vcpus will spin in the hypervisor. Beyond the aggressive locking, an added inefficiency of blocking vcpus in the domctl lock is that dom0 is prevented from re-scheduling.
Quoted 7 lines
In this proposal we retain the domctl interface for setting up and tearing down paging/sharing/mem access for a domain. But we migrate all the per page operations to use the
memory_ophypercalls (e.g XENMEM_*).While we naturally welcome comments on the correctness of the approach, we are also concerned about the viability of this API change. With 4.2 coming, this is the right time to get an interface right, for the long run.
I'm happy with the API change but I'd like the other users of it to comment.
Tim.
Quoted 12 lines · Andres Lagar-Cavilla
+++
b/xen/include/public/domctl.hxen/include/public/domctl.h +2
-4+/* Use for teardown/setup of helper<->hypervisor interface for paging, +* access and sharing.*/ struct xen_domctl_mem_event_op {uint32_t op;/* XEN_DOMCTL_MEM_EVENT_OP_*_* */ uint32_t mode;/* XEN_DOMCTL_MEM_EVENT_OP_* */ -union { -/* OP_ENABLE IN: Virtual address of shared page */ -uint64_aligned_t shared_addr; -/* PAGING_PREP IN: buffer to immediately fill page in */
xen/include/public/domctl.h struct xen_domctl_gdbsx_domstatus { · line 754
Quoted 10 lines
xen/include/public/domctl.h +3
-4-uint64_aligned_t buffer; - } u; +uint64_aligned_t shared_addr;/* IN: Virtual address of shared page */ uint64_aligned_t ring_addr;/* IN: Virtual address of ring page */ -/* Other OPs */ -uint64_aligned_t gfn;/* IN: gfn of page being operated on */ +/* For binary backwards compatibility */ +uint64_aligned_t pad; };
Assuming this struct is routed through libxc, and libxc gets a new SONAME for every release, doesnt this mean that every old binary has to be recompiled anyway for the new release?
If so, the padding is not needed.
Olaf
Quoted 28 lines · Andres Lagar-Cavilla
Quoted 23 lines
+++
b/xen/include/public/domctl.hxen/include/public/domctl.h +3
-6+/* Use for teardown/setup of helper<->hypervisor interface for paging, +* access and sharing.*/ struct xen_domctl_mem_event_op {uint32_t op;/* XEN_DOMCTL_MEM_EVENT_OP_*_* */ uint32_t mode;/* XEN_DOMCTL_MEM_EVENT_OP_* */ -union { -/* OP_ENABLE IN: Virtual address of shared page */ -uint64_aligned_t shared_addr; -/* PAGING_PREP IN: buffer to immediately fill page in */ -uint64_aligned_t buffer; - } u; +uint64_aligned_t shared_addr;/* IN: Virtual address of shared page */
uint64_aligned_tring_addr; /* IN: Virtual address of ring page
*/(quoted diff) +0
-2- /* Other OPs */ - uint64_aligned_t gfn; /* IN: gfn of page being operatedon */
xen/include/public/domctl.h struct xen_domctl_gdbsx_domstatus { · line 754
Quoted 3 lines
xen/include/public/domctl.h +2
-0+/* For binary backwards compatibility */ +uint64_aligned_t pad; };
Quoted 4 lines
Assuming this struct is routed through libxc, and libxc gets a new SONAME for every release, doesnt this mean that every old binary has to be recompiled anyway for the new release?
If so, the padding is not needed.
Agreed, basically. Waiting to hear from tools maintainers about best approach to libxc.
It seems that there aren't that many users relying on a fixed ABI, so we can (still, until 4.2) change things. But obviously I want to be careful.
Andres
Quoted 4 lines
Olaf
Quoted 32 lines · Andres Lagar-Cavilla
Quoted 28 lines · Andres Lagar-Cavilla
Quoted 23 lines
+++
b/xen/include/public/domctl.hxen/include/public/domctl.h +3
-6+/* Use for teardown/setup of helper<->hypervisor interface for paging, +* access and sharing.*/ struct xen_domctl_mem_event_op {uint32_t op;/* XEN_DOMCTL_MEM_EVENT_OP_*_* */ uint32_t mode;/* XEN_DOMCTL_MEM_EVENT_OP_* */ -union { -/* OP_ENABLE IN: Virtual address of shared page */ -uint64_aligned_t shared_addr; -/* PAGING_PREP IN: buffer to immediately fill page in */ -uint64_aligned_t buffer; - } u; +uint64_aligned_t shared_addr;/* IN: Virtual address of shared page */
uint64_aligned_tring_addr; /* IN: Virtual address of ring page
*/(quoted diff) +0
-2- /* Other OPs */ - uint64_aligned_t gfn; /* IN: gfn of page being operatedon */
xen/include/public/domctl.h struct xen_domctl_gdbsx_domstatus { · line 754
Quoted 3 lines
xen/include/public/domctl.h +2
-0+/* For binary backwards compatibility */ +uint64_aligned_t pad; };Quoted 4 lines
Assuming this struct is routed through libxc, and libxc gets a new SONAME for every release, doesnt this mean that every old binary has to be recompiled anyway for the new release?
If so, the padding is not needed.
Quoted 5 lines
Agreed, basically. Waiting to hear from tools maintainers about best approach to libxc.
It seems that there aren't that many users relying on a fixed ABI, so we can (still, until 4.2) change things. But obviously I want to be careful.
Ping?
Tim.
Quoted 37 lines
Quoted 36 lines · Andres Lagar-Cavilla
Quoted 5 lines · Andres Lagar-Cavilla
Quoted 4 lines
+++
b/xen/include/public/domctl.h+/* Use for teardown/setup of helper<->hypervisor interface for
paging,
Quoted 5 lines
Quoted 5 lines
+ * access and sharing.*/
structxen_domctl_mem_event_op{uint32_t op; /* XEN_DOMCTL_MEM_EVENT_OP_*_* */ uint32_t mode; /* XEN_DOMCTL_MEM_EVENT_OP_* */Quoted 9 lines
Quoted 9 lines
xen/include/public/domctl.h +1
-6-union { -/* OP_ENABLE IN: Virtual address of shared page */ -uint64_aligned_t shared_addr; -/* PAGING_PREP IN: buffer to immediately fill page in */ -uint64_aligned_t buffer; - } u; +uint64_aligned_t shared_addr;/* IN: Virtual address of shared page */
uint64_aligned_tring_addr; /* IN: Virtual address of ringpage
Quoted 4 lines
Review
Quoted 4 lines
*/
(quoted diff) +0
-2- /* Other OPs */ - uint64_aligned_t gfn; /* IN: gfn of page beingoperated
Quoted 7 lines
xen/include/public/domctl.h struct xen_domctl_gdbsx_domstatus { · line 754
Quoted 4 lines
on */
xen/include/public/domctl.h +2
-0+/* For binary backwards compatibility */ +uint64_aligned_t pad; };Assuming this struct is routed through libxc, and libxc gets a new SONAME for every release, doesnt this mean that every old binary has
to
Quoted 2 lines
be recompiled anyway for the new release?
If so, the padding is not needed.
Quoted 8 lines
Quoted 6 lines
Agreed, basically. Waiting to hear from tools maintainers about best approach to libxc.
It seems that there aren't that many users relying on a fixed ABI, so we can (still, until 4.2) change things. But obviously I want to be careful.
Ping?
I have working code. Except that it blue-screened W7 once, so it's been put in the back-burner for next week.
I can repost for review. Ok, I will.
I have not heard any objections thus far to the ABI change.
Andres
Quoted 3 lines
Tim.