[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Xen-changelog] [xen master] move XENMEM_add_to_physmap_range handling framework to common code



commit 0627c56cb6ff61e197da75c6958fff3b43159237
Author:     Jan Beulich <jbeulich@xxxxxxxx>
AuthorDate: Fri Dec 20 12:01:44 2013 +0100
Commit:     Jan Beulich <jbeulich@xxxxxxxx>
CommitDate: Fri Dec 20 12:01:44 2013 +0100

    move XENMEM_add_to_physmap_range handling framework to common code
    
    There's really nothing really architecture specific here; the
    architecture specific handling is limited to
    xenmem_add_to_physmap_one().
    
    This further eliminates the erroneous bailing from
    xenmem_add_to_physmap_range() if xenmem_add_to_physmap_one() fails.
    
    Signed-off-by: Jan Beulich <jbeulich@xxxxxxxx>
    Reviewed-by: Tim Deegan <tim@xxxxxxx>
    Acked-by: Keir Fraser <keir@xxxxxxx>
    Acked-by: Ian Campbell <ian.campbell@xxxxxxxxxx>
---
 xen/arch/arm/mm.c   |   93 ---------------------------------------------------
 xen/common/memory.c |   93 +++++++++++++++++++++++++++++++++++++++++++++++++++
 2 files changed, 93 insertions(+), 93 deletions(-)

diff --git a/xen/arch/arm/mm.c b/xen/arch/arm/mm.c
index 86015c7..293b6e2 100644
--- a/xen/arch/arm/mm.c
+++ b/xen/arch/arm/mm.c
@@ -1078,103 +1078,10 @@ int xenmem_add_to_physmap_one(
     return rc;
 }
 
