Skip to contentSkip to conversation

efi: Return EFI_RESERVED_TYPE in efi_mem_type() for absent addresses

PATCH In review Anshuman Khandual 2 participants 3 messages Nov 5, 2019 – Nov 7, 2019 EFI

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 efi: Return EFI_RESERVED_TYPE in efi_mem_type() for absent addresses

The function efi_mem_type() is expected (per documentation above) to return EFI_RESERVED_TYPE when a given physical address is not present in the EFI memory map. Even though EFI_RESERVED_TYPE is not getting checked explicitly anywhere in the callers, it is always better to return expected values.

---
 drivers/firmware/efi/efi.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/firmware/efi/efi.c +1 -1
index 69f00f7453a3..bdda90a4601e 100644
@@ -914,7 +914,7 @@ int efi_mem_type(unsigned long phys_addr)
 				  (md->num_pages << EFI_PAGE_SHIFT))))
 			return md->type;
 	}
-	return -EINVAL;
+	return EFI_RESERVED_TYPE;
 }
 #endif
 
Signature · 1 line
2.20.1
#1 lore raw
Quoted 10 lines · Anshuman Khandual

The function efi_mem_type() is expected (per documentation above) to return EFI_RESERVED_TYPE when a given physical address is not present in the EFI memory map. Even though EFI_RESERVED_TYPE is not getting checked explicitly anywhere in the callers, it is always better to return expected values.

This reverts commit f99afd08a45fbbd9ce35a7624ffd1d850a1906c0.

Could you explain why it is better to fix the code than fix the comment?

Quoted 20 lines
---
 drivers/firmware/efi/efi.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/firmware/efi/efi.c +1 -2
index 69f00f7453a3..bdda90a4601e 100644
@@ -914,7 +914,7 @@ int efi_mem_type(unsigned long phys_addr)
                                  (md->num_pages << EFI_PAGE_SHIFT))))
                        return md->type;
        }
-       return -EINVAL;
+       return EFI_RESERVED_TYPE;
 }
 #endif
 
--

2.20.1

#2 lore raw
Quoted 8 lines · Ard Biesheuvel
Quoted 6 lines · Anshuman Khandual

The function efi_mem_type() is expected (per documentation above) to return EFI_RESERVED_TYPE when a given physical address is not present in the EFI memory map. Even though EFI_RESERVED_TYPE is not getting checked explicitly anywhere in the callers, it is always better to return expected values.

Quoted 8 lines
Quoted 4 lines

This reverts commit f99afd08a45fbbd9ce35a7624ffd1d850a1906c0.

Could you explain why it is better to fix the code than fix the comment?

From the above commit message, its not clear how returning EFI_RESERVED_TYPE would have meant that a memory descriptor really exists.

Just wondering if firmware itself can send across memory descriptors with EFI_RESERVED_TYPE attribute or it is only a software specific attribute ? Currently it is being used while merging two adjacent regions with similar type and attributes. Searching for physical addresses within those merged memory descriptors will return EFI_RESERVED_TYPE but that is different than the entry not being present at all. So I think the previous commit which introduced -EINVAL/-ENOTSUPP in place for EFI_RESERVED_TYPE did the right thing.

We should fix the comment instead, will send a patch.

Quoted 21 lines
Quoted 21 lines
---
 drivers/firmware/efi/efi.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/firmware/efi/efi.c +1 -2
index 69f00f7453a3..bdda90a4601e 100644
@@ -914,7 +914,7 @@ int efi_mem_type(unsigned long phys_addr)
                                  (md->num_pages << EFI_PAGE_SHIFT))))
                        return md->type;
        }
-       return -EINVAL;
+       return EFI_RESERVED_TYPE;
 }
 #endif
 
--

2.20.1