Skip to contentSkip to conversation

xen/dt: Only parse direct child nodes of /reserved-memory

PATCH In review Kuan-Wei Chiu 2 participants 2 messages Oct 27

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 xen/dt: Only parse direct child nodes of /reserved-memory

process_reserved_memory() uses device_tree_for_each_node(), which walks all descendants of /reserved-memory rather than just its direct children. However, a child node such as nvmem-rmem can contain nvmem-layout and cell subnodes whose reg properties specify internal offsets rather than physical memory addresses. Parsing these subnodes records invalid reserved memory regions and fails the overlap check when bitfield cells share the same offset.

Ignore nodes with depth != 1 in process_reserved_memory_node().

Fixes d96594eef39a ("xen/arm: keep track of reserved-memory regions")
---
 xen/common/device-tree/bootinfo-fdt.c | 9 +++++++--
 1 file changed, 7 insertions(+), 2 deletions(-)
xen/common/device-tree/bootinfo-fdt.c +7 -2
index ca64daf4cd..eea35325f7 100644
@@ -185,8 +185,13 @@ static int __init process_reserved_memory_node(const void *fdt, int node,
                                                u32 size_cells,
                                                void *data)
 {
-    int rc = process_memory_node(fdt, node, name, depth, address_cells,
-                                 size_cells, data);
+    int rc;
+
+    if ( depth != 1 )
+        return 0;
+
+    rc = process_memory_node(fdt, node, name, depth, address_cells,
+                             size_cells, data);
 
     if ( rc == -ENOSPC )
         panic("Max number of supported reserved-memory regions reached.\n");
Signature · 1 line
2.56.0.307.g5fe7bd680c-goog
Reviewed-by on v1 1/1
#1 lore raw
Quoted 21 lines · Kuan-Wei Chiu

process_reserved_memory() uses device_tree_for_each_node(), which walks all descendants of /reserved-memory rather than just its direct children. However, a child node such as nvmem-rmem can contain nvmem-layout and cell subnodes whose reg properties specify internal offsets rather than physical memory addresses. Parsing these subnodes records invalid reserved memory regions and fails the overlap check when bitfield cells share the same offset.

Ignore nodes with depth != 1 in process_reserved_memory_node().

Fixes d96594eef39a ("xen/arm: keep track of reserved-memory regions")
---
 xen/common/device-tree/bootinfo-fdt.c | 9 +++++++--
 1 file changed, 7 insertions(+), 2 deletions(-)
xen/common/device-tree/bootinfo-fdt.c +0 -0
index ca64daf4cd..eea35325f7 100644

xen/common/device-tree/bootinfo-fdt.c static int __init process_reserved_memory_node(const void *fdt, int node, · line 189

Quoted 7 lines
xen/common/device-tree/bootinfo-fdt.c +2 -2
@@ -185,8 +185,13 @@ static int __init process_reserved_memory_node(const void *fdt, int node,
                                                u32 size_cells,
                                                void *data)
 {
-    int rc = process_memory_node(fdt, node, name, depth, address_cells,
-                                 size_cells, data);
+    int rc;
+

It would be easier to understand with the comment like:
/* Only direct children of /reserved-memory describe memory regions */

xen/common/device-tree/bootinfo-fdt.c static int __init process_reserved_memory_node(const void *fdt, int node, · line 197

Quoted 8 lines
xen/common/device-tree/bootinfo-fdt.c +5 -0
+    if ( depth != 1 )
+        return 0;
+
+    rc = process_memory_node(fdt, node, name, depth, address_cells,
+                             size_cells, data);
 
     if ( rc == -ENOSPC )
         panic("Max number of supported reserved-memory regions reached.\n");

I will change on commit. Thanks for the submission.

~Michal