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

[PATCH v1 06/13] xen/arm: set up shared memory foreign mapping for borrower domain


  • To: <xen-devel@xxxxxxxxxxxxxxxxxxxx>
  • From: Penny Zheng <Penny.Zheng@xxxxxxx>
  • Date: Fri, 11 Mar 2022 14:11:16 +0800
  • Arc-authentication-results: i=1; mx.microsoft.com 1; spf=pass (sender ip is 40.67.248.234) smtp.rcpttodomain=lists.xenproject.org smtp.mailfrom=arm.com; dmarc=pass (p=none sp=none pct=100) action=none header.from=arm.com; dkim=none (message not signed); arc=none
  • Arc-message-signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=M1TXqrctcdUtGEYuF9ixd4KtwFZVaadgy8ENe9JSK4o=; b=BiOurEmGP0PA/pzA9GhezVuc+DM8ZTDdwbBDNS+lFp3yKj+6jafA6QuxrMj0yseOukyydi6tj/GCRNsxix8xWlG94hoqY9Ait493RZySDVYyllo+RmbMt6Wbkw15+DJwE7VgJOlxutr6MFjHHvh1KpK05ZSe6VwLGCO5JYd+YEioZ08+kpqwk++/ej5ZazNeG/FVyicabJ1z6WJNjppmutCNIAWiiEEmfeGuBBF0BRS5Y4g6sDqoazQojTPX4QCPLa9hp5NNgflkKWhYbtrVmUTOsJnkt3gcHOiN6Jkl7N9z7/sS2Wx89YDo0qkRQOkDMwhNvdNmqkZWA2fTUZZnuw==
  • Arc-seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=NcBL3IvWw1tRx2VjBREMxVo7+VsJ4jt+rZjRD4XhkEXjdx1HEB35TAszNwbZX5/S8wKhm0SWRdgV6yi4d2kW45l9PotuMpqipoLAvjUCYt4lFB3AVzgFqmlg+QhfDm93weRAW4eR2RDNXmLCa3SZlLhVR2EuuQXpIOE8YNpjS2R+U0s2d8YiSl54fuByeShdEfSspOKELppQyNvVQeWt8mDsOYpCFl3T1Rz/JTGLEVaZs599UrCrBKbiXEADcxE7v5wZr6Y6D7kVx+WHFuH8dMRs3BAtLP42xWQ9UiAcHtWkm1v2F6v0/Es0J9IJyJdq1B06RcJevVJE2vOysl9UTA==
  • Cc: <nd@xxxxxxx>, Penny Zheng <penny.zheng@xxxxxxx>, Stefano Stabellini <sstabellini@xxxxxxxxxx>, Julien Grall <julien@xxxxxxx>, Bertrand Marquis <bertrand.marquis@xxxxxxx>, Volodymyr Babchuk <Volodymyr_Babchuk@xxxxxxxx>
  • Delivery-date: Fri, 11 Mar 2022 06:12:53 +0000
  • List-id: Xen developer discussion <xen-devel.lists.xenproject.org>
  • Nodisclaimer: true

From: Penny Zheng <penny.zheng@xxxxxxx>

This commits introduces a new helper guest_physmap_add_shm to set up shared
memory foreign mapping for borrower domain.

Firstly it should get and take reference of statically shared pages from
owner dom_shared. Then it will setup P2M foreign memory map of these statically
shared pages for borrower domain.

This commits only considers owner domain is the default dom_shared, the
other scenario will be covered in the following patches.

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

diff --git a/xen/arch/arm/domain_build.c b/xen/arch/arm/domain_build.c
index 984e70e5fc..8cee5ffbd1 100644
--- a/xen/arch/arm/domain_build.c
+++ b/xen/arch/arm/domain_build.c
@@ -798,6 +798,48 @@ static int __init allocate_shared_memory(struct domain *d,
     return ret;
 }
 
+static int __init guest_physmap_add_shm(struct domain *od, struct domain *bd,
+                                        unsigned long o_gfn,
+                                        unsigned long b_gfn,
+                                        unsigned long nr_gfns)
+{
+    struct page_info **pages = NULL;
+    p2m_type_t p2mt, t;
+    int ret = 0;
+
+    pages = xmalloc_array(struct page_info *, nr_gfns);
+    if ( !pages )
+        return -ENOMEM;
+
+    /*
+     * Take reference of statically shared pages from owner domain.
+     * Reference will be released when destroying shared memory region.
+     */
+    ret = get_pages_from_gfn(od, o_gfn, nr_gfns, pages, &p2mt, P2M_ALLOC);
+    if ( ret )
+    {
+        ret = -EINVAL;
+        goto fail_pages;
+    }
+
+    if ( p2m_is_ram(p2mt) )
+        t = (p2mt == p2m_ram_rw) ? p2m_map_foreign_rw : p2m_map_foreign_ro;
+    else
+    {
+        ret = -EINVAL;
+        goto fail_pages;
+    }
+
+    /* Set up guest foreign map. */
+    ret = guest_physmap_add_pages(bd, _gfn(b_gfn), page_to_mfn(pages[0]),
+                                  nr_gfns, t);
+
+ fail_pages:
+        xfree(pages);
+
+    return ret;
+}
+
 static int __init process_shm(struct domain *d,
                               const struct dt_device_node *node)
 {
@@ -855,6 +897,16 @@ static int __init process_shm(struct domain *d,
 
             set_bit(shm_id, shm_mask);
         }
+
+        /*
+         * All domains are borrower domains when owner domain is the
+         * default dom_shared, so here we could just set up P2M foreign
+         * mapping for borrower domain immediately.
+         */
+        ret = guest_physmap_add_shm(dom_shared, d, PFN_DOWN(pbase),
+                                    PFN_DOWN(gbase), PFN_DOWN(psize));
+        if ( ret )
+            return ret;
     }
 
     return 0;
-- 
2.25.1




 


Rackspace

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