Skip to content

Commit f0a3585

Browse files
junjiemao1lijinxia
authored andcommitted
HV: common: cleanup of remaining integral-type issues
This is the final cleanup of the integral type related issues, reported by the static checker, under common/, mostly including * make explicit the narrowings of vm_ids passed by register. * work around the confusion of the static checker by abstracting sub-expressions to local variables. The remaining reports that are not trivial to suppress will be in the scope of a separate document. v1 -> v2: * Instead of converting vm_ids inside hcall_xxx, update the prototypes of these functions and do the conversion in vmcall_vmexit_handler. Signed-off-by: Junjie Mao <junjie.mao@intel.com> Acked-by: Eddie Dong <eddie.dong@intel.com>
1 parent 112b5b8 commit f0a3585

File tree

7 files changed

+154
-124
lines changed

7 files changed

+154
-124
lines changed

hypervisor/arch/x86/guest/vmcall.c

Lines changed: 36 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -55,75 +55,94 @@ int vmcall_vmexit_handler(struct vcpu *vcpu)
5555
break;
5656

5757
case HC_DESTROY_VM:
58-
ret = hcall_destroy_vm(param1);
58+
/* param1: vmid */
59+
ret = hcall_destroy_vm((uint16_t)param1);
5960
break;
6061

6162
case HC_START_VM:
62-
ret = hcall_resume_vm(param1);
63+
/* param1: vmid */
64+
ret = hcall_resume_vm((uint16_t)param1);
6365
break;
6466

6567
case HC_PAUSE_VM:
66-
ret = hcall_pause_vm(param1);
68+
/* param1: vmid */
69+
ret = hcall_pause_vm((uint16_t)param1);
6770
break;
6871

6972
case HC_CREATE_VCPU:
70-
ret = hcall_create_vcpu(vm, param1, param2);
73+
/* param1: vmid */
74+
ret = hcall_create_vcpu(vm, (uint16_t)param1, param2);
7175
break;
7276

7377
case HC_ASSERT_IRQLINE:
74-
ret = hcall_assert_irqline(vm, param1, param2);
78+
/* param1: vmid */
79+
ret = hcall_assert_irqline(vm, (uint16_t)param1, param2);
7580
break;
7681

7782
case HC_DEASSERT_IRQLINE:
78-
ret = hcall_deassert_irqline(vm, param1, param2);
83+
/* param1: vmid */
84+
ret = hcall_deassert_irqline(vm, (uint16_t)param1, param2);
7985
break;
8086

8187
case HC_PULSE_IRQLINE:
82-
ret = hcall_pulse_irqline(vm, param1, param2);
88+
/* param1: vmid */
89+
ret = hcall_pulse_irqline(vm, (uint16_t)param1, param2);
8390
break;
8491

8592
case HC_INJECT_MSI:
86-
ret = hcall_inject_msi(vm, param1, param2);
93+
/* param1: vmid */
94+
ret = hcall_inject_msi(vm, (uint16_t)param1, param2);
8795
break;
8896

8997
case HC_SET_IOREQ_BUFFER:
90-
ret = hcall_set_ioreq_buffer(vm, param1, param2);
98+
/* param1: vmid */
99+
ret = hcall_set_ioreq_buffer(vm, (uint16_t)param1, param2);
91100
break;
92101

93102
case HC_NOTIFY_REQUEST_FINISH:
94-
ret = hcall_notify_req_finish(param1, param2);
103+
/* param1: vmid
104+
* param2: vcpu_id */
105+
ret = hcall_notify_req_finish((uint16_t)param1,
106+
(uint16_t)param2);
95107
break;
96108

97109
case HC_VM_SET_MEMMAP:
98-
ret = hcall_set_vm_memmap(vm, param1, param2);
110+
/* param1: vmid */
111+
ret = hcall_set_vm_memmap(vm, (uint16_t)param1, param2);
99112
break;
100113

101114
case HC_VM_SET_MEMMAPS:
102115
ret = hcall_set_vm_memmaps(vm, param1);
103116
break;
104117

