From ab156c9633ffe2d6b478cbb29b9224a104f542f1 Mon Sep 17 00:00:00 2001 From: Junjie Mao Date: Wed, 4 Jul 2018 21:02:43 +0800 Subject: [PATCH] HV: instr_emul: convert return value of get_vmcs_field to unsigned get_vmcs_field() returns a VMCS field offset which is normally unsigned, but it also returns negatives (-1 here) on invalid arguments. Following the convention we use for vectors, pins, etc., use a special unsigned value to indicate such errors. v1 -> v2: * Use a special value (VMX_INVALID_VMCS_FIELD) instead of a seperate output parameter to indicate errors. Signed-off-by: Junjie Mao --- hypervisor/arch/x86/guest/instr_emul_wrapper.c | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) diff --git a/hypervisor/arch/x86/guest/instr_emul_wrapper.c b/hypervisor/arch/x86/guest/instr_emul_wrapper.c index 4c7ffd9a1..5d4348299 100644 --- a/hypervisor/arch/x86/guest/instr_emul_wrapper.c +++ b/hypervisor/arch/x86/guest/instr_emul_wrapper.c @@ -9,11 +9,13 @@ #include "instr_emul_wrapper.h" #include "instr_emul.h" +#define VMX_INVALID_VMCS_FIELD 0xffffffffU + static int encode_vmcs_seg_desc(enum cpu_reg_name seg, uint32_t *base, uint32_t *lim, uint32_t *acc); -static int32_t +static uint32_t get_vmcs_field(enum cpu_reg_name ident); static bool @@ -36,9 +38,9 @@ int vm_get_register(struct vcpu *vcpu, enum cpu_reg_name reg, uint64_t *retval) &vcpu->arch_vcpu.contexts[vcpu->arch_vcpu.cur_context]; *retval = cur_context->guest_cpu_regs.longs[reg]; } else if ((reg > CPU_REG_RDI) && (reg < CPU_REG_LAST)) { - int32_t field = get_vmcs_field(reg); + uint32_t field = get_vmcs_field(reg); - if (field != -1) + if (field != VMX_INVALID_VMCS_FIELD) *retval = exec_vmread(field); else return -EINVAL; @@ -61,9 +63,9 @@ int vm_set_register(struct vcpu *vcpu, enum cpu_reg_name reg, uint64_t val) &vcpu->arch_vcpu.contexts[vcpu->arch_vcpu.cur_context]; cur_context->guest_cpu_regs.longs[reg] = val; } else if ((reg > CPU_REG_RDI) && (reg < CPU_REG_LAST)) { - int32_t field = get_vmcs_field(reg); + uint32_t field = get_vmcs_field(reg); - if (field != -1) + if (field != VMX_INVALID_VMCS_FIELD) exec_vmwrite(field, val); else return -EINVAL; @@ -208,7 +210,7 @@ encode_vmcs_seg_desc(enum cpu_reg_name seg, return 0; } -static int32_t get_vmcs_field(enum cpu_reg_name ident) +static uint32_t get_vmcs_field(enum cpu_reg_name ident) { switch (ident) { case CPU_REG_CR0: @@ -252,7 +254,7 @@ static int32_t get_vmcs_field(enum cpu_reg_name ident) case CPU_REG_PDPTE3: return VMX_GUEST_PDPTE3_FULL; default: - return -1; + return VMX_INVALID_VMCS_FIELD; } }