From patchwork Mon Jan 25 12:07:27 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: 08005325@163.com X-Patchwork-Id: 370217 Delivered-To: patch@linaro.org Received: by 2002:a02:a60d:0:0:0:0:0 with SMTP id c13csp3939558jam; Mon, 25 Jan 2021 04:26:36 -0800 (PST) X-Google-Smtp-Source: ABdhPJzbDPKvAD+F96mpX3CDaLLlApdBKeHBLGHjZ0PH4Pz+lLdIe2UA5TP420AT8faYqiy3+okh X-Received: by 2002:a25:ba08:: with SMTP id t8mr345406ybg.316.1611577596718; Mon, 25 Jan 2021 04:26:36 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1611577596; cv=none; d=google.com; s=arc-20160816; b=akpQu7yWPWoKXip7SJUK9FB8bGWSrXK4uKH37WXS1I1YXMbLfIlGsgTpRDkUlOp5rS LNuYCYW8bL6asw3DIU8l3zv9YcmO7EdPWKfFjO+dcMOox6TO8yOEhN5uHBt5RHm2h/O5 XHA1Pn+pDJ4w9a7IsksYoImHt7d46C6/poPH3aCli4J+7g5Apq0Ielm9YaNz7DAtl+5D 2524oOiVts8yv+TiOv2lkueqOdnHzbQ12d9YbdwPFxwViYUQsG6oT4UKM8gjOkXbgXI5 XwEyXXMr2VU4mF/rQYwL6l/y9KH8oqwxZTIFEHsYxdSyf6+U25uee2icsvkxNOw2xguc YDdQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:cc:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:content-transfer-encoding :mime-version:message-id:date:subject:to:from:dkim-signature; bh=IzJtaDBWMa1mh6350s4GLf654FExhE6JDGCznqKqZp4=; b=FUtRya0UDCgzYPAJjuBL4P7KFxjSSVh/2/INvey4sc5V/X4i5H8JUaTlUkAWkAHUQ0 4Qr9cz8Jeo8rB+ncs4lHp89fGFJJ6TkzLSDEQbEoY7doOGlhqnZjQuAP71YPc7ne1LMY RJS4h/YgAdydnzENPvHsjkeWZ4jve4YqQ4b88HRp0YpfcZpoBAix3wUVZOXX4nCSoHxx JtFq5zyGYRvLyZA3XCFqeFf47a13UtGuhn6UYsHA8a4eQBmpaYS7FGjXCoUoxDeHvwoZ ztxxqdy7qpn5pkwT2GESx4s+EmNa2F2JsRMNdq+CyYRYnUuzdfiDedazFQT+Vl6N+iAY 1/mQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@163.com header.s=s110527 header.b=jnDrIn7n; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="qemu-devel-bounces+patch=linaro.org@nongnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=163.com Return-Path: Received: from lists.gnu.org (lists.gnu.org. [209.51.188.17]) by mx.google.com with ESMTPS id p197si18523649ybc.155.2021.01.25.04.26.36 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Mon, 25 Jan 2021 04:26:36 -0800 (PST) Received-SPF: pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; Authentication-Results: mx.google.com; dkim=pass header.i=@163.com header.s=s110527 header.b=jnDrIn7n; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="qemu-devel-bounces+patch=linaro.org@nongnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=163.com Received: from localhost ([::1]:45972 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1l40x2-00068f-87 for patch@linaro.org; Mon, 25 Jan 2021 07:26:36 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]:53138) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from <08005325@163.com>) id 1l40uN-0003m5-KX; Mon, 25 Jan 2021 07:23:51 -0500 Received: from m12-14.163.com ([220.181.12.14]:35382) by eggs.gnu.org with esmtps (TLS1.2:DHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.90_1) (envelope-from <08005325@163.com>) id 1l40uJ-00082M-HP; Mon, 25 Jan 2021 07:23:51 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=163.com; s=s110527; h=From:Subject:Date:Message-Id:MIME-Version; bh=IzJta DBWMa1mh6350s4GLf654FExhE6JDGCznqKqZp4=; b=jnDrIn7n+4F1BhbknqhTY IiCNqlWg9U9dlZeNZkkV1lJij4SmIbZKviSdoeDRXQY0J6UuK0TURXPDkns11lmb iR8zI4IRXyim3zl3RO1Rq0RNL2HMy2GBjnDiOLXVfCfD7xbi8umlJBi68oksB4rU lA1oWBD9Ym6/aalIJCC820= Received: from localhost.localdomain (unknown [116.228.45.98]) by smtp10 (Coremail) with SMTP id DsCowAAnIw+BtA5gjYAihw--.8366S2; Mon, 25 Jan 2021 20:07:30 +0800 (CST) From: 08005325@163.com To: kwolf@redhat.com, mreitz@redhat.com, jsnow@redhat.com Subject: [PATCH] Fix crash with IOthread when block commit after snapshot Date: Mon, 25 Jan 2021 20:07:27 +0800 Message-Id: <20210125120727.7799-1-08005325@163.com> X-Mailer: git-send-email 2.25.1 MIME-Version: 1.0 X-CM-TRANSID: DsCowAAnIw+BtA5gjYAihw--.8366S2 X-Coremail-Antispam: 1Uf129KBjvJXoWxAFyfWF1xAFW7WFyxuw4DArb_yoW5tF1kpr W8Xw4Skr48Kas7ZanFy3W2gw15Kw4v9F4DG3sxJw1rCry7J3WxKFWrAr1YgFy2vrs7Ja1q vFWjga4ftan8C3DanT9S1TB71UUUUUJqnTZGkaVYY2UrUUUUjbIjqfuFe4nvWSU5nxnvy2 9KBjDUYxBIdaVFxhVjvjDU0xZFpf9x07jLEfrUUUUU= X-Originating-IP: [116.228.45.98] X-CM-SenderInfo: qqyqikqtsvqiywtou0bp/xtbBNwIlrF-PIbHe8QAAsT Received-SPF: pass client-ip=220.181.12.14; envelope-from=08005325@163.com; helo=m12-14.163.com X-Spam_score_int: -17 X-Spam_score: -1.8 X-Spam_bar: - X-Spam_report: (-1.8 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, FREEMAIL_ENVFROM_END_DIGIT=0.25, FREEMAIL_FROM=0.001, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H3=0.001, RCVD_IN_MSPIKE_WL=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Michael Qiu , qemu-devel@nongnu.org, qemu-block@nongnu.org Errors-To: qemu-devel-bounces+patch=linaro.org@nongnu.org Sender: "Qemu-devel" From: Michael Qiu Currently, if guest has workloads, IO thread will acquire aio_context lock before do io_submit, it leads to segmentfault when do block commit after snapshot. Just like below: [Switching to thread 2 (Thread 0x7f046c312700 (LWP 108791))] #0 0x00005573f57930db in bdrv_mirror_top_pwritev ... at block/mirror.c:1420 1420 in block/mirror.c (gdb) p s->job $17 = (MirrorBlockJob *) 0x0 (gdb) p s->stop $18 = false (gdb) (gdb) bt #0 0x00005573f57930db in bdrv_mirror_top_pwritev ... at block/mirror.c:1420 #1 0x00005573f5798ceb in bdrv_driver_pwritev ... at block/io.c:1183 #2 0x00005573f579ae7a in bdrv_aligned_pwritev ... at block/io.c:1980 #3 0x00005573f579b667 in bdrv_co_pwritev_part ... at block/io.c:2137 #4 0x00005573f57886c8 in blk_do_pwritev_part ... at block/block-backend.c:1231 #5 0x00005573f578879d in blk_aio_write_entry ... at block/block-backend.c:1439 #6 0x00005573f58317cb in coroutine_trampoline ... at util/coroutine-ucontext.c:115 #7 0x00007f047414a0d0 in __start_context () at /lib64/libc.so.6 #8 0x00007f046c310e60 in () #9 0x0000000000000000 in () Switch to qmp: #0 0x00007f04744dd4ed in __lll_lock_wait () at /lib64/libpthread.so.0 #1 0x00007f04744d8de6 in _L_lock_941 () at /lib64/libpthread.so.0 #2 0x00007f04744d8cdf in pthread_mutex_lock () at /lib64/libpthread.so.0 #3 0x00005573f581de89 in qemu_mutex_lock_impl ... at util/qemu-thread-posix.c:78 #4 0x00005573f575789e in block_job_add_bdrv ... at blockjob.c:223 #5 0x00005573f5757ebd in block_job_create ... at blockjob.c:441 #6 0x00005573f5792430 in mirror_start_job ... at block/mirror.c:1604 #7 0x00005573f5794b6f in commit_active_start ... at block/mirror.c:1789 in IO thread when do bdrv_mirror_top_pwritev, the job is NULL, and stop field is false, this means the s object has not been initialized, and this object is initialized by block_job_create(), but the initialize process stuck in acquire the lock. The rootcause is that qemu do release/acquire when hold the lock, at the same time, IO thread get the lock after release stage, and the crash occured. Actually, in this situation, job->job.aio_context will not equal to qemu_get_aio_context(), and will be the same as bs->aio_context, thus, no need to release the lock, becasue bdrv_root_attach_child() will not change the context. This patch fix this issue. Signed-off-by: Michael Qiu --- blockjob.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) -- 2.22.0 diff --git a/blockjob.c b/blockjob.c index c6e20e2f..e1d41db9 100644 --- a/blockjob.c +++ b/blockjob.c @@ -214,12 +214,14 @@ int block_job_add_bdrv(BlockJob *job, const char *name, BlockDriverState *bs, BdrvChild *c; bdrv_ref(bs); - if (job->job.aio_context != qemu_get_aio_context()) { + if (bdrv_get_aio_context(bs) != job->job.aio_context && + job->job.aio_context != qemu_get_aio_context()) { aio_context_release(job->job.aio_context); } c = bdrv_root_attach_child(bs, name, &child_job, job->job.aio_context, perm, shared_perm, job, errp); - if (job->job.aio_context != qemu_get_aio_context()) { + if (bdrv_get_aio_context(bs) != job->job.aio_context && + job->job.aio_context != qemu_get_aio_context()) { aio_context_acquire(job->job.aio_context); } if (c == NULL) {