@@ -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
{
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@citrix.com> --- Cc: Ian Campbell <ian.campbell@citrix.com> Cc: Ian Jackson <ian.jackson@eu.citrix.com> Cc: Jan Beulich <jbeulich@suse.com> Cc: Keir Fraser <keir@xen.org> Cc: Tim Deegan <tim@xen.org> --- xen/common/memory.c | 62 ++++++++++++++++++++++++++++++++++------------------- 1 file changed, 40 insertions(+), 22 deletions(-)