diff --git a/hypervisor/arch/x86/ept.c b/hypervisor/arch/x86/ept.c index 78151695e..a87219ee6 100644 --- a/hypervisor/arch/x86/ept.c +++ b/hypervisor/arch/x86/ept.c @@ -26,7 +26,8 @@ void destroy_ept(struct acrn_vm *vm) uint64_t local_gpa2hpa(struct acrn_vm *vm, uint64_t gpa, uint32_t *size) { uint64_t hpa = INVALID_HPA; - uint64_t *pgentry, pg_size = 0UL; + const uint64_t *pgentry; + uint64_t pg_size = 0UL; void *eptp; struct acrn_vcpu *vcpu = vcpu_from_pid(vm, get_cpu_id()); diff --git a/hypervisor/arch/x86/guest/vcpuid.c b/hypervisor/arch/x86/guest/vcpuid.c index 370e41681..5718f2911 100644 --- a/hypervisor/arch/x86/guest/vcpuid.c +++ b/hypervisor/arch/x86/guest/vcpuid.c @@ -6,11 +6,11 @@ #include -static inline struct vcpuid_entry *local_find_vcpuid_entry(const struct acrn_vcpu *vcpu, +static inline const struct vcpuid_entry *local_find_vcpuid_entry(const struct acrn_vcpu *vcpu, uint32_t leaf, uint32_t subleaf) { uint32_t i = 0U, nr, half; - struct vcpuid_entry *entry = NULL; + const struct vcpuid_entry *found_entry = NULL; struct acrn_vm *vm = vcpu->vm; nr = vm->vcpuid_entry_nr; @@ -20,16 +20,15 @@ static inline struct vcpuid_entry *local_find_vcpuid_entry(const struct acrn_vcp } for (; i < nr; i++) { - struct vcpuid_entry *tmp = &vm->vcpuid_entries[i]; + const struct vcpuid_entry *tmp = (const struct vcpuid_entry *)(&vm->vcpuid_entries[i]); if (tmp->leaf < leaf) { continue; } else if (tmp->leaf == leaf) { - if (((tmp->flags & CPUID_CHECK_SUBLEAF) != 0U) && - (tmp->subleaf != subleaf)) { + if (((tmp->flags & CPUID_CHECK_SUBLEAF) != 0U) && (tmp->subleaf != subleaf)) { continue; } - entry = tmp; + found_entry = tmp; break; } else { /* tmp->leaf > leaf */ @@ -37,13 +36,13 @@ static inline struct vcpuid_entry *local_find_vcpuid_entry(const struct acrn_vcp } } - return entry; + return found_entry; } -static inline struct vcpuid_entry *find_vcpuid_entry(const struct acrn_vcpu *vcpu, +static inline const struct vcpuid_entry *find_vcpuid_entry(const struct acrn_vcpu *vcpu, uint32_t leaf_arg, uint32_t subleaf) { - struct vcpuid_entry *entry; + const struct vcpuid_entry *entry; uint32_t leaf = leaf_arg; entry = local_find_vcpuid_entry(vcpu, leaf, subleaf); @@ -81,8 +80,7 @@ static inline int32_t set_vcpuid_entry(struct acrn_vm *vm, int32_t ret; if (vm->vcpuid_entry_nr == MAX_VM_VCPUID_ENTRIES) { - pr_err("%s, vcpuid entry over MAX_VM_VCPUID_ENTRIES(%u)\n", - __func__, MAX_VM_VCPUID_ENTRIES); + pr_err("%s, vcpuid entry over MAX_VM_VCPUID_ENTRIES(%u)\n", __func__, MAX_VM_VCPUID_ENTRIES); ret = -ENOMEM; } else { tmp = &vm->vcpuid_entries[vm->vcpuid_entry_nr]; @@ -106,13 +104,9 @@ static void init_vcpuid_entry(uint32_t leaf, uint32_t subleaf, switch (leaf) { case 0x07U: if (subleaf == 0U) { - cpuid_subleaf(leaf, subleaf, - &entry->eax, &entry->ebx, - &entry->ecx, &entry->edx); + cpuid_subleaf(leaf, subleaf, &entry->eax, &entry->ebx, &entry->ecx, &entry->edx); /* mask invpcid */ - entry->ebx &= ~(CPUID_EBX_INVPCID | - CPUID_EBX_PQM | - CPUID_EBX_PQE); + entry->ebx &= ~(CPUID_EBX_INVPCID | CPUID_EBX_PQM | CPUID_EBX_PQE); /* mask SGX and SGX_LC */ entry->ebx &= ~CPUID_EBX_SGX; @@ -131,9 +125,7 @@ static void init_vcpuid_entry(uint32_t leaf, uint32_t subleaf, case 0x16U: if (boot_cpu_data.cpuid_level >= 0x16U) { /* call the cpuid when 0x16 is supported */ - cpuid_subleaf(leaf, subleaf, - &entry->eax, &entry->ebx, - &entry->ecx, &entry->edx); + cpuid_subleaf(leaf, subleaf, &entry->eax, &entry->ebx, &entry->ecx, &entry->edx); } else { /* Use the tsc to derive the emulated 0x16U cpuid. */ entry->eax = (uint32_t) (tsc_khz / 1000U); @@ -182,9 +174,7 @@ static void init_vcpuid_entry(uint32_t leaf, uint32_t subleaf, break; default: - cpuid_subleaf(leaf, subleaf, - &entry->eax, &entry->ebx, - &entry->ecx, &entry->edx); + cpuid_subleaf(leaf, subleaf, &entry->eax, &entry->ebx, &entry->ecx, &entry->edx); break; } } @@ -198,8 +188,7 @@ int32_t set_vcpuid_entries(struct acrn_vm *vm) init_vcpuid_entry(0U, 0U, 0U, &entry); if (boot_cpu_data.cpuid_level < 0x16U) { - /* The cpuid with zero leaf returns the max level. - * Emulate that the 0x16U is supported */ + /* The cpuid with zero leaf returns the max level. Emulate that the 0x16U is supported */ entry.eax = 0x16U; } result = set_vcpuid_entry(vm, &entry); @@ -290,17 +279,14 @@ int32_t set_vcpuid_entries(struct acrn_vm *vm) return result; } -void guest_cpuid(struct acrn_vcpu *vcpu, - uint32_t *eax, uint32_t *ebx, - uint32_t *ecx, uint32_t *edx) +void guest_cpuid(struct acrn_vcpu *vcpu, uint32_t *eax, uint32_t *ebx, uint32_t *ecx, uint32_t *edx) { uint32_t leaf = *eax; uint32_t subleaf = *ecx; /* vm related */ if ((leaf != 0x1U) && (leaf != 0xbU) && (leaf != 0xdU)) { - struct vcpuid_entry *entry = - find_vcpuid_entry(vcpu, leaf, subleaf); + const struct vcpuid_entry *entry = find_vcpuid_entry(vcpu, leaf, subleaf); if (entry != NULL) { *eax = entry->eax; diff --git a/hypervisor/arch/x86/pagetable.c b/hypervisor/arch/x86/pagetable.c index 1fa77055b..bf3e82a64 100644 --- a/hypervisor/arch/x86/pagetable.c +++ b/hypervisor/arch/x86/pagetable.c @@ -374,9 +374,9 @@ void mmu_add(uint64_t *pml4_page, uint64_t paddr_base, uint64_t vaddr_base, uint /** * @pre (pml4_page != NULL) && (pg_size != NULL) */ -uint64_t *lookup_address(uint64_t *pml4_page, uint64_t addr, uint64_t *pg_size, const struct memory_ops *mem_ops) +const uint64_t *lookup_address(uint64_t *pml4_page, uint64_t addr, uint64_t *pg_size, const struct memory_ops *mem_ops) { - uint64_t *pret = NULL; + const uint64_t *pret = NULL; bool present = true; uint64_t *pml4e, *pdpte, *pde, *pte; @@ -390,29 +390,25 @@ uint64_t *lookup_address(uint64_t *pml4_page, uint64_t addr, uint64_t *pg_size, if (pdpte_large(*pdpte) != 0UL) { *pg_size = PDPTE_SIZE; pret = pdpte; + } else { + pde = pde_offset(pdpte, addr); + present = (mem_ops->pgentry_present(*pde) != 0UL); + if (present) { + if (pde_large(*pde) != 0UL) { + *pg_size = PDE_SIZE; + pret = pde; + } else { + pte = pte_offset(pde, addr); + present = (mem_ops->pgentry_present(*pte) != 0UL); + if (present) { + *pg_size = PTE_SIZE; + pret = pte; + } + } + } } } } - if (present && (pret == NULL)) { - pde = pde_offset(pdpte, addr); - present = (mem_ops->pgentry_present(*pde) != 0UL); - if (present) { - if (pde_large(*pde) != 0UL) { - *pg_size = PDE_SIZE; - pret = pde; - } - } - } - - if (present && (pret == NULL)) { - pte = pte_offset(pde, addr); - present = (mem_ops->pgentry_present(*pte) != 0UL); - if (present) { - *pg_size = PTE_SIZE; - pret = pte; - } - } - return pret; } diff --git a/hypervisor/arch/x86/trusty.c b/hypervisor/arch/x86/trusty.c index 8bdb9348c..fba14754e 100644 --- a/hypervisor/arch/x86/trusty.c +++ b/hypervisor/arch/x86/trusty.c @@ -8,8 +8,6 @@ #include #include -#define ACRN_DBG_TRUSTY 6U - #define TRUSTY_VERSION 1U #define TRUSTY_VERSION_2 2U diff --git a/hypervisor/include/arch/x86/mmu.h b/hypervisor/include/arch/x86/mmu.h index af2ef8b26..8d14d9fe4 100644 --- a/hypervisor/include/arch/x86/mmu.h +++ b/hypervisor/include/arch/x86/mmu.h @@ -169,7 +169,7 @@ void invept(const struct acrn_vcpu *vcpu); /** *@pre (pml4_page != NULL) && (pg_size != NULL) */ -uint64_t *lookup_address(uint64_t *pml4_page, uint64_t addr, +const uint64_t *lookup_address(uint64_t *pml4_page, uint64_t addr, uint64_t *pg_size, const struct memory_ops *mem_ops); /** Defines a single entry in an E820 memory map. */