Skip to content

Commit 188210a

Browse files
wuxyintellijinxia
authored andcommitted
HV:Treewide:Update the type of vcpu id as uint16_t
In the hypervisor, virtual cpu id is defined as "int" or "uint32_t" type in the hypervisor. So there are some sign conversion issues about virtual cpu id (vcpu_id) reported by static analysis tool. Sign conversion violates the rules of MISRA C:2012. BTW, virtual cpu id has different names (vcpu_id, cpu_id, logical_id) for different modules of HV, its type is defined as "int" or "uint32_t" in the HV. cpu_id type and logical_id type clean up will be done in other patchs. V1-->V2: More clean up the type of vcpu id; "%hu" is for vcpu id in the print function. Signed-off-by: Xiangyang Wu <xiangyang.wu@intel.com>
1 parent b3fa2ef commit 188210a

File tree

14 files changed

+54
-45
lines changed

14 files changed

+54
-45
lines changed

hypervisor/arch/x86/ept.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -275,7 +275,7 @@ void unregister_mmio_emulation_handler(struct vm *vm, uint64_t start,
275275
int dm_emulate_mmio_post(struct vcpu *vcpu)
276276
{
277277
int ret = 0;
278-
int cur = vcpu->vcpu_id;
278+
uint16_t cur = vcpu->vcpu_id;
279279
union vhm_request_buffer *req_buf;
280280

281281
req_buf = (union vhm_request_buffer *)(vcpu->vm->sw.io_shared_page);

hypervisor/arch/x86/guest/guest.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ is_vm0(struct vm *vm)
3434
return (vm->attr.boot_idx & 0x7FU) == 0;
3535
}
3636

37-
inline struct vcpu *vcpu_from_vid(struct vm *vm, int vcpu_id)
37+
inline struct vcpu *vcpu_from_vid(struct vm *vm, uint16_t vcpu_id)
3838
{
3939
int i;
4040
struct vcpu *vcpu;

hypervisor/arch/x86/guest/vcpu.c

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,7 @@ int create_vcpu(uint16_t cpu_id, struct vm *vm, struct vcpu **rtn_vcpu_handle)
8383
if (is_vcpu_bsp(vcpu) && is_vm0(vcpu->vm)) {
8484
/* Set up temporary guest page tables */
8585
vm->arch_vm.guest_init_pml4 = create_guest_initial_paging(vm);
86-
pr_info("VM %d VCPU %d CR3: 0x%016llx ",
86+
pr_info("VM %d VCPU %hu CR3: 0x%016llx ",
8787
vm->attr.id, vcpu->vcpu_id,
8888
vm->arch_vm.guest_init_pml4);
8989
}
@@ -154,7 +154,7 @@ int start_vcpu(struct vcpu *vcpu)
154154

155155
/* If this VCPU is not already launched, launch it */
156156
if (!vcpu->launched) {
157-
pr_info("VM %d Starting VCPU %d",
157+
pr_info("VM %d Starting VCPU %hu",
158158
vcpu->vm->attr.id, vcpu->vcpu_id);
159159

160160
if (vcpu->arch_vcpu.vpid)
@@ -183,7 +183,7 @@ int start_vcpu(struct vcpu *vcpu)
183183
/* See if VM launched successfully */
184184
if (status == 0) {
185185
if (is_vcpu_bsp(vcpu)) {
186-
pr_info("VM %d VCPU %d successfully launched",
186+
pr_info("VM %d VCPU %hu successfully launched",
187187
vcpu->vm->attr.id, vcpu->vcpu_id);
188188
}
189189
}
@@ -263,7 +263,7 @@ void reset_vcpu(struct vcpu *vcpu)
263263
{
264264
struct vlapic *vlapic;
265265

266-
pr_dbg("vcpu%d reset", vcpu->vcpu_id);
266+
pr_dbg("vcpu%hu reset", vcpu->vcpu_id);
267267
ASSERT(vcpu->state != VCPU_RUNNING,
268268
"reset vcpu when it's running");
269269

@@ -293,7 +293,7 @@ void pause_vcpu(struct vcpu *vcpu, enum vcpu_state new_state)
293293
{
294294
uint16_t pcpu_id = get_cpu_id();
295295

296-
pr_dbg("vcpu%d paused, new state: %d",
296+
pr_dbg("vcpu%hu paused, new state: %d",
297297
vcpu->vcpu_id, new_state);
298298

299299
get_schedule_lock(vcpu->pcpu_id);
@@ -317,7 +317,7 @@ void pause_vcpu(struct vcpu *vcpu, enum vcpu_state new_state)
317317

318318
void resume_vcpu(struct vcpu *vcpu)
319319
{
320-
pr_dbg("vcpu%d resumed", vcpu->vcpu_id);
320+
pr_dbg("vcpu%hu resumed", vcpu->vcpu_id);
321321

322322
get_schedule_lock(vcpu->pcpu_id);
323323
vcpu->state = vcpu->prev_state;
@@ -332,7 +332,7 @@ void resume_vcpu(struct vcpu *vcpu)
332332
void schedule_vcpu(struct vcpu *vcpu)
333333
{
334334
vcpu->state = VCPU_RUNNING;
335-
pr_dbg("vcpu%d scheduled", vcpu->vcpu_id);
335+
pr_dbg("vcpu%hu scheduled", vcpu->vcpu_id);
336336

337337
get_schedule_lock(vcpu->pcpu_id);
338338
add_vcpu_to_runqueue(vcpu);

hypervisor/arch/x86/guest/vlapic.c

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -104,12 +104,12 @@ static void vlapic_set_error(struct vlapic *vlapic, uint32_t mask);
104104
static int vlapic_timer_expired(void *data);
105105

106106
static struct vlapic *
107-
vm_lapic_from_vcpu_id(struct vm *vm, int vcpu_id)
107+
vm_lapic_from_vcpu_id(struct vm *vm, uint16_t vcpu_id)
108108
{
109109
struct vcpu *vcpu;
110110

111111
vcpu = vcpu_from_vid(vm, vcpu_id);
112-
ASSERT(vcpu != NULL, "vm%d, vcpu%d", vm->attr.id, vcpu_id);
112+
ASSERT(vcpu != NULL, "vm%d, vcpu%hu", vm->attr.id, vcpu_id);
113113

114114
return vcpu->arch_vcpu.vlapic;
115115
}
@@ -170,7 +170,7 @@ static inline uint32_t
170170
vlapic_build_id(struct vlapic *vlapic)
171171
{
172172
struct vcpu *vcpu = vlapic->vcpu;
173-
uint32_t id;
173+
uint16_t id;
174174

175175
if (is_vm0(vcpu->vm)) {
176176
/* Get APIC ID sequence format from cpu_storage */
@@ -1528,7 +1528,7 @@ void
15281528
vlapic_init(struct vlapic *vlapic)
15291529
{
15301530
ASSERT(vlapic->vm != NULL, "%s: vm is not initialized", __func__);
1531-
ASSERT(vlapic->vcpu->vcpu_id >= 0 &&
1531+
ASSERT(vlapic->vcpu->vcpu_id >= 0U &&
15321532
vlapic->vcpu->vcpu_id < phys_cpu_num,
15331533
"%s: vcpu_id is not initialized", __func__);
15341534
ASSERT(vlapic->apic_page != NULL,
@@ -1540,7 +1540,7 @@ vlapic_init(struct vlapic *vlapic)
15401540
*/
15411541
vlapic->msr_apicbase = DEFAULT_APIC_BASE | APICBASE_ENABLED;
15421542

1543-
if (vlapic->vcpu->vcpu_id == 0)
1543+
if (vlapic->vcpu->vcpu_id == 0U)
15441544
vlapic->msr_apicbase |= APICBASE_BSP;
15451545

15461546
vlapic_create_timer(vlapic);
@@ -1867,7 +1867,7 @@ vlapic_rdmsr(struct vcpu *vcpu, uint32_t msr, uint64_t *rval)
18671867
uint32_t offset;
18681868
struct vlapic *vlapic;
18691869

1870-
dev_dbg(ACRN_DBG_LAPIC, "cpu[%d] rdmsr: %x", vcpu->vcpu_id, msr);
1870+
dev_dbg(ACRN_DBG_LAPIC, "cpu[%hu] rdmsr: %x", vcpu->vcpu_id, msr);
18711871
vlapic = vcpu->arch_vcpu.vlapic;
18721872

18731873
switch (msr) {
@@ -1912,7 +1912,7 @@ vlapic_wrmsr(struct vcpu *vcpu, uint32_t msr, uint64_t val)
19121912
break;
19131913
}
19141914

1915-
dev_dbg(ACRN_DBG_LAPIC, "cpu[%d] wrmsr: %x val=%#x",
1915+
dev_dbg(ACRN_DBG_LAPIC, "cpu[%hu] wrmsr: %x val=%#x",
19161916
vcpu->vcpu_id, msr, val);
19171917
return error;
19181918
}

hypervisor/arch/x86/io.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88

99
int dm_emulate_pio_post(struct vcpu *vcpu)
1010
{
11-
int cur = vcpu->vcpu_id;
11+
uint16_t cur = vcpu->vcpu_id;
1212
int cur_context = vcpu->arch_vcpu.cur_context;
1313
union vhm_request_buffer *req_buf = NULL;
1414
uint32_t mask =

hypervisor/arch/x86/mtrr.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -124,7 +124,7 @@ void init_mtrr(struct vcpu *vcpu)
124124
vcpu->mtrr.fixed_range[i].value = MTRR_FIXED_RANGE_ALL_WB;
125125
}
126126

127-
pr_dbg("vm%d vcpu%d fixed-range MTRR[%d]: %16llx",
127+
pr_dbg("vm%d vcpu%hu fixed-range MTRR[%d]: %16llx",
128128
vcpu->vm->attr.id, vcpu->vcpu_id, i,
129129
vcpu->mtrr.fixed_range[i].value);
130130
}

hypervisor/common/hypercall.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -372,7 +372,7 @@ int64_t hcall_notify_req_finish(uint64_t vmid, uint64_t vcpu_id)
372372
dev_dbg(ACRN_DBG_HYCALL, "[%d] NOTIFY_FINISH for vcpu %d",
373373
vmid, vcpu_id);
374374

375-
vcpu = vcpu_from_vid(target_vm, vcpu_id);
375+
vcpu = vcpu_from_vid(target_vm, (uint16_t)vcpu_id);
376376
if (vcpu == NULL) {
377377
pr_err("%s, failed to get VCPU %d context from VM %d\n",
378378
__func__, vcpu_id, target_vm->attr.id);

hypervisor/common/io_request.c

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -25,11 +25,11 @@ static void fire_vhm_interrupt(void)
2525
vlapic_intr_edge(vcpu, VECTOR_VIRT_IRQ_VHM);
2626
}
2727

28-
static void acrn_print_request(int vcpu_id, struct vhm_request *req)
28+
static void acrn_print_request(uint16_t vcpu_id, struct vhm_request *req)
2929
{
3030
switch (req->type) {
3131
case REQ_MMIO:
32-
dev_dbg(ACRN_DBG_IOREQUEST, "[vcpu_id=%d type=MMIO]", vcpu_id);
32+
dev_dbg(ACRN_DBG_IOREQUEST, "[vcpu_id=%hu type=MMIO]", vcpu_id);
3333
dev_dbg(ACRN_DBG_IOREQUEST,
3434
"gpa=0x%lx, R/W=%d, size=%ld value=0x%lx processed=%lx",
3535
req->reqs.mmio_request.address,
@@ -39,7 +39,7 @@ static void acrn_print_request(int vcpu_id, struct vhm_request *req)
3939
req->processed);
4040
break;
4141
case REQ_PORTIO:
42-
dev_dbg(ACRN_DBG_IOREQUEST, "[vcpu_id=%d type=PORTIO]", vcpu_id);
42+
dev_dbg(ACRN_DBG_IOREQUEST, "[vcpu_id=%hu type=PORTIO]", vcpu_id);
4343
dev_dbg(ACRN_DBG_IOREQUEST,
4444
"IO=0x%lx, R/W=%d, size=%ld value=0x%lx processed=%lx",
4545
req->reqs.pio_request.address,
@@ -49,7 +49,7 @@ static void acrn_print_request(int vcpu_id, struct vhm_request *req)
4949
req->processed);
5050
break;
5151
default:
52-
dev_dbg(ACRN_DBG_IOREQUEST, "[vcpu_id=%d type=%d] NOT support type",
52+
dev_dbg(ACRN_DBG_IOREQUEST, "[vcpu_id=%hu type=%d] NOT support type",
5353
vcpu_id, req->type);
5454
break;
5555
}

hypervisor/common/vm_load.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,7 @@ int load_guest(struct vm *vm, struct vcpu *vcpu)
9292

9393
pr_info("%s, Set config according to predefined offset:",
9494
__func__);
95-
pr_info("VCPU%d Entry: 0x%llx, RSI: 0x%016llx, cr3: 0x%016llx",
95+
pr_info("VCPU%hu Entry: 0x%llx, RSI: 0x%016llx, cr3: 0x%016llx",
9696
vcpu->vcpu_id, vcpu->entry_addr,
9797
cur_context->guest_cpu_regs.regs.rsi,
9898
vm->arch_vm.guest_init_pml4);
@@ -132,7 +132,7 @@ int general_sw_loader(struct vm *vm, struct vcpu *vcpu)
132132
if (is_vcpu_bsp(vcpu)) {
133133
/* Set VCPU entry point to kernel entry */
134134
vcpu->entry_addr = vm->sw.kernel_info.kernel_entry_addr;
135-
pr_info("%s, VM *d VCPU %d Entry: 0x%016llx ",
135+
pr_info("%s, VM *d VCPU %hu Entry: 0x%016llx ",
136136
__func__, vm->attr.id, vcpu->vcpu_id, vcpu->entry_addr);
137137
}
138138

hypervisor/debug/dump.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ static void dump_guest_reg(struct vcpu *vcpu)
5555
printf("\n\n================================================");
5656
printf("================================\n\n");
5757
printf("Guest Registers:\r\n");
58-
printf("= VM ID %d ==== vCPU ID %d === pCPU ID %d ===="
58+
printf("= VM ID %d ==== vCPU ID %hu === pCPU ID %d ===="
5959
"world %d =============\r\n",
6060
vcpu->vm->attr.id, vcpu->vcpu_id, vcpu->pcpu_id,
6161
vcpu->arch_vcpu.cur_context);
@@ -112,7 +112,7 @@ static void dump_guest_stack(struct vcpu *vcpu)
112112
}
113113

114114
printf("\r\nGuest Stack:\r\n");
115-
printf("Dump stack for vcpu %d, from gva 0x%016llx\r\n",
115+
printf("Dump stack for vcpu %hu, from gva 0x%016llx\r\n",
116116
vcpu->vcpu_id, cur_context->rsp);
117117
for (i = 0U; i < DUMP_STACK_SIZE/32U; i++) {
118118
printf("guest_rsp(0x%llx): 0x%016llx 0x%016llx "

0 commit comments

Comments
 (0)