[PATCH] powerpc/powernv/prd: Validate whether address to be mapped is part of system RAM

Vasant Hegde hegdevasant at linux.vnet.ibm.com
Wed Oct 2 17:48:56 AEST 2019


Add check to validate whether requested page is part of system RAM
or not before mmap() and error out if its not part of system RAM.

cat /proc/iomem:
-----------------
00000000-27ffffffff : System RAM
2800000000-2fffffffff : namespace0.0
200000000000-2027ffffffff : System RAM
202800000000-202fffffffff : namespace1.0
6000000000000-6003fbfffffff : pciex at 600c3c0000000
6004000000000-6007f7fffffff : pciex at 600c3c0100000
....
....

Sample dmesg output with this fix:
----------------------------------
[  160.371911] opal-prd: mmap: Requested page is not part of system RAM (addr : 0x0000202ffcfc0000, size : 0x0000000000570000)
[  160.665366] opal-prd: mmap: Requested page is not part of system RAM (addr : 0x0000202ffcfc0000, size : 0x0000000000570000)
[  160.914627] opal-prd: mmap: Requested page is not part of system RAM (addr : 0x0000202ffcfc0000, size : 0x0000000000570000)
[  161.165253] opal-prd: mmap: Requested page is not part of system RAM (addr : 0x0000202ffcfc0000, size : 0x0000000000570000)
[  161.414604] opal-prd: mmap: Requested page is not part of system RAM (addr : 0x0000202ffcfc0000, size : 0x0000000000570000)

CC: Aneesh Kumar K.V <aneesh.kumar at linux.vnet.ibm.com>
CC: Jeremy Kerr <jk at ozlabs.org>
CC: Vaidyanathan Srinivasan <svaidy at linux.vnet.ibm.com>
Signed-off-by: Vasant Hegde <hegdevasant at linux.vnet.ibm.com>
---
 arch/powerpc/platforms/powernv/opal-prd.c | 16 +++++++++++++++-
 1 file changed, 15 insertions(+), 1 deletion(-)

diff --git a/arch/powerpc/platforms/powernv/opal-prd.c b/arch/powerpc/platforms/powernv/opal-prd.c
index 45f4223a790f..0f88752302a2 100644
--- a/arch/powerpc/platforms/powernv/opal-prd.c
+++ b/arch/powerpc/platforms/powernv/opal-prd.c
@@ -3,7 +3,7 @@
  * OPAL Runtime Diagnostics interface driver
  * Supported on POWERNV platform
  *
- * Copyright IBM Corporation 2015
+ * Copyright IBM Corporation 2015-2019
  */
 
 #define pr_fmt(fmt) "opal-prd: " fmt
@@ -47,6 +47,20 @@ static bool opal_prd_range_is_valid(uint64_t addr, uint64_t size)
 	if (addr + size < addr)
 		return false;
 
+	/*
+	 * Check if region is in system RAM and error out if the address
+	 * belongs to special devices like NVDIMM. phys_mem_access_prot()
+	 * routine will change ATT bits to non cachable if page is not in
+	 * RAM, causing HBRT to not fetch and execute in the mapped memory
+	 * and fail. Page permissions can be left at default since all
+	 * firmware component should be in system RAM only.
+	 */
+	if (!page_is_ram(addr >> PAGE_SHIFT)) {
+		pr_warn("mmap: Requested page is not part of system RAM "
+			"(addr : 0x%016llx, size : 0x%016llx)\n", addr, size);
+		return false;
+	}
+
 	parent = of_find_node_by_path("/reserved-memory");
 	if (!parent)
 		return false;
-- 
2.21.0



More information about the Linuxppc-dev mailing list