Skip to content

Commit

Permalink
hv: mmu: add pre-assumption for hpa2gpa
Browse files Browse the repository at this point in the history
They're: (a) only SOS would use hpa2gpa and (b) the GPA and HPA
in SOS is identical mapping.
Rename hpa2gpa to vm0_hpa2gpa then.

Tracked-On: #1124
Signed-off-by: Li, Fei1 <fei1.li@intel.com>
  • Loading branch information
lifeix authored and wenlingz committed Oct 23, 2018
1 parent 49b476b commit 70ddca3
Show file tree
Hide file tree
Showing 5 changed files with 16 additions and 20 deletions.
17 changes: 5 additions & 12 deletions hypervisor/arch/x86/ept.c
Expand Up @@ -103,19 +103,12 @@ uint64_t gpa2hpa(struct vm *vm, uint64_t gpa)
return local_gpa2hpa(vm, gpa, NULL);
}

uint64_t hpa2gpa(struct vm *vm, uint64_t hpa)
/**
* @pre: the gpa and hpa are identical mapping in SOS.
*/
uint64_t vm0_hpa2gpa(uint64_t hpa)
{
uint64_t *pgentry, pg_size = 0UL;

pgentry = lookup_address((uint64_t *)vm->arch_vm.m2p,
hpa, &pg_size, PTT_EPT);
if (pgentry == NULL) {
pr_err("VM %d hpa2gpa: failed for hpa 0x%llx",
vm->vm_id, hpa);
ASSERT(false, "hpa2gpa not found");
}
return ((*pgentry & (~(pg_size - 1UL)))
| (hpa & (pg_size - 1UL)));
return hpa;
}

int ept_violation_vmexit_handler(struct vcpu *vcpu)
Expand Down
3 changes: 2 additions & 1 deletion hypervisor/arch/x86/trusty.c
Expand Up @@ -131,7 +131,8 @@ static void create_secure_world_ept(struct vm *vm, uint64_t gpa_orig,
hpa, gpa_rebased, size, EPT_RWX | EPT_WB);

/* Get the gpa address in SOS */
gpa = hpa2gpa(vm0, hpa);
gpa = vm0_hpa2gpa(hpa);

/* Unmap trusty memory space from sos ept mapping*/
ept_mr_del(vm0, (uint64_t *)vm0->arch_vm.nworld_eptp,
gpa, size);
Expand Down
8 changes: 3 additions & 5 deletions hypervisor/boot/sbl/sbl_seed_parse.c
Expand Up @@ -140,7 +140,7 @@ bool sbl_seed_parse(struct vm *vm, char *cmdline, char *out_arg, uint32_t out_le
struct image_boot_params *boot_params;
uint32_t len;

if (cmdline == NULL) {
if (!is_vm0(vm) || (cmdline == NULL)) {
goto fail;
}

Expand All @@ -165,10 +165,8 @@ bool sbl_seed_parse(struct vm *vm, char *cmdline, char *out_arg, uint32_t out_le
* Convert the addresses to SOS GPA since this structure will
* be used in SOS.
*/
boot_params->p_seed_list =
hpa2gpa(vm, boot_params->p_seed_list);
boot_params->p_platform_info =
hpa2gpa(vm, boot_params->p_platform_info);
boot_params->p_seed_list = vm0_hpa2gpa(boot_params->p_seed_list);
boot_params->p_platform_info = vm0_hpa2gpa(boot_params->p_platform_info);

/*
* Replace original arguments with spaces since SOS's GPA is not
Expand Down
6 changes: 5 additions & 1 deletion hypervisor/include/arch/x86/mmu.h
Expand Up @@ -134,6 +134,7 @@ static inline void clflush(volatile void *p)
* host physical address width is 52
*/
#define INVALID_HPA (0x1UL << 52U)
#define INVALID_GPA (0x1UL << 52U)
/* External Interfaces */
void destroy_ept(struct vm *vm);
/**
Expand All @@ -146,7 +147,10 @@ uint64_t gpa2hpa(struct vm *vm, uint64_t gpa);
* @return hpa - the HPA of parameter gpa is hpa
*/
uint64_t local_gpa2hpa(struct vm *vm, uint64_t gpa, uint32_t *size);
uint64_t hpa2gpa(struct vm *vm, uint64_t hpa);
/**
* @pre: the gpa and hpa are identical mapping in SOS.
*/
uint64_t vm0_hpa2gpa(uint64_t hpa);
void ept_mr_add(struct vm *vm, uint64_t *pml4_page, uint64_t hpa,
uint64_t gpa, uint64_t size, uint64_t prot_orig);
void ept_mr_modify(struct vm *vm, uint64_t *pml4_page, uint64_t gpa,
Expand Down
2 changes: 1 addition & 1 deletion hypervisor/include/hypervisor.h
Expand Up @@ -45,7 +45,7 @@ static inline void *gpa2hva(struct vm *vm, uint64_t x)

static inline uint64_t hva2gpa(struct vm *vm, void *x)
{
return hpa2gpa(vm, hva2hpa(x));
return (is_vm0(vm)) ? vm0_hpa2gpa(hva2hpa(x)) : INVALID_GPA;
}

#endif /* !ASSEMBLER */
Expand Down

0 comments on commit 70ddca3

Please sign in to comment.