diff --git a/hypervisor/arch/x86/assign.c b/hypervisor/arch/x86/assign.c index 69fc38292..718466f82 100644 --- a/hypervisor/arch/x86/assign.c +++ b/hypervisor/arch/x86/assign.c @@ -598,7 +598,7 @@ static void activate_physical_ioapic(struct acrn_vm *vm, /* build physical IOAPIC RTE */ rte = ptdev_build_physical_rte(vm, entry); - intr_mask = (rte.full & IOAPIC_RTE_INTMASK); + intr_mask = (uint32_t)(rte.full & IOAPIC_RTE_INTMASK); /* update irq trigger mode according to info in guest */ if ((rte.full & IOAPIC_RTE_TRGRMOD) == IOAPIC_RTE_TRGRLVL) { diff --git a/hypervisor/arch/x86/guest/instr_emul.c b/hypervisor/arch/x86/guest/instr_emul.c index 95b89b1f5..c42c68777 100644 --- a/hypervisor/arch/x86/guest/instr_emul.c +++ b/hypervisor/arch/x86/guest/instr_emul.c @@ -2213,7 +2213,7 @@ static int instr_check_gva(struct acrn_vcpu *vcpu, struct instr_emul_ctxt *emul_ segbase = desc.base; } - gva = segbase + base + vie->scale * idx + vie->displacement; + gva = segbase + base + (uint64_t)vie->scale * idx + (uint64_t)vie->displacement; if (vie_canonical_check(cpu_mode, gva) != 0) { if (seg == CPU_REG_SS) { diff --git a/hypervisor/arch/x86/guest/vlapic.c b/hypervisor/arch/x86/guest/vlapic.c index d82ddd9de..8d96fa587 100644 --- a/hypervisor/arch/x86/guest/vlapic.c +++ b/hypervisor/arch/x86/guest/vlapic.c @@ -164,8 +164,7 @@ static inline uint32_t vlapic_build_id(const struct acrn_vlapic *vlapic) { const struct acrn_vcpu *vcpu = vlapic->vcpu; - uint8_t vlapic_id; - uint32_t lapic_regs_id; + uint32_t vlapic_id, lapic_regs_id; #ifdef CONFIG_PARTITION_MODE /* @@ -179,14 +178,14 @@ vlapic_build_id(const struct acrn_vlapic *vlapic) /* Get APIC ID sequence format from cpu_storage */ vlapic_id = per_cpu(lapic_id, vcpu->vcpu_id); } else { - vlapic_id = (uint8_t)vcpu->vcpu_id; + vlapic_id = (uint32_t)vcpu->vcpu_id; } #endif if (is_x2apic_enabled(vlapic)) { lapic_regs_id = vlapic_id; } else { - lapic_regs_id = (uint32_t)vlapic_id << APIC_ID_SHIFT; + lapic_regs_id = vlapic_id << APIC_ID_SHIFT; } dev_dbg(ACRN_DBG_LAPIC, "vlapic APIC PAGE ID : 0x%08x", lapic_regs_id); diff --git a/hypervisor/arch/x86/guest/vm.c b/hypervisor/arch/x86/guest/vm.c index 22ddfeb86..51287793e 100644 --- a/hypervisor/arch/x86/guest/vm.c +++ b/hypervisor/arch/x86/guest/vm.c @@ -242,7 +242,7 @@ int start_vm(struct acrn_vm *vm) */ int reset_vm(struct acrn_vm *vm) { - int i; + uint16_t i; struct acrn_vcpu *vcpu = NULL; if (vm->state != VM_PAUSED) { diff --git a/hypervisor/arch/x86/guest/vmsr.c b/hypervisor/arch/x86/guest/vmsr.c index f4e025ff9..3f68b566e 100644 --- a/hypervisor/arch/x86/guest/vmsr.c +++ b/hypervisor/arch/x86/guest/vmsr.c @@ -191,7 +191,7 @@ int rdmsr_vmexit_handler(struct acrn_vcpu *vcpu) uint64_t v = 0UL; /* Read the msr value */ - msr = vcpu_get_gpreg(vcpu, CPU_REG_RCX); + msr = (uint32_t)vcpu_get_gpreg(vcpu, CPU_REG_RCX); /* Do the required processing for each msr case */ switch (msr) { diff --git a/hypervisor/arch/x86/io.c b/hypervisor/arch/x86/io.c index a4330eb86..d62be2866 100644 --- a/hypervisor/arch/x86/io.c +++ b/hypervisor/arch/x86/io.c @@ -443,10 +443,10 @@ static void deny_guest_pio_access(struct acrn_vm *vm, uint16_t port_address, void setup_io_bitmap(struct acrn_vm *vm) { if (is_vm0(vm)) { - (void)memset(vm->arch_vm.io_bitmap, 0x00U, CPU_PAGE_SIZE * 2); + (void)memset(vm->arch_vm.io_bitmap, 0x00U, CPU_PAGE_SIZE * 2U); } else { /* block all IO port access from Guest */ - (void)memset(vm->arch_vm.io_bitmap, 0xFFU, CPU_PAGE_SIZE * 2); + (void)memset(vm->arch_vm.io_bitmap, 0xFFU, CPU_PAGE_SIZE * 2U); } } diff --git a/hypervisor/arch/x86/irq.c b/hypervisor/arch/x86/irq.c index 80ecbe56b..b0cfa3f8e 100644 --- a/hypervisor/arch/x86/irq.c +++ b/hypervisor/arch/x86/irq.c @@ -46,7 +46,7 @@ uint32_t alloc_irq_num(uint32_t req_irq) spinlock_irqsave_obtain(&irq_alloc_spinlock, &rflags); if (irq == IRQ_INVALID) { /* if no valid irq num given, find a free one */ - irq = ffz64_ex(irq_alloc_bitmap, NR_IRQS); + irq = (uint32_t)ffz64_ex(irq_alloc_bitmap, NR_IRQS); } if (irq >= NR_IRQS) { diff --git a/hypervisor/arch/x86/mtrr.c b/hypervisor/arch/x86/mtrr.c index 683ee0575..e4ef81a63 100644 --- a/hypervisor/arch/x86/mtrr.c +++ b/hypervisor/arch/x86/mtrr.c @@ -125,7 +125,7 @@ void init_mtrr(struct acrn_vcpu *vcpu) } } -static uint32_t update_ept(struct acrn_vm *vm, uint64_t start, +static void update_ept(struct acrn_vm *vm, uint64_t start, uint64_t size, uint8_t type) { uint64_t attr; @@ -149,9 +149,7 @@ static uint32_t update_ept(struct acrn_vm *vm, uint64_t start, break; } - ept_mr_modify(vm, (uint64_t *)vm->arch_vm.nworld_eptp, - start, size, attr, EPT_MT_MASK); - return attr; + ept_mr_modify(vm, (uint64_t *)vm->arch_vm.nworld_eptp, start, size, attr, EPT_MT_MASK); } static void update_ept_mem_type(const struct acrn_vcpu *vcpu) @@ -166,8 +164,7 @@ static void update_ept_mem_type(const struct acrn_vcpu *vcpu) * - when def_type.FE is clear, MTRRdefType.type is applied */ if (!is_mtrr_enabled(vcpu) || !is_fixed_range_mtrr_enabled(vcpu)) { - (void)update_ept(vcpu->vm, 0U, MAX_FIXED_RANGE_ADDR, - get_default_memory_type(vcpu)); + update_ept(vcpu->vm, 0U, MAX_FIXED_RANGE_ADDR, get_default_memory_type(vcpu)); return; } @@ -182,14 +179,14 @@ static void update_ept_mem_type(const struct acrn_vcpu *vcpu) if (type == vcpu->mtrr.fixed_range[i].type[j]) { size += get_subrange_size_of_fixed_mtrr(i); } else { - (void)update_ept(vcpu->vm, start, size, type); + update_ept(vcpu->vm, start, size, type); type = vcpu->mtrr.fixed_range[i].type[j]; start = get_subrange_start_of_fixed_mtrr(i, j); size = get_subrange_size_of_fixed_mtrr(i); } } - (void)update_ept(vcpu->vm, start, size, type); + update_ept(vcpu->vm, start, size, type); } } diff --git a/hypervisor/boot/reloc.c b/hypervisor/boot/reloc.c index 269b7761f..44cd59745 100644 --- a/hypervisor/boot/reloc.c +++ b/hypervisor/boot/reloc.c @@ -198,9 +198,8 @@ static void update_trampoline_code_refs(uint64_t dest_pa) *(uint64_t *)(ptr + 2) += dest_pa; /* update trampoline jump pointer with relocated offset */ - ptr = hpa2hva(dest_pa + - trampoline_relo_addr(&trampoline_start64_fixup)); - *(uint32_t *)ptr += dest_pa; + ptr = hpa2hva(dest_pa + trampoline_relo_addr(&trampoline_start64_fixup)); + *(uint32_t *)ptr += (uint32_t)dest_pa; /* update trampoline's main entry pointer */ ptr = hpa2hva(dest_pa + trampoline_relo_addr(main_entry)); diff --git a/hypervisor/common/hypercall.c b/hypervisor/common/hypercall.c index 5d01f9f63..be9f4ac27 100644 --- a/hypervisor/common/hypercall.c +++ b/hypervisor/common/hypercall.c @@ -39,7 +39,7 @@ bool is_hypercall_from_ring0(void) int32_t hcall_sos_offline_cpu(struct acrn_vm *vm, uint64_t lapicid) { struct acrn_vcpu *vcpu; - int i; + uint16_t i; pr_info("sos offline cpu with lapicid %lld", lapicid); @@ -1173,7 +1173,7 @@ int32_t hcall_set_callback_vector(const struct acrn_vm *vm, uint64_t param) return -EINVAL; } - acrn_vhm_vector = param; + acrn_vhm_vector = (uint32_t)param; return 0; } diff --git a/hypervisor/common/trusty_hypercall.c b/hypervisor/common/trusty_hypercall.c index 086c13127..9f60730a1 100644 --- a/hypervisor/common/trusty_hypercall.c +++ b/hypervisor/common/trusty_hypercall.c @@ -101,7 +101,7 @@ int32_t hcall_initialize_trusty(struct acrn_vcpu *vcpu, uint64_t param) * * @return 0 on success, non-zero on error. */ -int64_t hcall_save_restore_sworld_ctx(struct acrn_vcpu *vcpu) +int32_t hcall_save_restore_sworld_ctx(struct acrn_vcpu *vcpu) { struct acrn_vm *vm = vcpu->vm; diff --git a/hypervisor/debug/npk_log.c b/hypervisor/debug/npk_log.c index 957b8c4a1..09af3aa3e 100644 --- a/hypervisor/debug/npk_log.c +++ b/hypervisor/debug/npk_log.c @@ -32,7 +32,7 @@ static inline int npk_write(const char *value, void *addr, size_t sz) void npk_log_setup(struct hv_npk_log_param *param) { - int i; + uint16_t i; pr_info("HV_NPK_LOG: cmd %d param 0x%llx\n", param->cmd, param->mmio_addr); @@ -57,8 +57,9 @@ void npk_log_setup(struct hv_npk_log_param *param) } if ((base != 0UL) && (param->cmd == HV_NPK_LOG_CMD_ENABLE)) { if (!npk_log_enabled) { - for (i = 0; i < phys_cpu_num; i++) - per_cpu(npk_log_ref, i) = 0; + for (i = 0U; i < phys_cpu_num; i++) { + per_cpu(npk_log_ref, i) = 0U; + } } param->res = HV_NPK_LOG_RES_OK; npk_log_enabled = 1; diff --git a/hypervisor/debug/shell.c b/hypervisor/debug/shell.c index 44eb8844e..fb18d39dd 100644 --- a/hypervisor/debug/shell.c +++ b/hypervisor/debug/shell.c @@ -129,9 +129,9 @@ static struct shell_cmd shell_cmds[] = { }; /* The initial log level*/ -uint32_t console_loglevel = CONFIG_CONSOLE_LOGLEVEL_DEFAULT; -uint32_t mem_loglevel = CONFIG_MEM_LOGLEVEL_DEFAULT; -uint32_t npk_loglevel = CONFIG_NPK_LOGLEVEL_DEFAULT; +uint16_t console_loglevel = CONFIG_CONSOLE_LOGLEVEL_DEFAULT; +uint16_t mem_loglevel = CONFIG_MEM_LOGLEVEL_DEFAULT; +uint16_t npk_loglevel = CONFIG_NPK_LOGLEVEL_DEFAULT; static struct shell hv_shell; static struct shell *p_shell = &hv_shell; @@ -448,10 +448,10 @@ void shell_init(void) } #define SHELL_ROWS 10 -#define MAX_INDENT_LEN 16 +#define MAX_INDENT_LEN 16U static int shell_cmd_help(__unused int argc, __unused char **argv) { - int spaces; + uint16_t spaces; struct shell_cmd *p_cmd = NULL; char space_buf[MAX_INDENT_LEN + 1]; @@ -497,8 +497,7 @@ static int shell_cmd_help(__unused int argc, __unused char **argv) shell_puts(p_cmd->str); /* Calculate spaces needed for alignment */ - spaces = MAX_INDENT_LEN - strnlen_s(p_cmd->str, - MAX_INDENT_LEN - 1); + spaces = MAX_INDENT_LEN - strnlen_s(p_cmd->str, MAX_INDENT_LEN - 1); space_buf[spaces] = '\0'; shell_puts(space_buf); @@ -533,23 +532,23 @@ static int shell_list_vm(__unused int argc, __unused char **argv) shell_puts("\r\nVM NAME VM ID VM STATE" "\r\n======= ===== ========\r\n"); - for (idx = 0; idx < CONFIG_MAX_VM_NUM; idx++) { + for (idx = 0U; idx < CONFIG_MAX_VM_NUM; idx++) { vm = get_vm_from_vmid(idx); if (vm == NULL) { continue; } switch (vm->state) { case VM_CREATED: - (void)strcpy_s(state, 32, "Created"); + (void)strcpy_s(state, 32U, "Created"); break; case VM_STARTED: - (void)strcpy_s(state, 32, "Started"); + (void)strcpy_s(state, 32U, "Started"); break; case VM_PAUSED: - (void)strcpy_s(state, 32, "Paused"); + (void)strcpy_s(state, 32U, "Paused"); break; default: - (void)strcpy_s(state, 32, "Unknown"); + (void)strcpy_s(state, 32U, "Unknown"); break; } /* Create output string consisting of VM name and VM id @@ -577,7 +576,7 @@ static int shell_list_vcpu(__unused int argc, __unused char **argv) shell_puts("\r\nVM ID PCPU ID VCPU ID VCPU ROLE VCPU STATE" "\r\n===== ======= ======= ========= ==========\r\n"); - for (idx = 0; idx < CONFIG_MAX_VM_NUM; idx++) { + for (idx = 0U; idx < CONFIG_MAX_VM_NUM; idx++) { vm = get_vm_from_vmid(idx); if (vm == NULL) { continue; @@ -585,19 +584,19 @@ static int shell_list_vcpu(__unused int argc, __unused char **argv) foreach_vcpu(i, vm, vcpu) { switch (vcpu->state) { case VCPU_INIT: - (void)strcpy_s(state, 32, "Init"); + (void)strcpy_s(state, 32U, "Init"); break; case VCPU_PAUSED: - (void)strcpy_s(state, 32, "Paused"); + (void)strcpy_s(state, 32U, "Paused"); break; case VCPU_RUNNING: - (void)strcpy_s(state, 32, "Running"); + (void)strcpy_s(state, 32U, "Running"); break; case VCPU_ZOMBIE: - (void)strcpy_s(state, 32, "Zombie"); + (void)strcpy_s(state, 32U, "Zombie"); break; default: - (void)strcpy_s(state, 32, "Unknown"); + (void)strcpy_s(state, 32U, "Unknown"); } /* Create output string consisting of VM name * and VM id @@ -672,7 +671,7 @@ out: return status; } -#define MAX_MEMDUMP_LEN (32U*8U) +#define MAX_MEMDUMP_LEN (32U * 8U) static int shell_dumpmem(int argc, char **argv) { uint64_t addr; @@ -686,7 +685,7 @@ static int shell_dumpmem(int argc, char **argv) } addr = strtoul_hex(argv[1]); - length = atoi(argv[2]); + length = (uint32_t)atoi(argv[2]); if (length > MAX_MEMDUMP_LEN) { shell_puts("over max length, round back\r\n"); length = MAX_MEMDUMP_LEN; @@ -701,16 +700,16 @@ static int shell_dumpmem(int argc, char **argv) for (i = 0U; i < (length >> 5U); i++) { snprintf(temp_str, MAX_STR_SIZE, "= 0x%016llx 0x%016llx 0x%016llx 0x%016llx\r\n", - *(ptr + (i*4)), *(ptr + ((i*4)+1)), - *(ptr + ((i*4)+2)), *(ptr + ((i*4)+3))); + *(ptr + (i * 4U)), *(ptr + ((i * 4U) + 1U)), + *(ptr + ((i * 4U) + 2U)), *(ptr + ((i * 4U) + 3U))); shell_puts(temp_str); } - if ((length & 0x1fU) != 0) { + if ((length & 0x1fU) != 0U) { snprintf(temp_str, MAX_STR_SIZE, "= 0x%016llx 0x%016llx 0x%016llx 0x%016llx\r\n", - *(ptr + (i*4)), *(ptr + ((i*4)+1)), - *(ptr + ((i*4)+2)), *(ptr + ((i*4)+3))); + *(ptr + (i * 4U)), *(ptr + ((i * 4U) + 1U)), + *(ptr + ((i * 4U) + 2U)), *(ptr + ((i * 4U) + 3U))); shell_puts(temp_str); } @@ -839,13 +838,13 @@ static int shell_loglevel(int argc, char **argv) switch (argc) { case 4: - npk_loglevel = atoi(argv[3]); + npk_loglevel = (uint16_t)atoi(argv[3]); /* falls through */ case 3: - mem_loglevel = atoi(argv[2]); + mem_loglevel = (uint16_t)atoi(argv[2]); /* falls through */ case 2: - console_loglevel = atoi(argv[1]); + console_loglevel = (uint16_t)atoi(argv[1]); break; case 1: snprintf(str, MAX_STR_SIZE, "console_loglevel: %u, " @@ -867,10 +866,10 @@ static int shell_cpuid(int argc, char **argv) uint32_t eax, ebx, ecx, edx; if (argc == 2) { - leaf = strtoul_hex(argv[1]); + leaf = (uint32_t)strtoul_hex(argv[1]); } else if (argc == 3) { - leaf = strtoul_hex(argv[1]); - subleaf = strtoul_hex(argv[2]); + leaf = (uint32_t)strtoul_hex(argv[1]); + subleaf = (uint32_t)strtoul_hex(argv[2]); } else { shell_puts("Please enter correct cmd with " "cpuid [subleaf]\r\n"); diff --git a/hypervisor/include/common/hypercall.h b/hypervisor/include/common/hypercall.h index 0ad4e97c2..5f76e7328 100644 --- a/hypervisor/include/common/hypercall.h +++ b/hypervisor/include/common/hypercall.h @@ -421,7 +421,7 @@ int32_t hcall_initialize_trusty(struct acrn_vcpu *vcpu, uint64_t param); * * @return 0 on success, non-zero on error. */ -int64_t hcall_save_restore_sworld_ctx(struct acrn_vcpu *vcpu); +int32_t hcall_save_restore_sworld_ctx(struct acrn_vcpu *vcpu); /** * @} diff --git a/hypervisor/include/debug/logmsg.h b/hypervisor/include/debug/logmsg.h index fdbd8a6cc..bdff0dd8a 100644 --- a/hypervisor/include/debug/logmsg.h +++ b/hypervisor/include/debug/logmsg.h @@ -28,9 +28,9 @@ #if defined(HV_DEBUG) -extern uint32_t console_loglevel; -extern uint32_t mem_loglevel; -extern uint32_t npk_loglevel; +extern uint16_t console_loglevel; +extern uint16_t mem_loglevel; +extern uint16_t npk_loglevel; void init_logmsg(uint32_t flags); void print_logmsg_buffer(uint16_t pcpu_id); void do_logmsg(uint32_t severity, const char *fmt, ...); diff --git a/hypervisor/include/debug/npk_log.h b/hypervisor/include/debug/npk_log.h index a44bd1fc3..7475d27cd 100644 --- a/hypervisor/include/debug/npk_log.h +++ b/hypervisor/include/debug/npk_log.h @@ -13,7 +13,7 @@ #define HV_NPK_LOG_HDR 0x01000242U enum { - HV_NPK_LOG_CMD_INVALID, + HV_NPK_LOG_CMD_INVALID = 0U, HV_NPK_LOG_CMD_CONF, HV_NPK_LOG_CMD_ENABLE, HV_NPK_LOG_CMD_DISABLE, diff --git a/hypervisor/include/debug/sbuf.h b/hypervisor/include/debug/sbuf.h index 401ee70d2..72a08da28 100644 --- a/hypervisor/include/debug/sbuf.h +++ b/hypervisor/include/debug/sbuf.h @@ -37,7 +37,7 @@ */ enum { - ACRN_TRACE, + ACRN_TRACE = 0U, ACRN_HVLOG, ACRN_SEP, ACRN_SOCWATCH, @@ -51,7 +51,8 @@ struct shared_buf { uint32_t ele_size; /* sizeof of elements */ uint32_t head; /* offset from base, to read */ uint32_t tail; /* offset from base, to write */ - uint64_t flags; + uint32_t flags; + uint32_t reserved; uint32_t overrun_cnt; /* count of overrun */ uint32_t size; /* ele_num * ele_size */ uint32_t padding[6]; @@ -59,17 +60,17 @@ struct shared_buf { #ifdef HV_DEBUG -static inline void sbuf_clear_flags(struct shared_buf *sbuf, uint64_t flags) +static inline void sbuf_clear_flags(struct shared_buf *sbuf, uint32_t flags) { sbuf->flags &= ~flags; } -static inline void sbuf_set_flags(struct shared_buf *sbuf, uint64_t flags) +static inline void sbuf_set_flags(struct shared_buf *sbuf, uint32_t flags) { sbuf->flags = flags; } -static inline void sbuf_add_flags(struct shared_buf *sbuf, uint64_t flags) +static inline void sbuf_add_flags(struct shared_buf *sbuf, uint32_t flags) { sbuf->flags |= flags; } @@ -91,19 +92,19 @@ uint32_t sbuf_next_ptr(uint32_t pos, uint32_t span, uint32_t scope); static inline void sbuf_clear_flags( __unused struct shared_buf *sbuf, - __unused uint64_t flags) + __unused uint32_t flags) { } static inline void sbuf_set_flags( __unused struct shared_buf *sbuf, - __unused uint64_t flags) + __unused uint32_t flags) { } static inline void sbuf_add_flags( __unused struct shared_buf *sbuf, - __unused uint64_t flags) + __unused uint32_t flags) { }