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 v1 12/13] xen/arm: implement "xen,offset" feature when host address not provided
Date: Tue, 15 Nov 2022 10:52:34 +0800	[thread overview]
Message-ID: <20221115025235.1378931-13-Penny.Zheng@arm.com> (raw)
In-Reply-To: <20221115025235.1378931-1-Penny.Zheng@arm.com>

When host address is not provided in "xen,shared-mem" property, shared
memory region is allocated from heap by Xen. It is normally not
contiguous and consisted of multiple memory blocks.
Under above scenario, when "xen,offset" is also offered, we need to find at
which memory block the offset locates, and the borrower memory map shall start
at this block offset.

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

diff --git a/xen/arch/arm/domain_build.c b/xen/arch/arm/domain_build.c
index 95600c640c..494f6aff2e 100644
--- a/xen/arch/arm/domain_build.c
+++ b/xen/arch/arm/domain_build.c
@@ -48,6 +48,10 @@ boolean_param("ext_regions", opt_ext_regions);
 static u64 __initdata dom0_mem;
 static bool __initdata dom0_mem_set;
 
+#ifdef CONFIG_STATIC_SHM
+static uint64_t __initdata allocated = 0UL;
+#endif
+
 static int __init parse_dom0_mem(const char *s)
 {
     dom0_mem_set = true;
@@ -1110,6 +1114,26 @@ static int __init assign_shared_memory(struct domain *d,
     return ret;
 }
 
+static bool __init find_anchor_offset(paddr_t *bank_start, paddr_t *bank_size,
+                                      uint64_t offset)
+{
+    uint64_t bank_offset;
+
+    allocated += *bank_size;
+    if ( allocated <= offset )
+        return false;
+
+    /* Find the bank when offset locates */
+    bank_offset = *bank_size - (allocated - offset);
+    *bank_start += bank_offset;
+    *bank_size = allocated - offset;
+
+    /* Reset after finding the anchor */
+    allocated = 0UL;
+
+    return true;
+}
+
 static int __init borrower_physmap_add_memory(struct domain *d,
                                               struct shm_membank *shm_membank,
                                               paddr_t gbase, paddr_t offset)
@@ -1123,12 +1147,17 @@ static int __init borrower_physmap_add_memory(struct domain *d,
     /* Host address is not provided in "xen,shared-mem" */
     if ( shm_membank->mem.banks.meminfo )
     {
+        bool found = false;
         meminfo = shm_membank->mem.banks.meminfo;
+        sgfn = _gfn(PFN_UP(gbase));
+
         for ( i = 0; i < meminfo->nr_banks; i++ )
         {
             start = meminfo->bank[i].start;
             size = meminfo->bank[i].size;
-            sgfn = _gfn(PFN_UP(gbase));
+
+            if ( offset && !found )
+                found = find_anchor_offset(&start, &size, offset);
 
             /* Set up P2M foreign mapping for borrower domain. */
             ret = map_regions_p2mt(d, sgfn, PFN_DOWN(size), _mfn(PFN_UP(start)),
-- 
2.25.1



  parent reply	other threads:[~2022-11-15  3:00 UTC|newest]

Thread overview: 38+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-11-15  2:52 [PATCH V1 00/13 for 4.17-post] Follow-up static shared memory Penny Zheng
2022-11-15  2:52 ` [PATCH v1 01/13] xen/arm: re-arrange the static shared memory region Penny Zheng
2023-01-08 11:44   ` Julien Grall
2023-01-09  7:48     ` Penny Zheng
2023-01-09 10:01       ` Julien Grall
2023-02-07 20:55   ` Stewart Hildebrand
2023-02-14  9:56     ` Penny Zheng
2022-11-15  2:52 ` [PATCH v1 02/13] xen/arm: switch to use shm_membank as function parameter Penny Zheng
2022-11-15  6:58   ` Jeungwoo Yoo
2023-01-08 11:56   ` Julien Grall
2022-11-15  2:52 ` [PATCH v1 03/13] xen/arm: introduce allocate_domheap_memory and guest_physmap_memory Penny Zheng
2023-02-07 20:56   ` Stewart Hildebrand
2022-11-15  2:52 ` [PATCH v1 04/13] xen/arm: expand shm_membank for unprovided host address Penny Zheng
2023-01-08 12:13   ` Julien Grall
2023-01-08 12:54     ` Julien Grall
2022-11-15  2:52 ` [PATCH v1 05/13] xen/arm: allocate shared memory from heap when host address not provided Penny Zheng
2023-01-08 12:22   ` Julien Grall
2023-01-09  7:50     ` Penny Zheng
2023-01-09 10:07       ` Julien Grall
2023-02-07 20:57   ` Stewart Hildebrand
2022-11-15  2:52 ` [PATCH v1 06/13] xen/arm: assign shared memory to owner " Penny Zheng
2023-01-08 12:52   ` Julien Grall
2023-01-09  7:49     ` Penny Zheng
2023-01-09 10:57       ` Julien Grall
2023-01-09 11:58         ` Penny Zheng
2023-01-09 18:23           ` Julien Grall
2023-01-10  3:38             ` Penny Zheng
2023-01-10 12:47               ` Julien Grall
2023-01-18  6:09         ` Penny Zheng
2023-02-07 20:58   ` Stewart Hildebrand
2022-11-15  2:52 ` [PATCH v1 07/13] xen/arm: map shared memory to borrower " Penny Zheng
2022-11-15  2:52 ` [PATCH v1 08/13] xen/arm: use paddr_assigned to indicate whether host address is provided Penny Zheng
2022-11-15  2:52 ` [PATCH v1 09/13] xen/arm: refine docs about static shared memory Penny Zheng
2022-11-15  2:52 ` [PATCH v1 10/13] xen/arm: introduce "xen,offset" feature Penny Zheng
2022-11-15  2:52 ` [PATCH v1 11/13] xen/arm: implement "xen,offset" feature when host address provided Penny Zheng
2022-11-15  2:52 ` Penny Zheng [this message]
2022-11-15  2:52 ` [PATCH v1 13/13] xen: make static shared memory supported in SUPPORT.md Penny Zheng
2023-01-08 13:18   ` Julien Grall

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=20221115025235.1378931-13-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.