From patchwork Mon Jun 27 16:37:48 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Stefan Hajnoczi X-Patchwork-Id: 9200905 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id 9B32960752 for ; Mon, 27 Jun 2016 16:38:21 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 8D40428470 for ; Mon, 27 Jun 2016 16:38:21 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 81A68285A2; Mon, 27 Jun 2016 16:38:21 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-6.9 required=2.0 tests=BAYES_00,RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id BB2DD28470 for ; Mon, 27 Jun 2016 16:38:20 +0000 (UTC) Received: from localhost ([::1]:59882 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1bHZYB-0004Rg-NP for patchwork-qemu-devel@patchwork.kernel.org; Mon, 27 Jun 2016 12:38:19 -0400 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 Received: from int-mx13.intmail.prod.int.phx2.redhat.com (int-mx13.intmail.prod.int.phx2.redhat.com [10.5.11.26]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 183B4C049D7F; Mon, 27 Jun 2016 16:37:50 +0000 (UTC) Received: from localhost (ovpn-112-65.ams2.redhat.com [10.36.112.65]) by int-mx13.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id u5RGbmPi007887; Mon, 27 Jun 2016 12:37:49 -0400 From: Stefan Hajnoczi To: qemu-devel@nongnu.org Date: Mon, 27 Jun 2016 17:37:48 +0100 Message-Id: <1467045468-25709-1-git-send-email-stefanha@redhat.com> X-Scanned-By: MIMEDefang 2.68 on 10.5.11.26 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.31]); Mon, 27 Jun 2016 16:37:50 +0000 (UTC) X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 209.132.183.28 Subject: [Qemu-devel] [PATCH] linux-aio: keep processing events if MAX_EVENTS reached X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Kevin Wolf , Paolo Bonzini , Stefan Hajnoczi , roman.penyaev@profitbricks.com Errors-To: qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Sender: "Qemu-devel" X-Virus-Scanned: ClamAV using ClamSMTP 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); }