efi-stub: don't relocate hypervisor to address lower than 256MB

With this patch, we relocate hypervisor image to HPA 256MB and above,
thus the hardcoded hvlog and ramoops buffer for SOS can safely reside at
addresses under HPA 256MB, given that 1:1 mapping between SOS GPA and HPA.

Tracked-On: #4760
Signed-off-by: Zide Chen <zide.chen@intel.com>
Reviewed-by: Jason Chen CJ <jason.cj.chen@intel.com>
This commit is contained in:
Zide Chen 2020-04-23 10:41:51 -07:00 committed by wenlingz
parent b64aa2b2f6
commit be4797a10c
3 changed files with 12 additions and 4 deletions

View File

@ -481,9 +481,13 @@ efi_main(EFI_HANDLE image, EFI_SYSTEM_TABLE *_table)
* hypervisor is able to do relocation, the only requirement is that * hypervisor is able to do relocation, the only requirement is that
* it need to reside in memory below 4GB, call emalloc_reserved_mem() * it need to reside in memory below 4GB, call emalloc_reserved_mem()
* instead. * 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 #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 #else
err = emalloc_fixed_addr(&hv_hpa, CONFIG_HV_RAM_SIZE, CONFIG_HV_RAM_START); err = emalloc_fixed_addr(&hv_hpa, CONFIG_HV_RAM_SIZE, CONFIG_HV_RAM_START);
#endif #endif

View File

@ -53,7 +53,8 @@ extern EFI_SYSTEM_TABLE *sys_table;
extern EFI_BOOT_SERVICES *boot; extern EFI_BOOT_SERVICES *boot;
extern EFI_STATUS 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 * allocate_pages - Allocate memory pages from the system

View File

@ -96,7 +96,7 @@ failed:
EFI_STATUS EFI_STATUS
emalloc_reserved_aligned(EFI_PHYSICAL_ADDRESS *addr, UINTN size, UINTN align, 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; UINTN msize, mkey, desc_sz, desc_addr, pages;
UINT32 desc_version; UINT32 desc_version;
@ -137,6 +137,10 @@ emalloc_reserved_aligned(EFI_PHYSICAL_ADDRESS *addr, UINTN size, UINTN align,
if (start < 4096) { if (start < 4096) {
start = 4096; start = 4096;
} }
if (start < minaddr) {
start = minaddr;
}
start = (start + align - 1) & ~(align - 1); start = (start + align - 1) & ~(align - 1);
/* Since this routine is called during booting, memory block is large /* 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; break;
} }
} }
} }
if (desc_addr < (UINTN)mbuf) { if (desc_addr < (UINTN)mbuf) {
err = EFI_OUT_OF_RESOURCES; err = EFI_OUT_OF_RESOURCES;