From 0b1418d395aeb29e9857f7419864bc40740e5f6e Mon Sep 17 00:00:00 2001 From: Jie Deng Date: Fri, 12 Nov 2021 13:56:45 +0800 Subject: [PATCH] hv: tee: add an API for creating identical memmap according to e820 Given an e820, this API creates an identical memmap for specified e820 memory type, EPT memory cache type and access right. Tracked-On: #6571 Signed-off-by: Jie Deng Reviewed-by: Wang, Yu1 Acked-by: Eddie Dong --- hypervisor/arch/x86/guest/vm.c | 18 ++++++++++++++++++ hypervisor/include/arch/x86/asm/guest/vm.h | 1 + 2 files changed, 19 insertions(+) diff --git a/hypervisor/arch/x86/guest/vm.c b/hypervisor/arch/x86/guest/vm.c index bda4b9761..338760660 100644 --- a/hypervisor/arch/x86/guest/vm.c +++ b/hypervisor/arch/x86/guest/vm.c @@ -551,6 +551,24 @@ static uint64_t lapic_pt_enabled_pcpu_bitmap(struct acrn_vm *vm) return bitmap; } +void prepare_vm_identical_memmap(struct acrn_vm *vm, uint16_t e820_entry_type, uint64_t prot_orig) +{ + const struct e820_entry *entry; + const struct e820_entry *p_e820 = vm->e820_entries; + uint32_t entries_count = vm->e820_entry_num; + uint64_t *pml4_page = (uint64_t *)vm->arch_vm.nworld_eptp; + uint32_t i; + + for (i = 0U; i < entries_count; i++) { + entry = p_e820 + i; + if (entry->type == e820_entry_type) { + ept_add_mr(vm, pml4_page, entry->baseaddr, + entry->baseaddr, entry->length, + prot_orig); + } + } +} + /** * @pre vm_id < CONFIG_MAX_VM_NUM && vm_config != NULL && rtn_vm != NULL * @pre vm->state == VM_POWERED_OFF diff --git a/hypervisor/include/arch/x86/asm/guest/vm.h b/hypervisor/include/arch/x86/asm/guest/vm.h index c3d9d8d2d..a4d510893 100644 --- a/hypervisor/include/arch/x86/asm/guest/vm.h +++ b/hypervisor/include/arch/x86/asm/guest/vm.h @@ -247,6 +247,7 @@ struct acrn_vm *get_service_vm(void); void create_service_vm_e820(struct acrn_vm *vm); void create_prelaunched_vm_e820(struct acrn_vm *vm); +void prepare_vm_identical_memmap(struct acrn_vm *vm, uint16_t e820_entry_type, uint64_t prot_orig); uint64_t find_space_from_ve820(struct acrn_vm *vm, uint32_t size, uint64_t min_addr, uint64_t max_addr); int32_t prepare_os_image(struct acrn_vm *vm);