mirror of
https://github.com/projectacrn/acrn-hypervisor.git
synced 2025-08-04 09:50:54 +00:00
hv: fix type conversion without cast with explicit conversion
Implicit conversion may result in loss of information or undefined behaviour. So make it with explicit conversion. Tracked-On: #861 Signed-off-by: Li, Fei1 <fei1.li@intel.com>
This commit is contained in:
parent
79463fd5ce
commit
9bb16bce77
@ -229,7 +229,7 @@ static int local_gva2gpa_pae(struct acrn_vcpu *vcpu, struct page_walk_info *pw_i
|
|||||||
int ret;
|
int ret;
|
||||||
|
|
||||||
addr = pw_info->top_entry & 0xFFFFFFF0U;
|
addr = pw_info->top_entry & 0xFFFFFFF0U;
|
||||||
base = gpa2hva(vcpu->vm, addr);
|
base = (uint64_t *)gpa2hva(vcpu->vm, addr);
|
||||||
if (base == NULL) {
|
if (base == NULL) {
|
||||||
ret = -EFAULT;
|
ret = -EFAULT;
|
||||||
goto out;
|
goto out;
|
||||||
@ -282,7 +282,7 @@ int gva2gpa(struct acrn_vcpu *vcpu, uint64_t gva, uint64_t *gpa,
|
|||||||
*gpa = 0UL;
|
*gpa = 0UL;
|
||||||
|
|
||||||
pw_info.top_entry = exec_vmread(VMX_GUEST_CR3);
|
pw_info.top_entry = exec_vmread(VMX_GUEST_CR3);
|
||||||
pw_info.level = pm;
|
pw_info.level = (uint32_t)pm;
|
||||||
pw_info.is_write_access = ((*err_code & PAGE_FAULT_WR_FLAG) != 0U);
|
pw_info.is_write_access = ((*err_code & PAGE_FAULT_WR_FLAG) != 0U);
|
||||||
pw_info.is_inst_fetch = ((*err_code & PAGE_FAULT_ID_FLAG) != 0U);
|
pw_info.is_inst_fetch = ((*err_code & PAGE_FAULT_ID_FLAG) != 0U);
|
||||||
|
|
||||||
|
@ -1005,7 +1005,7 @@ static int emulate_movs(struct acrn_vcpu *vcpu, const struct instr_emul_vie *vie
|
|||||||
|
|
||||||
/* we are sure it will success */
|
/* we are sure it will success */
|
||||||
(void)gva2gpa(vcpu, src_gva, &gpa, &err_code);
|
(void)gva2gpa(vcpu, src_gva, &gpa, &err_code);
|
||||||
src_hva = gpa2hva(vcpu->vm, gpa);
|
src_hva = (uint64_t *)gpa2hva(vcpu->vm, gpa);
|
||||||
(void)memcpy_s(&val, opsize, src_hva, opsize);
|
(void)memcpy_s(&val, opsize, src_hva, opsize);
|
||||||
|
|
||||||
vie_mmio_write(vcpu, val);
|
vie_mmio_write(vcpu, val);
|
||||||
@ -1015,7 +1015,7 @@ static int emulate_movs(struct acrn_vcpu *vcpu, const struct instr_emul_vie *vie
|
|||||||
/* The dest gpa is saved during dst check instruction
|
/* The dest gpa is saved during dst check instruction
|
||||||
* decoding.
|
* decoding.
|
||||||
*/
|
*/
|
||||||
dst_hva = gpa2hva(vcpu->vm, vie->dst_gpa);
|
dst_hva = (uint64_t *)gpa2hva(vcpu->vm, vie->dst_gpa);
|
||||||
(void)memcpy_s(dst_hva, opsize, &val, opsize);
|
(void)memcpy_s(dst_hva, opsize, &val, opsize);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -27,17 +27,13 @@ static uint64_t trampoline_relo_addr(const void *addr)
|
|||||||
|
|
||||||
uint64_t read_trampoline_sym(const void *sym)
|
uint64_t read_trampoline_sym(const void *sym)
|
||||||
{
|
{
|
||||||
uint64_t *hva;
|
uint64_t *hva = (uint64_t *)(hpa2hva(trampoline_start16_paddr) + trampoline_relo_addr(sym));
|
||||||
|
|
||||||
hva = hpa2hva(trampoline_start16_paddr) + trampoline_relo_addr(sym);
|
|
||||||
return *hva;
|
return *hva;
|
||||||
}
|
}
|
||||||
|
|
||||||
void write_trampoline_sym(const void *sym, uint64_t val)
|
void write_trampoline_sym(const void *sym, uint64_t val)
|
||||||
{
|
{
|
||||||
uint64_t *hva;
|
uint64_t *hva = (uint64_t *)(hpa2hva(trampoline_start16_paddr) + trampoline_relo_addr(sym));
|
||||||
|
|
||||||
hva = hpa2hva(trampoline_start16_paddr) + trampoline_relo_addr(sym);
|
|
||||||
*hva = val;
|
*hva = val;
|
||||||
clflush(hva);
|
clflush(hva);
|
||||||
}
|
}
|
||||||
|
@ -235,8 +235,7 @@ local_parse_madt(void *madt, uint32_t lapic_id_array[CONFIG_MAX_PCPU_NUM])
|
|||||||
uint16_t pcpu_num = 0U;
|
uint16_t pcpu_num = 0U;
|
||||||
struct acpi_madt_local_apic *processor;
|
struct acpi_madt_local_apic *processor;
|
||||||
struct acpi_table_madt *madt_ptr;
|
struct acpi_table_madt *madt_ptr;
|
||||||
void *first;
|
void *first, *end, *iterator;
|
||||||
void *end;
|
|
||||||
struct acpi_subtable_header *entry;
|
struct acpi_subtable_header *entry;
|
||||||
|
|
||||||
madt_ptr = (struct acpi_table_madt *)madt;
|
madt_ptr = (struct acpi_table_madt *)madt;
|
||||||
@ -244,13 +243,14 @@ local_parse_madt(void *madt, uint32_t lapic_id_array[CONFIG_MAX_PCPU_NUM])
|
|||||||
first = madt_ptr + 1;
|
first = madt_ptr + 1;
|
||||||
end = (char *)madt_ptr + madt_ptr->header.length;
|
end = (char *)madt_ptr + madt_ptr->header.length;
|
||||||
|
|
||||||
for (entry = first; (void *)entry < end; ) {
|
for (iterator = first; (iterator) < (end); iterator += entry->length) {
|
||||||
|
entry = (struct acpi_subtable_header *)iterator;
|
||||||
if (entry->length < sizeof(struct acpi_subtable_header)) {
|
if (entry->length < sizeof(struct acpi_subtable_header)) {
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (entry->type == ACPI_MADT_TYPE_LOCAL_APIC) {
|
if (entry->type == ACPI_MADT_TYPE_LOCAL_APIC) {
|
||||||
processor = (struct acpi_madt_local_apic *)entry;
|
processor = (struct acpi_madt_local_apic *)iterator;
|
||||||
if ((processor->lapic_flags & ACPI_MADT_ENABLED) != 0U) {
|
if ((processor->lapic_flags & ACPI_MADT_ENABLED) != 0U) {
|
||||||
if (pcpu_num < CONFIG_MAX_PCPU_NUM) {
|
if (pcpu_num < CONFIG_MAX_PCPU_NUM) {
|
||||||
lapic_id_array[pcpu_num] = processor->id;
|
lapic_id_array[pcpu_num] = processor->id;
|
||||||
@ -258,9 +258,6 @@ local_parse_madt(void *madt, uint32_t lapic_id_array[CONFIG_MAX_PCPU_NUM])
|
|||||||
pcpu_num++;
|
pcpu_num++;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
entry = (struct acpi_subtable_header *)
|
|
||||||
(((uint64_t)entry) + entry->length);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return pcpu_num;
|
return pcpu_num;
|
||||||
@ -369,16 +366,11 @@ static void *get_facs_table(void)
|
|||||||
/* put all ACPI fix up code here */
|
/* put all ACPI fix up code here */
|
||||||
void acpi_fixup(void)
|
void acpi_fixup(void)
|
||||||
{
|
{
|
||||||
uint8_t *facs_addr;
|
void *facs_addr = get_facs_table();
|
||||||
|
|
||||||
facs_addr = get_facs_table();
|
|
||||||
|
|
||||||
if (facs_addr != NULL) {
|
if (facs_addr != NULL) {
|
||||||
host_pm_s_state.wake_vector_32 =
|
host_pm_s_state.wake_vector_32 = (uint32_t *)(facs_addr + OFFSET_WAKE_VECTOR_32);
|
||||||
(uint32_t *)(facs_addr + OFFSET_WAKE_VECTOR_32);
|
host_pm_s_state.wake_vector_64 = (uint64_t *)(facs_addr + OFFSET_WAKE_VECTOR_64);
|
||||||
host_pm_s_state.wake_vector_64 =
|
|
||||||
(uint64_t *)(facs_addr + OFFSET_WAKE_VECTOR_64);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
@ -79,7 +79,7 @@ static void parse_other_modules(struct acrn_vm *vm,
|
|||||||
|
|
||||||
for (i = 0U; i < mods_count; i++) {
|
for (i = 0U; i < mods_count; i++) {
|
||||||
uint32_t type_len;
|
uint32_t type_len;
|
||||||
const char *start = hpa2hva((uint64_t)mods[i].mm_string);
|
const char *start = (char *)hpa2hva((uint64_t)mods[i].mm_string);
|
||||||
const char *end;
|
const char *end;
|
||||||
void *mod_addr = hpa2hva((uint64_t)mods[i].mm_mod_start);
|
void *mod_addr = hpa2hva((uint64_t)mods[i].mm_mod_start);
|
||||||
uint32_t mod_size = mods[i].mm_mod_end - mods[i].mm_mod_start;
|
uint32_t mod_size = mods[i].mm_mod_end - mods[i].mm_mod_start;
|
||||||
@ -174,7 +174,7 @@ int init_vm_boot_info(struct acrn_vm *vm)
|
|||||||
return -EINVAL;
|
return -EINVAL;
|
||||||
}
|
}
|
||||||
|
|
||||||
mbi = hpa2hva((uint64_t)boot_regs[1]);
|
mbi = (struct multiboot_info *)hpa2hva((uint64_t)boot_regs[1]);
|
||||||
|
|
||||||
dev_dbg(ACRN_DBG_BOOT, "Multiboot detected, flag=0x%x", mbi->mi_flags);
|
dev_dbg(ACRN_DBG_BOOT, "Multiboot detected, flag=0x%x", mbi->mi_flags);
|
||||||
if ((mbi->mi_flags & MULTIBOOT_INFO_HAS_MODS) == 0U) {
|
if ((mbi->mi_flags & MULTIBOOT_INFO_HAS_MODS) == 0U) {
|
||||||
@ -211,7 +211,7 @@ int init_vm_boot_info(struct acrn_vm *vm)
|
|||||||
char buf[MAX_BOOT_PARAMS_LEN];
|
char buf[MAX_BOOT_PARAMS_LEN];
|
||||||
|
|
||||||
cmd_dst = kernel_cmdline;
|
cmd_dst = kernel_cmdline;
|
||||||
cmd_src = hpa2hva((uint64_t)mbi->mi_cmdline);
|
cmd_src = (char *)hpa2hva((uint64_t)mbi->mi_cmdline);
|
||||||
|
|
||||||
(void)memset(buf, 0U, sizeof(buf));
|
(void)memset(buf, 0U, sizeof(buf));
|
||||||
/*
|
/*
|
||||||
@ -241,7 +241,7 @@ int init_vm_boot_info(struct acrn_vm *vm)
|
|||||||
off += 1U;
|
off += 1U;
|
||||||
|
|
||||||
cmd_dst += off;
|
cmd_dst += off;
|
||||||
cmd_src = hpa2hva((uint64_t)mods[0].mm_string);
|
cmd_src = (char *)hpa2hva((uint64_t)mods[0].mm_string);
|
||||||
(void)strncpy_s(cmd_dst, MEM_2K - off, cmd_src,
|
(void)strncpy_s(cmd_dst, MEM_2K - off, cmd_src,
|
||||||
strnlen_s(cmd_src, MEM_2K - off));
|
strnlen_s(cmd_src, MEM_2K - off));
|
||||||
|
|
||||||
|
@ -68,14 +68,14 @@ static uint64_t create_zero_page(struct acrn_vm *vm)
|
|||||||
|
|
||||||
/* Set zeropage in Linux Guest RAM region just past boot args */
|
/* Set zeropage in Linux Guest RAM region just past boot args */
|
||||||
gpa = (uint64_t)sw_linux->bootargs_load_addr + MEM_4K;
|
gpa = (uint64_t)sw_linux->bootargs_load_addr + MEM_4K;
|
||||||
hva = gpa2hva(vm, gpa);
|
hva = (struct zero_page *)gpa2hva(vm, gpa);
|
||||||
zeropage = hva;
|
zeropage = hva;
|
||||||
|
|
||||||
/* clear the zeropage */
|
/* clear the zeropage */
|
||||||
(void)memset(zeropage, 0U, MEM_2K);
|
(void)memset(zeropage, 0U, MEM_2K);
|
||||||
|
|
||||||
/* copy part of the header into the zero page */
|
/* copy part of the header into the zero page */
|
||||||
hva = gpa2hva(vm, (uint64_t)sw_kernel->kernel_load_addr);
|
hva = (struct zero_page *)gpa2hva(vm, (uint64_t)sw_kernel->kernel_load_addr);
|
||||||
(void)memcpy_s(&(zeropage->hdr), sizeof(zeropage->hdr),
|
(void)memcpy_s(&(zeropage->hdr), sizeof(zeropage->hdr),
|
||||||
&(hva->hdr), sizeof(hva->hdr));
|
&(hva->hdr), sizeof(hva->hdr));
|
||||||
|
|
||||||
|
@ -308,8 +308,8 @@ void *memcpy_s(void *d, size_t dmax, const void *s, size_t slen_arg)
|
|||||||
ASSERT(false);
|
ASSERT(false);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (((d > s) && (d <= ((s + slen) - 1U)))
|
if ((((d) > (s)) && ((d) <= ((s + slen) - 1U)))
|
||||||
|| ((d < s) && (s <= ((d + dmax) - 1U)))) {
|
|| (((d) < (s)) && ((s) <= ((d + dmax) - 1U)))) {
|
||||||
ASSERT(false);
|
ASSERT(false);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -90,7 +90,7 @@ long strtol_deci(const char *nptr)
|
|||||||
break;
|
break;
|
||||||
} else {
|
} else {
|
||||||
acc *= base;
|
acc *= base;
|
||||||
acc += c;
|
acc += (uint64_t)c;
|
||||||
}
|
}
|
||||||
|
|
||||||
c = *s;
|
c = *s;
|
||||||
@ -143,7 +143,7 @@ uint64_t strtoul_hex(const char *nptr)
|
|||||||
break;
|
break;
|
||||||
} else {
|
} else {
|
||||||
acc *= base;
|
acc *= base;
|
||||||
acc += digit;
|
acc += (uint64_t)digit;
|
||||||
}
|
}
|
||||||
|
|
||||||
c = *s;
|
c = *s;
|
||||||
|
Loading…
Reference in New Issue
Block a user