Received: from eggs.gnu.org ([2001:4830:134:3::10]:47753) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1bHZXn-0004QF-Dy for qemu-devel@nongnu.org; Mon, 27 Jun 2016 12:37:56 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1bHZXj-0006To-EM for qemu-devel@nongnu.org; Mon, 27 Jun 2016 12:37:55 -0400 Received: from mx1.redhat.com ([209.132.183.28]:48401) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1bHZXj-0006Th-91 for qemu-devel@nongnu.org; Mon, 27 Jun 2016 12:37:51 -0400 From: Stefan Hajnoczi Date: Mon, 27 Jun 2016 17:37:48 +0100 Message-Id: <1467045468-25709-1-git-send-email-stefanha@redhat.com> Subject: [Qemu-devel] [PATCH] linux-aio: keep processing events if MAX_EVENTS reached List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: qemu-devel@nongnu.org Cc: Kevin Wolf , Paolo Bonzini , roman.penyaev@profitbricks.com, Stefan Hajnoczi Commit ccb9dc10129954d0bcd7814298ed445e684d5a2a ("linux-aio: Cancel BH if not needed") exposed a side-effect of scheduling the BH for nested event loops. When io_getevents(2) fetches MAX_EVENTS events then it's necessary to call it again. Failure to do so can lead to hung I/O because the eventfd has already been cleared and the completion BH will not run again. This patch fixes the hang by calling io_getevents(2) again if the events array was totally full. Reported-by: Roman Penyaev Signed-off-by: Stefan Hajnoczi --- block/linux-aio.c | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/block/linux-aio.c b/block/linux-aio.c index e468960..af15f85 100644 --- a/block/linux-aio.c +++ b/block/linux-aio.c @@ -117,6 +117,7 @@ static void qemu_laio_completion_bh(void *opaque) LinuxAioState *s = opaque; /* Fetch more completion events when empty */ +more_events: if (s->event_idx == s->event_max) { do { struct timespec ts = { 0 }; @@ -146,6 +147,10 @@ static void qemu_laio_completion_bh(void *opaque) qemu_laio_process_completion(laiocb); } + if (s->event_idx == MAX_EVENTS) { + goto more_events; /* there might still be events waiting for us */ + } + if (!s->io_q.plugged && !QSIMPLEQ_EMPTY(&s->io_q.pending)) { ioq_submit(s); } -- 2.7.4