diff --git a/hypervisor/arch/x86/guest/vm.c b/hypervisor/arch/x86/guest/vm.c index e22690b27..afde6325b 100644 --- a/hypervisor/arch/x86/guest/vm.c +++ b/hypervisor/arch/x86/guest/vm.c @@ -39,10 +39,18 @@ /* Local variables */ +/* pre-assumption: TRUSTY_RAM_SIZE is 2M aligned */ +static struct page post_uos_sworld_memory[MAX_POST_VM_NUM][TRUSTY_RAM_SIZE >> PAGE_SHIFT] __aligned(MEM_2M); + static struct acrn_vm vm_array[CONFIG_MAX_VM_NUM] __aligned(PAGE_SIZE); static struct acrn_vm *sos_vm_ptr = NULL; +void *get_sworld_memory_base(void) +{ + return post_uos_sworld_memory; +} + uint16_t get_vmid_by_uuid(const uint8_t *uuid) { uint16_t vm_id = 0U; @@ -511,8 +519,11 @@ int32_t create_vm(uint16_t vm_id, uint64_t pcpu_bitmap, struct acrn_vm_config *v vm->sworld_control.flag.supported = 1U; } if (vm->sworld_control.flag.supported != 0UL) { + uint16_t sos_vm_id = (get_sos_vm())->vm_id; + uint16_t page_idx = vmid_2_rel_vmid(sos_vm_id, vm_id) - 1U; + ept_add_mr(vm, (uint64_t *)vm->arch_vm.nworld_eptp, - hva2hpa(vm->arch_vm.sworld_memory_base_hva), + hva2hpa(post_uos_sworld_memory[page_idx]), TRUSTY_EPT_REBASE_GPA, TRUSTY_RAM_SIZE, EPT_WB | EPT_RWX); } if (vm_config->name[0] == '\0') { @@ -520,11 +531,11 @@ int32_t create_vm(uint16_t vm_id, uint64_t pcpu_bitmap, struct acrn_vm_config *v snprintf(vm_config->name, 16, "ACRN VM_%d", vm_id); } - if (vm_config->load_order == PRE_LAUNCHED_VM) { + if (vm_config->load_order == PRE_LAUNCHED_VM) { create_prelaunched_vm_e820(vm); prepare_prelaunched_vm_memmap(vm, vm_config); status = init_vm_boot_info(vm); - } + } } if (status == 0) { diff --git a/hypervisor/arch/x86/mmu.c b/hypervisor/arch/x86/mmu.c index 21fd0f5e9..ae3d103d7 100644 --- a/hypervisor/arch/x86/mmu.c +++ b/hypervisor/arch/x86/mmu.c @@ -294,7 +294,7 @@ void init_paging(void) round_pde_up((uint64_t)&ld_text_end) - round_pde_down(hv_hva), 0UL, PAGE_NX, &ppt_pgtable, MR_MODIFY); #if (SOS_VM_NUM == 1) - mmu_modify_or_del((uint64_t *)ppt_mmu_pml4_addr, (uint64_t)get_reserve_sworld_memory_base(), + mmu_modify_or_del((uint64_t *)ppt_mmu_pml4_addr, (uint64_t)get_sworld_memory_base(), TRUSTY_RAM_SIZE * MAX_POST_VM_NUM, PAGE_USER, 0UL, &ppt_pgtable, MR_MODIFY); #endif diff --git a/hypervisor/arch/x86/page.c b/hypervisor/arch/x86/page.c index d7bc0cf52..70e5723dc 100644 --- a/hypervisor/arch/x86/page.c +++ b/hypervisor/arch/x86/page.c @@ -166,9 +166,6 @@ static struct page ept_dummy_pages[CONFIG_MAX_VM_NUM]; /* ept: extended page pool*/ static struct page_pool ept_page_pool[CONFIG_MAX_VM_NUM]; -/* pre-assumption: TRUSTY_RAM_SIZE is 2M aligned */ -static struct page post_uos_sworld_memory[MAX_POST_VM_NUM][TRUSTY_RAM_SIZE >> PAGE_SHIFT] __aligned(MEM_2M); - /* @@ -189,11 +186,6 @@ void reserve_buffer_for_ept_pages(void) } } -void *get_reserve_sworld_memory_base(void) -{ - return post_uos_sworld_memory; -} - /* * Pages without execution right, such as MMIO, can always use large page * base on hardware capability, even if the VM is an RTVM. This can save @@ -247,13 +239,6 @@ void init_ept_pgtable(struct pgtable *table, uint16_t vm_id) memset((void *)ept_page_pool[vm_id].bitmap, 0, ept_page_pool[vm_id].bitmap_size * sizeof(uint64_t)); ept_page_pool[vm_id].last_hint_id = 0UL; - if (is_postlaunched_vm(vm)) { - uint16_t sos_vm_id = (get_sos_vm())->vm_id; - uint16_t page_idx = vmid_2_rel_vmid(sos_vm_id, vm_id) - 1U; - - vm->arch_vm.sworld_memory_base_hva = post_uos_sworld_memory[page_idx]; - } - table->pool = &ept_page_pool[vm_id]; table->default_access_right = EPT_RWX; table->pgentry_present = ept_pgentry_present; diff --git a/hypervisor/include/arch/x86/guest/vm.h b/hypervisor/include/arch/x86/guest/vm.h index d8e922398..74676fa54 100644 --- a/hypervisor/include/arch/x86/guest/vm.h +++ b/hypervisor/include/arch/x86/guest/vm.h @@ -107,7 +107,6 @@ struct vm_arch { * but Normal World can not access Secure World's memory. */ void *sworld_eptp; - void *sworld_memory_base_hva; struct pgtable ept_pgtable; struct acrn_vioapics vioapics; /* Virtual IOAPIC/s */ @@ -270,6 +269,8 @@ void get_vm_lock(struct acrn_vm *vm); * @pre vm != NULL */ void put_vm_lock(struct acrn_vm *vm); + +void *get_sworld_memory_base(void); #endif /* !ASSEMBLER */ #endif /* VM_H_ */ diff --git a/hypervisor/include/arch/x86/page.h b/hypervisor/include/arch/x86/page.h index 8923bf609..e0a27f08c 100644 --- a/hypervisor/include/arch/x86/page.h +++ b/hypervisor/include/arch/x86/page.h @@ -80,6 +80,5 @@ extern const struct pgtable ppt_pgtable; void init_ept_pgtable(struct pgtable *table, uint16_t vm_id); struct page *alloc_page(struct page_pool *pool); void free_page(struct page_pool *pool, struct page *page); -void *get_reserve_sworld_memory_base(void); void reserve_buffer_for_ept_pages(void); #endif /* PAGE_H */