Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

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: 4444f8541dad16fe ("efi: Allow disabling PCI busmastering on bridges during boot")
Reported-by: Glenn Washburn <development@efficientek.com>
Acked-by: Matthew Garrett <mjg59@srcf.ucam.org>
Signed-off-by: Ard Biesheuvel <ardb@kernel.org>

+3 -3
+3 -3
drivers/firmware/efi/libstub/efi-stub-helper.c
··· 378 378 struct efi_boot_memmap *map; 379 379 efi_status_t status; 380 380 381 + if (efi_disable_pci_dma) 382 + efi_pci_disable_bridge_busmaster(); 383 + 381 384 status = efi_get_memory_map(&map, true); 382 385 if (status != EFI_SUCCESS) 383 386 return status; ··· 390 387 efi_bs_call(free_pool, map); 391 388 return status; 392 389 } 393 - 394 - if (efi_disable_pci_dma) 395 - efi_pci_disable_bridge_busmaster(); 396 390 397 391 status = efi_bs_call(exit_boot_services, handle, map->map_key); 398 392