Skip to content

Commit 2e28a79

Browse files
committed
efi/libstub: Disable PCI DMA before grabbing the EFI memory map
Currently, the EFI stub will disable PCI DMA as the very last thing it does before calling ExitBootServices(), to avoid interfering with the firmware's normal operation as much as possible. However, the stub will invoke DisconnectController() on all endpoints downstream of the PCI bridges it disables, and this may affect the layout of the EFI memory map, making it substantially more likely that ExitBootServices() will fail the first time around, and that the EFI memory map needs to be reloaded. This, in turn, increases the likelihood that the slack space we allocated is insufficient (and we can no longer allocate memory via boot services after having called ExitBootServices() once), causing the second call to GetMemoryMap (and therefore the boot) to fail. This makes the PCI DMA disable feature a bit more fragile than it already is, so let's make it more robust, by allocating the space for the EFI memory map after disabling PCI DMA. Fixes: 4444f85 ("efi: Allow disabling PCI busmastering on bridges during boot") Reported-by: Glenn Washburn <[email protected]> Acked-by: Matthew Garrett <[email protected]> Signed-off-by: Ard Biesheuvel <[email protected]>
1 parent d0a1865 commit 2e28a79

File tree

1 file changed

+3
-3
lines changed

1 file changed

+3
-3
lines changed

drivers/firmware/efi/libstub/efi-stub-helper.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -378,6 +378,9 @@ efi_status_t efi_exit_boot_services(void *handle, void *priv,
378378
struct efi_boot_memmap *map;
379379
efi_status_t status;
380380

381+
if (efi_disable_pci_dma)
382+
efi_pci_disable_bridge_busmaster();
383+
381384
status = efi_get_memory_map(&map, true);
382385
if (status != EFI_SUCCESS)
383386
return status;
@@ -388,9 +391,6 @@ efi_status_t efi_exit_boot_services(void *handle, void *priv,
388391
return status;
389392
}
390393

391-
if (efi_disable_pci_dma)
392-
efi_pci_disable_bridge_busmaster();
393-
394394
status = efi_bs_call(exit_boot_services, handle, map->map_key);
395395

396396
if (status == EFI_INVALID_PARAMETER) {

0 commit comments

Comments
 (0)