diff --git a/hypervisor/arch/x86/guest/instr_emul.c b/hypervisor/arch/x86/guest/instr_emul.c index b52ef991e..217dfd5fe 100644 --- a/hypervisor/arch/x86/guest/instr_emul.c +++ b/hypervisor/arch/x86/guest/instr_emul.c @@ -1527,13 +1527,13 @@ vmm_emulate_instruction(struct vcpu *vcpu, uint64_t gpa, struct vie *vie, } int -vie_alignment_check(int cpl, uint8_t size, uint64_t cr0, uint64_t rf, uint64_t gla) +vie_alignment_check(uint8_t cpl, uint8_t size, uint64_t cr0, uint64_t rf, uint64_t gla) { ASSERT(size == 1U || size == 2U || size == 4U || size == 8U, "%s: invalid size %hhu", __func__, size); - ASSERT(cpl >= 0 && cpl <= 3, "%s: invalid cpl %d", __func__, cpl); + ASSERT(cpl <= 3U, "%s: invalid cpl %d", __func__, cpl); - if (cpl != 3 || (cr0 & CR0_AM) == 0 || (rf & PSL_AC) == 0) + if (cpl != 3U || (cr0 & CR0_AM) == 0 || (rf & PSL_AC) == 0) return 0; return ((gla & (size - 1U)) != 0UL) ? 1 : 0; diff --git a/hypervisor/arch/x86/guest/instr_emul.h b/hypervisor/arch/x86/guest/instr_emul.h index 40862cbfa..81e7b1ff5 100644 --- a/hypervisor/arch/x86/guest/instr_emul.h +++ b/hypervisor/arch/x86/guest/instr_emul.h @@ -60,7 +60,7 @@ int vie_update_register(struct vcpu *vcpu, enum cpu_reg_name reg, /* * Returns 1 if an alignment check exception should be injected and 0 otherwise. */ -int vie_alignment_check(int cpl, uint8_t operand_size, uint64_t cr0, +int vie_alignment_check(uint8_t cpl, uint8_t operand_size, uint64_t cr0, uint64_t rflags, uint64_t gla); /* Returns 1 if the 'gla' is not canonical and 0 otherwise. */ diff --git a/hypervisor/arch/x86/guest/instr_emul_wrapper.c b/hypervisor/arch/x86/guest/instr_emul_wrapper.c index 5d4348299..7cae11e2c 100644 --- a/hypervisor/arch/x86/guest/instr_emul_wrapper.c +++ b/hypervisor/arch/x86/guest/instr_emul_wrapper.c @@ -261,11 +261,11 @@ static uint32_t get_vmcs_field(enum cpu_reg_name ident) static void get_guest_paging_info(struct vcpu *vcpu, struct emul_cnx *emul_cnx, uint32_t csar) { - uint32_t cpl; + uint8_t cpl; ASSERT(emul_cnx != NULL && vcpu != NULL, "Error in input arguments"); - cpl = (csar >> 5) & 3U; + cpl = (uint8_t)((csar >> 5) & 3U); emul_cnx->paging.cr3 = vcpu->arch_vcpu.contexts[vcpu->arch_vcpu.cur_context].cr3; emul_cnx->paging.cpl = cpl; diff --git a/hypervisor/arch/x86/guest/instr_emul_wrapper.h b/hypervisor/arch/x86/guest/instr_emul_wrapper.h index e8fae95da..7f714a8c5 100644 --- a/hypervisor/arch/x86/guest/instr_emul_wrapper.h +++ b/hypervisor/arch/x86/guest/instr_emul_wrapper.h @@ -173,7 +173,7 @@ struct seg_desc { struct vm_guest_paging { uint64_t cr3; - int cpl; + uint8_t cpl; enum vm_cpu_mode cpu_mode; enum vm_paging_mode paging_mode; };