All of lore.kernel.org
 help / color / mirror / Atom feed
From: Luca Fancellu <luca.fancellu@arm.com>
To: xen-devel@lists.xenproject.org
Cc: Penny Zheng <Penny.Zheng@arm.com>,
	Stefano Stabellini <sstabellini@kernel.org>,
	Julien Grall <julien@xen.org>,
	Bertrand Marquis <bertrand.marquis@arm.com>,
	Michal Orzel <michal.orzel@amd.com>,
	Volodymyr Babchuk <Volodymyr_Babchuk@epam.com>,
	Penny Zheng <penny.zheng@arm.com>
Subject: [PATCH v2 11/13] xen/arm: fix duplicate /reserved-memory node in Dom0
Date: Tue,  9 Apr 2024 12:45:41 +0100	[thread overview]
Message-ID: <20240409114543.3332150-12-luca.fancellu@arm.com> (raw)
In-Reply-To: <20240409114543.3332150-1-luca.fancellu@arm.com>

From: Penny Zheng <Penny.Zheng@arm.com>

In case there is a /reserved-memory node already present in the host
dtb, current Xen codes would create yet another /reserved-memory node
when the static shared memory feature is enabled and static shared
memory regions are present.
This would result in an incorrect device tree generation and hwdom
would not be able to detect the static shared memory region.

Avoid this issue by checking the presence of the /reserved-memory
node and appending the nodes instead of generating a duplicate
/reserved-memory.

Make make_shm_memory_node externally visible and rename it to
make_shm_resv_memory_node to make clear it produces childs for
/reserved-memory.

Signed-off-by: Penny Zheng <penny.zheng@arm.com>
Signed-off-by: Luca Fancellu <luca.fancellu@arm.com>
Reviewed-by: Michal Orzel <michal.orzel@amd.com>
---
v2:
 - fix comment, remove function signature change, fixed commit msg
 - rename make_shm_memory_node to make_shm_resv_memory_node in order
   to make clear that it produces childs for /reserved-memory
 - Add Michal R-by
v1:
 - Rework of https://patchwork.kernel.org/project/xen-devel/patch/20231206090623.1932275-11-Penny.Zheng@arm.com/
---
 xen/arch/arm/domain_build.c             | 23 ++++++++++++++++++++---
 xen/arch/arm/include/asm/static-shmem.h |  9 +++++++++
 xen/arch/arm/static-shmem.c             |  8 ++++----
 3 files changed, 33 insertions(+), 7 deletions(-)

diff --git a/xen/arch/arm/domain_build.c b/xen/arch/arm/domain_build.c
index 9b36d6bb70c9..71eebfcf7e03 100644
--- a/xen/arch/arm/domain_build.c
+++ b/xen/arch/arm/domain_build.c
@@ -1628,6 +1628,7 @@ static int __init handle_node(struct domain *d, struct kernel_info *kinfo,
         DT_MATCH_PATH("/hypervisor"),
         { /* sentinel */ },
     };
+    static __initdata bool res_mem_node_found = false;
     struct dt_device_node *child;
     int res, i, nirq, irq_id;
     const char *name;
