hv: mmu: replace ept_update_mt with ept_mr_modify

Signed-off-by: Li, Fei1 <fei1.li@intel.com>
Acked-by: Anthony Xu <anthony.xu@intel.com>
This commit is contained in:
Li, Fei1 2018-07-16 16:28:07 +08:00 committed by lijinxia
parent 1991823df1
commit 0a33c0deee
4 changed files with 12 additions and 63 deletions

View File

@ -470,10 +470,10 @@ int ept_misconfig_vmexit_handler(__unused struct vcpu *vcpu)
status = -EINVAL;
/* TODO - EPT Violation handler */
pr_info("%s, Guest linear address: 0x%016llx ",
pr_fatal("%s, Guest linear address: 0x%016llx ",
__func__, exec_vmread(VMX_GUEST_LINEAR_ADDR));
pr_info("%s, Guest physical address: 0x%016llx ",
pr_fatal("%s, Guest physical address: 0x%016llx ",
__func__, exec_vmread64(VMX_GUEST_PHYSICAL_ADDR_FULL));
ASSERT(status == 0, "EPT Misconfiguration is not handled.\n");
@ -531,23 +531,19 @@ 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)
int ept_mr_modify(struct vm *vm, uint64_t gpa, uint64_t size,
uint64_t attr_set, uint64_t attr_clr)
{
struct map_params map_params;
struct vcpu *vcpu;
uint16_t i;
int ret;
/* 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);
ret = mmu_modify((uint64_t *)HPA2HVA(vm->arch_vm.nworld_eptp),
gpa, size, attr_set, attr_clr, PTT_EPT);
foreach_vcpu(i, vm, vcpu) {
vcpu_make_request(vcpu, ACRN_REQUEST_EPT_FLUSH);
}
return 0;
return ret;
}

View File

@ -36,7 +36,6 @@ 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,
};
@ -386,30 +385,6 @@ static uint32_t map_mem_region(void *vaddr, void *paddr,
}
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(false, "Bad memory map request type");
return 0;
@ -1132,23 +1107,3 @@ 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;
}

View File

@ -133,7 +133,7 @@ void init_mtrr(struct vcpu *vcpu)
static uint32_t update_ept(struct vm *vm, uint64_t start,
uint64_t size, uint32_t type)
{
uint32_t attr;
uint64_t attr;
switch (type) {
case MTRR_MEM_TYPE_WC:
@ -153,7 +153,7 @@ static uint32_t update_ept(struct vm *vm, uint64_t start,
attr = IA32E_EPT_UNCACHED;
}
ept_update_mt(vm, gpa2hpa(vm, start), start, size, attr);
ept_mr_modify(vm, start, size, attr, IA32E_EPT_MT_MASK);
return attr;
}

View File

@ -327,8 +327,6 @@ int unmap_mem(struct map_params *map_params, void *paddr, void *vaddr,
uint64_t size, uint32_t flags);
int modify_mem(struct map_params *map_params, void *paddr, void *vaddr,
uint64_t size, uint32_t flags);
int modify_mem_mt(struct map_params *map_params, void *paddr, void *vaddr,
uint64_t size, uint32_t flags);
int mmu_modify(uint64_t *pml4_page,
uint64_t vaddr_base, uint64_t size,
uint64_t prot_set, uint64_t prot_clr,
@ -406,8 +404,8 @@ uint64_t _gpa2hpa(struct vm *vm, uint64_t gpa, uint32_t *size);
uint64_t hpa2gpa(struct vm *vm, uint64_t hpa);
int ept_mmap(struct vm *vm, uint64_t hpa,
uint64_t gpa, uint64_t size, uint32_t type, uint32_t prot);
int ept_update_mt(struct vm *vm, uint64_t hpa,
uint64_t gpa, uint64_t size, uint32_t prot);
int ept_mr_modify(struct vm *vm, uint64_t gpa, uint64_t size,
uint64_t attr_set, uint64_t attr_clr);
int ept_violation_vmexit_handler(struct vcpu *vcpu);
int ept_misconfig_vmexit_handler(struct vcpu *vcpu);