From 4131d46f84294cd4d00cb256310f6a762cc94121 Mon Sep 17 00:00:00 2001 From: "Li, Fei1" Date: Wed, 12 Dec 2018 23:26:32 +0800 Subject: [PATCH] hv: remove goto in ept_violation_vmexit_handler Using goto leads the code to be difficult to read and maintain Tracked-On: #861 Signed-off-by: Li, Fei1 --- hypervisor/arch/x86/ept.c | 65 ++++++++++++++++++--------------------- 1 file changed, 30 insertions(+), 35 deletions(-) diff --git a/hypervisor/arch/x86/ept.c b/hypervisor/arch/x86/ept.c index 5f62c8083..0371d6621 100644 --- a/hypervisor/arch/x86/ept.c +++ b/hypervisor/arch/x86/ept.c @@ -115,46 +115,41 @@ int32_t ept_violation_vmexit_handler(struct acrn_vcpu *vcpu) ret = decode_instruction(vcpu); if (ret > 0) { mmio_req->size = (uint64_t)ret; - } else if (ret == -EFAULT) { - pr_info("page fault happen during decode_instruction"); - status = 0; - goto out; + /* + * For MMIO write, ask DM to run MMIO emulation after + * instruction emulation. For MMIO read, ask DM to run MMIO + * emulation at first. + */ + + /* Determine value being written. */ + if (mmio_req->direction == REQUEST_WRITE) { + status = emulate_instruction(vcpu); + if (status != 0) { + ret = -EFAULT;; + } + } + + if (ret > 0) { + status = emulate_io(vcpu, io_req); + if (status == 0) { + emulate_mmio_post(vcpu, io_req); + } else { + if (status == IOREQ_PENDING) { + status = 0; + } + } + } } else { - goto out; - } - - - /* - * For MMIO write, ask DM to run MMIO emulation after - * instruction emulation. For MMIO read, ask DM to run MMIO - * emulation at first. - */ - - /* Determine value being written. */ - if (mmio_req->direction == REQUEST_WRITE) { - status = emulate_instruction(vcpu); - if (status != 0) { - goto out; + if (ret == -EFAULT) { + pr_info("page fault happen during decode_instruction"); + status = 0; } } - status = emulate_io(vcpu, io_req); - - if (status == 0) { - emulate_mmio_post(vcpu, io_req); - } else if (status == IOREQ_PENDING) { - status = 0; + if (ret <= 0) { + pr_acrnlog("Guest Linear Address: 0x%016llx", exec_vmread(VMX_GUEST_LINEAR_ADDR)); + pr_acrnlog("Guest Physical Address address: 0x%016llx", gpa); } - - return status; - -out: - pr_acrnlog("Guest Linear Address: 0x%016llx", - exec_vmread(VMX_GUEST_LINEAR_ADDR)); - - pr_acrnlog("Guest Physical Address address: 0x%016llx", - gpa); - return status; }