hv: coding style: add const qualifier for some function

Add `const` qualifier for lookup_address and find_vcpuid_entry.

Tracked-On: #861
Signed-off-by: Li, Fei1 <fei1.li@intel.com>
This commit is contained in:
Li, Fei1 2018-12-29 00:37:48 +08:00 committed by wenlingz
parent 6f0edfc38d
commit 860c444c55
5 changed files with 37 additions and 56 deletions

View File

@ -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 local_gpa2hpa(struct acrn_vm *vm, uint64_t gpa, uint32_t *size)
{ {
uint64_t hpa = INVALID_HPA; uint64_t hpa = INVALID_HPA;
uint64_t *pgentry, pg_size = 0UL; const uint64_t *pgentry;
uint64_t pg_size = 0UL;
void *eptp; void *eptp;
struct acrn_vcpu *vcpu = vcpu_from_pid(vm, get_cpu_id()); struct acrn_vcpu *vcpu = vcpu_from_pid(vm, get_cpu_id());

View File

@ -6,11 +6,11 @@
#include <hypervisor.h> #include <hypervisor.h>
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 leaf, uint32_t subleaf)
{ {
uint32_t i = 0U, nr, half; uint32_t i = 0U, nr, half;
struct vcpuid_entry *entry = NULL; const struct vcpuid_entry *found_entry = NULL;
struct acrn_vm *vm = vcpu->vm; struct acrn_vm *vm = vcpu->vm;
nr = vm->vcpuid_entry_nr; 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++) { 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) { if (tmp->leaf < leaf) {
continue; continue;
} else if (tmp->leaf == leaf) { } else if (tmp->leaf == leaf) {
if (((tmp->flags & CPUID_CHECK_SUBLEAF) != 0U) && if (((tmp->flags & CPUID_CHECK_SUBLEAF) != 0U) && (tmp->subleaf != subleaf)) {
(tmp->subleaf != subleaf)) {
continue; continue;
} }
entry = tmp; found_entry = tmp;
break; break;
} else { } else {
/* tmp->leaf > leaf */ /* 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) uint32_t leaf_arg, uint32_t subleaf)
{ {
struct vcpuid_entry *entry; const struct vcpuid_entry *entry;
uint32_t leaf = leaf_arg; uint32_t leaf = leaf_arg;
entry = local_find_vcpuid_entry(vcpu, leaf, subleaf); 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; int32_t ret;
if (vm->vcpuid_entry_nr == MAX_VM_VCPUID_ENTRIES) { if (vm->vcpuid_entry_nr == MAX_VM_VCPUID_ENTRIES) {
pr_err("%s, vcpuid entry over MAX_VM_VCPUID_ENTRIES(%u)\n", pr_err("%s, vcpuid entry over MAX_VM_VCPUID_ENTRIES(%u)\n", __func__, MAX_VM_VCPUID_ENTRIES);
__func__, MAX_VM_VCPUID_ENTRIES);
ret = -ENOMEM; ret = -ENOMEM;
} else { } else {
tmp = &vm->vcpuid_entries[vm->vcpuid_entry_nr]; 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) { switch (leaf) {
case 0x07U: case 0x07U:
if (subleaf == 0U) { if (subleaf == 0U) {
cpuid_subleaf(leaf, subleaf, cpuid_subleaf(leaf, subleaf, &entry->eax, &entry->ebx, &entry->ecx, &entry->edx);
&entry->eax, &entry->ebx,
&entry->ecx, &entry->edx);
/* mask invpcid */ /* mask invpcid */
entry->ebx &= ~(CPUID_EBX_INVPCID | entry->ebx &= ~(CPUID_EBX_INVPCID | CPUID_EBX_PQM | CPUID_EBX_PQE);
CPUID_EBX_PQM |
CPUID_EBX_PQE);
/* mask SGX and SGX_LC */ /* mask SGX and SGX_LC */
entry->ebx &= ~CPUID_EBX_SGX; entry->ebx &= ~CPUID_EBX_SGX;
@ -131,9 +125,7 @@ static void init_vcpuid_entry(uint32_t leaf, uint32_t subleaf,
case 0x16U: case 0x16U:
if (boot_cpu_data.cpuid_level >= 0x16U) { if (boot_cpu_data.cpuid_level >= 0x16U) {
/* call the cpuid when 0x16 is supported */ /* call the cpuid when 0x16 is supported */
cpuid_subleaf(leaf, subleaf, cpuid_subleaf(leaf, subleaf, &entry->eax, &entry->ebx, &entry->ecx, &entry->edx);
&entry->eax, &entry->ebx,
&entry->ecx, &entry->edx);
} else { } else {
/* Use the tsc to derive the emulated 0x16U cpuid. */ /* Use the tsc to derive the emulated 0x16U cpuid. */
entry->eax = (uint32_t) (tsc_khz / 1000U); entry->eax = (uint32_t) (tsc_khz / 1000U);
@ -182,9 +174,7 @@ static void init_vcpuid_entry(uint32_t leaf, uint32_t subleaf,
break; break;
default: default:
cpuid_subleaf(leaf, subleaf, cpuid_subleaf(leaf, subleaf, &entry->eax, &entry->ebx, &entry->ecx, &entry->edx);
&entry->eax, &entry->ebx,
&entry->ecx, &entry->edx);
break; break;
} }
} }
@ -198,8 +188,7 @@ int32_t set_vcpuid_entries(struct acrn_vm *vm)
init_vcpuid_entry(0U, 0U, 0U, &entry); init_vcpuid_entry(0U, 0U, 0U, &entry);
if (boot_cpu_data.cpuid_level < 0x16U) { if (boot_cpu_data.cpuid_level < 0x16U) {
/* The cpuid with zero leaf returns the max level. /* The cpuid with zero leaf returns the max level. Emulate that the 0x16U is supported */
* Emulate that the 0x16U is supported */
entry.eax = 0x16U; entry.eax = 0x16U;
} }
result = set_vcpuid_entry(vm, &entry); result = set_vcpuid_entry(vm, &entry);
@ -290,17 +279,14 @@ int32_t set_vcpuid_entries(struct acrn_vm *vm)
return result; return result;
} }
void guest_cpuid(struct acrn_vcpu *vcpu, void guest_cpuid(struct acrn_vcpu *vcpu, uint32_t *eax, uint32_t *ebx, uint32_t *ecx, uint32_t *edx)
uint32_t *eax, uint32_t *ebx,
uint32_t *ecx, uint32_t *edx)
{ {
uint32_t leaf = *eax; uint32_t leaf = *eax;
uint32_t subleaf = *ecx; uint32_t subleaf = *ecx;
/* vm related */ /* vm related */
if ((leaf != 0x1U) && (leaf != 0xbU) && (leaf != 0xdU)) { if ((leaf != 0x1U) && (leaf != 0xbU) && (leaf != 0xdU)) {
struct vcpuid_entry *entry = const struct vcpuid_entry *entry = find_vcpuid_entry(vcpu, leaf, subleaf);
find_vcpuid_entry(vcpu, leaf, subleaf);
if (entry != NULL) { if (entry != NULL) {
*eax = entry->eax; *eax = entry->eax;

View File

@ -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) * @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; bool present = true;
uint64_t *pml4e, *pdpte, *pde, *pte; 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) { if (pdpte_large(*pdpte) != 0UL) {
*pg_size = PDPTE_SIZE; *pg_size = PDPTE_SIZE;
pret = pdpte; 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; return pret;
} }

View File

@ -8,8 +8,6 @@
#include <crypto_api.h> #include <crypto_api.h>
#include <security.h> #include <security.h>
#define ACRN_DBG_TRUSTY 6U
#define TRUSTY_VERSION 1U #define TRUSTY_VERSION 1U
#define TRUSTY_VERSION_2 2U #define TRUSTY_VERSION_2 2U

View File

@ -169,7 +169,7 @@ void invept(const struct acrn_vcpu *vcpu);
/** /**
*@pre (pml4_page != NULL) && (pg_size != NULL) *@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); uint64_t *pg_size, const struct memory_ops *mem_ops);
/** Defines a single entry in an E820 memory map. */ /** Defines a single entry in an E820 memory map. */