105118
case HC_VM_PCI_MSIX_REMAP:
106-
ret = hcall_remap_pci_msix(vm, param1, param2);
119+
/* param1: vmid */
120+
ret = hcall_remap_pci_msix(vm, (uint16_t)param1, param2);
107121
break;
108122

109123
case HC_VM_GPA2HPA:
110-
ret = hcall_gpa_to_hpa(vm, param1, param2);
124+
/* param1: vmid */
125+
ret = hcall_gpa_to_hpa(vm, (uint16_t)param1, param2);
111126
break;
112127

113128
case HC_ASSIGN_PTDEV:
114-
ret = hcall_assign_ptdev(vm, param1, param2);
129+
/* param1: vmid */
130+
ret = hcall_assign_ptdev(vm, (uint16_t)param1, param2);
115131
break;
116132

117133
case HC_DEASSIGN_PTDEV:
118-
ret = hcall_deassign_ptdev(vm, param1, param2);
134+
/* param1: vmid */
135+
ret = hcall_deassign_ptdev(vm, (uint16_t)param1, param2);
119136
break;
120137

121138
case HC_SET_PTDEV_INTR_INFO:
122-
ret = hcall_set_ptdev_intr_info(vm, param1, param2);
139+
/* param1: vmid */
140+
ret = hcall_set_ptdev_intr_info(vm, (uint16_t)param1, param2);
123141
break;
124142

125143
case HC_RESET_PTDEV_INTR_INFO:
126-
ret = hcall_reset_ptdev_intr_info(vm, param1, param2);
144+
/* param1: vmid */
145+
ret = hcall_reset_ptdev_intr_info(vm, (uint16_t)param1, param2);
127146
break;
128147

129148
case HC_SETUP_SBUF:

hypervisor/common/hypercall.c

Lines changed: 27 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -113,8 +113,8 @@ handle_virt_irqline(struct vm *vm, uint16_t target_vmid,
113113
/* Call vpic for pic injection */
114114
ret = handle_vpic_irqline(target_vm, param->pic_irq, mode);
115115

116-
/* call vioapic for ioapic injection if ioapic_irq != ~0UL*/
117-
if (param->ioapic_irq != (~0UL)) {
116+
/* call vioapic for ioapic injection if ioapic_irq != ~0U*/
117+
if (param->ioapic_irq != (~0U)) {
118118
/* handle IOAPIC irqline */
119119
ret = handle_vioapic_irqline(target_vm,
120120
param->ioapic_irq, mode);
@@ -172,7 +172,7 @@ int32_t hcall_create_vm(struct vm *vm, uint64_t param)
172172
return ret;
173173
}
174174

175-
int32_t hcall_destroy_vm(uint64_t vmid)
175+
int32_t hcall_destroy_vm(uint16_t vmid)
176176
{
177177
int32_t ret = 0;
178178
struct vm *target_vm = get_vm_from_vmid(vmid);
@@ -185,7 +185,7 @@ int32_t hcall_destroy_vm(uint64_t vmid)
185185
return ret;
186186
}
187187

188-
int32_t hcall_resume_vm(uint64_t vmid)
188+
int32_t hcall_resume_vm(uint16_t vmid)
189189
{
190190
int32_t ret = 0;
191191
struct vm *target_vm = get_vm_from_vmid(vmid);
@@ -202,7 +202,7 @@ int32_t hcall_resume_vm(uint64_t vmid)
202202
return ret;
203203
}
204204

205-
int32_t hcall_pause_vm(uint64_t vmid)
205+
int32_t hcall_pause_vm(uint16_t vmid)
206206
{
207207
struct vm *target_vm = get_vm_from_vmid(vmid);
208208

@@ -215,7 +215,7 @@ int32_t hcall_pause_vm(uint64_t vmid)
215215
return 0;
216216
}
217217

218-
int32_t hcall_create_vcpu(struct vm *vm, uint64_t vmid, uint64_t param)
218+
int32_t hcall_create_vcpu(struct vm *vm, uint16_t vmid, uint64_t param)
219219
{
220220
int32_t ret;
221221
uint16_t pcpu_id;
@@ -242,7 +242,7 @@ int32_t hcall_create_vcpu(struct vm *vm, uint64_t vmid, uint64_t param)
242242
return ret;
243243
}
244244

245-
int32_t hcall_assert_irqline(struct vm *vm, uint64_t vmid, uint64_t param)
245+
int32_t hcall_assert_irqline(struct vm *vm, uint16_t vmid, uint64_t param)
246246
{
247247
int32_t ret = 0;
248248
struct acrn_irqline irqline;
@@ -251,12 +251,12 @@ int32_t hcall_assert_irqline(struct vm *vm, uint64_t vmid, uint64_t param)
251251
pr_err("%s: Unable copy param to vm\n", __func__);
252252
return -1;
253253
}
254-
ret = handle_virt_irqline(vm, (uint16_t)vmid, &irqline, IRQ_ASSERT);
254+
ret = handle_virt_irqline(vm, vmid, &irqline, IRQ_ASSERT);
255255

256256
return ret;
257257
}
258258

259-
int32_t hcall_deassert_irqline(struct vm *vm, uint64_t vmid, uint64_t param)
259+
int32_t hcall_deassert_irqline(struct vm *vm, uint16_t vmid, uint64_t param)
260260
{
261261
int32_t ret = 0;
262262
struct acrn_irqline irqline;
@@ -265,12 +265,12 @@ int32_t hcall_deassert_irqline(struct vm *vm, uint64_t vmid, uint64_t param)
265265
pr_err("%s: Unable copy param to vm\n", __func__);
266266
return -1;
267267
}
268-
ret = handle_virt_irqline(vm, (uint16_t)vmid, &irqline, IRQ_DEASSERT);
268+
ret = handle_virt_irqline(vm, vmid, &irqline, IRQ_DEASSERT);
269269

270270
return ret;
271271
}
272272

