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

[PATCH v1 11/13] xen/arm: store shm-info for deferred foreign memory map


  • To: <xen-devel@xxxxxxxxxxxxxxxxxxxx>
  • From: Penny Zheng <Penny.Zheng@xxxxxxx>
  • Date: Fri, 11 Mar 2022 14:11:21 +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=GHzNODlA8XFx6CtjhuogInLZztAvYsmJNbcr6OVan/s=; b=PvLWA++5/l1ZqLySqabS7OTUcUqYWPpp4t1aAdJdDY7A+YfYZXFckd1V7HkbrhU1qtf3Q/dzQDNEuf4mOO12QRRDM6ihljz6AxsdEYECOu7eDwYZh3aJ7dnNT0sQRH0c7gxI68YUrhpeNTJVrQsj0KHfs154iKo4fpuHEvamzOErEhDKkiHSUobl1c2NhprPVum8SeIasiJKLLaTgir85K6iV4Chz6TcDOm+fDO7iLQTGE/z3EMVxxYnRT0H/ihKb+hYEIfXoyPUu260vBAs09eNXdQyCVmSfhB+sa6FELZu1LDK5wJpgbzyugoSPJ9fshyl6iFrvvCTMmbADHj1PQ==
  • Arc-seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=nHjZnPQGR6vT2b//6gT3RJ7a4mApyEWbIMoiX1lBiyY+gDhxj9IPlgL8z0nB0qGetNlZFWcjqRg7N/EFkXdQ/+U2hGzbwf2PZc3TdZBgIXltredigv+hDI19Ny7KsI9pGBk5V41kST4m/vkRDUVRSY63T8u+8QBcbyvvbvkuAaQGoUu94kqGztXUygIrO6/PdTcnBj+V2olKy7Wbj4UYyRkb5GCiif/ELydsoxZ/2ujh6C7gnmYDKWgB6Q15iTvQD/1ikgjZCMcYYkcuP6zBLhgAgDfrP3Hmg1Jm98PdcAjy9ZCRePbMcVC0q3oKP3WPblK0+q3DVzwnZkvlmxeQ9g==
  • 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:16:27 +0000
  • List-id: Xen developer discussion <xen-devel.lists.xenproject.org>
  • Nodisclaimer: true

From: Penny Zheng <penny.zheng@xxxxxxx>

In a few scenarios where owner domain, is defined after borrower domain in
device tree configuration, then statically shared pages haven't been properly
allocated if borrower domain tries to do foreign memory map during
domain construction.

In order to cover such scenario, we defer all borrower domains' foreign
memory map after all domain construction finished, then only need to store
shm-info during domain construction.

Signed-off-by: Penny Zheng <penny.zheng@xxxxxxx>
---
 xen/arch/arm/domain.c             |  3 +++
 xen/arch/arm/domain_build.c       | 34 ++++++++++++++++++++++++++++++-
 xen/arch/arm/include/asm/domain.h | 25 +++++++++++++++++++++++
 3 files changed, 61 insertions(+), 1 deletion(-)

diff --git a/xen/arch/arm/domain.c b/xen/arch/arm/domain.c
index f0bfd67fe5..73ffbfb918 100644
--- a/xen/arch/arm/domain.c
+++ b/xen/arch/arm/domain.c
@@ -47,6 +47,9 @@ DEFINE_PER_CPU(struct vcpu *, curr_vcpu);
 
 #ifdef CONFIG_STATIC_SHM
 struct domain *__read_mostly dom_shared;
+
+shm_info_t shm_list[NR_MEM_BANKS];
+DECLARE_BITMAP(shm_list_mask, NR_MEM_BANKS);
 #endif
 
 static void do_idle(void)
diff --git a/xen/arch/arm/domain_build.c b/xen/arch/arm/domain_build.c
index 7ee4d33e0b..4b19160674 100644
--- a/xen/arch/arm/domain_build.c
+++ b/xen/arch/arm/domain_build.c
@@ -771,7 +771,7 @@ static mfn_t __init acquire_shared_memory_bank(struct 
domain *d,
 
 }
 
