From 8d35d8752b844c580084f8744767ef6eb8ac5e30 Mon Sep 17 00:00:00 2001 From: Jason Chen CJ Date: Thu, 24 May 2018 12:55:08 +0800 Subject: [PATCH] instr_emul: remove vm_gva2gpa - vm_gva2gpa is same as gva2gpa, so replace it with gva2gpa directly. - remove dead usage of vm_gva2gpa in emulate_movs. Signed-off-by: Jason Chen CJ Acked-by: Eddie Dong --- hypervisor/arch/x86/guest/instr_emul.c | 26 ++++++++----------- .../arch/x86/guest/instr_emul_wrapper.c | 11 -------- hypervisor/include/arch/x86/guest/guest.h | 2 -- 3 files changed, 11 insertions(+), 28 deletions(-) diff --git a/hypervisor/arch/x86/guest/instr_emul.c b/hypervisor/arch/x86/guest/instr_emul.c index f4eed0e01..99258adf4 100644 --- a/hypervisor/arch/x86/guest/instr_emul.c +++ b/hypervisor/arch/x86/guest/instr_emul.c @@ -243,7 +243,6 @@ static uint64_t size2mask[] = { [8] = 0xffffffffffffffff, }; - static int vie_read_register(struct vcpu *vcpu, enum vm_reg_name reg, uint64_t *rval) { @@ -671,10 +670,9 @@ emulate_movs(struct vcpu *vcpu, __unused uint64_t gpa, struct vie *vie, __unused mem_region_write_t memwrite, __unused void *arg) { - uint64_t dstaddr, srcaddr, dstgpa, srcgpa; + uint64_t dstaddr, srcaddr; uint64_t rcx, rdi, rsi, rflags; int error, fault, opsize, seg, repeat; - uint32_t err_code; opsize = (vie->op.op_byte == 0xA4) ? 1 : vie->opsize; error = 0; @@ -714,14 +712,6 @@ emulate_movs(struct vcpu *vcpu, __unused uint64_t gpa, struct vie *vie, if (error || fault) goto done; - err_code = 0; - error = vm_gva2gpa(vcpu, srcaddr, &srcgpa, &err_code); - if (error) - goto done; - err_code = PAGE_FAULT_WR_FLAG; - error = vm_gva2gpa(vcpu, dstaddr, &dstgpa, &err_code); - if (error) - goto done; memcpy_s((char *)dstaddr, 16, (char *)srcaddr, opsize); error = vie_read_register(vcpu, VM_REG_GUEST_RSI, &rsi); @@ -1310,13 +1300,19 @@ emulate_stack_op(struct vcpu *vcpu, uint64_t mmio_gpa, struct vie *vie, return 0; } + /* TODO: currently emulate_instruction is only for mmio, so here + * stack_gpa actually is unused for mmio_write & mmio_read, need + * take care of data trans if stack_gpa be used for memwrite in + * the future. + */ if (pushop) err_code |= PAGE_FAULT_WR_FLAG; - error = vm_gva2gpa(vcpu, stack_gla, &stack_gpa, &err_code); - if (error) { - pr_err("%s: failed to translate gva2gpa", __func__); + error = gva2gpa(vcpu, stack_gla, &stack_gpa, &err_code); + if (error == -EFAULT) { + vcpu_inject_pf(vcpu, stack_gla, err_code); + return error; + } else if (error < 0) return error; - } if (pushop) { error = memread(vcpu, mmio_gpa, &val, size, arg); if (error == 0) diff --git a/hypervisor/arch/x86/guest/instr_emul_wrapper.c b/hypervisor/arch/x86/guest/instr_emul_wrapper.c index d7d114cca..25e076fe3 100644 --- a/hypervisor/arch/x86/guest/instr_emul_wrapper.c +++ b/hypervisor/arch/x86/guest/instr_emul_wrapper.c @@ -287,17 +287,6 @@ static int mmio_write(struct vcpu *vcpu, __unused uint64_t gpa, uint64_t wval, return 0; } -int vm_gva2gpa(struct vcpu *vcpu, uint64_t gva, uint64_t *gpa, - uint32_t *err_code) -{ - - ASSERT(gpa != NULL, "Error in input arguments"); - ASSERT(vcpu != NULL, - "Invalid vcpu id when gva2gpa"); - - return gva2gpa(vcpu, gva, gpa, err_code); -} - int decode_instruction(struct vcpu *vcpu) { struct emul_cnx *emul_cnx; diff --git a/hypervisor/include/arch/x86/guest/guest.h b/hypervisor/include/arch/x86/guest/guest.h index 7f0d78b60..fff924e08 100644 --- a/hypervisor/include/arch/x86/guest/guest.h +++ b/hypervisor/include/arch/x86/guest/guest.h @@ -93,8 +93,6 @@ bool vm_lapic_disabled(struct vm *vm); uint64_t vcpumask2pcpumask(struct vm *vm, uint64_t vdmask); int gva2gpa(struct vcpu *vcpu, uint64_t gva, uint64_t *gpa, uint32_t *err_code); -int vm_gva2gpa(struct vcpu *vcpu, uint64_t gla, uint64_t *gpa, - uint32_t *err_code); struct vcpu *get_primary_vcpu(struct vm *vm); struct vcpu *vcpu_from_vid(struct vm *vm, int vcpu_id);