From 11d0e59b3e42de64375a026e02a5c02e1a2bcc00 Mon Sep 17 00:00:00 2001 From: Yonghua Huang Date: Mon, 16 Apr 2018 23:15:31 +0800 Subject: [PATCH] revise type of 'exit_reason' and 'inst_len' in vcpu_arch SDM 24.9.1 Volume3: - 'Exit reason' field in VMCS is 32 bits. SDM 24.9.4 in Volume3 - 'VM-exit instruction length' field in VMCS is 32 bits. This patch is to redefine the data types of above fields in 'struct vcpu_arch' and udpate the code using these two fields. Signed-off-by: Yonghua Huang --- hypervisor/arch/x86/guest/instr_emul.c | 4 ++-- hypervisor/arch/x86/guest/instr_emul.h | 2 +- hypervisor/arch/x86/guest/vcpu.c | 3 ++- hypervisor/common/hv_main.c | 15 +++++++-------- hypervisor/include/arch/x86/guest/vcpu.h | 4 ++-- 5 files changed, 14 insertions(+), 14 deletions(-) diff --git a/hypervisor/arch/x86/guest/instr_emul.c b/hypervisor/arch/x86/guest/instr_emul.c index 3f9b259c6..f24528f46 100644 --- a/hypervisor/arch/x86/guest/instr_emul.c +++ b/hypervisor/arch/x86/guest/instr_emul.c @@ -1665,9 +1665,9 @@ vie_calculate_gla(enum vm_cpu_mode cpu_mode, enum vm_reg_name seg, } void -vie_init(struct vie *vie, const char *inst_bytes, int inst_length) +vie_init(struct vie *vie, const char *inst_bytes, uint32_t inst_length) { - ASSERT(inst_length >= 0 && inst_length <= VIE_INST_SIZE, + ASSERT(inst_length <= VIE_INST_SIZE, "%s: invalid instruction length (%d)", __func__, inst_length); memset(vie, 0, sizeof(struct vie)); diff --git a/hypervisor/arch/x86/guest/instr_emul.h b/hypervisor/arch/x86/guest/instr_emul.h index f92015d7c..c3186e56c 100644 --- a/hypervisor/arch/x86/guest/instr_emul.h +++ b/hypervisor/arch/x86/guest/instr_emul.h @@ -72,7 +72,7 @@ int vie_calculate_gla(enum vm_cpu_mode cpu_mode, enum vm_reg_name seg, struct seg_desc *desc, uint64_t off, int length, int addrsize, int prot, uint64_t *gla); -void vie_init(struct vie *vie, const char *inst_bytes, int inst_length); +void vie_init(struct vie *vie, const char *inst_bytes, uint32_t inst_length); /* * Decode the instruction fetched into 'vie' so it can be emulated. diff --git a/hypervisor/arch/x86/guest/vcpu.c b/hypervisor/arch/x86/guest/vcpu.c index 185904fbd..016a7d6ec 100644 --- a/hypervisor/arch/x86/guest/vcpu.c +++ b/hypervisor/arch/x86/guest/vcpu.c @@ -136,7 +136,8 @@ int create_vcpu(int cpu_id, struct vm *vm, struct vcpu **rtn_vcpu_handle) int start_vcpu(struct vcpu *vcpu) { - uint64_t rip, instlen; + uint32_t instlen; + uint64_t rip; struct run_context *cur_context = &vcpu->arch_vcpu.contexts[vcpu->arch_vcpu.cur_context]; int64_t status = 0; diff --git a/hypervisor/common/hv_main.c b/hypervisor/common/hv_main.c index 6bad1a806..8fb5aabfa 100644 --- a/hypervisor/common/hv_main.c +++ b/hypervisor/common/hv_main.c @@ -50,13 +50,12 @@ static void run_vcpu_pre_work(struct vcpu *vcpu) void vcpu_thread(struct vcpu *vcpu) { - uint64_t vmexit_begin, vmexit_end; - uint16_t exit_reason; + uint64_t vmexit_begin = 0, vmexit_end = 0; + uint16_t basic_exit_reason = 0; uint64_t tsc_aux_hyp_cpu = vcpu->pcpu_id; struct vm_exit_dispatch *vmexit_hdlr; int ret = 0; - vmexit_begin = vmexit_end = exit_reason = 0; /* If vcpu is not launched, we need to do init_vmcs first */ if (!vcpu->launched) init_vmcs(vcpu); @@ -87,7 +86,7 @@ void vcpu_thread(struct vcpu *vcpu) vmexit_end = rdtsc(); if (vmexit_begin > 0) - per_cpu(vmexit_time, vcpu->pcpu_id)[exit_reason] + per_cpu(vmexit_time, vcpu->pcpu_id)[basic_exit_reason] += (vmexit_end - vmexit_begin); TRACE_2L(TRACE_VM_ENTER, 0, 0); @@ -114,12 +113,12 @@ void vcpu_thread(struct vcpu *vcpu) ASSERT(vmexit_hdlr != 0, "Unable to dispatch VM exit handler!"); - exit_reason = vcpu->arch_vcpu.exit_reason & 0xFFFF; - per_cpu(vmexit_cnt, vcpu->pcpu_id)[exit_reason]++; - TRACE_2L(TRACE_VM_EXIT, exit_reason, + basic_exit_reason = vcpu->arch_vcpu.exit_reason & 0xFFFF; + per_cpu(vmexit_cnt, vcpu->pcpu_id)[basic_exit_reason]++; + TRACE_2L(TRACE_VM_EXIT, basic_exit_reason, vcpu->arch_vcpu.contexts[vcpu->arch_vcpu.cur_context].rip); - if (exit_reason == VMX_EXIT_REASON_EXTERNAL_INTERRUPT) { + if (basic_exit_reason == VMX_EXIT_REASON_EXTERNAL_INTERRUPT) { /* Handling external_interrupt * should disable intr */ diff --git a/hypervisor/include/arch/x86/guest/vcpu.h b/hypervisor/include/arch/x86/guest/vcpu.h index e13df9d3b..c8cc1ab8e 100644 --- a/hypervisor/include/arch/x86/guest/vcpu.h +++ b/hypervisor/include/arch/x86/guest/vcpu.h @@ -214,10 +214,10 @@ struct vcpu_arch { uint64_t msr_tsc_aux; /* VCPU context state information */ - uint64_t exit_reason; + uint32_t exit_reason; uint64_t exit_interrupt_info; uint64_t exit_qualification; - uint8_t inst_len; + uint32_t inst_len; /* Information related to secondary / AP VCPU start-up */ uint8_t cpu_mode;