From patchwork Tue Nov 17 20:12:53 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: John Snow X-Patchwork-Id: 545769 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from lists.gnu.org (lists.gnu.org [IPv6:2001:4830:134:3::11]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id BD65814030F for ; Wed, 18 Nov 2015 07:17:07 +1100 (AEDT) Received: from localhost ([::1]:60535 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Zymgc-00086S-00 for incoming@patchwork.ozlabs.org; Tue, 17 Nov 2015 15:17:06 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:58228) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Zymcg-0002NW-6v for qemu-devel@nongnu.org; Tue, 17 Nov 2015 15:13:03 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1Zymce-0002K2-HD for qemu-devel@nongnu.org; Tue, 17 Nov 2015 15:13:02 -0500 Received: from mx1.redhat.com ([209.132.183.28]:44145) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Zymce-0002Jx-Bd for qemu-devel@nongnu.org; Tue, 17 Nov 2015 15:13:00 -0500 Received: from int-mx09.intmail.prod.int.phx2.redhat.com (int-mx09.intmail.prod.int.phx2.redhat.com [10.5.11.22]) by mx1.redhat.com (Postfix) with ESMTPS id E9535AACE1; Tue, 17 Nov 2015 20:12:59 +0000 (UTC) Received: from scv.usersys.redhat.com (dhcp-17-163.bos.redhat.com [10.18.17.163]) by int-mx09.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id tAHKCuLb016753; Tue, 17 Nov 2015 15:12:59 -0500 From: John Snow To: qemu-devel@nongnu.org Date: Tue, 17 Nov 2015 15:12:53 -0500 Message-Id: <1447791175-22814-5-git-send-email-jsnow@redhat.com> In-Reply-To: <1447791175-22814-1-git-send-email-jsnow@redhat.com> References: <1447791175-22814-1-git-send-email-jsnow@redhat.com> X-Scanned-By: MIMEDefang 2.68 on 10.5.11.22 X-detected-operating-system: by eggs.gnu.org: GNU/Linux 3.x X-Received-From: 209.132.183.28 Cc: Peter Lieven , peter.maydell@linaro.org, jsnow@redhat.com Subject: [Qemu-devel] [PULL 4/6] ide: orphan all buffered requests on DMA cancel 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 From: Peter Lieven If the guests canceles a DMA request we can prematurely invoke all callbacks of buffered requests and flag all them as orphaned. Ideally this avoids the need for draining all requests. For CDROM devices this works in 100% of all cases. Signed-off-by: Peter Lieven Reviewed-by: Fam Zheng Message-id: 1447345846-15624-5-git-send-email-pl@kamp.de Signed-off-by: John Snow --- hw/ide/pci.c | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/hw/ide/pci.c b/hw/ide/pci.c index 9c54b37..37dbc29 100644 --- a/hw/ide/pci.c +++ b/hw/ide/pci.c @@ -233,6 +233,22 @@ void bmdma_cmd_writeb(BMDMAState *bm, uint32_t val) /* Ignore writes to SSBM if it keeps the old value */ if ((val & BM_CMD_START) != (bm->cmd & BM_CMD_START)) { if (!(val & BM_CMD_START)) { + /* First invoke the callbacks of all buffered requests + * and flag those requests as orphaned. Ideally there + * are no unbuffered (Scatter Gather DMA Requests or + * write requests) pending and we can avoid to drain. */ + IDEBufferedRequest *req; + IDEState *s = idebus_active_if(bm->bus); + QLIST_FOREACH(req, &s->buffered_requests, list) { + if (!req->orphaned) { +#ifdef DEBUG_IDE + printf("%s: invoking cb %p of buffered request %p with" + " -ECANCELED\n", __func__, req->original_cb, req); +#endif + req->original_cb(req->original_opaque, -ECANCELED); + } + req->orphaned = true; + } /* * We can't cancel Scatter Gather DMA in the middle of the * operation or a partial (not full) DMA transfer would reach @@ -246,6 +262,9 @@ void bmdma_cmd_writeb(BMDMAState *bm, uint32_t val) * aio operation with preadv/pwritev. */ if (bm->bus->dma->aiocb) { +#ifdef DEBUG_IDE + printf("%s: draining all remaining requests", __func__); +#endif blk_drain_all(); assert(bm->bus->dma->aiocb == NULL); }