[Skiboot] [PATCH] core: Fix mismatched names between reserved memory nodes & properties

Jeremy Kerr jk at ozlabs.org
Tue Feb 20 16:35:58 AEDT 2018


OPAL exposes reserved memory regions through the device tree in both new
(nodes) and old (properties) formats.

However, the names used for these don't match - we use a generated cell
address for the nodes, but the plain region name for the properties.

This change, heavily based on code from Oliver O'Halloran
<oohall at gmail.com>, reworks the dt-generation code to firstly generate
the new-format nodes, then uses those same names to generate the
property data.

Reported-by: Deb McLemore <debmc at linux.vnet.ibm.com>
CC: Oliver O'Halloran <oohall at gmail.com>
Signed-off-by: Jeremy Kerr <jk at ozlabs.org>
---
 core/mem_region.c | 34 ++++++++++++++++++++--------------
 1 file changed, 20 insertions(+), 14 deletions(-)

diff --git a/core/mem_region.c b/core/mem_region.c
index 3c93cd47..4479a23a 100644
--- a/core/mem_region.c
+++ b/core/mem_region.c
@@ -1232,32 +1232,39 @@ void mem_region_add_dt_reserved(void)
 		dt_add_property(node, "ranges", NULL, 0);
 	}
 
-	/* First pass: calculate length of property data */
+	prlog(PR_INFO, "Reserved regions:\n");
+
+	/* First pass, create /reserved-memory/ nodes for each reservation,
+	 * and calculate the length for the /reserved-names and
+	 * /reserved-ranges properties */
 	list_for_each(&regions, region, list) {
 		if (!region_is_reservable(region))
 			continue;
-		names_len += strlen(region->name) + 1;
+
+		prlog(PR_INFO, "  0x%012llx..%012llx : %s\n",
+		       (long long)region->start,
+		       (long long)(region->start + region->len - 1),
+		       region->name);
+
+		mem_region_add_dt_reserved_node(node, region);
+
+		/* calculate the size of the properties populated later */
+		names_len += strlen(region->node->name) + 1;
 		ranges_len += 2 * sizeof(uint64_t);
 	}
 
 	name = names = malloc(names_len);
 	range = ranges = malloc(ranges_len);
 
-	prlog(PR_INFO, "Reserved regions:\n");
-	/* Second pass: populate property data */
+	/* Second pass: populate the old-style reserved-names and
+	 * reserved-regions arrays based on the node data */
 	list_for_each(&regions, region, list) {
 		if (!region_is_reservable(region))
 			continue;
-		len = strlen(region->name) + 1;
-		memcpy(name, region->name, len);
-		name += len;
-
-		prlog(PR_INFO, "  0x%012llx..%012llx : %s\n",
-		       (long long)region->start,
-		       (long long)(region->start + region->len - 1),
-		       region->name);
 
-		mem_region_add_dt_reserved_node(node, region);
+		len = strlen(region->node->name) + 1;
+		memcpy(name, region->node->name, len);
+		name += len;
 
 		range[0] = cpu_to_fdt64(region->start);
 		range[1] = cpu_to_fdt64(region->len);
@@ -1265,7 +1272,6 @@ void mem_region_add_dt_reserved(void)
 	}
 	unlock(&mem_region_lock);
 
-
 	prop = dt_find_property(dt_root, "reserved-names");
 	if (prop)
 		dt_del_property(dt_root, (struct dt_property *)prop);
-- 
2.14.1



More information about the Skiboot mailing list