From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([2001:4830:134:3::10]:51036) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ZydNF-0002yM-Qt for qemu-devel@nongnu.org; Tue, 17 Nov 2015 05:20:30 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1ZydNF-0005zB-0b for qemu-devel@nongnu.org; Tue, 17 Nov 2015 05:20:29 -0500 From: Fam Zheng Date: Tue, 17 Nov 2015 18:20:11 +0800 Message-Id: <1447755611-11117-1-git-send-email-famz@redhat.com> Subject: [Qemu-devel] [PATCH v3] virtio-blk: Fix double completion for werror=stop List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: qemu-devel@nongnu.org Cc: Kevin Wolf , lvivier@redhat.com, qemu-block@nongnu.org, pl@kamp.de, qemu-stable@nongnu.org, Stefan Hajnoczi , pbonzini@redhat.com, dgibson@redhat.com When a request R is absorbed by request M, it is appended to the "mr_next" queue led by M, and is completed together with the completion of M, in virtio_blk_rw_complete. During DMA restart in virtio_blk_dma_restart_bh, requests in s->rq are parsed and submitted again, possibly with a stale req->mr_next. It could be a problem if the request merging in virtio_blk_handle_request hasn't refreshed every mr_next pointer, in which case, virtio_blk_rw_complete could walk through unexpected requests following the stale pointers. Fix this by unsetting the pointer in virtio_blk_rw_complete. It is safe because this req is either completed and freed right away, or it will be restarted and parsed from scratch out of the vq later. Signed-off-by: Fam Zheng --- v3: Fix as Stefan suggested. --- hw/block/virtio-blk.c | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/hw/block/virtio-blk.c b/hw/block/virtio-blk.c index e70fccf..848f3fe 100644 --- a/hw/block/virtio-blk.c +++ b/hw/block/virtio-blk.c @@ -112,6 +112,10 @@ static void virtio_blk_rw_complete(void *opaque, int ret) * happen on the other side of the migration). */ if (virtio_blk_handle_rw_error(req, -ret, is_read)) { + /* Break the link in case the next request is added to the + * restart queue and is going to be parsed from the ring again. + */ + req->mr_next = NULL; continue; } } -- 2.4.3