Skip to contentSkip to conversation

arm64/efi: handle potential failure to remap memory map

PATCH New Ard Biesheuvel 4 participants 4 messages Jan 15, 2015 – Jan 16, 2015

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 arm64/efi: handle potential failure to remap memory map

When remapping the UEFI memory map using ioremap_cache(), we have to deal with potential failure. Note that, even if the common case is for ioremap_cache() to return the existing linear mapping of the memory map, we cannot rely on that to be always the case, e.g., in the presence of a mem= kernel parameter.

At the same time, remove a stale comment and move the memmap code together.

---
 arch/arm64/kernel/efi.c | 10 ++++++----
 1 file changed, 6 insertions(+), 4 deletions(-)
arch/arm64/kernel/efi.c +6 -4
index a98415b5979c..c9cb0fbe7aa4 100644
@@ -229,19 +229,21 @@ static int __init arm64_enable_runtime_services(void)
 		return -1;
 	}
 
-	mapsize = memmap.map_end - memmap.map;
-
 	if (efi_runtime_disabled()) {
 		pr_info("EFI runtime services will be disabled.\n");
 		return -1;
 	}
 
 	pr_info("Remapping and enabling EFI services.\n");
-	/* replace early memmap mapping with permanent mapping */
+
+	mapsize = memmap.map_end - memmap.map;
 	memmap.map = (__force void *)ioremap_cache((phys_addr_t)memmap.phys_map,
 						   mapsize);
+	if (!memmap.map) {
+		pr_err("Failed to remap EFI memory map\n");
+		return -1;
+	}
 	memmap.map_end = memmap.map + mapsize;
-
 	efi.memmap = &memmap;
 
 	efi.systab = (__force void *)ioremap_cache(efi_system_table,
Signature · 1 line
1.8.3.2
reviewer
#1 lore raw

PATCH 1/1 arm64/efi: handle potential failure to remap memory map

Quoted 10 lines · Ard Biesheuvel

When remapping the UEFI memory map using ioremap_cache(), we have to deal with potential failure. Note that, even if the common case is for ioremap_cache() to return the existing linear mapping of the memory map, we cannot rely on that to be always the case, e.g., in the presence of a mem= kernel parameter.

At the same time, remove a stale comment and move the memmap code together.

This should probably be picked up before my mem= patch, which I will be resending shortly. I'll mention that when posting.

I guess Catalin should pick this up given the other portions are in the arm64 tree, and this falls under arch/arm64.

Thanks,
Mark.

Quoted 38 lines
---
 arch/arm64/kernel/efi.c | 10 ++++++----
 1 file changed, 6 insertions(+), 4 deletions(-)
arch/arm64/kernel/efi.c +6 -4
index a98415b5979c..c9cb0fbe7aa4 100644
@@ -229,19 +229,21 @@ static int __init arm64_enable_runtime_services(void)
 		return -1;
 	}
 
-	mapsize = memmap.map_end - memmap.map;
-
 	if (efi_runtime_disabled()) {
 		pr_info("EFI runtime services will be disabled.\n");
 		return -1;
 	}
 
 	pr_info("Remapping and enabling EFI services.\n");
-	/* replace early memmap mapping with permanent mapping */
+
+	mapsize = memmap.map_end - memmap.map;
 	memmap.map = (__force void *)ioremap_cache((phys_addr_t)memmap.phys_map,
 						   mapsize);
+	if (!memmap.map) {
+		pr_err("Failed to remap EFI memory map\n");
+		return -1;
+	}
 	memmap.map_end = memmap.map + mapsize;
-
 	efi.memmap = &memmap;
 
 	efi.systab = (__force void *)ioremap_cache(efi_system_table,
Signature · 1 line
1.8.3.2
maintainer Applied
#2 lore raw

PATCH 1/1 arm64/efi: handle potential failure to remap memory map

Quoted 12 lines · Mark Rutland
Quoted 10 lines · Ard Biesheuvel

When remapping the UEFI memory map using ioremap_cache(), we have to deal with potential failure. Note that, even if the common case is for ioremap_cache() to return the existing linear mapping of the memory map, we cannot rely on that to be always the case, e.g., in the presence of a mem= kernel parameter.

At the same time, remove a stale comment and move the memmap code together.

Quoted 7 lines

This should probably be picked up before my mem= patch, which I will be resending shortly. I'll mention that when posting.

I guess Catalin should pick this up given the other portions are in the arm64 tree, and this falls under arch/arm64.

I picked both up. Thanks.

Signature · 1 line
Catalin
#3 lore raw

PATCH 1/1 arm64/efi: handle potential failure to remap memory map

In reply to Ard Biesheuvel
Quoted 34 lines · Ard Biesheuvel

When remapping the UEFI memory map using ioremap_cache(), we have to deal with potential failure. Note that, even if the common case is for ioremap_cache() to return the existing linear mapping of the memory map, we cannot rely on that to be always the case, e.g., in the presence of a mem= kernel parameter.

At the same time, remove a stale comment and move the memmap code together.

---
 arch/arm64/kernel/efi.c | 10 ++++++----
 1 file changed, 6 insertions(+), 4 deletions(-)
arch/arm64/kernel/efi.c +2 -3
index a98415b5979c..c9cb0fbe7aa4 100644
@@ -229,19 +229,21 @@ static int __init arm64_enable_runtime_services(void)
 		return -1;
 	}
 
-	mapsize = memmap.map_end - memmap.map;
-
 	if (efi_runtime_disabled()) {
 		pr_info("EFI runtime services will be disabled.\n");
 		return -1;
 	}
 
 	pr_info("Remapping and enabling EFI services.\n");
-	/* replace early memmap mapping with permanent mapping */
+
+	mapsize = memmap.map_end - memmap.map;
 	memmap.map = (__force void *)ioremap_cache((phys_addr_t)memmap.phys_map,

arch/arm64/kernel/efi.c static int __init arm64_enable_runtime_services(void) · line 249

Quoted 10 lines
arch/arm64/kernel/efi.c +4 -1
 						   mapsize);
+	if (!memmap.map) {
+		pr_err("Failed to remap EFI memory map\n");
+		return -1;
+	}
 	memmap.map_end = memmap.map + mapsize;
-
 	efi.memmap = &memmap;
 
 	efi.systab = (__force void *)ioremap_cache(efi_system_table,

Somewhat unrelated but we should unmap memmap.map if the efi.systab mapping fails.