Skip to content

Commit aa5027a

Browse files
Shawnshhlijinxia
authored andcommitted
HV:misc:fix "signed/unsigned conversion with cast"
Signed/unsigned conversion should add cast explicitily or change the type of them to the same. V1->V2:Fixed the 0U to 0UL because of the mistakes. V2->V3:remove unsed macro Signed-off-by: HuiHuang Shi <huihuang.shi@intel.com> Acked-by: Eddie Dong <eddie.dong@intel.com>
1 parent 619c600 commit aa5027a

File tree

12 files changed

+97
-94
lines changed

12 files changed

+97
-94
lines changed

hypervisor/arch/x86/assign.c

Lines changed: 18 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,9 @@
99
static inline uint32_t
1010
entry_id_from_msix(uint16_t bdf, int8_t index)
1111
{
12-
uint32_t id = index;
12+
uint32_t id = (uint8_t)index;
1313

14-
id = bdf | (id << 16) | (PTDEV_INTR_MSI << 24);
14+
id = bdf | (id << 16U) | (PTDEV_INTR_MSI << 24);
1515
return id;
1616
}
1717

@@ -232,7 +232,7 @@ static uint64_t ptdev_build_physical_rte(struct vm *vm,
232232
struct ptdev_remapping_info *entry)
233233
{
234234
uint64_t rte;
235-
int phys_irq = dev_to_irq(entry->node);
235+
uint32_t phys_irq = dev_to_irq(entry->node);
236236
uint32_t vector = dev_to_vector(entry->node);
237237

238238
if (entry->ptdev_intr_info.intx.vpin_src == PTDEV_VPIN_IOAPIC) {
@@ -553,12 +553,12 @@ void ptdev_softirq(__unused uint16_t cpu_id)
553553
}
554554
}
555555

