From patchwork Tue Jul 17 13:52:13 2012 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Xiao Guangrong X-Patchwork-Id: 1205091 Return-Path: X-Original-To: patchwork-kvm@patchwork.kernel.org Delivered-To: patchwork-process-083081@patchwork1.kernel.org Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by patchwork1.kernel.org (Postfix) with ESMTP id BE00C3FD9C for ; Tue, 17 Jul 2012 13:52:46 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1754899Ab2GQNwY (ORCPT ); Tue, 17 Jul 2012 09:52:24 -0400 Received: from e23smtp04.au.ibm.com ([202.81.31.146]:51034 "EHLO e23smtp04.au.ibm.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752359Ab2GQNwV (ORCPT ); Tue, 17 Jul 2012 09:52:21 -0400 Received: from /spool/local by e23smtp04.au.ibm.com with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted for from ; Tue, 17 Jul 2012 13:30:17 +1000 Received: from d23relay03.au.ibm.com (202.81.31.245) by e23smtp04.au.ibm.com (202.81.31.210) with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted; Tue, 17 Jul 2012 13:30:14 +1000 Received: from d23av02.au.ibm.com (d23av02.au.ibm.com [9.190.235.138]) by d23relay03.au.ibm.com (8.13.8/8.13.8/NCO v10.0) with ESMTP id q6HDqGH532505888; Tue, 17 Jul 2012 23:52:16 +1000 Received: from d23av02.au.ibm.com (loopback [127.0.0.1]) by d23av02.au.ibm.com (8.14.4/8.13.1/NCO v10.0 AVout) with ESMTP id q6HDqFwB028843; Tue, 17 Jul 2012 23:52:16 +1000 Received: from localhost.localdomain ([9.123.236.99]) by d23av02.au.ibm.com (8.14.4/8.13.1/NCO v10.0 AVin) with ESMTP id q6HDqDcn028827; Tue, 17 Jul 2012 23:52:14 +1000 Message-ID: <50056E0D.1070905@linux.vnet.ibm.com> Date: Tue, 17 Jul 2012 21:52:13 +0800 From: Xiao Guangrong User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:13.0) Gecko/20120615 Thunderbird/13.0.1 MIME-Version: 1.0 To: Xiao Guangrong CC: Avi Kivity , Marcelo Tosatti , LKML , KVM Subject: [PATCH 3/9] KVM: x86: introduce set_mmio_exit_info References: <50056DB8.7080702@linux.vnet.ibm.com> In-Reply-To: <50056DB8.7080702@linux.vnet.ibm.com> x-cbid: 12071703-9264-0000-0000-000001EE0BF8 Sender: kvm-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: kvm@vger.kernel.org Introduce set_mmio_exit_info to cleanup the common code Signed-off-by: Xiao Guangrong --- arch/x86/kvm/x86.c | 33 +++++++++++++++++---------------- 1 files changed, 17 insertions(+), 16 deletions(-) diff --git a/arch/x86/kvm/x86.c b/arch/x86/kvm/x86.c index 875b8d8..8171836 100644 --- a/arch/x86/kvm/x86.c +++ b/arch/x86/kvm/x86.c @@ -3759,9 +3759,6 @@ static int read_exit_mmio(struct kvm_vcpu *vcpu, gpa_t gpa, static int write_exit_mmio(struct kvm_vcpu *vcpu, gpa_t gpa, void *val, int bytes) { - struct kvm_mmio_fragment *frag = &vcpu->mmio_fragments[0]; - - memcpy(vcpu->run->mmio.data, frag->data, frag->len); return X86EMUL_CONTINUE; } @@ -3829,6 +3826,20 @@ mmio: return X86EMUL_CONTINUE; } +static void set_mmio_exit_info(struct kvm_vcpu *vcpu, + struct kvm_mmio_fragment *frag, bool write) +{ + struct kvm_run *run = vcpu->run; + + run->exit_reason = KVM_EXIT_MMIO; + run->mmio.phys_addr = frag->gpa; + run->mmio.len = frag->len; + run->mmio.is_write = vcpu->mmio_is_write = write; + + if (write) + memcpy(run->mmio.data, frag->data, frag->len); +} + int emulator_read_write(struct x86_emulate_ctxt *ctxt, unsigned long addr, void *val, unsigned int bytes, struct x86_exception *exception, @@ -3868,14 +3879,10 @@ int emulator_read_write(struct x86_emulate_ctxt *ctxt, unsigned long addr, return rc; gpa = vcpu->mmio_fragments[0].gpa; - vcpu->mmio_needed = 1; vcpu->mmio_cur_fragment = 0; - vcpu->run->mmio.len = vcpu->mmio_fragments[0].len; - vcpu->run->mmio.is_write = vcpu->mmio_is_write = ops->write; - vcpu->run->exit_reason = KVM_EXIT_MMIO; - vcpu->run->mmio.phys_addr = gpa; + set_mmio_exit_info(vcpu, &vcpu->mmio_fragments[0], ops->write); return ops->read_write_exit_mmio(vcpu, gpa, val, bytes); } @@ -5485,7 +5492,6 @@ static int __vcpu_run(struct kvm_vcpu *vcpu) */ static int complete_mmio(struct kvm_vcpu *vcpu) { - struct kvm_run *run = vcpu->run; struct kvm_mmio_fragment *frag; int r; @@ -5496,7 +5502,7 @@ static int complete_mmio(struct kvm_vcpu *vcpu) /* Complete previous fragment */ frag = &vcpu->mmio_fragments[vcpu->mmio_cur_fragment++]; if (!vcpu->mmio_is_write) - memcpy(frag->data, run->mmio.data, frag->len); + memcpy(frag->data, vcpu->run->mmio.data, frag->len); if (vcpu->mmio_cur_fragment == vcpu->mmio_nr_fragments) { vcpu->mmio_needed = 0; if (vcpu->mmio_is_write) @@ -5506,12 +5512,7 @@ static int complete_mmio(struct kvm_vcpu *vcpu) } /* Initiate next fragment */ ++frag; - run->exit_reason = KVM_EXIT_MMIO; - run->mmio.phys_addr = frag->gpa; - if (vcpu->mmio_is_write) - memcpy(run->mmio.data, frag->data, frag->len); - run->mmio.len = frag->len; - run->mmio.is_write = vcpu->mmio_is_write; + set_mmio_exit_info(vcpu, frag, vcpu->mmio_is_write); return 0; }