loader.efi: reduce the size of the staging area if necessary
authordexuan <dexuan@FreeBSD.org>
Thu, 2 Mar 2017 07:25:50 +0000 (07:25 +0000)
committerdexuan <dexuan@FreeBSD.org>
Thu, 2 Mar 2017 07:25:50 +0000 (07:25 +0000)
commit55d5acd16391e37562da6db1a0afc223d8e53abf
tree695ed54d768d75142dabed6e5dbdabe551cb6858
parentf8ec754345519aa71a663b0a9de8e770abf76aad
loader.efi: reduce the size of the staging area if necessary

The loader assumes physical memory in [2MB, 2MB + EFI_STAGING_SIZE)
is Conventional Memory, but actually it may not, e.g. in the case
of Hyper-V Generation-2 VM (i.e. UEFI VM) running on Windows
Server 2012 R2 host, there is a BootServiceData memory block at
the address 47.449MB and the memory is not writable.

Without the patch, the loader will crash in efi_copy_finish():
see PR 211746.

The patch verifies the end of the staging area, and reduces its
size if necessary. This way, the loader will not try to write into
the BootServiceData memory any longer.

Thank Marcel Moolenaar for helping me on this issue!

The patch also allocates the staging area in the first 1GB memory.
See the comment in the patch for this.

PR: 211746
Reviewed by: marcel, kib, sephe
Approved by: sephe (mentor)
MFC after: 2 weeks
Sponsored by: Microsoft
Differential Revision: https://reviews.freebsd.org/D9686
sys/boot/efi/loader/copy.c