From nobody Sat May 18 18:27:43 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org ARC-Seal: i=1; a=rsa-sha256; t=1598448413; cv=none; d=zohomail.com; s=zohoarc; b=JuKqqlbz2f3kzNSlMw0GT9zy43vz7kZSIsWrGHM+jG+RIRkBtnLOpyjPJoifKt5fHhglpp8H/wShJs9cKavssRzFh7Pc5pgA6G99t14cr6xjcMQ57jrLFqhmuqnHT2xAQYYMv8RFKf+CYdBUnfLLEGejnkCL0HT8Ch3JXSoT9w0= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1598448413; h=Content-Type:Cc:Date:From:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:Sender:Subject:To; bh=QHaHZSLnJakul0M5+93sa1GDOFicLRCu9tuDE9O63sM=; b=fbZr1hCc0hCXUlIktn3ueKPLnNppswKjhR2ZOH+96+2p+x3NvmX8whuGPvharbqGHiPfIC6NMa0e8lKT0dYca/BHkFsaMjqTIGgKmM3qjkPJTjw+zc79/ezWQw91mmHhLG7WKL35LGifsRuLu/fccrSNrsoOrCmkRX2g3xTfvGE= ARC-Authentication-Results: i=1; mx.zohomail.com; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 15984484132033.9855890206202957; Wed, 26 Aug 2020 06:26:53 -0700 (PDT) Received: from localhost ([::1]:56352 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1kAvRz-0002kH-Ct for importer@patchew.org; Wed, 26 Aug 2020 09:26:51 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:54768) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1kAvRO-0002Kt-06; Wed, 26 Aug 2020 09:26:14 -0400 Received: from szxga07-in.huawei.com ([45.249.212.35]:60870 helo=huawei.com) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1kAvRJ-00059m-An; Wed, 26 Aug 2020 09:26:13 -0400 Received: from DGGEMS410-HUB.china.huawei.com (unknown [172.30.72.59]) by Forcepoint Email with ESMTP id 67FFFD0FFA45DC9DE000; Wed, 26 Aug 2020 21:25:51 +0800 (CST) Received: from localhost.localdomain (10.175.104.175) by DGGEMS410-HUB.china.huawei.com (10.3.19.210) with Microsoft SMTP Server id 14.3.487.0; Wed, 26 Aug 2020 21:25:45 +0800 From: Peng Liang To: , , Subject: [PATCH] block/mirror: fix core when using iothreads Date: Wed, 26 Aug 2020 21:19:10 +0800 Message-ID: <20200826131910.1879079-1-liangpeng10@huawei.com> X-Mailer: git-send-email 2.18.4 MIME-Version: 1.0 X-Originating-IP: [10.175.104.175] X-CFilter-Loop: Reflected Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=45.249.212.35; envelope-from=liangpeng10@huawei.com; helo=huawei.com X-detected-operating-system: by eggs.gnu.org: First seen = 2020/08/26 09:25:52 X-ACL-Warn: Detected OS = Linux 3.11 and newer [fuzzy] X-Spam_score_int: -41 X-Spam_score: -4.2 X-Spam_bar: ---- X-Spam_report: (-4.2 / 5.0 requ) BAYES_00=-1.9, RCVD_IN_DNSWL_MED=-2.3, RCVD_IN_MSPIKE_H4=0.001, RCVD_IN_MSPIKE_WL=0.001, SPF_HELO_PASS=-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: Peng Liang , qemu-devel@nongnu.org, xiexiangyou@huawei.com, zhang.zhanghailiang@huawei.com Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" We found an issue when doing block-commit with iothreads, which tries to dereference a NULL pointer.
| | mirror_start_job | 1. bdrv_ref(mirror_top_bs); | bdrv_drained_begin(bs); | bdrv_append(mirror_top_bs, | bs, &local_err); | bdrv_drained_end(bs); | | 2. s =3D block_job_create(...); | |bdrv_mirror_top_pwritev | MirrorBDSOpaque *s =3D bs->opaque; | bool copy_to_target; | copy_to_target =3D s->job->ret >=3D 0 = && | s->job->copy_mode =3D=3D | MIRROR_COPY_MODE_WRITE_BLOCKING; | (s->job is not NULL until 3!) 3. bs_opaque->job =3D s; | Just moving step 2 & 3 before 1 can avoid this. Reported-by: Euler Robot Signed-off-by: Peng Liang --- block/mirror.c | 21 ++++++++++----------- 1 file changed, 10 insertions(+), 11 deletions(-) diff --git a/block/mirror.c b/block/mirror.c index e8e8844afc40..7c872be71149 100644 --- a/block/mirror.c +++ b/block/mirror.c @@ -1600,6 +1600,16 @@ static BlockJob *mirror_start_job( mirror_top_bs->supported_zero_flags =3D BDRV_REQ_WRITE_UNCHANGED | BDRV_REQ_NO_FALLBACK; bs_opaque =3D g_new0(MirrorBDSOpaque, 1); + /* Make sure that the source is not resized while the job is running */ + s =3D block_job_create(job_id, driver, NULL, bs, + BLK_PERM_CONSISTENT_READ, + BLK_PERM_CONSISTENT_READ | BLK_PERM_WRITE_UNCHANG= ED | + BLK_PERM_WRITE | BLK_PERM_GRAPH_MOD, speed, + creation_flags, cb, opaque, errp); + if (!s) { + goto fail; + } + bs_opaque->job =3D s; mirror_top_bs->opaque =3D bs_opaque; =20 /* bdrv_append takes ownership of the mirror_top_bs reference, need to= keep @@ -1612,19 +1622,8 @@ static BlockJob *mirror_start_job( if (local_err) { bdrv_unref(mirror_top_bs); error_propagate(errp, local_err); - return NULL; - } - - /* Make sure that the source is not resized while the job is running */ - s =3D block_job_create(job_id, driver, NULL, mirror_top_bs, - BLK_PERM_CONSISTENT_READ, - BLK_PERM_CONSISTENT_READ | BLK_PERM_WRITE_UNCHANG= ED | - BLK_PERM_WRITE | BLK_PERM_GRAPH_MOD, speed, - creation_flags, cb, opaque, errp); - if (!s) { goto fail; } - bs_opaque->job =3D s; =20 /* The block job now has a reference to this node */ bdrv_unref(mirror_top_bs); --=20 2.18.4