Bug 210244

Summary: [EFI] Corner case in UEFI GetMemoryMap usage
Product: Base System Reporter: rebecca+freebsd <rebecca+freebsd>
Component: kernAssignee: Rebecca Cran <bcran>
Status: Closed FIXED    
Severity: Affects Some People CC: bcran, dmgk
Priority: Normal    
Version: 10.3-RELEASE   
Hardware: Any   
OS: Any   

Description rebecca+freebsd@bluestop.org 2016-06-13 03:12:52 UTC
There are a couple of places in the sys/boot/efi tree that calls `BS->GetMemoryMap`. There appears to be a problem with the way it's called though, due to a corner case.

In some cases, allocating the memory requires to store the memory map can cause the map to become fragmented; this means a _second_ call to `BS->GetMemoryMap` can also return EFI_BUFFER_TOO_SMALL. One workaround is to call it in a loop (with a max of, say 10 times) until the memory needed to store the map doesn't change.
Comment 1 Rebecca Cran freebsd_committer freebsd_triage 2019-02-13 22:51:03 UTC
I saw this occur today on my MinnowBoard Turbot running firmware 1.0 X64 DEBUG, after doing some work in the shell before running fs2:\efi\boot\bootx64.efi :

Loading kernel...
/boot/kernel/kernel text=0x16d3d96 data=0x1d58e8+0x819650 syms=[0x8+0x182358+0x8+0x19f7dd]
Loading configured modules...
can't find '/boot/entropy'
Start @ 0xffffffff8036d000 ...
bi_load_efi_data: GetMemoryMap error 5

Error 5 means the buffer was too small.
Comment 2 Dmitri Goutnik freebsd_committer freebsd_triage 2019-02-16 11:56:02 UTC
Getting the same "GetMemoryMap error 5" on boot with Asus H81M-K motherboard, EFI version 2.31, EFI firmware: American Megatrends 4.654.

Also see bug #235714
Comment 3 Rebecca Cran freebsd_committer freebsd_triage 2019-03-07 00:06:59 UTC
Fixed in r344839 (https://svnweb.freebsd.org/base?view=revision&revision=344839).
I'll MFC it to 11.x and 12.x in the coming weeks.