@@ -1722,6 +1723,19 @@ static int __init handle_node(struct domain *d, struct kernel_info *kinfo,
     if ( res )
         return res;
 
+    if ( dt_node_path_is_equal(node, "/reserved-memory") )
+    {
+        res_mem_node_found = true;
+        /*
+         * Avoid duplicate /reserved-memory nodes in Device Tree, so add the
+         * static shared memory nodes there.
+         */
+        res = make_shm_resv_memory_node(kinfo, dt_n_addr_cells(node),
+                                        dt_n_size_cells(node));
+        if ( res )
+            return res;
+    }
+
     for ( child = node->child; child != NULL; child = child->sibling )
     {
         res = handle_node(d, kinfo, child, p2mt);
@@ -1774,9 +1788,12 @@ static int __init handle_node(struct domain *d, struct kernel_info *kinfo,
                 return res;
         }
 
-        res = make_resv_memory_node(kinfo, addrcells, sizecells);
-        if ( res )
-            return res;
+        if ( !res_mem_node_found )
+        {
+            res = make_resv_memory_node(kinfo, addrcells, sizecells);
+            if ( res )
+                return res;
+        }
     }
 
     res = fdt_end_node(kinfo->fdt);
diff --git a/xen/arch/arm/include/asm/static-shmem.h b/xen/arch/arm/include/asm/static-shmem.h
index 2e8b138eb989..7495a91e7a31 100644
--- a/xen/arch/arm/include/asm/static-shmem.h
+++ b/xen/arch/arm/include/asm/static-shmem.h
@@ -34,6 +34,9 @@ int remove_shm_from_rangeset(const struct kernel_info *kinfo,
 int remove_shm_holes_for_domU(const struct kernel_info *kinfo,
                               struct membanks *ext_regions);
 
+int make_shm_resv_memory_node(const struct kernel_info *kinfo, int addrcells,
+                              int sizecells);
+
 #else /* !CONFIG_STATIC_SHM */
 
 static inline int make_resv_memory_node(const struct kernel_info *kinfo,
@@ -77,6 +80,12 @@ static inline int remove_shm_holes_for_domU(const struct kernel_info *kinfo,
     return 0;
 }
 
+static inline int make_shm_resv_memory_node(const struct kernel_info *kinfo,
+                                            int addrcells, int sizecells)
+{
+    return 0;
+}
+
 #endif /* CONFIG_STATIC_SHM */
 
 #endif /* __ASM_STATIC_SHMEM_H_ */
diff --git a/xen/arch/arm/static-shmem.c b/xen/arch/arm/static-shmem.c
index a08413ff44e2..5ad6f1269c48 100644
--- a/xen/arch/arm/static-shmem.c
+++ b/xen/arch/arm/static-shmem.c
@@ -297,8 +297,8 @@ int __init process_shm(struct domain *d, struct kernel_info *kinfo,
     return 0;
 }
 
-static int __init make_shm_memory_node(const struct kernel_info *kinfo,
-                                       int addrcells, int sizecells)
+int __init make_shm_resv_memory_node(const struct kernel_info *kinfo,
+                                     int addrcells, int sizecells)
 {
     const struct membanks *mem = &kinfo->shm_mem.common;
     void *fdt = kinfo->fdt;
@@ -306,7 +306,7 @@ static int __init make_shm_memory_node(const struct kernel_info *kinfo,
     int res = 0;
 
     if ( mem->nr_banks == 0 )
-        return -ENOENT;
+        return 0;
 
     /*
      * For each shared memory region, a range is exposed under
@@ -544,7 +544,7 @@ int __init make_resv_memory_node(const struct kernel_info *kinfo, int addrcells,
     if ( res )
         return res;
 
-    res = make_shm_memory_node(kinfo, addrcells, sizecells);
+    res = make_shm_resv_memory_node(kinfo, addrcells, sizecells);
     if ( res )
         return res;
 
-- 
2.34.1



  parent reply	other threads:[~2024-04-09 11:46 UTC|newest]

Thread overview: 39+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-04-09 11:45 [PATCH v2 00/13] Static shared memory followup v2 - pt1 Luca Fancellu
2024-04-09 11:45 ` [PATCH v2 01/13] xen/arm: remove stale addr_cells/size_cells in assign_shared_memory Luca Fancellu
2024-04-09 11:45 ` [PATCH v2 02/13] xen/arm: avoid repetitive checking in process_shm_node Luca Fancellu
2024-04-09 11:45 ` [PATCH v2 03/13] xen/arm: Pass struct kernel_info parameter to make_resv_memory_node Luca Fancellu
2024-04-09 13:18   ` Michal Orzel
2024-04-09 11:45 ` [PATCH v2 04/13] xen/arm: Introduce a generic way to access memory bank structures Luca Fancellu
2024-04-09 13:24   ` Michal Orzel
2024-04-09 11:45 ` [PATCH v2 05/13] xen/arm: Conditional compilation of kernel_info.shm_mem member Luca Fancellu
2024-04-09 11:45 ` [PATCH v2 06/13] xen/arm: Avoid code duplication in find_unallocated_memory Luca Fancellu
2024-04-09 13:38   ` Michal Orzel
2024-04-09 14:37     ` Luca Fancellu
2024-04-09 11:45 ` [PATCH v2 07/13] xen/arm: Avoid code duplication in check_reserved_regions_overlap Luca Fancellu
2024-04-10  7:40   ` Michal Orzel
2024-04-09 11:45 ` [PATCH v2 08/13] xen/arm: Introduce helper for static memory pages Luca Fancellu
2024-04-09 11:45 ` [PATCH v2 09/13] xen/arm: Reduce struct membank size on static shared memory Luca Fancellu
2024-04-10 10:01   ` Michal Orzel
2024-04-10 10:56     ` Luca Fancellu
2024-04-10 11:01       ` Michal Orzel
2024-04-10 11:19         ` Luca Fancellu
2024-04-10 11:23           ` Michal Orzel
2024-04-09 11:45 ` [PATCH v2 10/13] xen/arm: remove shm holes from extended regions Luca Fancellu
2024-04-10 11:15   ` Michal Orzel
2024-04-10 14:08     ` Luca Fancellu
2024-04-10 14:58       ` Michal Orzel
2024-04-10 14:12     ` Luca Fancellu
2024-04-09 11:45 ` Luca Fancellu [this message]
2024-04-09 11:45 ` [PATCH v2 12/13] xen/device_tree: Introduce function to merge overlapping intervals Luca Fancellu
2024-04-11  9:50   ` Luca Fancellu
2024-04-11 13:36     ` Luca Fancellu
2024-04-18  6:28   ` Jan Beulich
2024-04-18  7:44     ` Luca Fancellu
2024-04-09 11:45 ` [PATCH v2 13/13] xen/arm: List static shared memory regions as /memory nodes Luca Fancellu
2024-04-15 18:41   ` Julien Grall
2024-04-16  6:27     ` Luca Fancellu
2024-04-16  8:50       ` Julien Grall
2024-04-16  8:57         ` Michal Orzel
2024-04-16  8:59         ` Luca Fancellu
2024-04-16  9:06           ` Julien Grall
2024-04-16 10:50             ` Luca Fancellu

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=20240409114543.3332150-12-luca.fancellu@arm.com \
    --to=luca.fancellu@arm.com \
    --cc=Penny.Zheng@arm.com \
    --cc=Volodymyr_Babchuk@epam.com \
    --cc=bertrand.marquis@arm.com \
    --cc=julien@xen.org \
    --cc=michal.orzel@amd.com \
    --cc=sstabellini@kernel.org \
    --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.