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

[Xen-devel] [RFC 1/3] xen/common: memory: Introduce check_range_domain_direct_mapped



This function will be used in various place to check a given set of
contiguous MFN belongs to a direct domain guest.

Signed-off-by: Julien Grall <julien.grall@xxxxxxxxxx>

---
Cc: Ian Campbell <ian.campbell@xxxxxxxxxx>
Cc: Ian Jackson <ian.jackson@xxxxxxxxxxxxx>
Cc: Jan Beulich <jbeulich@xxxxxxxx>
Cc: Keir Fraser <keir@xxxxxxx>
Cc: Tim Deegan <tim@xxxxxxx>
---
 xen/common/memory.c | 62 ++++++++++++++++++++++++++++++++++-------------------
 1 file changed, 40 insertions(+), 22 deletions(-)

diff --git a/xen/common/memory.c b/xen/common/memory.c
index 9ff1145..ac707e9 100644
--- a/xen/common/memory.c
+++ b/xen/common/memory.c
@@ -89,6 +89,42 @@ static unsigned int max_order(const struct domain *d)
     return min(order, MAX_ORDER + 0U);
 }
 
+/*
+ * Direct mapped domain has the property gpfn == mfn for RAM region.
+ *
+ * Check if a given contiguous set of MFN belongs to the guest.
+ */
+static bool_t check_range_domain_direct_mapped(struct domain *d,
+                                               xen_pfn_t gpfn,
+                                               unsigned int order)
+{
+    unsigned long i;
+    struct page_info *page;
+
+    ASSERT(is_domain_direct_mapped(d));
+
+    for ( i = 0; i < (1U << order); i++, gpfn++ )
+    {
+       if ( !mfn_valid(gpfn) )
+       {
+           gdprintk(XENLOG_INFO, "Invalid mfn %#"PRI_xen_pfn"\n", gpfn);
+           return 0;
+       }
+
+       page = mfn_to_page(gpfn);
+       if ( !get_page(page, d) )
+       {
+           gdprintk(XENLOG_INFO,
+                    "mfn %#"PRI_xen_pfn" doesn't belong to d%d\n", gpfn,
+                    d->domain_id);
+           return 0;
+        }
+        put_page(page);
+    }
+
+    return 1;
+}
+
 static void increase_reservation(struct memop_args *a)
 {
     struct page_info *page;
@@ -171,30 +207,12 @@ static void populate_physmap(struct memop_args *a)
         {
             if ( is_domain_direct_mapped(d) )
             {
-                mfn = gpfn;
-
-                for ( j = 0; j < (1U << a->extent_order); j++, mfn++ )
-                {
-                    if ( !mfn_valid(mfn) )
-                    {
-                        gdprintk(XENLOG_INFO, "Invalid mfn %#"PRI_xen_pfn"\n",
-                                 mfn);
-                        goto out;
-                    }
-
-                    page = mfn_to_page(mfn);
-                    if ( !get_page(page, d) )
-                    {
-                        gdprintk(XENLOG_INFO,
-                                 "mfn %#"PRI_xen_pfn" doesn't belong to d%d\n",
-                                  mfn, d->domain_id);
-                        goto out;
-                    }
-                    put_page(page);
-                }
+                if ( !check_range_domain_direct_mapped(d, gpfn,
+                                                       a->extent_order) )
+                    goto out;
 
+                /* For direct mapped domain mfn == gpfn */
                 mfn = gpfn;
-                page = mfn_to_page(mfn);
             }
             else
             {
-- 
2.1.4


_______________________________________________
Xen-devel mailing list
Xen-devel@xxxxxxxxxxxxx
http://lists.xen.org/xen-devel


 


Rackspace

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