From patchwork Wed Aug 22 12:31:52 2012 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Julien Grall X-Patchwork-Id: 179368 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (Client did not present a certificate) by ozlabs.org (Postfix) with ESMTPS id 96FC22C009E for ; Thu, 23 Aug 2012 04:56:27 +1000 (EST) Received: from localhost ([::1]:44346 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1T4G6L-0004hG-Oy for incoming@patchwork.ozlabs.org; Wed, 22 Aug 2012 14:56:25 -0400 Received: from eggs.gnu.org ([208.118.235.92]:55050) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1T4G5D-0002r5-Ey for qemu-devel@nongnu.org; Wed, 22 Aug 2012 14:55:23 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1T4G5C-0007Uh-84 for qemu-devel@nongnu.org; Wed, 22 Aug 2012 14:55:15 -0400 Received: from smtp.citrix.com ([66.165.176.89]:13432) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1T4G5B-0007FA-S0 for qemu-devel@nongnu.org; Wed, 22 Aug 2012 14:55:14 -0400 X-IronPort-AV: E=Sophos;i="4.80,809,1344225600"; d="scan'208";a="35484789" Received: from ftlpmailmx01.citrite.net ([10.13.107.65]) by FTLPIPO01.CITRIX.COM with ESMTP/TLS/RC4-MD5; 22 Aug 2012 14:55:13 -0400 Received: from meteora.cam.xci-test.com (10.80.248.22) by smtprelay.citrix.com (10.13.107.65) with Microsoft SMTP Server id 8.3.213.0; Wed, 22 Aug 2012 14:55:12 -0400 From: Julien Grall To: qemu-devel@nongnu.org Date: Wed, 22 Aug 2012 13:31:52 +0100 Message-ID: <89b7274240cda4511d4e7e11fc9c21a53ba23887.1345552068.git.julien.grall@citrix.com> X-Mailer: git-send-email 1.7.2.5 In-Reply-To: References: MIME-Version: 1.0 X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 66.165.176.89 Cc: Julien Grall , christian.limpach@gmail.com, Stefano.Stabellini@eu.citrix.com, xen-devel@lists.xen.org Subject: [Qemu-devel] [XEN][RFC PATCH V2 06/17] hvm-io: IO refactoring with ioreq server X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Modification of several parts of the IO handle. Each vcpu now contain a pointer to the current IO shared page. A default shared page has been created for IO handle by Xen. Each time that Xen receives an ioreq, it will use the default shared page and set the right shared page when it's able to know the server. Moreover, all IO which are unhandleabled by Xen or by a server will be directly discard inside Xen. Signed-off-by: Julien Grall --- xen/arch/x86/hvm/emulate.c | 56 +++++++++++++++++++++++++++++++++++++ xen/arch/x86/hvm/hvm.c | 5 ++- xen/include/asm-x86/hvm/support.h | 26 ++++++++++++++-- 3 files changed, 81 insertions(+), 6 deletions(-) diff --git a/xen/arch/x86/hvm/emulate.c b/xen/arch/x86/hvm/emulate.c index 9bfba48..9e636b6 100644 --- a/xen/arch/x86/hvm/emulate.c +++ b/xen/arch/x86/hvm/emulate.c @@ -49,6 +49,55 @@ static void hvmtrace_io_assist(int is_mmio, ioreq_t *p) trace_var(event, 0/*!cycles*/, size, buffer); } +static int hvmemul_prepare_assist(ioreq_t *p) +{ + struct vcpu *v = current; + struct hvm_ioreq_server *s; + int i; + int sign; + uint32_t data = ~0; + + if ( p->type == IOREQ_TYPE_PCI_CONFIG ) + return X86EMUL_UNHANDLEABLE; + + spin_lock(&v->domain->arch.hvm_domain.ioreq_server_lock); + for ( s = v->domain->arch.hvm_domain.ioreq_server_list; s; s = s->next ) + { + struct hvm_io_range *x = (p->type == IOREQ_TYPE_COPY) + ? s->mmio_range_list : s->portio_range_list; + + for ( ; x; x = x->next ) + { + if ( (p->addr >= x->s) && (p->addr <= x->e) ) + goto done_server_scan; + } + } + + spin_unlock(&v->domain->arch.hvm_domain.ioreq_server_lock); + + sign = p->df ? -1 : 1; + + if ( p->dir != IOREQ_WRITE ) + { + if ( !p->data_is_ptr ) + p->data = ~0; + else + { + for ( i = 0; i < p->count; i++ ) + hvm_copy_to_guest_phys(p->data + sign * i * p->size, &data, + p->size); + } + } + + return X86EMUL_OKAY; + + done_server_scan: + set_ioreq(v, &s->ioreq, p); + spin_unlock(&v->domain->arch.hvm_domain.ioreq_server_lock); + + return X86EMUL_UNHANDLEABLE; +} + static int hvmemul_do_io( int is_mmio, paddr_t addr, unsigned long *reps, int size, paddr_t ram_gpa, int dir, int df, void *p_data) @@ -173,6 +222,10 @@ static int hvmemul_do_io( (p_data == NULL) ? HVMIO_dispatched : HVMIO_awaiting_completion; vio->io_size = size; + /* Use the default shared page */ + current->arch.hvm_vcpu.ioreq = &curr->domain->arch.hvm_domain.ioreq; + p = get_ioreq(current); + p->dir = dir; p->data_is_ptr = value_is_ptr; p->type = is_mmio ? IOREQ_TYPE_COPY : IOREQ_TYPE_PIO; @@ -196,6 +249,9 @@ static int hvmemul_do_io( rc = hvm_portio_intercept(p); } + if ( rc == X86EMUL_UNHANDLEABLE ) + rc = hvmemul_prepare_assist(p); + switch ( rc ) { case X86EMUL_OKAY: diff --git a/xen/arch/x86/hvm/hvm.c b/xen/arch/x86/hvm/hvm.c index a2cd9b3..33ef0f2 100644 --- a/xen/arch/x86/hvm/hvm.c +++ b/xen/arch/x86/hvm/hvm.c @@ -1223,14 +1223,15 @@ bool_t hvm_send_assist_req(struct vcpu *v) return 0; } - prepare_wait_on_xen_event_channel(v->arch.hvm_vcpu.xen_port); + prepare_wait_on_xen_event_channel(p->vp_eport); /* * Following happens /after/ blocking and setting up ioreq contents. * prepare_wait_on_xen_event_channel() is an implicit barrier. */ p->state = STATE_IOREQ_READY; - notify_via_xen_event_channel(v->domain, v->arch.hvm_vcpu.xen_port); + + notify_via_xen_event_channel(v->domain, p->vp_eport); return 1; } diff --git a/xen/include/asm-x86/hvm/support.h b/xen/include/asm-x86/hvm/support.h index f9b102f..44acd37 100644 --- a/xen/include/asm-x86/hvm/support.h +++ b/xen/include/asm-x86/hvm/support.h @@ -29,13 +29,31 @@ static inline ioreq_t *get_ioreq(struct vcpu *v) { - struct domain *d = v->domain; - shared_iopage_t *p = d->arch.hvm_domain.ioreq.va; - ASSERT((v == current) || spin_is_locked(&d->arch.hvm_domain.ioreq.lock)); - ASSERT(d->arch.hvm_domain.ioreq.va != NULL); + shared_iopage_t *p = v->arch.hvm_vcpu.ioreq->va; + ASSERT((v == current) || spin_is_locked(&v->arch.hvm_vcpu.ioreq->lock)); + ASSERT(v->arch.hvm_vcpu.ioreq->va != NULL); return &p->vcpu_ioreq[v->vcpu_id]; } +static inline void set_ioreq(struct vcpu *v, struct hvm_ioreq_page *page, + ioreq_t *p) +{ + ioreq_t *np; + + v->arch.hvm_vcpu.ioreq = page; + spin_lock(&v->arch.hvm_vcpu.ioreq->lock); + np = get_ioreq(v); + np->dir = p->dir; + np->data_is_ptr = p->data_is_ptr; + np->type = p->type; + np->size = p->size; + np->addr = p->addr; + np->count = p->count; + np->df = p->df; + np->data = p->data; + spin_unlock(&v->arch.hvm_vcpu.ioreq->lock); +} + #define HVM_DELIVER_NO_ERROR_CODE -1 #ifndef NDEBUG