Skip to content

Commit 97aeb7f

Browse files
shiqingglijinxia
authored andcommitted
hv: pgtable: fix 'Use of function like macro'
Convert HPA2HVA, HVA2HPA, GPA2HVA and HVA2GPA to inline functions. v1 -> v2: * Modify the following statement. rsdp = biosacpi_search_rsdp((char *)hpa2hva((uint64_t)(*addr << 4)), 0x400); Instead of "(uint64_t)(*addr << 4)", "(uint64_t)(*addr) << 4U" would be clearer. Tracked-On: #861 Signed-off-by: Shiqing Gao <shiqing.gao@intel.com> Reviewed-by: Junjie Mao <junjie.mao@intel.com>
1 parent 6ee9321 commit 97aeb7f

File tree

24 files changed

+142
-116
lines changed

24 files changed

+142
-116
lines changed

hypervisor/arch/x86/guest/guest.c

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,7 @@ static int local_gva2gpa_common(struct vcpu *vcpu, struct page_walk_info *pw_inf
9292
i--;
9393

9494
addr = addr & IA32E_REF_MASK;
95-
base = GPA2HVA(vcpu->vm, addr);
95+
base = gpa2hva(vcpu->vm, addr);
9696
if (base == NULL) {
9797
ret = -EFAULT;
9898
goto out;
@@ -166,7 +166,7 @@ static int local_gva2gpa_pae(struct vcpu *vcpu, struct page_walk_info *pw_info,
166166
int ret;
167167

168168
addr = pw_info->top_entry & 0xFFFFFFF0U;
169-
base = GPA2HVA(vcpu->vm, addr);
169+
base = gpa2hva(vcpu->vm, addr);
170170
if (base == NULL) {
171171
ret = -EFAULT;
172172
goto out;
@@ -283,7 +283,7 @@ static inline uint32_t local_copy_gpa(const struct vm *vm, void *h_ptr, uint64_t
283283
len = (size > (pg_size - offset_in_pg)) ?
284284
(pg_size - offset_in_pg) : size;
285285

286-
g_ptr = HPA2HVA(hpa);
286+
g_ptr = hpa2hva(hpa);
287287

288288
if (cp_from_vm) {
289289
(void)memcpy_s(h_ptr, len, g_ptr, len);
@@ -399,13 +399,13 @@ void init_e820(void)
399399

400400
if (boot_regs[0] == MULTIBOOT_INFO_MAGIC) {
401401
struct multiboot_info *mbi = (struct multiboot_info *)
402-
(HPA2HVA((uint64_t)boot_regs[1]));
402+
(hpa2hva((uint64_t)boot_regs[1]));
403403

404404
pr_info("Multiboot info detected\n");
405405
if ((mbi->mi_flags & MULTIBOOT_INFO_HAS_MMAP) != 0U) {
406406
struct multiboot_mmap *mmap =
407407
(struct multiboot_mmap *)
408-
HPA2HVA((uint64_t)mbi->mi_mmap_addr);
408+
hpa2hva((uint64_t)mbi->mi_mmap_addr);
409409
e820_entries = mbi->mi_mmap_length/
410410
sizeof(struct multiboot_mmap);
411411
if (e820_entries > E820_MAX_ENTRIES) {
@@ -671,7 +671,7 @@ static const uint64_t guest_init_gdt[] = {
671671

672672
uint64_t create_guest_init_gdt(struct vm *vm, uint32_t *limit)
673673
{
674-
void *gtd_addr = GPA2HVA(vm, GUEST_INIT_GDT_START);
674+
void *gtd_addr = gpa2hva(vm, GUEST_INIT_GDT_START);
675675

676676
*limit = sizeof(guest_init_gdt) - 1U;
677677
(void)memcpy_s(gtd_addr, 64U, guest_init_gdt, sizeof(guest_init_gdt));

hypervisor/arch/x86/guest/mptable.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -301,7 +301,7 @@ int mptable_build(struct vm *vm)
301301
struct mpfps *mpfp;
302302
size_t mptable_length, table_length;
303303

304-
startaddr = (char *)GPA2HVA(vm, MPTABLE_BASE);
304+
startaddr = (char *)gpa2hva(vm, MPTABLE_BASE);
305305

306306
table_length = vm->vm_desc->mptable->mpch.base_table_length;
307307
mptable_length = sizeof(struct mpfps) + table_length;

hypervisor/arch/x86/guest/vlapic.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2096,7 +2096,7 @@ vlapic_apicv_get_apic_access_addr(__unused struct vm *vm)
20962096

20972097
(void)memset((void *)apicv_apic_access_addr, 0U, CPU_PAGE_SIZE);
20982098
}
2099-
return HVA2HPA(apicv_apic_access_addr);
2099+
return hva2hpa(apicv_apic_access_addr);
21002100
}
21012101

21022102
/**
@@ -2105,7 +2105,7 @@ vlapic_apicv_get_apic_access_addr(__unused struct vm *vm)
21052105
uint64_t
21062106
vlapic_apicv_get_apic_page_addr(struct acrn_vlapic *vlapic)
21072107
{
2108-
return HVA2HPA(&(vlapic->apic_page));
2108+
return hva2hpa(&(vlapic->apic_page));
21092109
}
21102110

21112111
/*

hypervisor/arch/x86/guest/vmsr.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,7 @@ void init_msr_emulation(struct vcpu *vcpu)
102102
}
103103

104104
/* Set up MSR bitmap - pg 2904 24.6.9 */
105-
value64 = HVA2HPA(vcpu->vm->arch_vm.msr_bitmap);
105+
value64 = hva2hpa(vcpu->vm->arch_vm.msr_bitmap);
106106
exec_vmwrite64(VMX_MSR_BITMAP_FULL, value64);
107107
pr_dbg("VMX_MSR_BITMAP: 0x%016llx ", value64);
108108
}

hypervisor/arch/x86/ioapic.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,7 @@ static void *map_ioapic(uint64_t ioapic_paddr)
8686
/* At some point we may need to translate this paddr to a vaddr.
8787
* 1:1 mapping for now.
8888
*/
89-
return HPA2HVA(ioapic_paddr);
89+
return hpa2hva(ioapic_paddr);
9090
}
9191

9292
static inline uint32_t

hypervisor/arch/x86/lapic.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -177,7 +177,7 @@ static void map_lapic(void)
177177
/* At some point we may need to translate this paddr to a vaddr. 1:1
178178
* mapping for now.
179179
*/
180-
lapic_info.xapic.vaddr = HPA2HVA(lapic_info.xapic.paddr);
180+
lapic_info.xapic.vaddr = hpa2hva(lapic_info.xapic.paddr);
181181
}
182182

183183
void early_init_lapic(void)

hypervisor/arch/x86/mmu.c

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -172,11 +172,11 @@ void invept(struct vcpu *vcpu)
172172
struct invept_desc desc = {0};
173173

174174
if (cpu_has_vmx_ept_cap(VMX_EPT_INVEPT_SINGLE_CONTEXT)) {
175-
desc.eptp = HVA2HPA(vcpu->vm->arch_vm.nworld_eptp) |
175+
desc.eptp = hva2hpa(vcpu->vm->arch_vm.nworld_eptp) |
176176
(3UL << 3U) | 6UL;
177177
local_invept(INVEPT_TYPE_SINGLE_CONTEXT, desc);
178178
if (vcpu->vm->sworld_control.flag.active != 0UL) {
179-
desc.eptp = HVA2HPA(vcpu->vm->arch_vm.sworld_eptp)
179+
desc.eptp = hva2hpa(vcpu->vm->arch_vm.sworld_eptp)
180180
| (3UL << 3U) | 6UL;
181181
local_invept(INVEPT_TYPE_SINGLE_CONTEXT, desc);
182182
}
@@ -190,7 +190,7 @@ void invept(struct vcpu *vcpu)
190190
uint64_t get_paging_pml4(void)
191191
{
192192
/* Return address to caller */
193-
return HVA2HPA(mmu_pml4_addr);
193+
return hva2hpa(mmu_pml4_addr);
194194
}
195195

196196
void enable_paging(uint64_t pml4_base_addr)
@@ -254,7 +254,7 @@ void init_paging(void)
254254
PTT_PRIMARY, MR_MODIFY);
255255

256256
/* Enable paging */
257-
enable_paging(HVA2HPA(mmu_pml4_addr));
257+
enable_paging(hva2hpa(mmu_pml4_addr));
258258
}
259259

260260
void *alloc_paging_struct(void)

hypervisor/arch/x86/pagetable.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ static int split_large_page(uint64_t *pte,
4949
}
5050

5151
ref_prot = (ptt == PTT_PRIMARY) ? PAGE_TABLE : EPT_RWX;
52-
set_pgentry(pte, HVA2HPA((void *)pbase) | ref_prot);
52+
set_pgentry(pte, hva2hpa((void *)pbase) | ref_prot);
5353

5454
/* TODO: flush the TLB */
5555

@@ -81,7 +81,7 @@ static inline int construct_pgentry(enum _page_table_type ptt, uint64_t *pde)
8181
}
8282

8383
prot = (ptt == PTT_PRIMARY) ? PAGE_TABLE: EPT_RWX;
84-
set_pgentry(pde, HVA2HPA(pd_page) | prot);
84+
set_pgentry(pde, hva2hpa(pd_page) | prot);
8585
return 0;
8686
}
8787

hypervisor/arch/x86/pm.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ static void acpi_gas_write(struct acpi_generic_address *gas, uint32_t val)
2424
uint16_t val16 = (uint16_t)val;
2525

2626
if (gas->space_id == SPACE_SYSTEM_MEMORY)
27-
mmio_write16(val16, HPA2HVA(gas->address));
27+
mmio_write16(val16, hpa2hva(gas->address));
2828
else
2929
pio_write16(val16, (uint16_t)gas->address);
3030
}
@@ -34,7 +34,7 @@ static uint32_t acpi_gas_read(struct acpi_generic_address *gas)
3434
uint32_t ret = 0U;
3535

3636
if (gas->space_id == SPACE_SYSTEM_MEMORY)
37-
ret = mmio_read16(HPA2HVA(gas->address));
37+
ret = mmio_read16(hpa2hva(gas->address));
3838
else
3939
ret = pio_read16((uint16_t)gas->address);
4040

hypervisor/arch/x86/trusty.c

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,7 @@ static void create_secure_world_ept(struct vm *vm, uint64_t gpa_orig,
105105
* of gpa_rebased to gpa_rebased + size
106106
*/
107107
sub_table_addr = alloc_paging_struct();
108-
sworld_pml4e = HVA2HPA(sub_table_addr) | table_present;
108+
sworld_pml4e = hva2hpa(sub_table_addr) | table_present;
109109
set_pgentry((uint64_t *)pml4_base, sworld_pml4e);
110110

111111
nworld_pml4e = get_pgentry((uint64_t *)vm->arch_vm.nworld_eptp);
@@ -160,7 +160,7 @@ void destroy_secure_world(struct vm *vm, bool need_clr_mem)
160160
}
161161
if (need_clr_mem) {
162162
/* clear trusty memory space */
163-
(void)memset(HPA2HVA(hpa), 0U, size);
163+
(void)memset(hpa2hva(hpa), 0U, size);
164164
}
165165

166166
/* restore memory to SOS ept mapping */
@@ -316,12 +316,12 @@ void switch_world(struct vcpu *vcpu, int next_world)
316316
/* load EPTP for next world */
317317
if (next_world == NORMAL_WORLD) {
318318
exec_vmwrite64(VMX_EPT_POINTER_FULL,
319-
HVA2HPA(vcpu->vm->arch_vm.nworld_eptp) |
320-
(3UL<<3) | 6UL);
319+
hva2hpa(vcpu->vm->arch_vm.nworld_eptp) |
320+
(3UL << 3) | 6UL);
321321
} else {
322322
exec_vmwrite64(VMX_EPT_POINTER_FULL,
323-
HVA2HPA(vcpu->vm->arch_vm.sworld_eptp) |
324-
(3UL<<3) | 6UL);
323+
hva2hpa(vcpu->vm->arch_vm.sworld_eptp) |
324+
(3UL << 3) | 6UL);
325325
}
326326

327327
/* Update world index */
@@ -338,7 +338,7 @@ static bool setup_trusty_info(struct vcpu *vcpu,
338338
struct trusty_mem *mem;
339339
struct trusty_key_info *key_info;
340340

341-
mem = (struct trusty_mem *)(HPA2HVA(mem_base_hpa));
341+
mem = (struct trusty_mem *)(hpa2hva(mem_base_hpa));
342342

343343
/* copy key_info to the first page of trusty memory */
344344
(void)memcpy_s(&mem->first_page.data.key_info, sizeof(g_key_info),
@@ -442,7 +442,7 @@ bool initialize_trusty(struct vcpu *vcpu, uint64_t param)
442442
trusty_base_hpa = vm->sworld_control.sworld_memory.base_hpa;
443443

444444
exec_vmwrite64(VMX_EPT_POINTER_FULL,
445-
HVA2HPA(vm->arch_vm.sworld_eptp) | (3UL<<3) | 6UL);
445+
hva2hpa(vm->arch_vm.sworld_eptp) | (3UL << 3) | 6UL);
446446

447447
/* save Normal World context */
448448
save_world_ctx(vcpu, &vcpu->arch_vcpu.contexts[NORMAL_WORLD].ext_ctx);

0 commit comments

Comments
 (0)