From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([2001:4830:134:3::10]:39453) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ZwnVl-0003Aj-7B for qemu-devel@nongnu.org; Thu, 12 Nov 2015 03:45:42 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1ZwnVh-0004wE-VJ for qemu-devel@nongnu.org; Thu, 12 Nov 2015 03:45:41 -0500 Received: from mx-v6.kamp.de ([2a02:248:0:51::16]:38001 helo=mx01.kamp.de) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ZwnVh-0004vf-Mp for qemu-devel@nongnu.org; Thu, 12 Nov 2015 03:45:37 -0500 References: <1446799373-6144-1-git-send-email-pl@kamp.de> <1446799373-6144-5-git-send-email-pl@kamp.de> <20151112082736.GP4082@ad.usersys.redhat.com> From: Peter Lieven Message-ID: <564451AC.7070203@kamp.de> Date: Thu, 12 Nov 2015 09:45:32 +0100 MIME-Version: 1.0 In-Reply-To: <20151112082736.GP4082@ad.usersys.redhat.com> Content-Type: text/plain; charset=windows-1252; format=flowed Content-Transfer-Encoding: 7bit Subject: Re: [Qemu-devel] [PATCH V3 4/6] ide: orphan all buffered requests on DMA cancel List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: Fam Zheng Cc: kwolf@redhat.com, qemu-block@nongnu.org, stefanha@gmail.com, jcody@redhat.com, qemu-devel@nongnu.org, jsnow@redhat.com Am 12.11.2015 um 09:27 schrieb Fam Zheng: > On Fri, 11/06 09:42, Peter Lieven wrote: >> 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 >> --- >> hw/ide/pci.c | 19 +++++++++++++++++++ >> 1 file changed, 19 insertions(+) >> >> diff --git a/hw/ide/pci.c b/hw/ide/pci.c >> index d31ff88..a9e164e 100644 >> --- a/hw/ide/pci.c >> +++ b/hw/ide/pci.c >> @@ -240,6 +240,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; >> + } > Why not use bdrv_aio_cancel or bdrv_aio_cancel_async with the aio returned by > bdrv_aio_cancel? bdrv_aio_cancel would block until the request is completed, that wouldn't help if the storage is no longer responsive. The trick with the buffered request is that we can avoid waiting for the storage and guarantee that a later completion on the storage won't corrupt guest memory. Peter