diff --git a/misc/efi-stub/boot.c b/misc/efi-stub/boot.c index c1e36c990..f0a4d3bb1 100644 --- a/misc/efi-stub/boot.c +++ b/misc/efi-stub/boot.c @@ -481,9 +481,13 @@ efi_main(EFI_HANDLE image, EFI_SYSTEM_TABLE *_table) * hypervisor is able to do relocation, the only requirement is that * it need to reside in memory below 4GB, call emalloc_reserved_mem() * instead. + * + * Don't relocate hypervisor binary under 256MB, which could be where + * guest Linux kernel boots from, and other usage, e.g. hvlog buffer */ #ifdef CONFIG_RELOC - err = emalloc_reserved_aligned(&hv_hpa, CONFIG_HV_RAM_SIZE, 1 << 21, MEM_ADDR_4GB); + err = emalloc_reserved_aligned(&hv_hpa, CONFIG_HV_RAM_SIZE, 2U * MEM_ADDR_1MB, + 256U * MEM_ADDR_1MB, MEM_ADDR_4GB); #else err = emalloc_fixed_addr(&hv_hpa, CONFIG_HV_RAM_SIZE, CONFIG_HV_RAM_START); #endif diff --git a/misc/efi-stub/efilinux.h b/misc/efi-stub/efilinux.h index 0f8fbf57d..eac427032 100644 --- a/misc/efi-stub/efilinux.h +++ b/misc/efi-stub/efilinux.h @@ -53,7 +53,8 @@ extern EFI_SYSTEM_TABLE *sys_table; extern EFI_BOOT_SERVICES *boot; extern EFI_STATUS -emalloc_reserved_aligned(EFI_PHYSICAL_ADDRESS *addr, UINTN size, UINTN align, EFI_PHYSICAL_ADDRESS maxaddr); +emalloc_reserved_aligned(EFI_PHYSICAL_ADDRESS *addr, UINTN size, UINTN align, + EFI_PHYSICAL_ADDRESS minaddr, EFI_PHYSICAL_ADDRESS maxaddr); /** * allocate_pages - Allocate memory pages from the system diff --git a/misc/efi-stub/malloc.c b/misc/efi-stub/malloc.c index bc31c7931..27ebcd07b 100644 --- a/misc/efi-stub/malloc.c +++ b/misc/efi-stub/malloc.c @@ -96,7 +96,7 @@ failed: EFI_STATUS emalloc_reserved_aligned(EFI_PHYSICAL_ADDRESS *addr, UINTN size, UINTN align, - EFI_PHYSICAL_ADDRESS maxaddr) + EFI_PHYSICAL_ADDRESS minaddr, EFI_PHYSICAL_ADDRESS maxaddr) { UINTN msize, mkey, desc_sz, desc_addr, pages; UINT32 desc_version; @@ -137,6 +137,10 @@ emalloc_reserved_aligned(EFI_PHYSICAL_ADDRESS *addr, UINTN size, UINTN align, if (start < 4096) { start = 4096; } + + if (start < minaddr) { + start = minaddr; + } start = (start + align - 1) & ~(align - 1); /* Since this routine is called during booting, memory block is large @@ -151,7 +155,6 @@ emalloc_reserved_aligned(EFI_PHYSICAL_ADDRESS *addr, UINTN size, UINTN align, break; } } - } if (desc_addr < (UINTN)mbuf) { err = EFI_OUT_OF_RESOURCES;