lists.openwall.net   lists  /  announce  owl-users  owl-dev  john-users  john-dev  passwdqc-users  yescrypt  popa3d-users  /  oss-security  kernel-hardening  musl  sabotage  tlsify  passwords  /  crypt-dev  xvendor  /  Bugtraq  Full-Disclosure  linux-kernel  linux-netdev  linux-ext4  linux-hardening  linux-cve-announce  PHC 
Open Source and information security mailing list archives
 
Hash Suite: Windows password security audit tool. GUI, reports in PDF.
[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <20240126235425.12233-32-quic_obabatun@quicinc.com>
Date: Fri, 26 Jan 2024 15:54:10 -0800
From: Oreoluwa Babatunde <quic_obabatun@...cinc.com>
To: <catalin.marinas@....com>, <will@...nel.org>, <robh+dt@...nel.org>,
        <frowand.list@...il.com>, <vgupta@...nel.org>, <arnd@...db.de>,
        <olof@...om.net>, <soc@...nel.org>, <guoren@...nel.org>,
        <monstr@...str.eu>, <palmer@...belt.com>, <aou@...s.berkeley.edu>,
        <dinguyen@...nel.org>, <chenhuacai@...nel.org>,
        <tsbogend@...ha.franken.de>, <jonas@...thpole.se>,
        <stefan.kristiansson@...nalahti.fi>, <shorne@...il.com>,
        <mpe@...erman.id.au>, <ysato@...rs.sourceforge.jp>, <dalias@...c.org>,
        <glaubitz@...sik.fu-berlin.de>, <richard@....at>,
        <anton.ivanov@...bridgegreys.com>, <johannes@...solutions.net>,
        <chris@...kel.net>, <jcmvbkbc@...il.com>
CC: <linux-arm-kernel@...ts.infradead.org>, <linux-kernel@...r.kernel.org>,
        <devicetree@...r.kernel.org>, <linux-arm-msm@...r.kernel.org>,
        <kernel@...cinc.com>, Oreoluwa Babatunde <quic_obabatun@...cinc.com>
Subject: [PATCH 31/46] of: reserved_mem: Rename fdt_* functions to refelct use of unflattened devicetree APIs

Rename the relevant fdt_* functions to a new scheme dt_* to reflect the
use of the unflattened devicetree APIs to process the reserved memory
regions.

Signed-off-by: Oreoluwa Babatunde <quic_obabatun@...cinc.com>
---
 drivers/of/of_private.h         |  4 +--
 drivers/of/of_reserved_mem.c    | 64 ++++++++++++++++++++++++++++++---
 include/linux/of_reserved_mem.h |  3 ++
 3 files changed, 64 insertions(+), 7 deletions(-)

diff --git a/drivers/of/of_private.h b/drivers/of/of_private.h
index f7da22108e7a..1092615faa90 100644
--- a/drivers/of/of_private.h
+++ b/drivers/of/of_private.h
@@ -177,7 +177,7 @@ static inline struct device_node *__of_get_dma_parent(const struct device_node *
 #endif
 
 void update_reserved_mem_max_cnt(int max_count);
-void fdt_reserved_mem_save_node(struct device_node *node, const char *uname,
-				phys_addr_t base, phys_addr_t size);
+void dt_reserved_mem_save_node(struct device_node *node, const char *uname,
+			       phys_addr_t base, phys_addr_t size);
 
 #endif /* _LINUX_OF_PRIVATE_H */
diff --git a/drivers/of/of_reserved_mem.c b/drivers/of/of_reserved_mem.c
index 645b02e27492..3650efab0afd 100644
--- a/drivers/of/of_reserved_mem.c
+++ b/drivers/of/of_reserved_mem.c
@@ -139,15 +139,15 @@ static void __init dt_scan_reserved_mem_reg_nodes(void)
 		size = dt_mem_next_cell(dt_root_size_cells, &prop);
 
 		if (size)
-			fdt_reserved_mem_save_node(child, uname, base, size);
+			dt_reserved_mem_save_node(child, uname, base, size);
 	}
 }
 
 /*
- * fdt_reserved_mem_save_node() - save fdt node for second pass initialization
+ * dt_reserved_mem_save_node() - save dt node for second pass initialization
  */
