From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([2001:4830:134:3::10]:58268) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1bHoae-0005tg-Fk for qemu-devel@nongnu.org; Tue, 28 Jun 2016 04:41:53 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1bHoac-0007CG-FY for qemu-devel@nongnu.org; Tue, 28 Jun 2016 04:41:51 -0400 Received: from mail-vk0-x241.google.com ([2607:f8b0:400c:c05::241]:35961) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1bHoac-0007C8-BZ for qemu-devel@nongnu.org; Tue, 28 Jun 2016 04:41:50 -0400 Received: by mail-vk0-x241.google.com with SMTP id v188so1359705vkf.3 for ; Tue, 28 Jun 2016 01:41:50 -0700 (PDT) MIME-Version: 1.0 In-Reply-To: <20160624144605.GF5422@noname.redhat.com> References: <1466775608-31052-1-git-send-email-roman.penyaev@profitbricks.com> <20160624144605.GF5422@noname.redhat.com> From: Stefan Hajnoczi Date: Tue, 28 Jun 2016 09:41:49 +0100 Message-ID: Content-Type: text/plain; charset=UTF-8 Subject: Re: [Qemu-devel] [PATCH 1/1] Revert "linux-aio: Cancel BH if not needed" List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: Kevin Wolf Cc: Roman Pen , Paolo Bonzini , qemu-devel , Stefan Hajnoczi On Fri, Jun 24, 2016 at 3:46 PM, Kevin Wolf wrote: >> diff --git a/block/linux-aio.c b/block/linux-aio.c >> index e468960..fe7cece 100644 >> --- a/block/linux-aio.c >> +++ b/block/linux-aio.c >> @@ -149,8 +149,6 @@ static void qemu_laio_completion_bh(void *opaque) >> if (!s->io_q.plugged && !QSIMPLEQ_EMPTY(&s->io_q.pending)) { >> ioq_submit(s); >> } >> - >> - qemu_bh_cancel(s->completion_bh); >> } > > Maybe if a nested event loops cancels the BH, it's missing on the next > loop iteration. Before my patch, the nested callback happened to leave > an additional BH around which the outer one actually needs. The scenario you described is: qemu_laio_completion_bh() -> cb1() -> aio_poll() -> qemu_laio_completion_bh() <- qemu_laio_completion_bh() (cancel BH) <- aio_poll() <- cb1() -> cb2() -> aio_poll() (hang!) This hang seems impossible because the qemu_laio_completion_bh() loop processes all pending events. Therefore cb1() consumes all pending events and cb2() will not poll. If new I/O was submitted during cb1() and cb2() waits for it, then the eventfd will become readable upon completion and cb2() does not hang in that case either. If, instead of the original scenario, cb1() nests deeper then the BH is still scheduled and events will be processed without a hang. In summary, the job of scheduling the BH is not to force all nested callbacks to call qemu_laio_completion_bh(). Only the first nested callback needs the BH so that all pending events will be processed. Stefan