-static int __init allocate_shared_memory(struct domain *d,
+static int __init allocate_shared_memory(struct domain *d, u32 shm_id,
                                          u32 addr_cells, u32 size_cells,
                                          paddr_t pbase, paddr_t psize,
                                          paddr_t gbase)
@@ -795,6 +795,18 @@ static int __init allocate_shared_memory(struct domain *d,
         return ret;
     }
 
+    /*
+     * If owner domain is not default dom_shared, shm-info of owner domain
+     * shall also be recorded for later deferred foreign memory map.
+     */
+    if ( d != dom_shared )
+    {
+        shm_list[shm_id].owner_dom = d->domain_id;
+        shm_list[shm_id].owner_gbase = gbase;
+        shm_list[shm_id].size = psize;
+        set_bit(shm_id, shm_list_mask);
+    }
+
     return ret;
 }
 
@@ -962,6 +974,26 @@ static int __init process_shm(struct domain *d,
             if ( ret )
                 return ret;
         }
+        else
+        {
+            if ( strcmp(role_str, "borrower") == 0 )
+            {
+                /*
+                 * In a few scenarios where owner domain, is defined after
+                 * borrower domain in device tree configuration, statically
+                 * shared pages haven't been properly allocated if borrower
+                 * domain here tries to do foreign memory map.
+                 * In order to cover such scenario, we defer all borrower
+                 * domains'foreign memory map after all domain construction
+                 * finished, and only store shm-info here for later use.
+                 */
+                shm_list[shm_id].borrower_dom[shm_list[shm_id].nr_borrower] =
+                                                                d->domain_id;
+                shm_list[shm_id].borrower_gbase[shm_list[shm_id].nr_borrower] =
+                                                                gbase;
+                shm_list[shm_id].nr_borrower++;
+            }
+        }
 
         /*
          * Record static shared memory region info for later setting
diff --git a/xen/arch/arm/include/asm/domain.h 
b/xen/arch/arm/include/asm/domain.h
index 6df37d2c46..1c0f2e22ca 100644
--- a/xen/arch/arm/include/asm/domain.h
+++ b/xen/arch/arm/include/asm/domain.h
@@ -10,6 +10,7 @@
 #include <asm/gic.h>
 #include <asm/vgic.h>
 #include <asm/vpl011.h>
+#include <asm/setup.h>
 #include <public/hvm/params.h>
 
 struct hvm_domain
@@ -33,6 +34,30 @@ enum domain_type {
 
 #ifdef CONFIG_STATIC_SHM
 extern struct domain *dom_shared;
+
+/* Maximum number of borrower domains. */
+#define NR_SHM_DOMAIN 32
+/*
+ * shm_list is indexed by unique identifier "xen,shm-id", but it only stores
+ * a subset of static shared memory regions, of which owner domain is not the
+ * default dom_shared.
+ * shm_list_mask bitmask is to record the position of these static shared
+ * memory regions.
+ * Per bit represents a entry in shm_list, and setting it 1 means the
+ * static shared memory region here is owned by a specific domain, then bit 0
+ * means the static shared memory region here is either owned by the default
+ * dom_shared or no static shared memory region here at all.
+ */
+typedef struct {
+    domid_t owner_dom;
+    paddr_t owner_gbase;
+    paddr_t size;
+    domid_t borrower_dom[NR_SHM_DOMAIN];
+    paddr_t borrower_gbase[NR_SHM_DOMAIN];
+    unsigned long nr_borrower;
+} shm_info_t;
+extern shm_info_t shm_list[NR_MEM_BANKS];
+extern unsigned long shm_list_mask[BITS_TO_LONGS(NR_MEM_BANKS)];
 #else
 #define dom_shared NULL
 #endif
-- 
2.25.1




 


Rackspace

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