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

[PATCH v1 07/13] xen/arm: map shared memory to borrower when host address not provided



With the introduction of new scenario where host address is not provided
in "xen,shared-mem", the function "map_regions_p2mt" for setting up
P2M foreign mapping for borrower domain shall be adapted to it too.

Here we implement a new helper "borrower_physmap_add_memory" to
cover both scenarios.

Signed-off-by: Penny Zheng <penny.zheng@xxxxxxx>
---
 xen/arch/arm/domain_build.c | 54 ++++++++++++++++++++++++++++++++++---
 1 file changed, 51 insertions(+), 3 deletions(-)

diff --git a/xen/arch/arm/domain_build.c b/xen/arch/arm/domain_build.c
index faf0784bb0..d0f7fc8fd7 100644
--- a/xen/arch/arm/domain_build.c
+++ b/xen/arch/arm/domain_build.c
@@ -1110,6 +1110,51 @@ static int __init assign_shared_memory(struct domain *d,
     return ret;
 }
 
+static int __init borrower_physmap_add_memory(struct domain *d,
+                                              struct shm_membank *shm_membank,
+                                              paddr_t gbase)
+{
+    int ret;
+    unsigned int i;
+    paddr_t start, size;
+    gfn_t sgfn;
+    struct meminfo *meminfo;
+
+    /* Host address is not provided in "xen,shared-mem" */
+    if ( shm_membank->mem.banks.meminfo )
+    {
+        meminfo = shm_membank->mem.banks.meminfo;
+        for ( i = 0; i < meminfo->nr_banks; i++ )
+        {
+            start = meminfo->bank[i].start;
+            size = meminfo->bank[i].size;
+            sgfn = _gfn(PFN_UP(gbase));
+
+            /* Set up P2M foreign mapping for borrower domain. */
+            ret = map_regions_p2mt(d, sgfn, PFN_DOWN(size), 
_mfn(PFN_UP(start)),
+                                   p2m_map_foreign_rw);
+            if ( ret )
+                return ret;
+
+            sgfn = gfn_add(sgfn, PFN_DOWN(size));
+        }
+    }
+    else
+    {
+        start = shm_membank->mem.bank->start;
+        size = shm_membank->mem.bank->size;
+        sgfn = _gfn(PFN_UP(gbase));
+
+        /* Set up P2M foreign mapping for borrower domain. */
+        ret = map_regions_p2mt(d, sgfn, PFN_DOWN(size), _mfn(PFN_UP(start)),
+                               p2m_map_foreign_rw);
+        if ( ret )
+            return ret;
+    }
+
+    return 0;
+}
+
 static int __init append_shm_bank_to_domain(struct kernel_info *kinfo,
                                             paddr_t start, paddr_t size,
                                             const char *shm_id)
@@ -1242,11 +1287,14 @@ static int __init process_shm(struct domain *d, struct 
kernel_info *kinfo,
 
         if ( owner_dom_io || (strcmp(role_str, "borrower") == 0) )
         {
-            /* Set up P2M foreign mapping for borrower domain. */
-            ret = map_regions_p2mt(d, _gfn(PFN_UP(gbase)), PFN_DOWN(psize),
-                                   _mfn(PFN_UP(pbase)), p2m_map_foreign_rw);
+            ret = borrower_physmap_add_memory(d, shm_membank, gbase);
             if ( ret )
+            {
+                printk(XENLOG_ERR
+                       "%pd: Failed to map foreign memory to borrower domain: 
%d",
+                       d, ret);
                 return ret;
+            }
         }
 
         /*
-- 
2.25.1




 


Rackspace

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