-void __init fdt_reserved_mem_save_node(struct device_node *node, const char *uname,
-				       phys_addr_t base, phys_addr_t size)
+void __init dt_reserved_mem_save_node(struct device_node *node, const char *uname,
+				      phys_addr_t base, phys_addr_t size)
 {
 	struct reserved_mem *rmem = &reserved_mem[reserved_mem_count];
 
@@ -299,7 +299,7 @@ int __init __reserved_mem_alloc_size(unsigned long node, const char *uname)
 		       uname, (unsigned long)(size / SZ_1M));
 		return -ENOMEM;
 	}
-	fdt_reserved_mem_save_node(NULL, uname, base, size);
+	dt_reserved_mem_save_node(NULL, uname, base, size);
 	return 0;
 }
 
@@ -436,6 +436,60 @@ void __init fdt_init_reserved_mem(void)
 	}
 }
 
+/**
+ * dt_init_reserved_mem() - allocate and init all saved reserved memory regions
+ */
+void __init dt_init_reserved_mem(void)
+{
+	int i, ret;
+
+	ret = alloc_reserved_mem_array();
+	if (ret)
+		pr_err("Failed to allocate memory for reserved_mem array with err: %d", ret);
+
+	dt_scan_reserved_mem_reg_nodes();
+
+	/* check for overlapping reserved regions */
+	__rmem_check_for_overlap();
+
+	for (i = 0; i < reserved_mem_count; i++) {
+		struct reserved_mem *rmem = &reserved_mem[i];
+		struct device_node *node = rmem->dev_node;
+		int len;
+		const __be32 *prop;
+		int err = 0;
+		bool nomap;
+
+		nomap = of_get_property(node, "no-map", NULL) != NULL;
+		prop = of_get_property(node, "phandle", &len);
+		if (!prop)
+			prop = of_get_property(node, "linux,phandle", &len);
+		if (prop)
+			rmem->phandle = of_read_number(prop, len/4);
+
+		err = __reserved_mem_init_node(rmem);
+		if (err != 0 && err != -ENOENT) {
+			pr_info("node %s compatible matching fail\n",
+				rmem->name);
+			if (nomap)
+				memblock_clear_nomap(rmem->base, rmem->size);
+			else
+				memblock_phys_free(rmem->base,
+						   rmem->size);
+		} else {
+			phys_addr_t end = rmem->base + rmem->size - 1;
+			bool reusable =
+				(of_get_property(node, "reusable", NULL)) != NULL;
+
+			pr_info("%pa..%pa (%lu KiB) %s %s %s\n",
+				&rmem->base, &end, (unsigned long)(rmem->size / SZ_1K),
+				nomap ? "nomap" : "map",
+				reusable ? "reusable" : "non-reusable",
+				rmem->name ? rmem->name : "unknown");
+		}
+	}
+}
+
 static inline struct reserved_mem *__find_rmem(struct device_node *node)
 {
 	unsigned int i;
diff --git a/include/linux/of_reserved_mem.h b/include/linux/of_reserved_mem.h
index e92babd669c2..b1f71a4894aa 100644
--- a/include/linux/of_reserved_mem.h
+++ b/include/linux/of_reserved_mem.h
@@ -32,6 +32,7 @@ typedef int (*reservedmem_of_init_fn)(struct reserved_mem *rmem);
 #define RESERVEDMEM_OF_DECLARE(name, compat, init)			\
 	_OF_DECLARE(reservedmem, name, compat, init, reservedmem_of_init_fn)
 
+void dt_init_reserved_mem(void);
 void fdt_init_reserved_mem(void);
 int of_reserved_mem_device_init_by_idx(struct device *dev,
 				       struct device_node *np, int idx);
@@ -47,6 +48,8 @@ struct reserved_mem *of_reserved_mem_lookup(struct device_node *np);
 #define RESERVEDMEM_OF_DECLARE(name, compat, init)			\
 	_OF_DECLARE_STUB(reservedmem, name, compat, init, reservedmem_of_init_fn)
 
+static inline void dt_init_reserved_mem(void) { }
+
 static inline void fdt_init_reserved_mem(void) { }
 
 static inline int of_reserved_mem_device_init_by_idx(struct device *dev,
-- 
2.17.1


Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