Skip to content

Commit 366042c

Browse files
shiqingglijinxia
authored andcommitted
hv: fix integer violations
- Fix the integer violations related to the following rules: 1. The operands to shift operations (<<, >>) shall be unsigned integers. 2. The operands to bit operations (&, |, ~) shall be unsigned integers. - Replace 12U with CPU_PAGE_SHIFT when it is address shift case. v1 -> v2: * use existed MACRO to get bus/slot/func values * update PCI_SLOT MACRO to make it more straightforward * remove the incorrect replacement of 12U with CPU_PAGE_SHIFT dmar_fault_msi_write Tracked-On: #861 Signed-off-by: Shiqing Gao <shiqing.gao@intel.com> Acked-by: Eddie Dong <eddie.dong@intel.com>
1 parent 65a2613 commit 366042c

File tree

10 files changed

+20
-22
lines changed

10 files changed

+20
-22
lines changed

hypervisor/arch/x86/assign.c

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,7 @@ static void ptdev_build_physical_msi(struct acrn_vm *vm, struct ptdev_msi_info *
9797
/* update physical dest mode & dest field */
9898
info->pmsi_addr = info->vmsi_addr;
9999
info->pmsi_addr &= ~0xFF00CU;
100-
info->pmsi_addr |= (dest_mask << 12U) | MSI_ADDR_RH | MSI_ADDR_LOG;
100+
info->pmsi_addr |= (dest_mask << CPU_PAGE_SHIFT) | MSI_ADDR_RH | MSI_ADDR_LOG;
101101

102102
dev_dbg(ACRN_DBG_IRQ, "MSI addr:data = 0x%llx:%x(V) -> 0x%llx:%x(P)",
103103
info->vmsi_addr, info->vmsi_data,
@@ -578,13 +578,9 @@ int ptdev_msix_remap(struct acrn_vm *vm, uint16_t virt_bdf,
578578
ptdev_build_physical_msi(vm, info, irq_to_vector(entry->allocated_pirq));
579579
entry->msi = *info;
580580

581-
dev_dbg(ACRN_DBG_IRQ,
582-
"PCI %x:%x.%x MSI VR[%d] 0x%x->0x%x assigned to vm%d",
583-
(virt_bdf >> 8) & 0xFFU, (virt_bdf >> 3) & 0x1FU,
584-
(virt_bdf) & 0x7U, entry_nr,
585-
info->vmsi_data & 0xFFU,
586-
irq_to_vector(entry->allocated_pirq),
587-
entry->vm->vm_id);
581+
dev_dbg(ACRN_DBG_IRQ, "PCI %x:%x.%x MSI VR[%d] 0x%x->0x%x assigned to vm%d",
582+
PCI_BUS(virt_bdf), PCI_SLOT(virt_bdf), PCI_FUNC(virt_bdf), entry_nr,
583+
info->vmsi_data & 0xFFU, irq_to_vector(entry->allocated_pirq), entry->vm->vm_id);
588584
END:
589585
return 0;
590586
}

hypervisor/arch/x86/guest/guest.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -294,7 +294,7 @@ int gva2gpa(struct acrn_vcpu *vcpu, uint64_t gva, uint64_t *gpa,
294294
* So we use DPL of SS access rights field for guest DPL.
295295
*/
296296
pw_info.is_user_mode_access =
297-
(((exec_vmread32(VMX_GUEST_SS_ATTR)>>5) & 0x3U) == 3U);
297+
(((exec_vmread32(VMX_GUEST_SS_ATTR) >> 5U) & 0x3U) == 3U);
298298
pw_info.pse = true;
299299
pw_info.nxe = ((vcpu_get_efer(vcpu) & MSR_IA32_EFER_NXE_BIT) != 0UL);
300300
pw_info.wp = ((vcpu_get_cr0(vcpu) & CR0_WP) != 0UL);

hypervisor/arch/x86/guest/instr_emul.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -392,7 +392,7 @@ static void get_guest_paging_info(struct acrn_vcpu *vcpu, struct instr_emul_ctxt
392392
{
393393
uint8_t cpl;
394394

395-
cpl = (uint8_t)((csar >> 5) & 3U);
395+
cpl = (uint8_t)((csar >> 5U) & 3U);
396396
emul_ctxt->paging.cr3 = exec_vmread(VMX_GUEST_CR3);
397397
emul_ctxt->paging.cpl = cpl;
398398
emul_ctxt->paging.cpu_mode = get_vcpu_mode(vcpu);

hypervisor/arch/x86/guest/vcpu.c

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -167,10 +167,12 @@ static void set_vcpu_mode(struct acrn_vcpu *vcpu, uint32_t cs_attr, uint64_t ia3
167167
uint64_t cr0)
168168
{
169169
if (ia32_efer & MSR_IA32_EFER_LMA_BIT) {
170-
if (cs_attr & 0x2000) /* CS.L = 1 */
170+
if (cs_attr & 0x2000U) {
171+
/* CS.L = 1 */
171172
vcpu->arch.cpu_mode = CPU_MODE_64BIT;
172-
else
173+
} else {
173174
vcpu->arch.cpu_mode = CPU_MODE_COMPATIBILITY;
175+
}
174176
} else if (cr0 & CR0_PE) {
175177
vcpu->arch.cpu_mode = CPU_MODE_PROTECTED;
176178
} else {

hypervisor/arch/x86/vtd.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1037,7 +1037,7 @@ static int add_iommu_device(const struct iommu_domain *domain, uint16_t segment,
10371037
lower = dmar_set_bitslice(lower,
10381038
CTX_ENTRY_LOWER_SLPTPTR_MASK,
10391039
CTX_ENTRY_LOWER_SLPTPTR_POS,
1040-
domain->trans_table_ptr >> 12U);
1040+
domain->trans_table_ptr >> CPU_PAGE_SHIFT);
10411041
lower = dmar_set_bitslice(lower,
10421042
CTX_ENTRY_LOWER_P_MASK,
10431043
CTX_ENTRY_LOWER_P_POS,

hypervisor/boot/dmar_parse.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -198,8 +198,8 @@ handle_dmar_devscope(struct dmar_dev_scope *dev_scope,
198198
sizeof(struct acpi_dmar_pci_path);
199199

200200
bdf = dmar_path_bdf(path_len, apci_devscope->bus, path);
201-
dev_scope->bus = (bdf >> 8) & 0xff;
202-
dev_scope->devfun = bdf & 0xff;
201+
dev_scope->bus = (bdf >> 8U) & 0xffU;
202+
dev_scope->devfun = bdf & 0xffU;
203203

204204
return apci_devscope->length;
205205
}

hypervisor/boot/reloc.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -176,7 +176,7 @@ static void update_trampoline_code_refs(uint64_t dest_pa)
176176
val = dest_pa + trampoline_relo_addr(&trampoline_fixup_target);
177177

178178
ptr = hpa2hva(dest_pa + trampoline_relo_addr(&trampoline_fixup_cs));
179-
*(uint16_t *)(ptr) = (uint16_t)((val >> 4) & 0xFFFFU);
179+
*(uint16_t *)(ptr) = (uint16_t)((val >> 4U) & 0xFFFFU);
180180

181181
ptr = hpa2hva(dest_pa + trampoline_relo_addr(&trampoline_fixup_ip));
182182
*(uint16_t *)(ptr) = (uint16_t)(val & 0xfU);

hypervisor/common/hypercall.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -812,7 +812,7 @@ int32_t hcall_assign_ptdev(struct acrn_vm *vm, uint16_t vmid, uint64_t param)
812812

813813
}
814814
ret = assign_iommu_device(target_vm->iommu,
815-
(uint8_t)(bdf >> 8), (uint8_t)(bdf & 0xffU));
815+
(uint8_t)(bdf >> 8U), (uint8_t)(bdf & 0xffU));
816816

817817
return ret;
818818
}
@@ -843,7 +843,7 @@ int32_t hcall_deassign_ptdev(struct acrn_vm *vm, uint16_t vmid, uint64_t param)
843843
return -1;
844844
}
845845
ret = unassign_iommu_device(target_vm->iommu,
846-
(uint8_t)(bdf >> 8), (uint8_t)(bdf & 0xffU));
846+
(uint8_t)(bdf >> 8U), (uint8_t)(bdf & 0xffU));
847847

848848
return ret;
849849
}

hypervisor/common/vm_load.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -168,7 +168,7 @@ int general_sw_loader(struct acrn_vm *vm)
168168
/* add "cma=XXXXM@0xXXXXXXXX" to cmdline*/
169169
if (is_vm0(vm) && (e820_mem.max_ram_blk_size > 0)) {
170170
snprintf(dyn_bootargs, 100U, " cma=%dM@0x%llx",
171-
(e820_mem.max_ram_blk_size >> 20),
171+
(e820_mem.max_ram_blk_size >> 20U),
172172
e820_mem.max_ram_blk_base);
173173
(void)strcpy_s((char *)hva
174174
+ sw_linux->bootargs_size,
@@ -183,10 +183,10 @@ int general_sw_loader(struct acrn_vm *vm)
183183
int32_t reserving_1g_pages;
184184

185185
#ifdef CONFIG_REMAIN_1G_PAGES
186-
reserving_1g_pages = (e820_mem.total_mem_size >> 30) -
186+
reserving_1g_pages = (e820_mem.total_mem_size >> 30U) -
187187
CONFIG_REMAIN_1G_PAGES;
188188
#else
189-
reserving_1g_pages = (e820_mem.total_mem_size >> 30) -
189+
reserving_1g_pages = (e820_mem.total_mem_size >> 30U) -
190190
3;
191191
#endif
192192
if (reserving_1g_pages > 0) {

hypervisor/include/dm/pci.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@
5050
#define PCI_REGMAX 0xFFU
5151

5252
#define PCI_BUS(bdf) (((bdf) >> 8U) & 0xFFU)
53-
#define PCI_SLOT(bdf) (((bdf) >> 3U) & 0x1FU)
53+
#define PCI_SLOT(bdf) (((bdf) & 0xFFU) >> 3U)
5454
#define PCI_FUNC(bdf) ((bdf) & 0x7U)
5555

5656
/* I/O ports */

0 commit comments

Comments
 (0)