All of lore.kernel.org
 help / color / mirror / Atom feed
From: Penny Zheng <Penny.Zheng@arm.com>
To: xen-devel@lists.xenproject.org
Cc: wei.chen@arm.com, Penny Zheng <Penny.Zheng@arm.com>,
	Stefano Stabellini <sstabellini@kernel.org>,
	Julien Grall <julien@xen.org>,
	Bertrand Marquis <bertrand.marquis@arm.com>,
	Volodymyr Babchuk <Volodymyr_Babchuk@epam.com>,
	Penny Zheng <penny.zheng@arm.com>
Subject: [PATCH v5 3/8] xen/arm: allocate static shared memory to a specific owner domain
Date: Mon, 20 Jun 2022 13:11:09 +0800	[thread overview]
Message-ID: <20220620051114.210118-4-Penny.Zheng@arm.com> (raw)
In-Reply-To: <20220620051114.210118-1-Penny.Zheng@arm.com>

If owner property is defined, then owner domain of a static shared memory
region is not the default dom_io anymore, but a specific domain.

This commit implements allocating static shared memory to a specific domain
when owner property is defined.

Coding flow for dealing borrower domain will be introduced later in the
following commits.

Signed-off-by: Penny Zheng <penny.zheng@arm.com>
Reviewed-by: Stefano Stabellini <sstabellini@kernel.org>
---
v5 change:
- no change
---
v4 change:
- no changes
---
v3 change:
- simplify the code since o_gbase is not used if the domain is dom_io
---
v2 change:
- P2M mapping is restricted to normal domain
- in-code comment fix
---
 xen/arch/arm/domain_build.c | 44 +++++++++++++++++++++++++++----------
 1 file changed, 33 insertions(+), 11 deletions(-)