273-
int32_t hcall_pulse_irqline(struct vm *vm, uint64_t vmid, uint64_t param)
273+
int32_t hcall_pulse_irqline(struct vm *vm, uint16_t vmid, uint64_t param)
274274
{
275275
int32_t ret = 0;
276276
struct acrn_irqline irqline;
@@ -279,12 +279,12 @@ int32_t hcall_pulse_irqline(struct vm *vm, uint64_t vmid, uint64_t param)
279279
pr_err("%s: Unable copy param to vm\n", __func__);
280280
return -1;
281281
}
282-
ret = handle_virt_irqline(vm, (uint16_t)vmid, &irqline, IRQ_PULSE);
282+
ret = handle_virt_irqline(vm, vmid, &irqline, IRQ_PULSE);
283283

284284
return ret;
285285
}
286286

287-
int32_t hcall_inject_msi(struct vm *vm, uint64_t vmid, uint64_t param)
287+
int32_t hcall_inject_msi(struct vm *vm, uint16_t vmid, uint64_t param)
288288
{
289289
int32_t ret = 0;
290290
struct acrn_msi_entry msi;
@@ -304,7 +304,7 @@ int32_t hcall_inject_msi(struct vm *vm, uint64_t vmid, uint64_t param)
304304
return ret;
305305
}
306306

307-
int32_t hcall_set_ioreq_buffer(struct vm *vm, uint64_t vmid, uint64_t param)
307+
int32_t hcall_set_ioreq_buffer(struct vm *vm, uint16_t vmid, uint64_t param)
308308
{
309309
int32_t ret = 0;
310310
uint64_t hpa = 0UL;
@@ -370,7 +370,7 @@ static void complete_request(struct vcpu *vcpu)
370370
resume_vcpu(vcpu);
371371
}
372372

