mirror of
https://github.com/projectacrn/acrn-hypervisor.git
synced 2025-06-21 21:19:35 +00:00
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 <junjie.mao@intel.com>
This commit is contained in:
parent
d457874cf5
commit
ab156c9633
@ -9,11 +9,13 @@
|
|||||||
#include "instr_emul_wrapper.h"
|
#include "instr_emul_wrapper.h"
|
||||||
#include "instr_emul.h"
|
#include "instr_emul.h"
|
||||||
|
|
||||||
|
#define VMX_INVALID_VMCS_FIELD 0xffffffffU
|
||||||
|
|
||||||
static int
|
static int
|
||||||
encode_vmcs_seg_desc(enum cpu_reg_name seg,
|
encode_vmcs_seg_desc(enum cpu_reg_name seg,
|
||||||
uint32_t *base, uint32_t *lim, uint32_t *acc);
|
uint32_t *base, uint32_t *lim, uint32_t *acc);
|
||||||
|
|
||||||
static int32_t
|
static uint32_t
|
||||||
get_vmcs_field(enum cpu_reg_name ident);
|
get_vmcs_field(enum cpu_reg_name ident);
|
||||||
|
|
||||||
static bool
|
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];
|
&vcpu->arch_vcpu.contexts[vcpu->arch_vcpu.cur_context];
|
||||||
*retval = cur_context->guest_cpu_regs.longs[reg];
|
*retval = cur_context->guest_cpu_regs.longs[reg];
|
||||||
} else if ((reg > CPU_REG_RDI) && (reg < CPU_REG_LAST)) {
|
} 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);
|
*retval = exec_vmread(field);
|
||||||
else
|
else
|
||||||
return -EINVAL;
|
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];
|
&vcpu->arch_vcpu.contexts[vcpu->arch_vcpu.cur_context];
|
||||||
cur_context->guest_cpu_regs.longs[reg] = val;
|
cur_context->guest_cpu_regs.longs[reg] = val;
|
||||||
} else if ((reg > CPU_REG_RDI) && (reg < CPU_REG_LAST)) {
|
} 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);
|
exec_vmwrite(field, val);
|
||||||
else
|
else
|
||||||
return -EINVAL;
|
return -EINVAL;
|
||||||
@ -208,7 +210,7 @@ encode_vmcs_seg_desc(enum cpu_reg_name seg,
|
|||||||
return 0;
|
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) {
|
switch (ident) {
|
||||||
case CPU_REG_CR0:
|
case CPU_REG_CR0:
|
||||||
@ -252,7 +254,7 @@ static int32_t get_vmcs_field(enum cpu_reg_name ident)
|
|||||||
case CPU_REG_PDPTE3:
|
case CPU_REG_PDPTE3:
|
||||||
return VMX_GUEST_PDPTE3_FULL;
|
return VMX_GUEST_PDPTE3_FULL;
|
||||||
default:
|
default:
|
||||||
return -1;
|
return VMX_INVALID_VMCS_FIELD;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user