diff --git a/xen/arch/x86/mm.c b/xen/arch/x86/mm.c index 7cbbb07..126f5b6 100644 --- a/xen/arch/x86/mm.c +++ b/xen/arch/x86/mm.c @@ -4592,8 +4592,8 @@ static int handle_iomem_range(unsigned long s, unsigned long e, void *p) return 0; } -static int xenmem_add_to_physmap(struct domain *d, - struct xen_add_to_physmap xatp) +static int xenmem_add_to_physmap_once(struct domain *d, + struct xen_add_to_physmap xatp) { struct page_info* page = NULL; unsigned long mfn = 0; @@ -4631,6 +4631,7 @@ static int xenmem_add_to_physmap(struct domain *d, spin_unlock(&d->grant_table->lock); break; + case XENMAPSPACE_gmfn_range: case XENMAPSPACE_gmfn: { p2m_type_t p2mt; @@ -4691,6 +4692,37 @@ static int xenmem_add_to_physmap(struct domain *d, return rc; } +static int xenmem_add_to_physmap(struct domain *d, + struct xen_add_to_physmap *xatp) +{ + int rc = 0; + + if ( xatp->space == XENMAPSPACE_gmfn_range ) + { + while ( xatp->size > 0 ) + { + rc = xenmem_add_to_physmap_once(d, *xatp); + if ( rc < 0 ) + return rc; + + xatp->idx++; + xatp->gpfn++; + xatp->size--; + + /* Check for continuation if it's not the last interation */ + if ( xatp->size > 0 && hypercall_preempt_check() ) + { + rc = -EAGAIN; + break; + } + } + + return rc; + } + + return xenmem_add_to_physmap_once(d, *xatp); +} + long arch_memory_op(int op, XEN_GUEST_HANDLE(void) arg) { int rc; @@ -4715,10 +4747,20 @@ long arch_memory_op(int op, XEN_GUEST_HANDLE(void) arg) return -EPERM; } - rc = xenmem_add_to_physmap(d, xatp); + rc = xenmem_add_to_physmap(d, &xatp); rcu_unlock_domain(d); + if ( rc ) + { + if ( copy_to_guest(arg, &xatp, 1) ) + return -EFAULT; + } + + if ( rc == -EAGAIN ) + rc = hypercall_create_continuation( + __HYPERVISOR_memory_op, "ih", op, arg); + return rc; } diff --git a/xen/arch/x86/x86_64/compat/mm.c b/xen/arch/x86/x86_64/compat/mm.c index 3ef08a5..2644770 100644 --- a/xen/arch/x86/x86_64/compat/mm.c +++ b/xen/arch/x86/x86_64/compat/mm.c @@ -63,6 +63,20 @@ int compat_arch_memory_op(int op, XEN_GUEST_HANDLE(void) arg) XLAT_add_to_physmap(nat, &cmp); rc = arch_memory_op(op, guest_handle_from_ptr(nat, void)); + if ( rc ) + { + XLAT_add_to_physmap(&cmp, nat); + if ( copy_to_guest(arg, &cmp, 1) ) + { + hypercall_cancel_continuation(); + return -EFAULT; + } + } + if ( rc < 0 ) + break; + + if ( rc == __HYPERVISOR_memory_op ) + hypercall_xlat_continuation(NULL, 0x2, nat, arg); break; } diff --git a/xen/include/public/memory.h b/xen/include/public/memory.h index 08355e3..c5b78a8 100644 --- a/xen/include/public/memory.h +++ b/xen/include/public/memory.h @@ -208,10 +208,14 @@ struct xen_add_to_physmap { /* Which domain to change the mapping for. */ domid_t domid; + /* Number of pages to go through for gmfn_range */ + uint16_t size; + /* Source mapping space. */ #define XENMAPSPACE_shared_info 0 /* shared info page */ #define XENMAPSPACE_grant_table 1 /* grant table page */ #define XENMAPSPACE_gmfn 2 /* GMFN */ +#define XENMAPSPACE_gmfn_range 3 /* GMFN range */ unsigned int space; #define XENMAPIDX_grant_table_status 0x80000000