mirror of
https://github.com/projectacrn/acrn-hypervisor.git
synced 2025-09-23 01:37:44 +00:00
hv: add APIs to allow updating EPT mem type
- Add PAGING_REQUEST_TYPE_MODIFY_MT memory map request type - Update map_mem_region() to allow modifying the memory type related fields in a page table entry - Add ept_update_mt() - add modify_mem_mt() for both EPT and MMU Signed-off-by: Zide Chen <zide.chen@intel.com> Reviewed-by: Jason Chen CJ <jason.cj.chen@intel.com> Acked-by: Eddie Dong <eddie.dong@intel.com>
This commit is contained in:
@@ -489,3 +489,24 @@ int ept_mmap(struct vm *vm, uint64_t hpa,
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
int ept_update_mt(struct vm *vm, uint64_t hpa,
|
||||
uint64_t gpa, uint64_t size, uint32_t prot)
|
||||
{
|
||||
struct map_params map_params;
|
||||
struct vcpu *vcpu;
|
||||
int i;
|
||||
|
||||
/* Setup memory map parameters */
|
||||
map_params.page_table_type = PTT_EPT;
|
||||
map_params.pml4_base = HPA2HVA(vm->arch_vm.nworld_eptp);
|
||||
map_params.pml4_inverted = HPA2HVA(vm->arch_vm.m2p);
|
||||
|
||||
modify_mem_mt(&map_params, (void *)hpa, (void *)gpa, size, prot);
|
||||
|
||||
foreach_vcpu(i, vm, vcpu) {
|
||||
vcpu_make_request(vcpu, ACRN_REQUEST_EPT_FLUSH);
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
@@ -35,6 +35,7 @@ enum mem_map_request_type {
|
||||
PAGING_REQUEST_TYPE_MAP = 0, /* Creates a new mapping. */
|
||||
PAGING_REQUEST_TYPE_UNMAP = 1, /* Removes a pre-existing entry */
|
||||
PAGING_REQUEST_TYPE_MODIFY = 2,
|
||||
PAGING_REQUEST_TYPE_MODIFY_MT = 3, /* Update the memory type fields */
|
||||
/* Modifies a pre-existing entries attributes. */
|
||||
PAGING_REQUEST_TYPE_UNKNOWN,
|
||||
};
|
||||
@@ -375,6 +376,28 @@ static uint32_t map_mem_region(void *vaddr, void *paddr,
|
||||
mmu_need_invtlb = true;
|
||||
break;
|
||||
}
|
||||
case PAGING_REQUEST_TYPE_MODIFY_MT:
|
||||
{
|
||||
if (prev_entry_present) {
|
||||
/* modify the memory type related fields only */
|
||||
if (table_type == PTT_EPT)
|
||||
table_entry = entry & ~IA32E_EPT_MT_MASK;
|
||||
else
|
||||
table_entry = entry & ~MMU_MEM_ATTR_TYPE_MASK;
|
||||
|
||||
table_entry |= attr;
|
||||
|
||||
/* Write the table entry to map this memory */
|
||||
MEM_WRITE64(table_base + table_offset, table_entry);
|
||||
|
||||
/* Modify, need to invalidate TLB and
|
||||
* page-structure cache
|
||||
*/
|
||||
if (table_type == PTT_HOST)
|
||||
mmu_need_invtlb = true;
|
||||
}
|
||||
break;
|
||||
}
|
||||
default:
|
||||
ASSERT(0, "Bad memory map request type");
|
||||
return 0;
|
||||
@@ -1124,3 +1147,23 @@ int modify_mem(struct map_params *map_params, void *paddr, void *vaddr,
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
int modify_mem_mt(struct map_params *map_params, void *paddr, void *vaddr,
|
||||
uint64_t size, uint32_t flags)
|
||||
{
|
||||
int ret = 0;
|
||||
|
||||
/* used for MMU and EPT*/
|
||||
ret = modify_paging(map_params, paddr, vaddr, size, flags,
|
||||
PAGING_REQUEST_TYPE_MODIFY_MT, true);
|
||||
if (ret < 0)
|
||||
return ret;
|
||||
|
||||
/* only for EPT */
|
||||
if (map_params->page_table_type == PTT_EPT) {
|
||||
ret = modify_paging(map_params, vaddr, paddr, size, flags,
|
||||
PAGING_REQUEST_TYPE_MODIFY_MT, false);
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user