mirror of
https://github.com/projectacrn/acrn-hypervisor.git
synced 2025-09-22 17:27:53 +00:00
HV: Add walk_ept_table and get_ept_entry APIs
The walk_ept_table API is used to walk through EPT table for getting all of present pages, user can get each page entry and its size from the walk_ept_table callback. The get_ept_entry is used to getting EPT pointer of the vm, if current context of mv is secure world, return secure world EPT pointer, otherwise return normal world EPT pointer. Signed-off-by: Jack Ren <jack.ren@intel.com> Signed-off-by: Yuan Liu <yuan1.liu@intel.com> Reviewed-by: Li, Fei1 <fei1.li@intel.com> Acked-by: Eddie Dong <eddie.dong@intel.com>
This commit is contained in:
committed by
ACRN System Integration
parent
f81585eb3d
commit
f320130d58
@@ -30,21 +30,18 @@ void destroy_ept(struct acrn_vm *vm)
|
||||
}
|
||||
}
|
||||
|
||||
/* using return value INVALID_HPA as error code */
|
||||
/**
|
||||
* @pre: vm != NULL.
|
||||
*/
|
||||
uint64_t local_gpa2hpa(struct acrn_vm *vm, uint64_t gpa, uint32_t *size)
|
||||
{
|
||||
/* using return value INVALID_HPA as error code */
|
||||
uint64_t hpa = INVALID_HPA;
|
||||
const uint64_t *pgentry;
|
||||
uint64_t pg_size = 0UL;
|
||||
void *eptp;
|
||||
struct acrn_vcpu *vcpu = vcpu_from_pid(vm, get_pcpu_id());
|
||||
|
||||
if ((vcpu != NULL) && (vcpu->arch.cur_context == SECURE_WORLD)) {
|
||||
eptp = vm->arch_vm.sworld_eptp;
|
||||
} else {
|
||||
eptp = vm->arch_vm.nworld_eptp;
|
||||
}
|
||||
|
||||
eptp = get_ept_entry(vm);
|
||||
pgentry = lookup_address((uint64_t *)eptp, gpa, &pg_size, &vm->arch_vm.ept_mem_ops);
|
||||
if (pgentry != NULL) {
|
||||
hpa = ((*pgentry & (~(pg_size - 1UL)))
|
||||
@@ -158,3 +155,63 @@ void ept_del_mr(struct acrn_vm *vm, uint64_t *pml4_page, uint64_t gpa, uint64_t
|
||||
vcpu_make_request(vcpu, ACRN_REQUEST_EPT_FLUSH);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @pre: vm != NULL.
|
||||
*/
|
||||
void *get_ept_entry(struct acrn_vm *vm)
|
||||
{
|
||||
void *eptp;
|
||||
struct acrn_vcpu *vcpu = vcpu_from_pid(vm, get_pcpu_id());
|
||||
|
||||
if ((vcpu != NULL) && (vcpu->arch.cur_context == SECURE_WORLD)) {
|
||||
eptp = vm->arch_vm.sworld_eptp;
|
||||
} else {
|
||||
eptp = vm->arch_vm.nworld_eptp;
|
||||
}
|
||||
|
||||
return eptp;
|
||||
}
|
||||
|
||||
/**
|
||||
* @pre vm != NULL && cb != NULL.
|
||||
*/
|
||||
void walk_ept_table(struct acrn_vm *vm, pge_handler cb)
|
||||
{
|
||||
const struct memory_ops *mem_ops = &vm->arch_vm.ept_mem_ops;
|
||||
uint64_t *pml4e, *pdpte, *pde, *pte;
|
||||
uint64_t i, j, k, m;
|
||||
|
||||
for (i = 0UL; i < PTRS_PER_PML4E; i++) {
|
||||
pml4e = pml4e_offset((uint64_t *)get_ept_entry(vm), i << PML4E_SHIFT);
|
||||
if (mem_ops->pgentry_present(*pml4e) == 0UL) {
|
||||
continue;
|
||||
}
|
||||
for (j = 0UL; j < PTRS_PER_PDPTE; j++) {
|
||||
pdpte = pdpte_offset(pml4e, j << PDPTE_SHIFT);
|
||||
if (mem_ops->pgentry_present(*pdpte) == 0UL) {
|
||||
continue;
|
||||
}
|
||||
if (pdpte_large(*pdpte) != 0UL) {
|
||||
cb(pdpte, PDPTE_SIZE);
|
||||
continue;
|
||||
}
|
||||
for (k = 0UL; k < PTRS_PER_PDE; k++) {
|
||||
pde = pde_offset(pdpte, k << PDE_SHIFT);
|
||||
if (mem_ops->pgentry_present(*pde) == 0UL) {
|
||||
continue;
|
||||
}
|
||||
if (pde_large(*pde) != 0UL) {
|
||||
cb(pde, PDE_SIZE);
|
||||
continue;
|
||||
}
|
||||
for (m = 0UL; m < PTRS_PER_PTE; m++) {
|
||||
pte = pte_offset(pde, m << PTE_SHIFT);
|
||||
if (mem_ops->pgentry_present(*pte) != 0UL) {
|
||||
cb(pte, PTE_SIZE);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user