On Thu, Nov 28, 2024 at 09:52:33AM +0100, Ard Biesheuvel wrote: > On Thu, 28 Nov 2024 at 09:20, Johan Hovold <johan@xxxxxxxxxx> wrote: > > We've run into a buggy UEFI implementation on the Qualcomm Snapdragon > > based Lenovo ThinkPad T14s where ExitBootServices() often fails. > > Based on your comments to a similar report for an older Snapdragon based > > Lenovo UEFI implementation [1], I discovered that allocating an event > > before calling ExitBootServices() can make the call succeed. There is > > often no need to actually signal the event group, but the event must > > remain allocated (i.e. CloseEvent() must not be called). > > > > (Raising TPL or disabling interrupts does not seem to help.) > > > > Also with the event signalling, ExitBootServices() sometimes fails when > > starting the kernel automatically from a shell startup.nsh, while > > systemd-boot seems to always work. This was only observed after removing > > some efi_printk() used during the experiments from the stub.. . > So the error code is EFI_INVALID_PARAMETER in all cases? In the > upstream implementation, the only thing that can make > ExitBootServices() return an error is a mismatch of the map key, and > so there is something changing the memory map. Yes, it's always EFI_INVALID_PARAMETER. > This might be due to a handler of the > gEfiEventBeforeExitBootServicesGuid event group that fails to close > the event, and so it gets signaled every time. This is a fairly recent > addition, though, so I'm not sure it even exists in QCOM's tree. > > In upstream EDK2, the map key is just a monotonic counter that gets > incremented on every memory map update, so one experiment worth > conducting is to repeat the second call to ExitBootServices() a couple > of times, increasing the map key each time. I had already tried repeating the second call (GMM + EBS) by running it in a loop, and I do see the map_key increasing for each iteration (e.g. by 0x1a). > Or use GetMemoryMap() to > just grab the map key without the actual memory map, and printing it > to the console (although the timer is disabled on the first call so > anything that relies on that will be shut down at this point) I just tried adding another inner loop just calling GetMemoryMap() a few times and I see the map_key increasing there too for each iteration (e.g. by 0x6). (The map size remains constant.) I do get the feeling that efi_printk() contributes to the memory map updates, and I can indeed get the reference design fw to similarly fail if I try to print the map_key after each call to GetMemoryMap() in a retry loop. Johan