Skip to content

Commit f81fcf2

Browse files
wuxyintellijinxia
authored andcommitted
HV:MM:add 'U/UL' suffix for unsigned contant value
In the current memory module, there are many constatn value without U/UL suffix, it is reported as MISRA C violations by static analysis tool. Add 'U/UL' suffix for unsigned contant value in memory module as needed. Note:In the most case, CPU_PAGE_SIZE(0x1000) is used as unsigned integer contant value, so CPU_PAGE_SIZE is defined as unsigned integer contant value, and it is safety converted into unsigned long type according to MISRA C standard. Signed-off-by: Xiangyang Wu <xiangyang.wu@intel.com> Acked-by: Eddie Dong <eddie.dong@intel.com>
1 parent b25caad commit f81fcf2

File tree

11 files changed

+41
-41
lines changed

11 files changed

+41
-41
lines changed

hypervisor/arch/x86/ept.c

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -9,14 +9,14 @@
99
#include "guest/instr_emul_wrapper.h"
1010
#include "guest/instr_emul.h"
1111

12-
#define ACRN_DBG_EPT 6
12+
#define ACRN_DBG_EPT 6U
1313

1414

1515
static uint64_t find_next_table(uint32_t table_offset, void *table_base)
1616
{
1717
uint64_t table_entry;
1818
uint64_t table_present;
19-
uint64_t sub_table_addr = 0;
19+
uint64_t sub_table_addr = 0UL;
2020

2121
/* Read the table entry */
2222
table_entry = mem_read64(table_base
@@ -31,7 +31,7 @@ static uint64_t find_next_table(uint32_t table_offset, void *table_base)
3131
table_present = (IA32E_EPT_R_BIT | IA32E_EPT_W_BIT | IA32E_EPT_X_BIT);
3232

3333
/* Determine if a valid entry exists */
34-
if ((table_entry & table_present) == 0) {
34+
if ((table_entry & table_present) == 0UL) {
3535
/* No entry present */
3636
return sub_table_addr;
3737
}
@@ -111,8 +111,8 @@ void destroy_ept(struct vm *vm)
111111

112112
uint64_t _gpa2hpa(struct vm *vm, uint64_t gpa, uint32_t *size)
113113
{
114-
uint64_t hpa = 0;
115-
uint32_t pg_size = 0;
114+
uint64_t hpa = 0UL;
115+
uint32_t pg_size = 0U;
116116
struct entry_params entry;
117117
struct map_params map_params;
118118

@@ -221,7 +221,7 @@ int register_mmio_emulation_handler(struct vm *vm,
221221
if ((read_write != NULL) && (end > start)) {
222222
/* Allocate memory for node */
223223
mmio_node =
224-
(struct mem_io_node *)calloc(1, sizeof(struct mem_io_node));
224+
(struct mem_io_node *)calloc(1U, sizeof(struct mem_io_node));
225225

226226
/* Ensure memory successfully allocated */
227227
if (mmio_node != NULL) {
@@ -460,7 +460,7 @@ int ept_misconfig_vmexit_handler(__unused struct vcpu *vcpu)
460460

461461
ASSERT(status == 0, "EPT Misconfiguration is not handled.\n");
462462

463-
TRACE_2L(TRACE_VMEXIT_EPT_MISCONFIGURATION, 0, 0);
463+
TRACE_2L(TRACE_VMEXIT_EPT_MISCONFIGURATION, 0UL, 0UL);
464464

465465
return status;
466466
}

hypervisor/arch/x86/mmu.c

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -165,12 +165,12 @@ void flush_vpid_single(int vpid)
165165
if (vpid == 0)
166166
return;
167167

168-
_invvpid(VMX_VPID_TYPE_SINGLE_CONTEXT, vpid, 0);
168+
_invvpid(VMX_VPID_TYPE_SINGLE_CONTEXT, vpid, 0UL);
169169
}
170170

171171
void flush_vpid_global(void)
172172
{
173-
_invvpid(VMX_VPID_TYPE_ALL_CONTEXT, 0, 0);
173+
_invvpid(VMX_VPID_TYPE_ALL_CONTEXT, 0, 0UL);
174174
}
175175

176176
void invept(struct vcpu *vcpu)
@@ -530,7 +530,7 @@ static void *walk_paging_struct(void *addr, void *table_base,
530530
}
531531

532532
/* Determine if a valid entry exists */
533-
if ((table_entry & entry_present) == 0) {
533+
if ((table_entry & entry_present) == 0UL) {
534534
/* No entry present - need to allocate a new table */
535535
sub_table_addr = alloc_paging_struct();
536536
/* Check to ensure memory available for this structure*/
@@ -570,7 +570,7 @@ uint64_t get_paging_pml4(void)
570570

571571
void enable_paging(uint64_t pml4_base_addr)
572572
{
573-
uint64_t tmp64 = 0;
573+
uint64_t tmp64 = 0UL;
574574

575575
/* Enable Write Protect, inhibiting writing to read-only pages */
576576
CPU_CR_READ(cr0, &tmp64);
@@ -581,7 +581,7 @@ void enable_paging(uint64_t pml4_base_addr)
581581

582582
void enable_smep(void)
583583
{
584-
uint64_t val64 = 0;
584+
uint64_t val64 = 0UL;
585585

586586
/* Enable CR4.SMEP*/
587587
CPU_CR_READ(cr4, &val64);
@@ -665,8 +665,8 @@ void free_paging_struct(void *ptr)
665665

666666
bool check_continuous_hpa(struct vm *vm, uint64_t gpa, uint64_t size)
667667
{
668-
uint64_t curr_hpa = 0;
669-
uint64_t next_hpa = 0;
668+
uint64_t curr_hpa = 0UL;
669+
uint64_t next_hpa = 0UL;
670670

671671
/* if size <= PAGE_SIZE_4K, it is continuous,no need check
672672
* if size > PAGE_SIZE_4K, need to fetch next page
@@ -687,7 +687,7 @@ int obtain_last_page_table_entry(struct map_params *map_params,
687687
struct entry_params *entry, void *addr, bool direct)
688688
{
689689
uint64_t table_entry;
690-
uint32_t entry_present = 0;
690+
uint32_t entry_present = 0U;
691691
int ret = 0;
692692
/* Obtain the PML4 address */
693693
void *table_addr = direct ? (map_params->pml4_base)

hypervisor/arch/x86/trusty.c

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -74,10 +74,10 @@ static struct key_info g_key_info = {
7474
static void create_secure_world_ept(struct vm *vm, uint64_t gpa_orig,
7575
uint64_t size, uint64_t gpa_rebased)
7676
{
77-
uint64_t nworld_pml4e = 0;
78-
uint64_t sworld_pml4e = 0;
77+
uint64_t nworld_pml4e = 0UL;
78+
uint64_t sworld_pml4e = 0UL;
7979
struct map_params map_params;
80-
uint64_t gpa = 0;
80+
uint64_t gpa = 0UL;
8181
uint64_t hpa = gpa2hpa(vm, gpa_orig);
8282
uint64_t table_present = (IA32E_EPT_R_BIT |
8383
IA32E_EPT_W_BIT |
@@ -109,7 +109,7 @@ static void create_secure_world_ept(struct vm *vm, uint64_t gpa_orig,
109109

110110
/* Unmap gpa_orig~gpa_orig+size from guest normal world ept mapping */
111111
map_params.pml4_base = HPA2HVA(vm->arch_vm.nworld_eptp);
112-
unmap_mem(&map_params, (void *)hpa, (void *)gpa_orig, size, 0);
112+
unmap_mem(&map_params, (void *)hpa, (void *)gpa_orig, size, 0U);
113113

114114
/* Copy PDPT entries from Normal world to Secure world
115115
* Secure world can access Normal World's memory,
@@ -350,7 +350,7 @@ static bool setup_trusty_info(struct vcpu *vcpu,
350350
BUP_MKHI_BOOTLOADER_SEED_LEN,
351351
g_key_info.dseed_list[i].seed,
352352
BUP_MKHI_BOOTLOADER_SEED_LEN,
353-
NULL, 0,
353+
NULL, 0U,
354354
vcpu->vm->GUID, sizeof(vcpu->vm->GUID)) == 0) {
355355
(void)memset(key_info, 0, sizeof(struct key_info));
356356
pr_err("%s: derive dvseed failed!", __func__);
@@ -495,7 +495,7 @@ void trusty_set_dseed(void *dseed, uint8_t dseed_num)
495495
if ((dseed == NULL) || (dseed_num == 0U) ||
496496
(dseed_num > BOOTLOADER_SEED_MAX_ENTRIES)) {
497497

498-
g_key_info.num_seeds = 1;
498+
g_key_info.num_seeds = 1U;
499499
(void)memset(g_key_info.dseed_list[0].seed, 0xA5,
500500
sizeof(g_key_info.dseed_list[0].seed));
501501
return;

hypervisor/include/arch/x86/cpu.h

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

4141
/* Define page size */
4242
#define CPU_PAGE_SHIFT 12
43-
#define CPU_PAGE_SIZE 0x1000
43+
#define CPU_PAGE_SIZE 0x1000U
4444
#define CPU_PAGE_MASK 0xFFFFFFFFFFFFF000UL
4545

4646
#define MMU_PTE_PAGE_SHIFT CPU_PAGE_SHIFT

hypervisor/include/arch/x86/io.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -331,8 +331,8 @@ enum mem_io_type {
331331
};
332332

333333
/* MMIO emulation related structures */
334-
#define MMIO_TRANS_VALID 1
335-
#define MMIO_TRANS_INVALID 0
334+
#define MMIO_TRANS_VALID 1U
335+
#define MMIO_TRANS_INVALID 0U
336336
struct mem_io {
337337
uint64_t paddr; /* Physical address being accessed */
338338
enum mem_io_type read_write; /* 0 = read / 1 = write operation */

hypervisor/include/arch/x86/mmu.h

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
#define MMU_H
99

1010
/* Size of all page-table entries (in bytes) */
11-
#define IA32E_COMM_ENTRY_SIZE 8
11+
#define IA32E_COMM_ENTRY_SIZE 8U
1212

1313
/* Definitions common for all IA-32e related paging entries */
1414
#define IA32E_COMM_P_BIT 0x0000000000000001UL
@@ -144,8 +144,8 @@
144144

145145
/* IA32E Paging constants */
146146
#define IA32E_INDEX_MASK_BITS 9
147-
#define IA32E_NUM_ENTRIES 512
148-
#define IA32E_INDEX_MASK (uint64_t)(IA32E_NUM_ENTRIES - 1)
147+
#define IA32E_NUM_ENTRIES 512U
148+
#define IA32E_INDEX_MASK (uint64_t)(IA32E_NUM_ENTRIES - 1U)
149149
#define IA32E_REF_MASK \
150150
(boot_cpu_data.physical_address_mask)
151151
#define IA32E_FIRST_BLOCK_INDEX 1
@@ -210,7 +210,7 @@
210210
#define MMU_MEM_ATTR_TYPE_MASK \
211211
(IA32E_PDPTE_PAT_BIT | IA32E_COMM_PCD_BIT | IA32E_COMM_PWT_BIT)
212212

213-
#define ROUND_PAGE_UP(addr) (((addr) + CPU_PAGE_SIZE - 1U) & CPU_PAGE_MASK)
213+
#define ROUND_PAGE_UP(addr) (((addr) + (uint64_t)CPU_PAGE_SIZE - 1UL) & CPU_PAGE_MASK)
214214
#define ROUND_PAGE_DOWN(addr) ((addr) & CPU_PAGE_MASK)
215215

216216
enum _page_table_type {

hypervisor/include/arch/x86/trusty.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
#ifndef TRUSTY_H_
88
#define TRUSTY_H_
99

10-
#define BOOTLOADER_SEED_MAX_ENTRIES 10
10+
#define BOOTLOADER_SEED_MAX_ENTRIES 10U
1111
#define RPMB_MAX_PARTITION_NUMBER 6
1212
#define MMC_PROD_NAME_WITH_PSN_LEN 15
1313
#define BUP_MKHI_BOOTLOADER_SEED_LEN 64

hypervisor/include/arch/x86/vmx.h

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -317,10 +317,10 @@
317317
#define VMX_MIN_NR_VPID 1
318318
#define VMX_MAX_NR_VPID (1 << 5)
319319

320-
#define VMX_VPID_TYPE_INDIVIDUAL_ADDR 0
321-
#define VMX_VPID_TYPE_SINGLE_CONTEXT 1
322-
#define VMX_VPID_TYPE_ALL_CONTEXT 2
323-
#define VMX_VPID_TYPE_SINGLE_NON_GLOBAL 3
320+
#define VMX_VPID_TYPE_INDIVIDUAL_ADDR 0UL
321+
#define VMX_VPID_TYPE_SINGLE_CONTEXT 1UL
322+
#define VMX_VPID_TYPE_ALL_CONTEXT 2UL
323+
#define VMX_VPID_TYPE_SINGLE_NON_GLOBAL 3UL
324324

325325
#define VMX_VPID_INVVPID (1U << 0) /* (32 - 32) */
326326
#define VMX_VPID_INVVPID_INDIVIDUAL_ADDR (1U << 8) /* (40 - 32) */

hypervisor/include/lib/macros.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@
3838
* NOTE: The required alignment must be a power of 2 (2, 4, 8, 16, 32, etc)
3939
*/
4040
#define MEM_ALIGNED_CHECK(value, req_align) \
41-
(((uint64_t)(value) & ((uint64_t)(req_align) - (uint64_t)1)) == 0)
41+
(((uint64_t)(value) & ((uint64_t)(req_align) - 1UL)) == 0UL)
4242

4343
#if !defined(ASSEMBLER) && !defined(LINKER_SCRIPT)
4444

hypervisor/include/public/acrn_common.h

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -31,10 +31,10 @@
3131
#define REQ_STATE_PROCESSING 2
3232
#define REQ_STATE_FAILED -1
3333

34-
#define REQ_PORTIO 0
35-
#define REQ_MMIO 1
36-
#define REQ_PCICFG 2
37-
#define REQ_WP 3
34+
#define REQ_PORTIO 0U
35+
#define REQ_MMIO 1U
36+
#define REQ_PCICFG 2U
37+
#define REQ_WP 3U
3838

3939
#define REQUEST_READ 0
4040
#define REQUEST_WRITE 1

0 commit comments

Comments
 (0)