Skip to content

Commit d97224a

Browse files
shiqinggwenlingz
authored andcommitted
hv: fix integer violations
fix the following integer violations: 1. Signed/unsigned conversion without cast 2. Literal value requires a U suffix 3. Implicit conversion of underlying type v3 -> v4: * change the type of npk_loglevel/mem_loglevel/console_loglevel from uint32_t to uint16_t v2 -> v3: * discard the return value of update_ept * discard changes related to npk loglevel v1 -> v2: * remove the unnecessary changes related to the false positive issues caused by scanning tool * change the type of the local variable 'vlapic_id' from uint8_t to uint32_t in function 'vlapic_build_id' * change the type of the struct member 'flags' in shared_buf from uint64_t to uint32_t Tracked-On: #861 Signed-off-by: Shiqing Gao <shiqing.gao@intel.com> Acked-by: Eddie Dong <eddie.dong@intel.com>
1 parent 7e6d0a2 commit d97224a

File tree

17 files changed

+68
-72
lines changed

17 files changed

+68
-72
lines changed

hypervisor/arch/x86/assign.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -598,7 +598,7 @@ static void activate_physical_ioapic(struct acrn_vm *vm,
598598

599599
/* build physical IOAPIC RTE */
600600
rte = ptdev_build_physical_rte(vm, entry);
601-
intr_mask = (rte.full & IOAPIC_RTE_INTMASK);
601+
intr_mask = (uint32_t)(rte.full & IOAPIC_RTE_INTMASK);
602602

603603
/* update irq trigger mode according to info in guest */
604604
if ((rte.full & IOAPIC_RTE_TRGRMOD) == IOAPIC_RTE_TRGRLVL) {

hypervisor/arch/x86/guest/instr_emul.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2213,7 +2213,7 @@ static int instr_check_gva(struct acrn_vcpu *vcpu, struct instr_emul_ctxt *emul_
22132213
segbase = desc.base;
22142214
}
22152215

2216-
gva = segbase + base + vie->scale * idx + vie->displacement;
2216+
gva = segbase + base + (uint64_t)vie->scale * idx + (uint64_t)vie->displacement;
22172217

22182218
if (vie_canonical_check(cpu_mode, gva) != 0) {
22192219
if (seg == CPU_REG_SS) {

hypervisor/arch/x86/guest/vlapic.c

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -164,8 +164,7 @@ static inline uint32_t
164164
vlapic_build_id(const struct acrn_vlapic *vlapic)
165165
{
166166
const struct acrn_vcpu *vcpu = vlapic->vcpu;
167-
uint8_t vlapic_id;
168-
uint32_t lapic_regs_id;
167+
uint32_t vlapic_id, lapic_regs_id;
169168

170169
#ifdef CONFIG_PARTITION_MODE
171170
/*
@@ -179,14 +178,14 @@ vlapic_build_id(const struct acrn_vlapic *vlapic)
179178
/* Get APIC ID sequence format from cpu_storage */
180179
vlapic_id = per_cpu(lapic_id, vcpu->vcpu_id);
181180
} else {
182-
vlapic_id = (uint8_t)vcpu->vcpu_id;
181+
vlapic_id = (uint32_t)vcpu->vcpu_id;
183182
}
184183
#endif
185184

186185
if (is_x2apic_enabled(vlapic)) {
187186
lapic_regs_id = vlapic_id;
188187
} else {
189-
lapic_regs_id = (uint32_t)vlapic_id << APIC_ID_SHIFT;
188+
lapic_regs_id = vlapic_id << APIC_ID_SHIFT;
190189
}
191190

192191
dev_dbg(ACRN_DBG_LAPIC, "vlapic APIC PAGE ID : 0x%08x", lapic_regs_id);

hypervisor/arch/x86/guest/vm.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -242,7 +242,7 @@ int start_vm(struct acrn_vm *vm)
242242
*/
243243
int reset_vm(struct acrn_vm *vm)
244244
{
245-
int i;
245+
uint16_t i;
246246
struct acrn_vcpu *vcpu = NULL;
247247

248248
if (vm->state != VM_PAUSED) {

hypervisor/arch/x86/guest/vmsr.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -191,7 +191,7 @@ int rdmsr_vmexit_handler(struct acrn_vcpu *vcpu)
191191
uint64_t v = 0UL;
192192

193193
/* Read the msr value */
194-
msr = vcpu_get_gpreg(vcpu, CPU_REG_RCX);
194+
msr = (uint32_t)vcpu_get_gpreg(vcpu, CPU_REG_RCX);
195195

196196
/* Do the required processing for each msr case */
197197
switch (msr) {

hypervisor/arch/x86/io.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -443,10 +443,10 @@ static void deny_guest_pio_access(struct acrn_vm *vm, uint16_t port_address,
443443
void setup_io_bitmap(struct acrn_vm *vm)
444444
{
445445
if (is_vm0(vm)) {
446-
(void)memset(vm->arch_vm.io_bitmap, 0x00U, CPU_PAGE_SIZE * 2);
446+
(void)memset(vm->arch_vm.io_bitmap, 0x00U, CPU_PAGE_SIZE * 2U);
447447
} else {
448448
/* block all IO port access from Guest */
449-
(void)memset(vm->arch_vm.io_bitmap, 0xFFU, CPU_PAGE_SIZE * 2);
449+
(void)memset(vm->arch_vm.io_bitmap, 0xFFU, CPU_PAGE_SIZE * 2U);
450450
}
451451
}
452452

hypervisor/arch/x86/irq.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ uint32_t alloc_irq_num(uint32_t req_irq)
4646
spinlock_irqsave_obtain(&irq_alloc_spinlock, &rflags);
4747
if (irq == IRQ_INVALID) {
4848
/* if no valid irq num given, find a free one */
49-
irq = ffz64_ex(irq_alloc_bitmap, NR_IRQS);
49+
irq = (uint32_t)ffz64_ex(irq_alloc_bitmap, NR_IRQS);
5050
}
5151

5252
if (irq >= NR_IRQS) {

hypervisor/arch/x86/mtrr.c

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -125,7 +125,7 @@ void init_mtrr(struct acrn_vcpu *vcpu)
125125
}
126126
}
127127

128-
static uint32_t update_ept(struct acrn_vm *vm, uint64_t start,
128+
static void update_ept(struct acrn_vm *vm, uint64_t start,
129129
uint64_t size, uint8_t type)
130130
{
131131
uint64_t attr;
@@ -149,9 +149,7 @@ static uint32_t update_ept(struct acrn_vm *vm, uint64_t start,
149149
break;
150150
}
151151

152-
ept_mr_modify(vm, (uint64_t *)vm->arch_vm.nworld_eptp,
153-
start, size, attr, EPT_MT_MASK);
154-
return attr;
152+
ept_mr_modify(vm, (uint64_t *)vm->arch_vm.nworld_eptp, start, size, attr, EPT_MT_MASK);
155153
}
156154

157155
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)
166164
* - when def_type.FE is clear, MTRRdefType.type is applied
167165
*/
168166
if (!is_mtrr_enabled(vcpu) || !is_fixed_range_mtrr_enabled(vcpu)) {
169-
(void)update_ept(vcpu->vm, 0U, MAX_FIXED_RANGE_ADDR,
170-
get_default_memory_type(vcpu));
167+
update_ept(vcpu->vm, 0U, MAX_FIXED_RANGE_ADDR, get_default_memory_type(vcpu));
171168
return;
172169
}
173170

@@ -182,14 +179,14 @@ static void update_ept_mem_type(const struct acrn_vcpu *vcpu)
182179
if (type == vcpu->mtrr.fixed_range[i].type[j]) {
183180
size += get_subrange_size_of_fixed_mtrr(i);
184181
} else {
185-
(void)update_ept(vcpu->vm, start, size, type);
182+
update_ept(vcpu->vm, start, size, type);
186183
type = vcpu->mtrr.fixed_range[i].type[j];
187184
start = get_subrange_start_of_fixed_mtrr(i, j);
188185
size = get_subrange_size_of_fixed_mtrr(i);
189186
}
190187
}
191188

192-
(void)update_ept(vcpu->vm, start, size, type);
189+
update_ept(vcpu->vm, start, size, type);
193190
}
194191
}
195192

hypervisor/boot/reloc.c

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -198,9 +198,8 @@ static void update_trampoline_code_refs(uint64_t dest_pa)
198198
*(uint64_t *)(ptr + 2) += dest_pa;
199199

200200
/* update trampoline jump pointer with relocated offset */
201-
ptr = hpa2hva(dest_pa +
202-
trampoline_relo_addr(&trampoline_start64_fixup));
203-
*(uint32_t *)ptr += dest_pa;
201+
ptr = hpa2hva(dest_pa + trampoline_relo_addr(&trampoline_start64_fixup));
202+
*(uint32_t *)ptr += (uint32_t)dest_pa;
204203

205204
/* update trampoline's main entry pointer */
206205
ptr = hpa2hva(dest_pa + trampoline_relo_addr(main_entry));

hypervisor/common/hypercall.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ bool is_hypercall_from_ring0(void)
3939
int32_t hcall_sos_offline_cpu(struct acrn_vm *vm, uint64_t lapicid)
4040
{
4141
struct acrn_vcpu *vcpu;
42-
int i;
42+
uint16_t i;
4343

4444
pr_info("sos offline cpu with lapicid %lld", lapicid);
4545

@@ -1173,7 +1173,7 @@ int32_t hcall_set_callback_vector(const struct acrn_vm *vm, uint64_t param)
11731173
return -EINVAL;
11741174
}
11751175

1176-
acrn_vhm_vector = param;
1176+
acrn_vhm_vector = (uint32_t)param;
11771177

11781178
return 0;
11791179
}

0 commit comments

Comments
 (0)