From patchwork Sun Jun 10 07:43:33 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Fam Zheng X-Patchwork-Id: 10456593 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 32C18603B4 for ; Sun, 10 Jun 2018 07:44:27 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 16965223B3 for ; Sun, 10 Jun 2018 07:44:27 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 075082621E; Sun, 10 Jun 2018 07:44:27 +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=-7.9 required=2.0 tests=BAYES_00, MAILING_LIST_MULTI, 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 61B87223B3 for ; Sun, 10 Jun 2018 07:44:26 +0000 (UTC) Received: from localhost ([::1]:43104 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fRv1V-0006jy-7b for patchwork-qemu-devel@patchwork.kernel.org; Sun, 10 Jun 2018 03:44:25 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:41418) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fRv0n-0006Ma-Pl for qemu-devel@nongnu.org; Sun, 10 Jun 2018 03:43:43 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1fRv0k-000134-Lt for qemu-devel@nongnu.org; Sun, 10 Jun 2018 03:43:41 -0400 Received: from mx3-rdu2.redhat.com ([66.187.233.73]:33864 helo=mx1.redhat.com) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1fRv0k-00012N-FL for qemu-devel@nongnu.org; Sun, 10 Jun 2018 03:43:38 -0400 Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.rdu2.redhat.com [10.11.54.3]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id ECEE3C12B9; Sun, 10 Jun 2018 07:43:36 +0000 (UTC) Received: from localhost (ovpn-12-31.pek2.redhat.com [10.72.12.31]) by smtp.corp.redhat.com (Postfix) with ESMTP id 1351D111AF39; Sun, 10 Jun 2018 07:43:35 +0000 (UTC) Date: Sun, 10 Jun 2018 15:43:33 +0800 From: Fam Zheng To: l00284672 Message-ID: <20180610074333.GA16232@lemon.usersys.redhat.com> References: MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: User-Agent: Mutt/1.9.5 (2018-04-13) X-Scanned-By: MIMEDefang 2.78 on 10.11.54.3 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.11.55.1]); Sun, 10 Jun 2018 07:43:36 +0000 (UTC) X-Greylist: inspected by milter-greylist-4.5.16 (mx1.redhat.com [10.11.55.1]); Sun, 10 Jun 2018 07:43:36 +0000 (UTC) for IP:'10.11.54.3' DOMAIN:'int-mx03.intmail.prod.int.rdu2.redhat.com' HELO:'smtp.corp.redhat.com' FROM:'famz@redhat.com' RCPT:'' X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 66.187.233.73 Subject: Re: [Qemu-devel] question: a dead loop in qemu when do blockJobAbort and vm suspend coinstantaneously 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: kwolf@redhat.com, stefanha@gmail.com, qemu-devel@nongnu.org Errors-To: qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Sender: "Qemu-devel" X-Virus-Scanned: ClamAV using ClamSMTP On Sat, 06/09 17:10, l00284672 wrote: > Hi, I found a dead loop in qemu when do blockJobAbort and vm suspend > coinstantaneously. > > The qemu bt is below: > > #0  0x00007ff58b53af1f in ppoll () from /lib64/libc.so.6 > #1  0x00000000007fdbd9 in ppoll (__ss=0x0, __timeout=0x7ffcf7055390, > __nfds=, __fds=) at > /usr/include/bits/poll2.h:77 > #2  qemu_poll_ns (fds=, nfds=, > timeout=timeout@entry=0) at util/qemu-timer.c:334 > #3  0x00000000007ff83a in aio_poll (ctx=ctx@entry=0x269d800, > blocking=blocking@entry=false) at util/aio-posix.c:629 > #4  0x0000000000776e91 in bdrv_drain_recurse (bs=bs@entry=0x26d9cb0) at > block/io.c:198 > #5  0x0000000000776ef2 in bdrv_drain_recurse (bs=bs@entry=0x3665990) at > block/io.c:215 > #6  0x00000000007774b8 in bdrv_do_drained_begin (bs=0x3665990, > recursive=, parent=0x0) at block/io.c:291 > #7  0x000000000076a79e in blk_drain (blk=0x2780fc0) at > block/block-backend.c:1586 > #8  0x000000000072d2a9 in block_job_drain (job=0x29df040) at blockjob.c:123 > #9  0x000000000072d228 in block_job_detach_aio_context (opaque=0x29df040) at > blockjob.c:139 > #10 0x00000000007298b1 in bdrv_detach_aio_context (bs=bs@entry=0x3665990) at > block.c:4885 > #11 0x0000000000729a46 in bdrv_set_aio_context (bs=0x3665990, > new_context=0x268e140) at block.c:4946 > #12 0x0000000000499743 in virtio_blk_data_plane_stop (vdev=) > at > /mnt/sdb/lzg/code/shequ_code/5_29/qemu/hw/block/dataplane/virtio-blk.c:285 > #13 0x00000000006bce30 in virtio_bus_stop_ioeventfd (bus=0x3de5378) at > hw/virtio/virtio-bus.c:246 > #14 0x00000000004c654d in virtio_vmstate_change (opaque=0x3de53f0, > running=, state=) >     at /mnt/sdb/lzg/code/shequ_code/5_29/qemu/hw/virtio/virtio.c:2222 > #15 0x0000000000561b52 in vm_state_notify (running=running@entry=0, > state=state@entry=RUN_STATE_PAUSED) at vl.c:1514 > #16 0x000000000045d67a in do_vm_stop (state=state@entry=RUN_STATE_PAUSED, > send_stop=send_stop@entry=true) >     at /mnt/sdb/lzg/code/shequ_code/5_29/qemu/cpus.c:1012 > #17 0x000000000045dafd in vm_stop (state=state@entry=RUN_STATE_PAUSED) at > /mnt/sdb/lzg/code/shequ_code/5_29/qemu/cpus.c:2035 > #18 0x000000000057301b in qmp_stop (errp=errp@entry=0x7ffcf70556f0) at > qmp.c:106 > #19 0x000000000056bf7a in qmp_marshal_stop (args=, > ret=, errp=0x7ffcf7055738) at qapi/qapi-commands-misc.c:784 > #20 0x00000000007f2d27 in do_qmp_dispatch (errp=0x7ffcf7055730, > request=0x3e121e0, cmds=) at qapi/qmp-dispatch.c:119 > #21 qmp_dispatch (cmds=, request=request@entry=0x26f2800) at > qapi/qmp-dispatch.c:168 > #22 0x00000000004655be in monitor_qmp_dispatch_one > (req_obj=req_obj@entry=0x39abff0) at > /mnt/sdb/lzg/code/shequ_code/5_29/qemu/monitor.c:4088 > #23 0x0000000000465894 in monitor_qmp_bh_dispatcher (data=) > at /mnt/sdb/lzg/code/shequ_code/5_29/qemu/monitor.c:4146 > #24 0x00000000007fc571 in aio_bh_call (bh=0x26de7e0) at util/async.c:90 > #25 aio_bh_poll (ctx=ctx@entry=0x268dd50) at util/async.c:118 > #26 0x00000000007ff6f0 in aio_dispatch (ctx=0x268dd50) at > util/aio-posix.c:436 > #27 0x00000000007fc44e in aio_ctx_dispatch (source=, > callback=, user_data=) at util/async.c:261 > #28 0x00007ff58bc7c99a in g_main_context_dispatch () from > /lib64/libglib-2.0.so.0 > #29 0x00000000007fea3a in glib_pollfds_poll () at util/main-loop.c:215 > #30 os_host_main_loop_wait (timeout=) at util/main-loop.c:238 > #31 main_loop_wait (nonblocking=nonblocking@entry=0) at util/main-loop.c:497 > #32 0x0000000000561cad in main_loop () at vl.c:1848 > #33 0x000000000041995c in main (argc=, argv=, > envp=) at vl.c:4605 > > The disk is a virtio-blk dataplane disk with a mirror job running.  The dead > loop is here: > > static void block_job_detach_aio_context(void *opaque) > { >     BlockJob *job = opaque; > >     /* In case the job terminates during aio_poll()... */ >     job_ref(&job->job); > >     job_pause(&job->job); > >   while (!job->job.paused && !job_is_completed(&job->job)) { >         job_drain(&job->job); >     } > >     job->job.aio_context = NULL; >     job_unref(&job->job); > } > > The job is deferred to main loop now,  but the  job_drain only processes the > AIO context of bs which has no more work to do, > > while the main loop BH is scheduled for setting the job->completed flag is > never processed. In that case, main loop's AioContext should be driven like in job_finish_sync(). Could you try this patch? diff --git a/blockjob.c b/blockjob.c index 0306533a2e..72aa82ac2d 100644 --- a/blockjob.c +++ b/blockjob.c @@ -135,7 +135,15 @@ static void block_job_detach_aio_context(void *opaque) job_pause(&job->job); - while (!job->job.paused && !job_is_completed(&job->job)) { + + while (true) { + if (job->job.paused || job_is_completed(&job->job)) { + break; + } + if (job->deferred_to_main_loop) { + aio_poll(qemu_get_aio_context(), true); + continue; + } job_drain(&job->job); }