From 42cbb448916340f8d9c6b47a911033e5e583bfae Mon Sep 17 00:00:00 2001 From: Victor Sun Date: Wed, 24 Nov 2021 11:02:05 +0800 Subject: [PATCH] HV: correct hv_ram_size when hv is relocated In previous commit df7ffab4413034eaa221a104575d8f0bb705ba9f the CONFIG_HV_RAM_SIZE was removed and the hv_ram_size was calculated in link script by following formula: ld_ram_size = _ld_ram_end - _ld_ram_start ; but _ld_ram_start is a relative address in boot section whereas _ld_ram_end is a absolute address in global, the mix operation cause hv_ram_size is incorrect when HV binary is relocated. The patch fix this issue by getting _ld_ram_start and _ld_ram_end respectively and calculated at runtime. Tracked-On: #6885 Signed-off-by: Victor Sun Acked-by: Anthony Xu --- hypervisor/arch/x86/mmu.c | 2 +- hypervisor/bsp/ld/link_ram.ld.in | 1 - hypervisor/include/arch/x86/asm/boot/ld_sym.h | 3 ++- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/hypervisor/arch/x86/mmu.c b/hypervisor/arch/x86/mmu.c index dd7b8f53e..c5248d31c 100644 --- a/hypervisor/arch/x86/mmu.c +++ b/hypervisor/arch/x86/mmu.c @@ -255,7 +255,7 @@ void init_paging(void) const struct abi_mmap *p_mmap = abi->mmap_entry; pr_dbg("HV MMU Initialization"); - hv_ram_size = (uint64_t)&ld_ram_size; + hv_ram_size = (uint64_t)(&_ld_ram_end - &_ld_ram_start); init_sanitized_page((uint64_t *)sanitized_page, hva2hpa_early(sanitized_page)); diff --git a/hypervisor/bsp/ld/link_ram.ld.in b/hypervisor/bsp/ld/link_ram.ld.in index a1bb65c56..7f27d1b87 100644 --- a/hypervisor/bsp/ld/link_ram.ld.in +++ b/hypervisor/bsp/ld/link_ram.ld.in @@ -100,5 +100,4 @@ SECTIONS . = ALIGN(0x200000) ; _ld_ram_end = . ; - ld_ram_size = _ld_ram_end - _ld_ram_start ; } diff --git a/hypervisor/include/arch/x86/asm/boot/ld_sym.h b/hypervisor/include/arch/x86/asm/boot/ld_sym.h index 8eb8e6ac1..6c2e3327b 100644 --- a/hypervisor/include/arch/x86/asm/boot/ld_sym.h +++ b/hypervisor/include/arch/x86/asm/boot/ld_sym.h @@ -14,6 +14,7 @@ extern uint8_t ld_entry_end; extern const uint8_t ld_trampoline_load; extern uint8_t ld_trampoline_start; extern uint8_t ld_trampoline_end; -extern uint8_t ld_ram_size; +extern uint8_t _ld_ram_start; +extern uint8_t _ld_ram_end; #endif /* LD_SYM_H */