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 <mingqiang.chi@intel.com>
Acked-by: Eddie Dong <eddie.dong@intel.com>
This commit is contained in:
Mingqiang Chi 2018-04-04 14:29:08 +08:00 committed by Jack Ren
parent e5be957945
commit 92d86383be
3 changed files with 26 additions and 0 deletions

View File

@ -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;

View File

@ -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;

View File

@ -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);