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

[PATCH for-4.20 v2] xen/arm: bootfdt: Fix device tree memory node probing


  • To: <xen-devel@xxxxxxxxxxxxxxxxxxxx>
  • From: Michal Orzel <michal.orzel@xxxxxxx>
  • Date: Wed, 10 Jul 2024 13:22:04 +0200
  • Arc-authentication-results: i=1; mx.microsoft.com 1; spf=pass (sender ip is 165.204.84.17) smtp.rcpttodomain=lists.xenproject.org smtp.mailfrom=amd.com; dmarc=pass (p=quarantine sp=quarantine pct=100) action=none header.from=amd.com; dkim=none (message not signed); arc=none (0)
  • 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=Z43cZeKSdhq3v6JXln/ykC0j1uv41JjKp5FJGFs3XtE=; b=YjExbOcqpfmGB9XyFMkJWCdgXzPQe70kK+g3/AleptwziRDrzvFbhYsDnar9VK9d1Ppz2yck3fEa3WcRdzicJCpYlZAXVyzNe1ttv81qOS5vSxcohnLNepxz3ncR3/scmcavYg9Oj4/4/4+pRXNgh8Lkc9fTrb01FiLhBUIQk/vnS1MpdsbPDZNRpbqPmnv4l2I5OpWdvLyK1JsSMXBEWIcjOlNjOj7oGuyHRUGkZCMnzEBniYn/N8XL805fEIWqoqy4YdySOD0H5niPG1CY0o3QX1rim62SNQ6LiLyTYvW7c7HuGECOTb0Ioy7TnXUJYZazC33syW9hwRSDuppT/w==
  • Arc-seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=NKRHZ5jb8SOGZUdDfViQy4fLM6wNiNmPHJhgd4uVxcml81aocyQxgdqmomfJIrlBRx78xlA4As99t9jdEJhnijJuyogXm770Y8DU2qBoO3ic5mwF2n30pUeYOH6BIVCATeElIHon//e+z114e/rkONpon5aTcg9RY1NcT6yEcz1EyQAchYRccX5GsWeRR7Yz04WKqEfmgTjNpO9Ffaaq5kiUZxwXaajDob01Ic6kBWB9yzNjir5rJ6W/mPLvp0auWDrM2lZYSmHZdYEngQ2TA0iv5ZIrnnQCJev1haOnXTYbYEvWcE+vX5vAfcYjceC5Bo99FHKiuNyPWOK/QbH1sw==
  • Cc: Michal Orzel <michal.orzel@xxxxxxx>, Stefano Stabellini <sstabellini@xxxxxxxxxx>, Julien Grall <julien@xxxxxxx>, Bertrand Marquis <bertrand.marquis@xxxxxxx>, Volodymyr Babchuk <Volodymyr_Babchuk@xxxxxxxx>, Luca Fancellu <luca.fancellu@xxxxxxx>
  • Delivery-date: Wed, 10 Jul 2024 11:30:14 +0000
  • List-id: Xen developer discussion <xen-devel.lists.xenproject.org>

Memory node probing is done as part of early_scan_node() that is called
for each node with depth >= 1 (root node is at depth 0). According to
Devicetree Specification v0.4, chapter 3.4, /memory node can only exists
as a top level node. However, Xen incorrectly considers all the nodes with
unit node name "memory" as RAM. This buggy behavior can result in a
failure if there are other nodes in the device tree (at depth >= 2) with
"memory" as unit node name. An example can be a "memory@xxx" node under
/reserved-memory. Fix it by introducing device_tree_is_memory_node() to
perform all the required checks to assess if a node is a proper /memory
node.

Fixes: 3e99c95ba1c8 ("arm, device tree: parse the DTB for RAM location and 
size")
Signed-off-by: Michal Orzel <michal.orzel@xxxxxxx>
Reviewed-by: Luca Fancellu <luca.fancellu@xxxxxxx>
Tested-by: Luca Fancellu <luca.fancellu@xxxxxxx>
---
Changes in v2:
 - improve the length check
---
 xen/arch/arm/bootfdt.c | 28 +++++++++++++++++++++++++++-
 1 file changed, 27 insertions(+), 1 deletion(-)

diff --git a/xen/arch/arm/bootfdt.c b/xen/arch/arm/bootfdt.c
index 6e060111d95b..f2892fce0a9c 100644
--- a/xen/arch/arm/bootfdt.c
+++ b/xen/arch/arm/bootfdt.c
@@ -83,6 +83,32 @@ static bool __init device_tree_node_compatible(const void 
*fdt, int node,
     return false;
 }
 
+/*
+ * Check if a node is a proper /memory node according to Devicetree
+ * Specification v0.4, chapter 3.4.
+ */
+static bool __init device_tree_is_memory_node(const void *fdt, int node,
+                                              int depth)
+{
+    const char *type;
+    int len;
+
+    if ( depth != 1 )
+        return false;
+
+    if ( !device_tree_node_matches(fdt, node, "memory") )
+        return false;
+
+    type = fdt_getprop(fdt, node, "device_type", &len);
+    if ( !type )
+        return false;
+
+    if ( (len <= strlen("memory")) || strcmp(type, "memory") )
+        return false;
+
+    return true;
+}
+
 void __init device_tree_get_reg(const __be32 **cell, uint32_t address_cells,
                                 uint32_t size_cells, paddr_t *start,
                                 paddr_t *size)
@@ -448,7 +474,7 @@ static int __init early_scan_node(const void *fdt,
      * populated. So we should skip the parsing.
      */
     if ( !efi_enabled(EFI_BOOT) &&
-         device_tree_node_matches(fdt, node, "memory") )
+         device_tree_is_memory_node(fdt, node, depth) )
         rc = process_memory_node(fdt, node, name, depth,
                                  address_cells, size_cells, 
bootinfo_get_mem());
     else if ( depth == 1 && !dt_node_cmp(name, "reserved-memory") )
-- 
2.25.1




 


Rackspace

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