From 92d86383bed8e962d3817413bd36414ae7103a95 Mon Sep 17 00:00:00 2001 From: Mingqiang Chi Date: Wed, 4 Apr 2018 14:29:08 +0800 Subject: [PATCH] hv:check continuous hpa when create secure world Add check_continuous_hpa API: when create secure world,if the physical address is not continuous, will assert. Signed-off-by: Mingqiang Chi Acked-by: Eddie Dong --- hypervisor/arch/x86/mmu.c | 19 +++++++++++++++++++ hypervisor/arch/x86/trusty.c | 6 ++++++ hypervisor/include/arch/x86/mmu.h | 1 + 3 files changed, 26 insertions(+) diff --git a/hypervisor/arch/x86/mmu.c b/hypervisor/arch/x86/mmu.c index a76e07e55..505c1a293 100644 --- a/hypervisor/arch/x86/mmu.c +++ b/hypervisor/arch/x86/mmu.c @@ -520,6 +520,25 @@ void free_paging_struct(void *ptr) } } +bool check_continuous_hpa(struct vm *vm, uint64_t gpa, uint64_t size) +{ + uint64_t curr_hpa = 0; + uint64_t next_hpa = 0; + + /* if size <= PAGE_SIZE_4K, it is continuous,no need check + * if size > PAGE_SIZE_4K, need to fetch next page + */ + while (size > PAGE_SIZE_4K) { + curr_hpa = gpa2hpa(vm, gpa); + gpa += PAGE_SIZE_4K; + next_hpa = gpa2hpa(vm, gpa); + if (next_hpa != (curr_hpa + PAGE_SIZE_4K)) + return false; + size -= PAGE_SIZE_4K; + } + return true; + +} uint64_t config_page_table_attr(struct map_params *map_params, uint32_t flags) { int table_type = map_params->page_table_type; diff --git a/hypervisor/arch/x86/trusty.c b/hypervisor/arch/x86/trusty.c index accb6ae87..f86a70774 100644 --- a/hypervisor/arch/x86/trusty.c +++ b/hypervisor/arch/x86/trusty.c @@ -116,6 +116,12 @@ static void create_secure_world_ept(struct vm *vm, uint64_t gpa_orig, return; } + /* Check the physical address should be continuous */ + if (!check_continuous_hpa(vm, gpa_orig, size)) { + ASSERT(false, "The physical addr is not continuous for Trusty"); + return; + } + map_params.page_table_type = PTT_EPT; map_params.pml4_inverted = vm->arch_vm.m2p; diff --git a/hypervisor/include/arch/x86/mmu.h b/hypervisor/include/arch/x86/mmu.h index dca077e03..ea5ba451f 100644 --- a/hypervisor/include/arch/x86/mmu.h +++ b/hypervisor/include/arch/x86/mmu.h @@ -325,6 +325,7 @@ void unmap_mem(struct map_params *map_params, void *paddr, void *vaddr, void modify_mem(struct map_params *map_params, void *paddr, void *vaddr, uint64_t size, uint32_t flags); void mmu_invept(struct vcpu *vcpu); +bool check_continuous_hpa(struct vm *vm, uint64_t gpa, uint64_t size); void obtain_last_page_table_entry(struct map_params *map_params, struct entry_params *entry, void *addr, bool direct);