-static int xenmem_add_to_physmap_range(struct domain *d,
-                                       struct xen_add_to_physmap_range *xatpr)
-{
-    int rc;
-
-    while ( xatpr->size > 0 )
-    {
-        xen_ulong_t idx;
-        xen_pfn_t gpfn;
-
-        if ( unlikely(copy_from_guest_offset(&idx, xatpr->idxs, 0, 1)) )
-        {
-            rc = -EFAULT;
-            goto out;
-        }
-
-        if ( unlikely(copy_from_guest_offset(&gpfn, xatpr->gpfns, 0, 1)) )
-        {
-            rc = -EFAULT;
-            goto out;
-        }
-
-        rc = xenmem_add_to_physmap_one(d, xatpr->space,
-                                       xatpr->foreign_domid,
-                                       idx, gpfn);
-
-        if ( unlikely(copy_to_guest_offset(xatpr->errs, 0, &rc, 1)) )
-        {
-            rc = -EFAULT;
-            goto out;
-        }
-
-        if ( rc < 0 )
-            goto out;
-
-        guest_handle_add_offset(xatpr->idxs, 1);
-        guest_handle_add_offset(xatpr->gpfns, 1);
-        guest_handle_add_offset(xatpr->errs, 1);
-        xatpr->size--;
-
-        /* Check for continuation if it's not the last interation */
-        if ( xatpr->size > 0 && hypercall_preempt_check() )
-        {
-            rc = -EAGAIN;
-            goto out;
-        }
-    }
-
-    rc = 0;
-
-out:
-    return rc;
-
-}
-
 long arch_memory_op(int op, XEN_GUEST_HANDLE_PARAM(void) arg)
 {
-    int rc;
-
     switch ( op )
     {
-    case XENMEM_add_to_physmap_range:
-    {
-        struct xen_add_to_physmap_range xatpr;
-        struct domain *d;
-
-        if ( copy_from_guest(&xatpr, arg, 1) )
-            return -EFAULT;
-
-        /* This mapspace is redundant for this hypercall */
-        if ( xatpr.space == XENMAPSPACE_gmfn_range )
-            return -EINVAL;
-
-        d = rcu_lock_domain_by_any_id(xatpr.domid);
-        if ( d == NULL )
-            return -ESRCH;
-
-        rc = xsm_add_to_physmap(XSM_TARGET, current->domain, d);
-        if ( rc )
-        {
-            rcu_unlock_domain(d);
-            return rc;
-        }
-
-        rc = xenmem_add_to_physmap_range(d, &xatpr);
-
-        rcu_unlock_domain(d);
-
-        if ( rc && copy_to_guest(arg, &xatpr, 1) )
-            rc = -EFAULT;
-
-        if ( rc == -EAGAIN )
-            rc = hypercall_create_continuation(
-                __HYPERVISOR_memory_op, "ih", op, arg);
-
-        return rc;
-    }
     /* XXX: memsharing not working yet */
     case XENMEM_get_sharing_shared_pages:
     case XENMEM_get_sharing_freed_pages:
diff --git a/xen/common/memory.c b/xen/common/memory.c
index 12264e0..ae0bbb8 100644
--- a/xen/common/memory.c
+++ b/xen/common/memory.c
@@ -595,6 +595,57 @@ static int xenmem_add_to_physmap(struct domain *d,
     return rc;
 }
 
+static int xenmem_add_to_physmap_range(struct domain *d,
+                                       struct xen_add_to_physmap_range *xatpr)
+{
+    int rc;
+
+    while ( xatpr->size > 0 )
+    {
+        xen_ulong_t idx;
+        xen_pfn_t gpfn;
+
+        if ( unlikely(__copy_from_guest_offset(&idx, xatpr->idxs, 0, 1)) )
+        {
+            rc = -EFAULT;
+            goto out;
+        }
+
+        if ( unlikely(__copy_from_guest_offset(&gpfn, xatpr->gpfns, 0, 1)) )
+        {
+            rc = -EFAULT;
+            goto out;
+        }
+
+        rc = xenmem_add_to_physmap_one(d, xatpr->space,
+                                       xatpr->foreign_domid,
+                                       idx, gpfn);
+
+        if ( unlikely(__copy_to_guest_offset(xatpr->errs, 0, &rc, 1)) )
+        {
+            rc = -EFAULT;
+            goto out;
+        }
+
+        guest_handle_add_offset(xatpr->idxs, 1);
+        guest_handle_add_offset(xatpr->gpfns, 1);
+        guest_handle_add_offset(xatpr->errs, 1);
+        xatpr->size--;
+
+        /* Check for continuation if it's not the last iteration. */
+        if ( xatpr->size > 0 && hypercall_preempt_check() )
+        {
+            rc = -EAGAIN;
+            goto out;
+        }
+    }
+
+    rc = 0;
+
+out:
+    return rc;
+}
+
 long do_memory_op(unsigned long cmd, XEN_GUEST_HANDLE_PARAM(void) arg)
 {
     struct domain *d;
@@ -764,6 +815,48 @@ long do_memory_op(unsigned long cmd, 
XEN_GUEST_HANDLE_PARAM(void) arg)
         return rc;
     }
 
+    case XENMEM_add_to_physmap_range:
+    {
+        struct xen_add_to_physmap_range xatpr;
+        struct domain *d;
+
+        if ( copy_from_guest(&xatpr, arg, 1) ||
+             !guest_handle_okay(xatpr.idxs, xatpr.size) ||
+             !guest_handle_okay(xatpr.gpfns, xatpr.size) ||
+             !guest_handle_okay(xatpr.errs, xatpr.size) )
+            return -EFAULT;
+
+        /* This mapspace is unsupported for this hypercall. */
+        if ( xatpr.space == XENMAPSPACE_gmfn_range )
+            return -EOPNOTSUPP;
+
+        d = rcu_lock_domain_by_any_id(xatpr.domid);
+        if ( d == NULL )
+            return -ESRCH;
+
+        rc = xsm_add_to_physmap(XSM_TARGET, current->domain, d);
+        if ( rc )
+        {
+            rcu_unlock_domain(d);
+            return rc;
+        }
+
+        rc = xenmem_add_to_physmap_range(d, &xatpr);
+
+        rcu_unlock_domain(d);
+
+        if ( rc == -EAGAIN )
+        {
+            if ( !__copy_to_guest(arg, &xatpr, 1) )
+                rc = hypercall_create_continuation(
+                    __HYPERVISOR_memory_op, "ih", op, arg);
+            else
+                rc = -EFAULT;
+        }
+
+        return rc;
+    }
+
     case XENMEM_remove_from_physmap:
     {
         struct xen_remove_from_physmap xrfp;
--
generated by git-patchbot for /home/xen/git/xen.git#master

_______________________________________________
Xen-changelog mailing list
Xen-changelog@xxxxxxxxxxxxx
http://lists.xensource.com/xen-changelog


 


Rackspace

Lists.xenproject.org is hosted with RackSpace, monitoring our
servers 24x7x365 and backed by RackSpace's Fanatical Support®.