Skip to contentSkip to conversation

UEFI: Don't pass boot services regions to SetVirtualAddressMap()

PATCH In review Matthew Garrett 2 participants 4 messages Jun 2, 2013 – Jun 6, 2013

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

PATCH 1/1 UEFI: Don't pass boot services regions to SetVirtualAddressMap()

We need to map boot services regions during startup in order to avoid firmware bugs, but we shouldn't be passing those regions to SetVirtualAddressMap(). Ensure that we're only passing regions that are marked as being mapped at runtime.

---
 arch/x86/platform/efi/efi.c | 7 +++++++
 1 file changed, 7 insertions(+)
arch/x86/platform/efi/efi.c +7 -0
index 63e167a..add0e37 100644
@@ -922,6 +922,13 @@ void __init efi_enter_virtual_mode(void)
 			va = efi_ioremap(md->phys_addr, size,
 					 md->type, md->attribute);
 
+		if (!(md->attribute & EFI_MEMORY_RUNTIME)) {
+			if (!va)
+				pr_err("ioremap of 0x%llX failed!\n",
+				       (unsigned long long)md->phys_addr);
+			continue;
+		}
+
 		md->virt_addr = (u64) (unsigned long) va;
 
 		if (!va) {
Signature · 1 line
1.8.1.4
#1 lore raw
Quoted 19 lines · Matthew Garrett

We need to map boot services regions during startup in order to avoid firmware bugs, but we shouldn't be passing those regions to SetVirtualAddressMap(). Ensure that we're only passing regions that are marked as being mapped at runtime.

---
 arch/x86/platform/efi/efi.c | 7 +++++++
 1 file changed, 7 insertions(+)
arch/x86/platform/efi/efi.c +0 -0
index 63e167a..add0e37 100644
@@ -922,6 +922,13 @@ void __init efi_enter_virtual_mode(void)
 			va = efi_ioremap(md->phys_addr, size,
 					 md->type, md->attribute);
 

arch/x86/platform/efi/efi.c void __init efi_enter_virtual_mode(void) · line 934

Quoted 10 lines
arch/x86/platform/efi/efi.c +7 -0
+		if (!(md->attribute & EFI_MEMORY_RUNTIME)) {
+			if (!va)
+				pr_err("ioremap of 0x%llX failed!\n",
+				       (unsigned long long)md->phys_addr);
+			continue;
+		}
+
 		md->virt_addr = (u64) (unsigned long) va;
 
 		if (!va) {

Is there any point in calling efi_ioremap() for non-runtime regions in this case? In other words, why not the following patch?

arch/x86/platform/efi/efi.c +1 -3
index 63e167a..a438ed3 100644
@@ -903,9 +903,7 @@ void __init efi_enter_virtual_mode(void)
 
 	for (p = memmap.map; p < memmap.map_end; p += memmap.desc_size) {
 		md = p;
-		if (!(md->attribute & EFI_MEMORY_RUNTIME) &&
-		    md->type != EFI_BOOT_SERVICES_CODE &&
-		    md->type != EFI_BOOT_SERVICES_DATA)
+		if (!(md->attribute & EFI_MEMORY_RUNTIME))
 			continue;
 
 		size = md->num_pages << EFI_PAGE_SHIFT;
#2 lore raw
Quoted 2 lines · Matt Fleming

Is there any point in calling efi_ioremap() for non-runtime regions in this case? In other words, why not the following patch?

Yeah, we need the boottime services regions to be mapped while we make this call.

Signature · 2 lines
Matthew Garrett | [email protected]
���{.n�+�������+%�����ݶ��w��{.n�+����{��G�����{ay�ʇڙ�,j��f���h��������z_�(�階�ݢj"���m������G������?����&���~��iO��z��v�^�m����������?�I�
#3 lore raw
In reply to Matthew Garrett
Quoted 9 lines · Matthew Garrett

We need to map boot services regions during startup in order to avoid firmware bugs, but we shouldn't be passing those regions to SetVirtualAddressMap(). Ensure that we're only passing regions that are marked as being mapped at runtime.

---
 arch/x86/platform/efi/efi.c | 7 +++++++
 1 file changed, 7 insertions(+)

This doesn't fix a crash or regression, right? If it's a "this just makes more sense" patch, I'll queue it up in the 'next' branch for v3.11.