373-
int32_t hcall_notify_req_finish(uint64_t vmid, uint64_t vcpu_id)
373+
int32_t hcall_notify_req_finish(uint16_t vmid, uint16_t vcpu_id)
374374
{
375375
union vhm_request_buffer *req_buf;
376376
struct vhm_request *req;
@@ -386,7 +386,7 @@ int32_t hcall_notify_req_finish(uint64_t vmid, uint64_t vcpu_id)
386386
dev_dbg(ACRN_DBG_HYCALL, "[%d] NOTIFY_FINISH for vcpu %d",
387387
vmid, vcpu_id);
388388

389-
vcpu = vcpu_from_vid(target_vm, (uint16_t)vcpu_id);
389+
vcpu = vcpu_from_vid(target_vm, vcpu_id);
390390
if (vcpu == NULL) {
391391
pr_err("%s, failed to get VCPU %d context from VM %d\n",
392392
__func__, vcpu_id, target_vm->attr.id);
@@ -410,7 +410,7 @@ _set_vm_memmap(struct vm *vm, struct vm *target_vm,
410410
struct vm_set_memmap *memmap)
411411
{
412412
uint64_t hpa, base_paddr;
413-
uint32_t attr, prot;
413+
uint64_t attr, prot;
414414

415415
if ((memmap->length & 0xFFFUL) != 0UL) {
416416
pr_err("%s: ERROR! [vm%d] map size 0x%x is not page aligned",
@@ -462,7 +462,7 @@ _set_vm_memmap(struct vm *vm, struct vm *target_vm,
462462
memmap->remote_gpa, memmap->length, memmap->type, attr);
463463
}
464464

465-
int32_t hcall_set_vm_memmap(struct vm *vm, uint64_t vmid, uint64_t param)
465+
int32_t hcall_set_vm_memmap(struct vm *vm, uint16_t vmid, uint64_t param)
466466
{
467467
struct vm_set_memmap memmap;
468468
struct vm *target_vm = get_vm_from_vmid(vmid);
@@ -534,7 +534,7 @@ int32_t hcall_set_vm_memmaps(struct vm *vm, uint64_t param)
534534
return 0;
535535
}
536536

537-
int32_t hcall_remap_pci_msix(struct vm *vm, uint64_t vmid, uint64_t param)
537+
int32_t hcall_remap_pci_msix(struct vm *vm, uint16_t vmid, uint64_t param)
538538
{
539539
int32_t ret = 0;
540540
struct acrn_vm_pci_msix_remap remap;
@@ -575,7 +575,7 @@ int32_t hcall_remap_pci_msix(struct vm *vm, uint64_t vmid, uint64_t param)
575575
return ret;
576576
}
577577

578-
int32_t hcall_gpa_to_hpa(struct vm *vm, uint64_t vmid, uint64_t param)
578+
int32_t hcall_gpa_to_hpa(struct vm *vm, uint16_t vmid, uint64_t param)
579579
{
580580
int32_t ret = 0;
581581
struct vm_gpa2hpa v_gpa2hpa;
@@ -600,7 +600,7 @@ int32_t hcall_gpa_to_hpa(struct vm *vm, uint64_t vmid, uint64_t param)
600600
return ret;
601601
}
602602

603-
int32_t hcall_assign_ptdev(struct vm *vm, uint64_t vmid, uint64_t param)
603+
int32_t hcall_assign_ptdev(struct vm *vm, uint16_t vmid, uint64_t param)
604604
{
605605
int32_t ret;
606606
uint16_t bdf;
@@ -638,7 +638,7 @@ int32_t hcall_assign_ptdev(struct vm *vm, uint64_t vmid, uint64_t param)
638638
return ret;
639639
}
640640

641-
int32_t hcall_deassign_ptdev(struct vm *vm, uint64_t vmid, uint64_t param)
641+
int32_t hcall_deassign_ptdev(struct vm *vm, uint16_t vmid, uint64_t param)
642642
{
643643
int32_t ret = 0;
644644
uint16_t bdf;
@@ -658,7 +658,7 @@ int32_t hcall_deassign_ptdev(struct vm *vm, uint64_t vmid, uint64_t param)
658658
return ret;
659659
}
660660

661-
int32_t hcall_set_ptdev_intr_info(struct vm *vm, uint64_t vmid, uint64_t param)
661+
int32_t hcall_set_ptdev_intr_info(struct vm *vm, uint16_t vmid, uint64_t param)
662662
{
663663
int32_t ret = 0;
664664
struct hc_ptdev_irq irq;
@@ -693,7 +693,7 @@ int32_t hcall_set_ptdev_intr_info(struct vm *vm, uint64_t vmid, uint64_t param)
693693
}
694694

695695
int32_t
696-
hcall_reset_ptdev_intr_info(struct vm *vm, uint64_t vmid, uint64_t param)
696+
hcall_reset_ptdev_intr_info(struct vm *vm, uint16_t vmid, uint64_t param)
697697
{
698698
int32_t ret = 0;
699699
struct hc_ptdev_irq irq;
@@ -752,7 +752,7 @@ int32_t hcall_get_cpu_pm_state(struct vm *vm, uint64_t cmd, uint64_t param)
752752
uint16_t target_vm_id;
753753
struct vm *target_vm;
754754

755-
target_vm_id = (cmd & PMCMD_VMID_MASK) >> PMCMD_VMID_SHIFT;
755+
target_vm_id = (uint16_t)((cmd & PMCMD_VMID_MASK) >> PMCMD_VMID_SHIFT);
756756
target_vm = get_vm_from_vmid(target_vm_id);
757757

758758
if (target_vm == NULL) {
@@ -820,7 +820,8 @@ int32_t hcall_get_cpu_pm_state(struct vm *vm, uint64_t cmd, uint64_t param)
820820
return -1;
821821
}
822822

823-
cx_idx = (cmd & PMCMD_STATE_NUM_MASK) >> PMCMD_STATE_NUM_SHIFT;
823+
cx_idx = (uint8_t)
824+
((cmd & PMCMD_STATE_NUM_MASK) >> PMCMD_STATE_NUM_SHIFT);
824825
if ((cx_idx == 0U) || (cx_idx > target_vm->pm.cx_cnt)) {
825826
return -1;
826827
}

hypervisor/common/io_request.c

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -87,9 +87,9 @@ int32_t acrn_insert_request_wait(struct vcpu *vcpu, struct vhm_request *req)
8787
* before we perform upcall.
8888
* because VHM can work in pulling mode without wait for upcall
8989
*/
90-
req_buf->req_queue[cur].valid = true;
90+
req_buf->req_queue[cur].valid = 1;
9191

92-
acrn_print_request(vcpu->vcpu_id, req_buf->req_queue + cur);
92+
acrn_print_request(vcpu->vcpu_id, &req_buf->req_queue[cur]);
9393

9494
/* signal VHM */
9595
fire_vhm_interrupt();
@@ -99,11 +99,11 @@ int32_t acrn_insert_request_wait(struct vcpu *vcpu, struct vhm_request *req)
9999

100100
#ifdef HV_DEBUG
101101
static void _get_req_info_(struct vhm_request *req, int *id, char *type,
102-
char *state, char *dir, int64_t *addr, long *val)
102+
char *state, char *dir, uint64_t *addr, uint64_t *val)
103103
{
104104
(void)strcpy_s(dir, 16U, "NONE");
105-
*addr = 0;
106-
*val = 0;
105+
*addr = 0UL;
106+
*val = 0UL;
107107
*id = req->client;
108108

109109
switch (req->type) {
@@ -158,7 +158,7 @@ void get_req_info(char *str, int str_max)
158158
union vhm_request_buffer *req_buf;
159159
struct vhm_request *req;
160160
char type[16], state[16], dir[16];
161-
int64_t addr, val;
161+
uint64_t addr, val;
162162
struct list_head *pos;
163163
struct vm *vm;
164164

hypervisor/common/ptdev.c

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -177,5 +177,3 @@ void ptdev_release_all_entries(struct vm *vm)
177177
release_all_entries(vm);
178178
spinlock_release(&ptdev_lock);
179179
}
180-
181-

0 commit comments

Comments
 (0)