Received: from eggs.gnu.org ([2001:4830:134:3::10]:46351) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1YWLQm-0000ZJ-4f for qemu-devel@nongnu.org; Fri, 13 Mar 2015 04:58:57 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1YWLQi-0006tD-VA for qemu-devel@nongnu.org; Fri, 13 Mar 2015 04:58:56 -0400 Received: from mx1.redhat.com ([209.132.183.28]:33554) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1YWLQi-0006t6-Na for qemu-devel@nongnu.org; Fri, 13 Mar 2015 04:58:52 -0400 Received: from int-mx13.intmail.prod.int.phx2.redhat.com (int-mx13.intmail.prod.int.phx2.redhat.com [10.5.11.26]) by mx1.redhat.com (8.14.4/8.14.4) with ESMTP id t2D8wpAI001351 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=FAIL) for ; Fri, 13 Mar 2015 04:58:51 -0400 Date: Fri, 13 Mar 2015 16:58:47 +0800 From: Fam Zheng Message-ID: <20150313085847.GC3527@ad.nay.redhat.com> References: <1426210723-16735-1-git-send-email-famz@redhat.com> <1426210723-16735-5-git-send-email-famz@redhat.com> <55029C22.1070901@redhat.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <55029C22.1070901@redhat.com> Subject: Re: [Qemu-devel] [PATCH v2 4/4] dma-helpers: Move reschedule_dma BH to blk's AioContext List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: Paolo Bonzini Cc: qemu-devel@nongnu.org On Fri, 03/13 09:13, Paolo Bonzini wrote: > > > On 13/03/2015 02:38, Fam Zheng wrote: > > That if the dbs' owner is an iothread, dma should be resumed on the right > > thread. In this case it is the AioContext of the block device. > > > > Signed-off-by: Fam Zheng > > --- > > dma-helpers.c | 4 +++- > > 1 file changed, 3 insertions(+), 1 deletion(-) > > > > diff --git a/dma-helpers.c b/dma-helpers.c > > index 6918572..84f61a7 100644 > > --- a/dma-helpers.c > > +++ b/dma-helpers.c > > @@ -95,8 +95,10 @@ static void reschedule_dma(void *opaque) > > static void continue_after_map_failure(void *opaque) > > { > > DMAAIOCB *dbs = (DMAAIOCB *)opaque; > > + AioContext *ctx; > > > > - dbs->bh = qemu_bh_new(reschedule_dma, dbs); > > + ctx = blk_get_aio_context(dbs->blk); > > + dbs->bh = aio_bh_new(ctx, reschedule_dma, dbs); > > qemu_bh_schedule(dbs->bh); > > } > > > > > > This looks good. However, I wonder if dma_aio_cancel should also call > cpu_unregister_map_client. In this case, it's much better to just use a > lock for the list (though you can still use atomics for the in-use flag). The other possibility is grab a reference for the cpu_register_map_client call, and release it in reschedule_dma. This way the atomics can keep, but we'll need a "finished" flag in DMAAIOCB to avoid double completion. Fam