diff --git a/xen/arch/arm/domain_build.c b/xen/arch/arm/domain_build.c
index 91a5ace851..d4fd64e2bd 100644
--- a/xen/arch/arm/domain_build.c
+++ b/xen/arch/arm/domain_build.c
@@ -805,9 +805,11 @@ static mfn_t __init acquire_shared_memory_bank(struct domain *d,
  */
 static int __init allocate_shared_memory(struct domain *d,
                                          u32 addr_cells, u32 size_cells,
-                                         paddr_t pbase, paddr_t psize)
+                                         paddr_t pbase, paddr_t psize,
+                                         paddr_t gbase)
 {
     mfn_t smfn;
+    int ret = 0;
 
     dprintk(XENLOG_INFO,
             "Allocate static shared memory BANK %#"PRIpaddr"-%#"PRIpaddr".\n",
@@ -822,8 +824,18 @@ static int __init allocate_shared_memory(struct domain *d,
      * DOMID_IO is the domain, like DOMID_XEN, that is not auto-translated.
      * It sees RAM 1:1 and we do not need to create P2M mapping for it
      */
-    ASSERT(d == dom_io);
-    return 0;
+    if ( d != dom_io )
+    {
+        ret = guest_physmap_add_pages(d, gaddr_to_gfn(gbase), smfn, PFN_DOWN(psize));
+        if ( ret )
+        {
+            printk(XENLOG_ERR
+                   "Failed to map shared memory to %pd.\n", d);
+            return ret;
+        }
+    }
+
+    return ret;
 }
 
 static int __init process_shm(struct domain *d,
@@ -836,6 +848,8 @@ static int __init process_shm(struct domain *d,
     u32 shm_id;
     u32 addr_cells, size_cells;
     paddr_t gbase, pbase, psize;
+    const char *role_str;
+    bool owner_dom_io = true;
 
     dt_for_each_child_node(node, shm_node)
     {
@@ -862,19 +876,27 @@ static int __init process_shm(struct domain *d,
         ASSERT(IS_ALIGNED(pbase, PAGE_SIZE) && IS_ALIGNED(psize, PAGE_SIZE));
         gbase = dt_read_number(cells, addr_cells);
 
-        /* TODO: Consider owner domain is not the default dom_io. */
+        /*
+         * "role" property is optional and if it is defined explicitly,
+         * then the owner domain is not the default "dom_io" domain.
+         */
+        if ( dt_property_read_string(shm_node, "role", &role_str) == 0 )
+            owner_dom_io = false;
+
         /*
          * Per static shared memory region could be shared between multiple
          * domains.
-         * In case re-allocating the same shared memory region, we check
-         * if it is already allocated to the default owner dom_io before
-         * the actual allocation.
+         * So when owner domain is the default dom_io, in case re-allocating
+         * the same shared memory region, we check if it is already allocated
+         * to the default owner dom_io before the actual allocation.
          */
-        if ( !is_shm_allocated_to_domio(pbase) )
+        if ( (owner_dom_io && !is_shm_allocated_to_domio(pbase)) ||
+             (!owner_dom_io && strcmp(role_str, "owner") == 0) )
         {
-            /* Allocate statically shared pages to the default owner dom_io. */
-            ret = allocate_shared_memory(dom_io, addr_cells, size_cells,
-                                         pbase, psize);
+            /* Allocate statically shared pages to the owner domain. */
+            ret = allocate_shared_memory(owner_dom_io ? dom_io : d,
+                                         addr_cells, size_cells,
+                                         pbase, psize, gbase);
             if ( ret )
                 return ret;
         }
-- 
2.25.1



  parent reply	other threads:[~2022-06-20  5:11 UTC|newest]

Thread overview: 38+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-06-20  5:11 [PATCH v5 0/8] static shared memory on dom0less system Penny Zheng
2022-06-20  5:11 ` [PATCH v5 1/8] xen/arm: introduce static shared memory Penny Zheng
2022-06-24 17:55   ` Julien Grall
2022-06-29  5:38     ` Penny Zheng
2022-06-29 10:17       ` Julien Grall
2022-07-13  2:42         ` Penny Zheng
2022-07-13  9:09           ` Julien Grall
2022-06-29  8:39     ` Penny Zheng
2022-07-15 18:10       ` Julien Grall
2022-07-18  2:35         ` Penny Zheng
2022-06-24 19:25   ` Julien Grall
2022-06-29  8:40     ` Penny Zheng
2022-06-20  5:11 ` [PATCH v5 2/8] xen/arm: allocate static shared memory to the default owner dom_io Penny Zheng
2022-06-24 18:22   ` Julien Grall
2022-06-29  7:13     ` Penny Zheng
2022-06-29 10:34       ` Julien Grall
2022-07-04  7:20         ` Penny Zheng
2022-07-15 18:43           ` Julien Grall
2022-06-20  5:11 ` Penny Zheng [this message]
2022-06-24 19:07   ` [PATCH v5 3/8] xen/arm: allocate static shared memory to a specific owner domain Julien Grall
2022-06-29  7:49     ` Penny Zheng
2022-06-20  5:11 ` [PATCH v5 4/8] xen/arm: introduce put_page_nr and get_page_nr Penny Zheng
2022-06-24 19:10   ` Julien Grall
2022-06-20  5:11 ` [PATCH v5 5/8] xen/arm: Add additional reference to owner domain when the owner is allocated Penny Zheng
2022-06-24 19:18   ` Julien Grall
2022-06-29  8:00     ` Penny Zheng
2022-06-20  5:11 ` [PATCH v5 6/8] xen/arm: set up shared memory foreign mapping for borrower domain Penny Zheng
2022-06-20  5:11 ` [PATCH v5 7/8] xen/arm: create shared memory nodes in guest device tree Penny Zheng
2022-06-24 19:30   ` Julien Grall
2022-06-24 21:56     ` Stefano Stabellini
2022-07-04  7:45       ` Penny Zheng
2022-07-05  8:09         ` Julien Grall
2022-07-05 23:21           ` Stefano Stabellini
2022-07-06 23:52         ` Stefano Stabellini
2022-07-07  4:01           ` Penny Zheng
2022-07-08 16:40             ` Stefano Stabellini
2022-07-11  7:59               ` Penny Zheng
2022-06-20  5:11 ` [PATCH v5 8/8] xen/arm: enable statically shared memory on Dom0 Penny Zheng

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20220620051114.210118-4-Penny.Zheng@arm.com \
    --to=penny.zheng@arm.com \
    --cc=Volodymyr_Babchuk@epam.com \
    --cc=bertrand.marquis@arm.com \
    --cc=julien@xen.org \
    --cc=sstabellini@kernel.org \
    --cc=wei.chen@arm.com \
    --cc=xen-devel@lists.xenproject.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.