mirror of
https://github.com/projectacrn/acrn-hypervisor.git
synced 2025-08-04 09:50:54 +00:00
hv: refactor hypervisor image size helper function
The hypervisor image size is determined at link time, but now it is calculated and stored in a global variable during mmu initialization, and the helper function reads from that variable. Change to calculate it inside helper function to avoid inconsistency. Tracked-On: #8738 Signed-off-by: Jiaqing Zhao <jiaqing.zhao@linux.intel.com> Reviewed-by: Fei Li <fei1.li@intel.com>
This commit is contained in:
parent
b55440dce9
commit
a8715330d1
@ -503,7 +503,7 @@ void cpu_dead(void)
|
|||||||
vmx_off();
|
vmx_off();
|
||||||
|
|
||||||
stac();
|
stac();
|
||||||
flush_cache_range((void *)get_hv_image_base(), get_hv_ram_size());
|
flush_cache_range((void *)get_hv_image_base(), get_hv_image_size());
|
||||||
clac();
|
clac();
|
||||||
|
|
||||||
/* Set state to show CPU is dead */
|
/* Set state to show CPU is dead */
|
||||||
|
@ -45,7 +45,7 @@ void prepare_tee_vm_memmap(struct acrn_vm *vm, const struct acrn_vm_config *vm_c
|
|||||||
prepare_vm_identical_memmap(vm, E820_TYPE_RAM, EPT_WB | EPT_RWX);
|
prepare_vm_identical_memmap(vm, E820_TYPE_RAM, EPT_WB | EPT_RWX);
|
||||||
|
|
||||||
hv_hpa = hva2hpa((void *)(get_hv_image_base()));
|
hv_hpa = hva2hpa((void *)(get_hv_image_base()));
|
||||||
ept_del_mr(vm, (uint64_t *)vm->arch_vm.nworld_eptp, hv_hpa, get_hv_ram_size());
|
ept_del_mr(vm, (uint64_t *)vm->arch_vm.nworld_eptp, hv_hpa, get_hv_image_size());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -139,7 +139,7 @@ void create_service_vm_e820(struct acrn_vm *vm)
|
|||||||
uint16_t vm_id;
|
uint16_t vm_id;
|
||||||
uint32_t i;
|
uint32_t i;
|
||||||
uint64_t hv_start_pa = hva2hpa((void *)(get_hv_image_base()));
|
uint64_t hv_start_pa = hva2hpa((void *)(get_hv_image_base()));
|
||||||
uint64_t hv_end_pa = hv_start_pa + get_hv_ram_size();
|
uint64_t hv_end_pa = hv_start_pa + get_hv_image_size();
|
||||||
uint32_t entries_count = get_e820_entries_count();
|
uint32_t entries_count = get_e820_entries_count();
|
||||||
struct acrn_vm_config *service_vm_config = get_vm_config(vm->vm_id);
|
struct acrn_vm_config *service_vm_config = get_vm_config(vm->vm_id);
|
||||||
|
|
||||||
|
@ -528,7 +528,7 @@ static void prepare_service_vm_memmap(struct acrn_vm *vm)
|
|||||||
* will cause EPT violation if Service VM accesses hv memory
|
* will cause EPT violation if Service VM accesses hv memory
|
||||||
*/
|
*/
|
||||||
hv_hpa = hva2hpa((void *)(get_hv_image_base()));
|
hv_hpa = hva2hpa((void *)(get_hv_image_base()));
|
||||||
ept_del_mr(vm, pml4_page, hv_hpa, get_hv_ram_size());
|
ept_del_mr(vm, pml4_page, hv_hpa, get_hv_image_size());
|
||||||
/* unmap prelaunch VM memory */
|
/* unmap prelaunch VM memory */
|
||||||
for (vm_id = 0U; vm_id < CONFIG_MAX_VM_NUM; vm_id++) {
|
for (vm_id = 0U; vm_id < CONFIG_MAX_VM_NUM; vm_id++) {
|
||||||
vm_config = get_vm_config(vm_id);
|
vm_config = get_vm_config(vm_id);
|
||||||
|
@ -39,7 +39,6 @@
|
|||||||
#include <logmsg.h>
|
#include <logmsg.h>
|
||||||
#include <misc_cfg.h>
|
#include <misc_cfg.h>
|
||||||
|
|
||||||
static uint64_t hv_ram_size;
|
|
||||||
static void *ppt_mmu_pml4_addr;
|
static void *ppt_mmu_pml4_addr;
|
||||||
/**
|
/**
|
||||||
* @brief The sanitized page
|
* @brief The sanitized page
|
||||||
@ -147,11 +146,6 @@ void invept(const void *eptp)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
uint64_t get_hv_ram_size(void)
|
|
||||||
{
|
|
||||||
return hv_ram_size;
|
|
||||||
}
|
|
||||||
|
|
||||||
void enable_paging(void)
|
void enable_paging(void)
|
||||||
{
|
{
|
||||||
uint64_t tmp64 = 0UL;
|
uint64_t tmp64 = 0UL;
|
||||||
@ -265,7 +259,6 @@ void init_paging(void)
|
|||||||
const struct abi_mmap *p_mmap = abi->mmap_entry;
|
const struct abi_mmap *p_mmap = abi->mmap_entry;
|
||||||
|
|
||||||
pr_dbg("HV MMU Initialization");
|
pr_dbg("HV MMU Initialization");
|
||||||
hv_ram_size = (uint64_t)(&ld_ram_end - &ld_ram_start);
|
|
||||||
|
|
||||||
init_sanitized_page((uint64_t *)sanitized_page, hva2hpa_early(sanitized_page));
|
init_sanitized_page((uint64_t *)sanitized_page, hva2hpa_early(sanitized_page));
|
||||||
|
|
||||||
@ -314,7 +307,7 @@ void init_paging(void)
|
|||||||
*/
|
*/
|
||||||
hv_hva = get_hv_image_base();
|
hv_hva = get_hv_image_base();
|
||||||
pgtable_modify_or_del_map((uint64_t *)ppt_mmu_pml4_addr, hv_hva & PDE_MASK,
|
pgtable_modify_or_del_map((uint64_t *)ppt_mmu_pml4_addr, hv_hva & PDE_MASK,
|
||||||
hv_ram_size + (((hv_hva & (PDE_SIZE - 1UL)) != 0UL) ? PDE_SIZE : 0UL),
|
get_hv_image_size() + (((hv_hva & (PDE_SIZE - 1UL)) != 0UL) ? PDE_SIZE : 0UL),
|
||||||
PAGE_CACHE_WB, PAGE_CACHE_MASK | PAGE_USER, &ppt_pgtable, MR_MODIFY);
|
PAGE_CACHE_WB, PAGE_CACHE_MASK | PAGE_USER, &ppt_pgtable, MR_MODIFY);
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
@ -9,6 +9,7 @@
|
|||||||
extern void relocate(void);
|
extern void relocate(void);
|
||||||
extern uint64_t get_hv_image_delta(void);
|
extern uint64_t get_hv_image_delta(void);
|
||||||
extern uint64_t get_hv_image_base(void);
|
extern uint64_t get_hv_image_base(void);
|
||||||
|
extern uint64_t get_hv_image_size(void);
|
||||||
|
|
||||||
/* external symbols that are helpful for relocation */
|
/* external symbols that are helpful for relocation */
|
||||||
extern uint8_t _DYNAMIC[1];
|
extern uint8_t _DYNAMIC[1];
|
||||||
|
@ -55,6 +55,11 @@ uint64_t get_hv_image_base(void)
|
|||||||
return (get_hv_image_delta() + CONFIG_HV_RAM_START);
|
return (get_hv_image_delta() + CONFIG_HV_RAM_START);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
inline uint64_t get_hv_image_size(void)
|
||||||
|
{
|
||||||
|
return (uint64_t)(&ld_ram_end - &ld_ram_start);
|
||||||
|
}
|
||||||
|
|
||||||
void relocate(void)
|
void relocate(void)
|
||||||
{
|
{
|
||||||
#ifdef CONFIG_RELOC
|
#ifdef CONFIG_RELOC
|
||||||
|
@ -764,7 +764,7 @@ static int32_t write_protect_page(struct acrn_vm *vm,const struct wp_data *wp)
|
|||||||
base_paddr = hva2hpa((void *)(get_hv_image_base()));
|
base_paddr = hva2hpa((void *)(get_hv_image_base()));
|
||||||
if (((hpa <= base_paddr) && ((hpa + PAGE_SIZE) > base_paddr)) ||
|
if (((hpa <= base_paddr) && ((hpa + PAGE_SIZE) > base_paddr)) ||
|
||||||
((hpa >= base_paddr) &&
|
((hpa >= base_paddr) &&
|
||||||
(hpa < (base_paddr + get_hv_ram_size())))) {
|
(hpa < (base_paddr + get_hv_image_size())))) {
|
||||||
pr_err("%s: overlap the HV memory region.", __func__);
|
pr_err("%s: overlap the HV memory region.", __func__);
|
||||||
} else {
|
} else {
|
||||||
prot_set = (wp->set != 0U) ? 0UL : EPT_WR;
|
prot_set = (wp->set != 0U) ? 0UL : EPT_WR;
|
||||||
|
@ -169,8 +169,6 @@ void flush_vpid_global(void);
|
|||||||
*/
|
*/
|
||||||
void invept(const void *eptp);
|
void invept(const void *eptp);
|
||||||
|
|
||||||
uint64_t get_hv_ram_size(void);
|
|
||||||
|
|
||||||
/* get PDPT address from CR3 vaule in PAE mode */
|
/* get PDPT address from CR3 vaule in PAE mode */
|
||||||
static inline uint64_t get_pae_pdpt_addr(uint64_t cr3)
|
static inline uint64_t get_pae_pdpt_addr(uint64_t cr3)
|
||||||
{
|
{
|
||||||
|
Loading…
Reference in New Issue
Block a user