556-
void ptdev_intx_ack(struct vm *vm, int virt_pin,
556+
void ptdev_intx_ack(struct vm *vm, uint8_t virt_pin,
557557
enum ptdev_vpin_source vpin_src)
558558
{
559559
uint32_t phys_irq;
560560
struct ptdev_remapping_info *entry;
561-
int phys_pin;
561+
uint8_t phys_pin;
562562

563563
entry = lookup_entry_by_vintx(vm, virt_pin, vpin_src);
564564
if (entry == NULL) {
@@ -632,7 +632,7 @@ int ptdev_msix_remap(struct vm *vm, uint16_t virt_bdf,
632632
}
633633

634634
/* handle destroy case */
635-
if (is_entry_active(entry) && info->vmsi_data == 0) {
635+
if (is_entry_active(entry) && info->vmsi_data == 0U) {
636636
info->pmsi_data = 0U;
637637
ptdev_deactivate_entry(entry);
638638
goto END;
@@ -712,7 +712,7 @@ int ptdev_intx_pin_remap(struct vm *vm, struct ptdev_intx_info *info)
712712
struct ptdev_remapping_info *entry;
713713
uint64_t rte;
714714
uint32_t phys_irq;
715-
int phys_pin;
715+
uint8_t phys_pin;
716716
bool lowpri = !is_vm0(vm);
717717
bool need_switch_vpin_src = false;
718718

@@ -807,7 +807,7 @@ int ptdev_intx_pin_remap(struct vm *vm, struct ptdev_intx_info *info)
807807
ptdev_deactivate_entry(entry);
808808
}
809809
dev_dbg(ACRN_DBG_IRQ,
810-
"IOAPIC pin=%d pirq=%d vpin=%d switch from %s to %s "
810+
"IOAPIC pin=%hhu pirq=%u vpin=%d switch from %s to %s "
811811
"vpin=%d for vm%d", phys_pin, phys_irq,
812812
entry->ptdev_intr_info.intx.virt_pin,
813813
(entry->ptdev_intr_info.intx.vpin_src != 0)?
@@ -829,7 +829,7 @@ int ptdev_intx_pin_remap(struct vm *vm, struct ptdev_intx_info *info)
829829
GSI_MASK_IRQ(phys_irq);
830830
ptdev_deactivate_entry(entry);
831831
dev_dbg(ACRN_DBG_IRQ,
832-
"IOAPIC pin=%d pirq=%d deassigned ",
832+
"IOAPIC pin=%hhu pirq=%u deassigned ",
833833
phys_pin, phys_irq);
834834
dev_dbg(ACRN_DBG_IRQ, "from vm%d vIOAPIC vpin=%d",
835835
entry->vm->attr.id,
@@ -852,7 +852,7 @@ int ptdev_intx_pin_remap(struct vm *vm, struct ptdev_intx_info *info)
852852
activate_physical_ioapic(vm, entry);
853853

854854
dev_dbg(ACRN_DBG_IRQ,
855-
"IOAPIC pin=%d pirq=%d assigned to vm%d %s vpin=%d",
855+
"IOAPIC pin=%hhu pirq=%u assigned to vm%d %s vpin=%d",
856856
phys_pin, phys_irq, entry->vm->attr.id,
857857
entry->ptdev_intr_info.intx.vpin_src == PTDEV_VPIN_PIC ?
858858
"vPIC" : "vIOAPIC",
@@ -937,7 +937,7 @@ void ptdev_remove_msix_remapping(struct vm *vm, uint16_t virt_bdf,
937937
#ifdef HV_DEBUG
938938
static void get_entry_info(struct ptdev_remapping_info *entry, char *type,
939939
uint32_t *irq, uint32_t *vector, uint64_t *dest, bool *lvl_tm,
940-
int *pin, int *vpin, int *bdf, int *vbdf)
940+
int *pin, int *vpin, uint32_t *bdf, uint32_t *vbdf)
941941
{
942942
if (is_entry_active(entry)) {
943943
if (entry->type == PTDEV_INTR_MSI) {
@@ -955,7 +955,7 @@ static void get_entry_info(struct ptdev_remapping_info *entry, char *type,
955955
*bdf = entry->phys_bdf;
956956
*vbdf = entry->virt_bdf;
957957
} else {
958-
int phys_irq = pin_to_irq(
958+
uint32_t phys_irq = pin_to_irq(
959959
entry->ptdev_intr_info.intx.phys_pin);
960960
uint64_t rte = 0;
961961

@@ -974,8 +974,8 @@ static void get_entry_info(struct ptdev_remapping_info *entry, char *type,
974974
}
975975
*pin = entry->ptdev_intr_info.intx.phys_pin;
976976
*vpin = entry->ptdev_intr_info.intx.virt_pin;
977-
*bdf = 0;
978-
*vbdf = 0;
977+
*bdf = 0U;
978+
*vbdf = 0U;
979979
}
980980
*irq = dev_to_irq(entry->node);
981981
*vector = dev_to_vector(entry->node);
@@ -987,8 +987,8 @@ static void get_entry_info(struct ptdev_remapping_info *entry, char *type,
987987
*lvl_tm = 0;
988988
*pin = -1;
989989
*vpin = -1;
990-
*bdf = 0;
991-
*vbdf = 0;
990+
*bdf = 0U;
991+
*vbdf = 0U;
992992
}
993993
}
994994

@@ -1000,7 +1000,8 @@ void get_ptdev_info(char *str, int str_max)
10001000
char type[16];
10011001
uint64_t dest;
10021002
bool lvl_tm;
1003-
int pin, vpin, bdf, vbdf;
1003+
int32_t pin, vpin;
1004+
uint32_t bdf, vbdf;
10041005
struct list_head *pos;
10051006

10061007
len = snprintf(str, size,

hypervisor/arch/x86/vtd.c

Lines changed: 39 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -23,31 +23,31 @@
2323
#define IOMMU_INIT_BUS_LIMIT (0xf)
2424

2525
#define PAGE_MASK (0xFFFUL)
26-
#define LEVEL_WIDTH 9
26+
#define LEVEL_WIDTH 9U
2727

28-
#define ROOT_ENTRY_LOWER_PRESENT_POS (0)
29-
#define ROOT_ENTRY_LOWER_PRESENT_MASK ((uint64_t)1)
30-
#define ROOT_ENTRY_LOWER_CTP_POS (12)
31-
#define ROOT_ENTRY_LOWER_CTP_MASK ((uint64_t)0xFFFFFFFFFFFFF)
28+
#define ROOT_ENTRY_LOWER_PRESENT_POS (0U)
29+
#define ROOT_ENTRY_LOWER_PRESENT_MASK (1UL)
30+
#define ROOT_ENTRY_LOWER_CTP_POS (12U)
31+
#define ROOT_ENTRY_LOWER_CTP_MASK (0xFFFFFFFFFFFFFUL)
3232

33-
#define CTX_ENTRY_UPPER_AW_POS (0)
33+
#define CTX_ENTRY_UPPER_AW_POS (0U)
3434
#define CTX_ENTRY_UPPER_AW_MASK \
35-
((uint64_t)0x7 << CTX_ENTRY_UPPER_AW_POS)
36-
#define CTX_ENTRY_UPPER_DID_POS (8)
35+
(0x7UL << CTX_ENTRY_UPPER_AW_POS)
36+
#define CTX_ENTRY_UPPER_DID_POS (8U)
3737
#define CTX_ENTRY_UPPER_DID_MASK \
38-
((uint64_t)0x3F << CTX_ENTRY_UPPER_DID_POS)
39-
#define CTX_ENTRY_LOWER_P_POS (0)
38+
(0x3FUL << CTX_ENTRY_UPPER_DID_POS)
39+
#define CTX_ENTRY_LOWER_P_POS (0U)
4040
#define CTX_ENTRY_LOWER_P_MASK \
41-
((uint64_t)0x1 << CTX_ENTRY_LOWER_P_POS)
42-
#define CTX_ENTRY_LOWER_FPD_POS (1)
41+
(0x1UL << CTX_ENTRY_LOWER_P_POS)
42+
#define CTX_ENTRY_LOWER_FPD_POS (1U)
4343
#define CTX_ENTRY_LOWER_FPD_MASK \
44-
((uint64_t)0x1 << CTX_ENTRY_LOWER_FPD_POS)
45-
#define CTX_ENTRY_LOWER_TT_POS (2)
44+
(0x1UL << CTX_ENTRY_LOWER_FPD_POS)
45+
#define CTX_ENTRY_LOWER_TT_POS (2U)
4646
#define CTX_ENTRY_LOWER_TT_MASK \
47-
((uint64_t)0x3 << CTX_ENTRY_LOWER_TT_POS)
48-
#define CTX_ENTRY_LOWER_SLPTPTR_POS (12)
47+
(0x3UL << CTX_ENTRY_LOWER_TT_POS)
48+
#define CTX_ENTRY_LOWER_SLPTPTR_POS (12U)
4949
#define CTX_ENTRY_LOWER_SLPTPTR_MASK \
50-
((uint64_t)0xFFFFFFFFFFFFF << CTX_ENTRY_LOWER_SLPTPTR_POS)
50+
(0xFFFFFFFFFFFFFUL << CTX_ENTRY_LOWER_SLPTPTR_POS)
5151

5252
#define DMAR_GET_BITSLICE(var, bitname) \
5353
((var & bitname ## _MASK) >> bitname ## _POS)
@@ -57,14 +57,14 @@
5757
~bitname ## _MASK) | ((val << bitname ## _POS) & bitname ## _MASK))
5858

5959
/* translation type */
60-
#define DMAR_CTX_TT_UNTRANSLATED 0x0
61-
#define DMAR_CTX_TT_ALL 0x1
62-
#define DMAR_CTX_TT_PASSTHROUGH 0x2
60+
#define DMAR_CTX_TT_UNTRANSLATED 0x0UL
61+
#define DMAR_CTX_TT_ALL 0x1UL
62+
#define DMAR_CTX_TT_PASSTHROUGH 0x2UL
6363

6464
/* Fault event MSI data register */
65-
#define DMAR_MSI_DELIVERY_MODE_SHIFT (8)
66-
#define DMAR_MSI_DELIVERY_FIXED (0 << DMAR_MSI_DELIVERY_MODE_SHIFT)
67-
#define DMAR_MSI_DELIVERY_LOWPRI (1 << DMAR_MSI_DELIVERY_MODE_SHIFT)
65+
#define DMAR_MSI_DELIVERY_MODE_SHIFT (8U)
66+
#define DMAR_MSI_DELIVERY_FIXED (0U << DMAR_MSI_DELIVERY_MODE_SHIFT)
67+
#define DMAR_MSI_DELIVERY_LOWPRI (1U << DMAR_MSI_DELIVERY_MODE_SHIFT)
6868

6969
/* Fault event MSI address register */
7070
#define DMAR_MSI_DEST_MODE_SHIFT (2)
@@ -312,37 +312,38 @@ static void dmar_uint_show_capability(struct dmar_drhd_rt *dmar_uint)
312312
}
313313
#endif
314314

315-
static inline uint8_t width_to_level(int width)
315+
static inline uint8_t width_to_level(uint32_t width)
316316
{
317-
return ((width - 12) + (LEVEL_WIDTH)-1) / (LEVEL_WIDTH);
317+
return ((width - 12U) + (LEVEL_WIDTH)-1U) / (LEVEL_WIDTH);
318318
}
319319

320-
static inline uint8_t width_to_agaw(int width)
320+
static inline uint8_t width_to_agaw(uint32_t width)
321321
{
322-
return width_to_level(width) - 2;
322+
return width_to_level(width) - 2U;
323323
}
324324

325325
static uint8_t dmar_uint_get_msagw(struct dmar_drhd_rt *dmar_uint)
326326
{
327-
int i;
327+
uint8_t i;
328328
uint8_t sgaw = iommu_cap_sagaw(dmar_uint->cap);
329329

330-
for (i = 4; i >= 0; i--) {
331-
if (((1 << i) & sgaw) != 0) {
330+
for (i = 5U; i > 0U;) {
331+
i--;
332+
if (((1U << i) & sgaw) != 0U) {
332333
break;
333334
}
334335
}
335-
return (uint8_t)i;
336+
return i;
336337
}
337338

338339
static bool
339340
dmar_unit_support_aw(struct dmar_drhd_rt *dmar_uint, uint32_t addr_width)
340341
{
341342
uint8_t aw;
342343

343-
aw = (uint8_t)width_to_agaw(addr_width);
344+
aw = width_to_agaw(addr_width);
344345

345-
return ((1U << aw) & iommu_cap_sagaw(dmar_uint->cap)) != 0;
346+
return (((1U << aw) & iommu_cap_sagaw(dmar_uint->cap)) != 0U);
346347
}
347348

348349
static void dmar_enable_translation(struct dmar_drhd_rt *dmar_uint)
@@ -390,6 +391,7 @@ static void dmar_register_hrhd(struct dmar_drhd_rt *dmar_uint)
390391
dmar_uint->gcmd = iommu_read64(dmar_uint, DMAR_GCMD_REG);
391392

392393
dmar_uint->cap_msagaw = dmar_uint_get_msagw(dmar_uint);
394+
393395
dmar_uint->cap_num_fault_regs =
394396
iommu_cap_num_fault_regs(dmar_uint->cap);
395397
dmar_uint->cap_fault_reg_offset =
@@ -508,7 +510,7 @@ static uint8_t alloc_domain_id(void)
508510

509511
static void free_domain_id(uint16_t dom_id)
510512
{
511-
uint64_t mask = (1 << dom_id);
513+
uint64_t mask = (1UL << dom_id);
512514

513515
spinlock_obtain(&domain_lock);
514516
domain_bitmap &= ~mask;
@@ -577,7 +579,7 @@ static void dmar_invalid_context_cache(struct dmar_drhd_rt *dmar_uint,
577579
IOMMU_LOCK(dmar_uint);
578580
iommu_write64(dmar_uint, DMAR_CCMD_REG, cmd);
579581
/* read upper 32bits to check */
580-
DMAR_WAIT_COMPLETION(DMAR_CCMD_REG + 4, (status & DMA_CCMD_ICC_32) == 0U,
582+
DMAR_WAIT_COMPLETION(DMAR_CCMD_REG + 4U, (status & DMA_CCMD_ICC_32) == 0U,
581583
status);
582584

583585
IOMMU_UNLOCK(dmar_uint);
@@ -867,7 +869,7 @@ static void dmar_disable(struct dmar_drhd_rt *dmar_uint)
867869
}
868870

869871
struct iommu_domain *create_iommu_domain(uint16_t vm_id, uint64_t translation_table,
870-
int addr_width)
872+
uint32_t addr_width)
871873
{
872874
struct iommu_domain *domain;
873875
uint16_t domain_id;
@@ -1172,7 +1174,7 @@ void disable_iommu(void)
11721174
}
11731175

11741176
/* 4 iommu fault register state */
1175-
#define IOMMU_FAULT_REGISTER_STATE_NUM 4
1177+
#define IOMMU_FAULT_REGISTER_STATE_NUM 4U
11761178
static uint32_t
11771179
iommu_fault_state[CONFIG_MAX_IOMMU_NUM][IOMMU_FAULT_REGISTER_STATE_NUM];
11781180

hypervisor/common/hv_main.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,9 +20,9 @@ static void run_vcpu_pre_work(struct vcpu *vcpu)
2020

2121
void vcpu_thread(struct vcpu *vcpu)
2222
{
23-
uint64_t vmexit_begin = 0, vmexit_end = 0;
24-
uint16_t basic_exit_reason = 0;
25-
uint64_t tsc_aux_hyp_cpu = vcpu->pcpu_id;
23+
uint64_t vmexit_begin = 0UL, vmexit_end = 0UL;
24+
uint16_t basic_exit_reason = 0U;
25+
uint64_t tsc_aux_hyp_cpu = (uint64_t) vcpu->pcpu_id;
2626
int32_t ret = 0;
2727

2828
/* If vcpu is not launched, we need to do init_vmcs first */

hypervisor/common/hypercall.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -623,7 +623,7 @@ int64_t hcall_assign_ptdev(struct vm *vm, uint64_t vmid, uint64_t param)
623623
}
624624
/* TODO: how to get vm's address width? */
625625
target_vm->iommu_domain = create_iommu_domain(vmid,
626-
target_vm->arch_vm.nworld_eptp, 48);
626+
target_vm->arch_vm.nworld_eptp, 48U);
627627
if (target_vm->iommu_domain == NULL) {
628628
return -ENODEV;
629629
}

hypervisor/common/io_request.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ int32_t acrn_insert_request_wait(struct vcpu *vcpu, struct vhm_request *req)
6060
union vhm_request_buffer *req_buf = NULL;
6161
uint16_t cur;
6262

63-
ASSERT(sizeof(*req) == (4096/VHM_REQUEST_MAX),
63+
ASSERT(sizeof(*req) == (4096U/VHM_REQUEST_MAX),
6464
"vhm_request page broken!");
6565

6666

@@ -99,7 +99,7 @@ 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, long *addr, long *val)
102+
char *state, char *dir, int64_t *addr, long *val)
103103
{
104104
(void)strcpy_s(dir, 16, "NONE");
105105
*addr = 0;

hypervisor/common/ptdev.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -128,7 +128,7 @@ static int ptdev_interrupt_handler(__unused int irq, void *data)
128128

129129
/* active intr with irq registering */
130130
void
131-
ptdev_activate_entry(struct ptdev_remapping_info *entry, int phys_irq,
131+
ptdev_activate_entry(struct ptdev_remapping_info *entry, uint32_t phys_irq,
132132
bool lowpri)
133133
{
134134
struct dev_handler_node *node;

hypervisor/common/vm_load.c

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -56,8 +56,8 @@ static uint64_t create_zero_page(struct vm *vm)
5656
(uint32_t)(uint64_t)sw_linux->bootargs_load_addr;
5757

5858
/* set constant arguments in zero page */
59-
zeropage->hdr.loader_type = 0xff;
60-
zeropage->hdr.load_flags |= (1U << 5); /* quiet */
59+
zeropage->hdr.loader_type = 0xffU;
60+
zeropage->hdr.load_flags |= (1U << 5U); /* quiet */
6161

6262
/* Create/add e820 table entries in zeropage */
6363
zeropage->e820_nentries = create_e820_table(zeropage->e820);
@@ -82,7 +82,7 @@ int load_guest(struct vm *vm, struct vcpu *vcpu)
8282

8383
/* hardcode vcpu entry addr(kernel entry) & rsi (zeropage)*/
8484
(void)memset(cur_context->guest_cpu_regs.longs,
85-
0, sizeof(uint64_t)*NUM_GPRS);
85+
0U, sizeof(uint64_t)*NUM_GPRS);
8686

8787
hva = GPA2HVA(vm, lowmem_gpa_top -
8888
MEM_4K - MEM_2K);
@@ -122,10 +122,10 @@ int general_sw_loader(struct vm *vm, struct vcpu *vcpu)
122122
/* calculate the kernel entry point */
123123
zeropage = (struct zero_page *)
124124
vm->sw.kernel_info.kernel_src_addr;
125-
kernel_entry_offset = (zeropage->hdr.setup_sects + 1) * 512;
125+
kernel_entry_offset = (zeropage->hdr.setup_sects + 1U) * 512U;
126126
if (vcpu->arch_vcpu.cpu_mode == CPU_MODE_64BIT) {
127127
/* 64bit entry is the 512bytes after the start */
128-
kernel_entry_offset += 512;
128+
kernel_entry_offset += 512U;
129129
}
130130

131131
vm->sw.kernel_info.kernel_entry_addr =
@@ -152,7 +152,7 @@ int general_sw_loader(struct vm *vm, struct vcpu *vcpu)
152152
* zeropage
153153
*/
154154
(void)memset(cur_context->guest_cpu_regs.longs,
155-
0, sizeof(uint64_t) * NUM_GPRS);
155+
0U, sizeof(uint64_t) * NUM_GPRS);
156156

157157
/* Get host-physical address for guest bootargs */
158158
hva = GPA2HVA(vm,

hypervisor/include/arch/x86/assign.h

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

1010
#include <ptdev.h>
1111

12-
void ptdev_intx_ack(struct vm *vm, int virt_pin,
12+
void ptdev_intx_ack(struct vm *vm, uint8_t virt_pin,
1313
enum ptdev_vpin_source vpin_src);
1414
int ptdev_msix_remap(struct vm *vm, uint16_t virt_bdf,
1515
struct ptdev_msi_info *info);

0 commit comments

Comments
 (0)