From nobody Mon May 20 13:01:29 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; 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; dmarc=pass(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1683751032; cv=none; d=zohomail.com; s=zohoarc; b=bsi8WPGviaeO+ZerWeesDSRXaUOt/Kf8wPJMCOiFSaA4nEUFhBayKTTyoz6XsUYiYiH0rqnWJeCofCpkZCmUXX1YXSPwremLVPOyeYV9lVDB5po3TdqgV9TIDvhb0iFUu3qFiSSEQSGkkTuHb13CcJVlcNhVS0X3RtEEigg+E8k= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1683751032; h=Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=aNhV+rBBNi2TzLpEJaq/ZsnHcLW446pXsJVZCiEGoGE=; b=npk0wEvZVsW1T2MPGNUb+JAjxQYi0a0FS5UgzSbrj65/OvjngnQ4wymkoe1SsVp3FaoXwDlxtlmUdoVTRT1rihqCsf/IEXIGTcVYu0exkKVEXdRvXkNkyW3LG+YSuvPPch785ax//EoBu/r8SnNaMZ6oL7h6ZbvQeDV0F1gPz9w= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; 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; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1683751032096439.4039921299724; Wed, 10 May 2023 13:37:12 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1pwqY3-0005Ch-IE; Wed, 10 May 2023 16:36:31 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1pwqY1-00059z-AX for qemu-devel@nongnu.org; Wed, 10 May 2023 16:36:29 -0400 Received: from us-smtp-delivery-124.mimecast.com ([170.10.133.124]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1pwqXy-0003Jh-RH for qemu-devel@nongnu.org; Wed, 10 May 2023 16:36:29 -0400 Received: from mimecast-mx02.redhat.com (mimecast-mx02.redhat.com [66.187.233.88]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-636-UVznQ8AgNP-xhE8pk57ROQ-1; Wed, 10 May 2023 16:36:22 -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 mimecast-mx02.redhat.com (Postfix) with ESMTPS id 8A9DF18E0BF2; Wed, 10 May 2023 20:36:22 +0000 (UTC) Received: from merkur.fritz.box (unknown [10.39.194.148]) by smtp.corp.redhat.com (Postfix) with ESMTP id 14E771121315; Wed, 10 May 2023 20:36:20 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1683750986; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=aNhV+rBBNi2TzLpEJaq/ZsnHcLW446pXsJVZCiEGoGE=; b=Nga0wdnNvdamKWkXo/95NAK11MYKv6Kx1ywZOgcte2chNb7MKbW9OGSr0E+gjKbLi3l1Jr QTJHxBRhhGldTf90itZEWYrAqLgFa3nVdf7u8ZNaUT2Ml72SFHTR8p1PhDoPheA/vVoi9p F/2VmS+DYUXiFPh/llqWsl20e8FXuko= X-MC-Unique: UVznQ8AgNP-xhE8pk57ROQ-1 From: Kevin Wolf To: qemu-block@nongnu.org Cc: kwolf@redhat.com, hreitz@redhat.com, stefanha@redhat.com, f.ebner@proxmox.com, qemu-devel@nongnu.org Subject: [PATCH 1/8] block: Call .bdrv_co_create(_opts) unlocked Date: Wed, 10 May 2023 22:35:54 +0200 Message-Id: <20230510203601.418015-2-kwolf@redhat.com> In-Reply-To: <20230510203601.418015-1-kwolf@redhat.com> References: <20230510203601.418015-1-kwolf@redhat.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Scanned-By: MIMEDefang 3.1 on 10.11.54.3 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=170.10.133.124; envelope-from=kwolf@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.001, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H2=-0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1683751034005100003 Content-Type: text/plain; charset="utf-8" These are functions that modify the graph, so they must be able to take a writer lock. This is impossible if they already hold the reader lock. If they need a reader lock for some of their operations, they should take it internally. Many of them go through blk_*(), which will always take the lock itself. Direct calls of bdrv_*() need to take the reader lock. Note that while locking for bdrv_co_*() calls is checked by TSA, this is not the case for the mixed_coroutine_fns bdrv_*(). Holding the lock is still required when they are called from coroutine context like here! This effectively reverts 4ec8df0183, but adds some internal locking instead. Signed-off-by: Kevin Wolf Reviewed-by: Eric Blake --- include/block/block-global-state.h | 8 +++---- include/block/block_int-common.h | 4 ++-- block.c | 1 - block/create.c | 1 - block/crypto.c | 25 ++++++++++---------- block/parallels.c | 6 ++--- block/qcow.c | 6 ++--- block/qcow2.c | 37 +++++++++++++++++++----------- block/qed.c | 6 ++--- block/raw-format.c | 2 +- block/vdi.c | 11 +++++---- block/vhdx.c | 8 ++++--- block/vmdk.c | 27 ++++++++++------------ block/vpc.c | 6 ++--- 14 files changed, 78 insertions(+), 70 deletions(-) diff --git a/include/block/block-global-state.h b/include/block/block-globa= l-state.h index 2d93423d35..f347199bff 100644 --- a/include/block/block-global-state.h +++ b/include/block/block-global-state.h @@ -58,14 +58,14 @@ BlockDriver *bdrv_find_protocol(const char *filename, Error **errp); BlockDriver *bdrv_find_format(const char *format_name); =20 -int coroutine_fn GRAPH_RDLOCK +int coroutine_fn GRAPH_UNLOCKED bdrv_co_create(BlockDriver *drv, const char *filename, QemuOpts *opts, Error **errp); =20 -int co_wrapper_bdrv_rdlock bdrv_create(BlockDriver *drv, const char *filen= ame, - QemuOpts *opts, Error **errp); +int co_wrapper bdrv_create(BlockDriver *drv, const char *filename, + QemuOpts *opts, Error **errp); =20 -int coroutine_fn GRAPH_RDLOCK +int coroutine_fn GRAPH_UNLOCKED bdrv_co_create_file(const char *filename, QemuOpts *opts, Error **errp); =20 BlockDriverState *bdrv_new(void); diff --git a/include/block/block_int-common.h b/include/block/block_int-com= mon.h index 4909876756..a19b85a6e1 100644 --- a/include/block/block_int-common.h +++ b/include/block/block_int-common.h @@ -245,10 +245,10 @@ struct BlockDriver { BlockDriverState *bs, QDict *options, int flags, Error **errp); void (*bdrv_close)(BlockDriverState *bs); =20 - int coroutine_fn GRAPH_RDLOCK_PTR (*bdrv_co_create)( + int coroutine_fn GRAPH_UNLOCKED_PTR (*bdrv_co_create)( BlockdevCreateOptions *opts, Error **errp); =20 - int coroutine_fn GRAPH_RDLOCK_PTR (*bdrv_co_create_opts)( + int coroutine_fn GRAPH_UNLOCKED_PTR (*bdrv_co_create_opts)( BlockDriver *drv, const char *filename, QemuOpts *opts, Error **er= rp); =20 int (*bdrv_amend_options)(BlockDriverState *bs, diff --git a/block.c b/block.c index dad9a4fa43..e8b51a4391 100644 --- a/block.c +++ b/block.c @@ -533,7 +533,6 @@ int coroutine_fn bdrv_co_create(BlockDriver *drv, const= char *filename, int ret; GLOBAL_STATE_CODE(); ERRP_GUARD(); - assert_bdrv_graph_readable(); =20 if (!drv->bdrv_co_create_opts) { error_setg(errp, "Driver '%s' does not support image creation", diff --git a/block/create.c b/block/create.c index bf67b9947c..6b23a21675 100644 --- a/block/create.c +++ b/block/create.c @@ -43,7 +43,6 @@ static int coroutine_fn blockdev_create_run(Job *job, Err= or **errp) int ret; =20 GLOBAL_STATE_CODE(); - GRAPH_RDLOCK_GUARD(); =20 job_progress_set_remaining(&s->common, 1); ret =3D s->drv->bdrv_co_create(s->opts, errp); diff --git a/block/crypto.c b/block/crypto.c index 30093cff9b..6ee8d46d30 100644 --- a/block/crypto.c +++ b/block/crypto.c @@ -99,12 +99,10 @@ struct BlockCryptoCreateData { }; =20 =20 -static int block_crypto_create_write_func(QCryptoBlock *block, - size_t offset, - const uint8_t *buf, - size_t buflen, - void *opaque, - Error **errp) +static int coroutine_fn GRAPH_UNLOCKED +block_crypto_create_write_func(QCryptoBlock *block, size_t offset, + const uint8_t *buf, size_t buflen, void *op= aque, + Error **errp) { struct BlockCryptoCreateData *data =3D opaque; ssize_t ret; @@ -117,10 +115,9 @@ static int block_crypto_create_write_func(QCryptoBlock= *block, return 0; } =20 -static int block_crypto_create_init_func(QCryptoBlock *block, - size_t headerlen, - void *opaque, - Error **errp) +static int coroutine_fn GRAPH_UNLOCKED +block_crypto_create_init_func(QCryptoBlock *block, size_t headerlen, + void *opaque, Error **errp) { struct BlockCryptoCreateData *data =3D opaque; Error *local_error =3D NULL; @@ -314,7 +311,7 @@ static int block_crypto_open_generic(QCryptoBlockFormat= format, } =20 =20 -static int coroutine_fn +static int coroutine_fn GRAPH_UNLOCKED block_crypto_co_create_generic(BlockDriverState *bs, int64_t size, QCryptoBlockCreateOptions *opts, PreallocMode prealloc, Error **errp) @@ -627,7 +624,7 @@ static int block_crypto_open_luks(BlockDriverState *bs, bs, options, flags, errp); } =20 -static int coroutine_fn +static int coroutine_fn GRAPH_UNLOCKED block_crypto_co_create_luks(BlockdevCreateOptions *create_options, Error *= *errp) { BlockdevCreateOptionsLUKS *luks_opts; @@ -665,7 +662,7 @@ fail: return ret; } =20 -static int coroutine_fn GRAPH_RDLOCK +static int coroutine_fn GRAPH_UNLOCKED block_crypto_co_create_opts_luks(BlockDriver *drv, const char *filename, QemuOpts *opts, Error **errp) { @@ -727,7 +724,9 @@ fail: * beforehand, it has been truncated and corrupted in the process. */ if (ret) { + bdrv_graph_co_rdlock(); bdrv_co_delete_file_noerr(bs); + bdrv_graph_co_rdunlock(); } =20 bdrv_co_unref(bs); diff --git a/block/parallels.c b/block/parallels.c index b49c35929e..d8a3f13e24 100644 --- a/block/parallels.c +++ b/block/parallels.c @@ -522,8 +522,8 @@ out: } =20 =20 -static int coroutine_fn parallels_co_create(BlockdevCreateOptions* opts, - Error **errp) +static int coroutine_fn GRAPH_UNLOCKED +parallels_co_create(BlockdevCreateOptions* opts, Error **errp) { BlockdevCreateOptionsParallels *parallels_opts; BlockDriverState *bs; @@ -622,7 +622,7 @@ exit: goto out; } =20 -static int coroutine_fn GRAPH_RDLOCK +static int coroutine_fn GRAPH_UNLOCKED parallels_co_create_opts(BlockDriver *drv, const char *filename, QemuOpts *opts, Error **errp) { diff --git a/block/qcow.c b/block/qcow.c index a0c701f578..3644bbf5cb 100644 --- a/block/qcow.c +++ b/block/qcow.c @@ -800,8 +800,8 @@ static void qcow_close(BlockDriverState *bs) error_free(s->migration_blocker); } =20 -static int coroutine_fn qcow_co_create(BlockdevCreateOptions *opts, - Error **errp) +static int coroutine_fn GRAPH_UNLOCKED +qcow_co_create(BlockdevCreateOptions *opts, Error **errp) { BlockdevCreateOptionsQcow *qcow_opts; int header_size, backing_filename_len, l1_size, shift, i; @@ -921,7 +921,7 @@ exit: return ret; } =20 -static int coroutine_fn GRAPH_RDLOCK +static int coroutine_fn GRAPH_UNLOCKED qcow_co_create_opts(BlockDriver *drv, const char *filename, QemuOpts *opts, Error **errp) { diff --git a/block/qcow2.c b/block/qcow2.c index 5bde3b8401..73f36447f9 100644 --- a/block/qcow2.c +++ b/block/qcow2.c @@ -118,8 +118,9 @@ static int qcow2_crypto_hdr_read_func(QCryptoBlock *blo= ck, size_t offset, } =20 =20 -static int qcow2_crypto_hdr_init_func(QCryptoBlock *block, size_t headerle= n, - void *opaque, Error **errp) +static int coroutine_fn GRAPH_RDLOCK +qcow2_crypto_hdr_init_func(QCryptoBlock *block, size_t headerlen, void *op= aque, + Error **errp) { BlockDriverState *bs =3D opaque; BDRVQcow2State *s =3D bs->opaque; @@ -144,9 +145,7 @@ static int qcow2_crypto_hdr_init_func(QCryptoBlock *blo= ck, size_t headerlen, */ clusterlen =3D size_to_clusters(s, headerlen) * s->cluster_size; assert(qcow2_pre_write_overlap_check(bs, 0, ret, clusterlen, false) = =3D=3D 0); - ret =3D bdrv_pwrite_zeroes(bs->file, - ret, - clusterlen, 0); + ret =3D bdrv_co_pwrite_zeroes(bs->file, ret, clusterlen, 0); if (ret < 0) { error_setg_errno(errp, -ret, "Could not zero fill encryption heade= r"); return -1; @@ -156,9 +155,11 @@ static int qcow2_crypto_hdr_init_func(QCryptoBlock *bl= ock, size_t headerlen, } =20 =20 -static int qcow2_crypto_hdr_write_func(QCryptoBlock *block, size_t offset, - const uint8_t *buf, size_t buflen, - void *opaque, Error **errp) +/* The graph lock must be held when called in coroutine context */ +static int coroutine_mixed_fn +qcow2_crypto_hdr_write_func(QCryptoBlock *block, size_t offset, + const uint8_t *buf, size_t buflen, + void *opaque, Error **errp) { BlockDriverState *bs =3D opaque; BDRVQcow2State *s =3D bs->opaque; @@ -3137,9 +3138,10 @@ static int qcow2_change_backing_file(BlockDriverStat= e *bs, return qcow2_update_header(bs); } =20 -static int qcow2_set_up_encryption(BlockDriverState *bs, - QCryptoBlockCreateOptions *cryptoopts, - Error **errp) +static int coroutine_fn GRAPH_RDLOCK +qcow2_set_up_encryption(BlockDriverState *bs, + QCryptoBlockCreateOptions *cryptoopts, + Error **errp) { BDRVQcow2State *s =3D bs->opaque; QCryptoBlock *crypto =3D NULL; @@ -3426,7 +3428,7 @@ static uint64_t qcow2_opt_get_refcount_bits_del(QemuO= pts *opts, int version, return refcount_bits; } =20 -static int coroutine_fn +static int coroutine_fn GRAPH_UNLOCKED qcow2_co_create(BlockdevCreateOptions *create_options, Error **errp) { BlockdevCreateOptionsQcow2 *qcow2_opts; @@ -3724,8 +3726,10 @@ qcow2_co_create(BlockdevCreateOptions *create_option= s, Error **errp) goto out; } =20 + bdrv_graph_co_rdlock(); ret =3D qcow2_alloc_clusters(blk_bs(blk), 3 * cluster_size); if (ret < 0) { + bdrv_graph_co_rdunlock(); error_setg_errno(errp, -ret, "Could not allocate clusters for qcow= 2 " "header and refcount table"); goto out; @@ -3743,6 +3747,8 @@ qcow2_co_create(BlockdevCreateOptions *create_options= , Error **errp) =20 /* Create a full header (including things like feature table) */ ret =3D qcow2_update_header(blk_bs(blk)); + bdrv_graph_co_rdunlock(); + if (ret < 0) { error_setg_errno(errp, -ret, "Could not update qcow2 header"); goto out; @@ -3776,7 +3782,10 @@ qcow2_co_create(BlockdevCreateOptions *create_option= s, Error **errp) =20 /* Want encryption? There you go. */ if (qcow2_opts->encrypt) { + bdrv_graph_co_rdlock(); ret =3D qcow2_set_up_encryption(blk_bs(blk), qcow2_opts->encrypt, = errp); + bdrv_graph_co_rdunlock(); + if (ret < 0) { goto out; } @@ -3813,7 +3822,7 @@ out: return ret; } =20 -static int coroutine_fn GRAPH_RDLOCK +static int coroutine_fn GRAPH_UNLOCKED qcow2_co_create_opts(BlockDriver *drv, const char *filename, QemuOpts *opt= s, Error **errp) { @@ -3933,8 +3942,10 @@ qcow2_co_create_opts(BlockDriver *drv, const char *f= ilename, QemuOpts *opts, ret =3D qcow2_co_create(create_options, errp); finish: if (ret < 0) { + bdrv_graph_co_rdlock(); bdrv_co_delete_file_noerr(bs); bdrv_co_delete_file_noerr(data_bs); + bdrv_graph_co_rdunlock(); } else { ret =3D 0; } diff --git a/block/qed.c b/block/qed.c index be9ff0fb34..9a0350b534 100644 --- a/block/qed.c +++ b/block/qed.c @@ -630,8 +630,8 @@ static void bdrv_qed_close(BlockDriverState *bs) qemu_vfree(s->l1_table); } =20 -static int coroutine_fn bdrv_qed_co_create(BlockdevCreateOptions *opts, - Error **errp) +static int coroutine_fn GRAPH_UNLOCKED +bdrv_qed_co_create(BlockdevCreateOptions *opts, Error **errp) { BlockdevCreateOptionsQed *qed_opts; BlockBackend *blk =3D NULL; @@ -751,7 +751,7 @@ out: return ret; } =20 -static int coroutine_fn GRAPH_RDLOCK +static int coroutine_fn GRAPH_UNLOCKED bdrv_qed_co_create_opts(BlockDriver *drv, const char *filename, QemuOpts *opts, Error **errp) { diff --git a/block/raw-format.c b/block/raw-format.c index fd9e61f58e..b4c8e7cf61 100644 --- a/block/raw-format.c +++ b/block/raw-format.c @@ -435,7 +435,7 @@ static int raw_has_zero_init(BlockDriverState *bs) return bdrv_has_zero_init(bs->file->bs); } =20 -static int coroutine_fn GRAPH_RDLOCK +static int coroutine_fn GRAPH_UNLOCKED raw_co_create_opts(BlockDriver *drv, const char *filename, QemuOpts *opts, Error **errp) { diff --git a/block/vdi.c b/block/vdi.c index 08331d2dd7..6c35309e04 100644 --- a/block/vdi.c +++ b/block/vdi.c @@ -734,8 +734,9 @@ nonallocating_write: return ret; } =20 -static int coroutine_fn vdi_co_do_create(BlockdevCreateOptions *create_opt= ions, - size_t block_size, Error **errp) +static int coroutine_fn GRAPH_UNLOCKED +vdi_co_do_create(BlockdevCreateOptions *create_options, size_t block_size, + Error **errp) { BlockdevCreateOptionsVdi *vdi_opts; int ret =3D 0; @@ -892,13 +893,13 @@ exit: return ret; } =20 -static int coroutine_fn vdi_co_create(BlockdevCreateOptions *create_option= s, - Error **errp) +static int coroutine_fn GRAPH_UNLOCKED +vdi_co_create(BlockdevCreateOptions *create_options, Error **errp) { return vdi_co_do_create(create_options, DEFAULT_CLUSTER_SIZE, errp); } =20 -static int coroutine_fn GRAPH_RDLOCK +static int coroutine_fn GRAPH_UNLOCKED vdi_co_create_opts(BlockDriver *drv, const char *filename, QemuOpts *opts, Error **errp) { diff --git a/block/vhdx.c b/block/vhdx.c index b20b1edf11..89913cba87 100644 --- a/block/vhdx.c +++ b/block/vhdx.c @@ -1506,7 +1506,7 @@ exit: * There are 2 headers, and the highest sequence number will represent * the active header */ -static int coroutine_fn GRAPH_RDLOCK +static int coroutine_fn GRAPH_UNLOCKED vhdx_create_new_headers(BlockBackend *blk, uint64_t image_size, uint32_t log_size) { @@ -1515,6 +1515,8 @@ vhdx_create_new_headers(BlockBackend *blk, uint64_t i= mage_size, int ret =3D 0; VHDXHeader *hdr =3D NULL; =20 + GRAPH_RDLOCK_GUARD(); + hdr =3D g_new0(VHDXHeader, 1); =20 hdr->signature =3D VHDX_HEADER_SIGNATURE; @@ -1898,7 +1900,7 @@ exit: * .---- ~ ----------- ~ ------------ ~ ---------------- ~ -----------. * 1MB */ -static int coroutine_fn GRAPH_RDLOCK +static int coroutine_fn GRAPH_UNLOCKED vhdx_co_create(BlockdevCreateOptions *opts, Error **errp) { BlockdevCreateOptionsVhdx *vhdx_opts; @@ -2060,7 +2062,7 @@ delete_and_exit: return ret; } =20 -static int coroutine_fn GRAPH_RDLOCK +static int coroutine_fn GRAPH_UNLOCKED vhdx_co_create_opts(BlockDriver *drv, const char *filename, QemuOpts *opts, Error **errp) { diff --git a/block/vmdk.c b/block/vmdk.c index fddbd1c86c..e3e86608ec 100644 --- a/block/vmdk.c +++ b/block/vmdk.c @@ -2165,10 +2165,9 @@ vmdk_co_pwrite_zeroes(BlockDriverState *bs, int64_t = offset, int64_t bytes, return ret; } =20 -static int vmdk_init_extent(BlockBackend *blk, - int64_t filesize, bool flat, - bool compress, bool zeroed_grain, - Error **errp) +static int GRAPH_UNLOCKED +vmdk_init_extent(BlockBackend *blk, int64_t filesize, bool flat, bool comp= ress, + bool zeroed_grain, Error **errp) { int ret, i; VMDK4Header header; @@ -2277,7 +2276,7 @@ exit: return ret; } =20 -static int coroutine_fn GRAPH_RDLOCK +static int coroutine_fn GRAPH_UNLOCKED vmdk_create_extent(const char *filename, int64_t filesize, bool flat, bool compress, bool zeroed_grain, BlockBackend **pbb, QemuOpts *opts, Error **errp) @@ -2358,7 +2357,7 @@ static int filename_decompose(const char *filename, c= har *path, char *prefix, * non-split format. * idx >=3D 1: get the n-th extent if in a split subformat */ -typedef BlockBackend * coroutine_fn /* GRAPH_RDLOCK */ +typedef BlockBackend * coroutine_fn GRAPH_UNLOCKED_PTR (*vmdk_create_extent_fn)(int64_t size, int idx, bool flat, bool split, bool compress, bool zeroed_grain, void *opaqu= e, Error **errp); @@ -2374,7 +2373,7 @@ static void vmdk_desc_add_extent(GString *desc, g_free(basename); } =20 -static int coroutine_fn GRAPH_RDLOCK +static int coroutine_fn GRAPH_UNLOCKED vmdk_co_do_create(int64_t size, BlockdevVmdkSubformat subformat, BlockdevVmdkAdapterType adapter_type, @@ -2605,7 +2604,7 @@ typedef struct { QemuOpts *opts; } VMDKCreateOptsData; =20 -static BlockBackend * coroutine_fn GRAPH_RDLOCK +static BlockBackend * coroutine_fn GRAPH_UNLOCKED vmdk_co_create_opts_cb(int64_t size, int idx, bool flat, bool split, bool compress, bool zeroed_grain, void *opaque, Error **errp) @@ -2647,7 +2646,7 @@ exit: return blk; } =20 -static int coroutine_fn GRAPH_RDLOCK +static int coroutine_fn GRAPH_UNLOCKED vmdk_co_create_opts(BlockDriver *drv, const char *filename, QemuOpts *opts, Error **errp) { @@ -2756,11 +2755,9 @@ exit: return ret; } =20 -static BlockBackend * coroutine_fn vmdk_co_create_cb(int64_t size, int idx, - bool flat, bool split, - bool compress, - bool zeroed_grain, - void *opaque, Error *= *errp) +static BlockBackend * coroutine_fn GRAPH_UNLOCKED +vmdk_co_create_cb(int64_t size, int idx, bool flat, bool split, bool compr= ess, + bool zeroed_grain, void *opaque, Error **errp) { int ret; BlockDriverState *bs; @@ -2809,7 +2806,7 @@ static BlockBackend * coroutine_fn vmdk_co_create_cb(= int64_t size, int idx, return blk; } =20 -static int coroutine_fn GRAPH_RDLOCK +static int coroutine_fn GRAPH_UNLOCKED vmdk_co_create(BlockdevCreateOptions *create_options, Error **errp) { BlockdevCreateOptionsVmdk *opts; diff --git a/block/vpc.c b/block/vpc.c index 07ddda5b99..7ee7c7b4e0 100644 --- a/block/vpc.c +++ b/block/vpc.c @@ -967,8 +967,8 @@ static int calculate_rounded_image_size(BlockdevCreateO= ptionsVpc *vpc_opts, return 0; } =20 -static int coroutine_fn vpc_co_create(BlockdevCreateOptions *opts, - Error **errp) +static int coroutine_fn GRAPH_UNLOCKED +vpc_co_create(BlockdevCreateOptions *opts, Error **errp) { BlockdevCreateOptionsVpc *vpc_opts; BlockBackend *blk =3D NULL; @@ -1087,7 +1087,7 @@ out: return ret; } =20 -static int coroutine_fn GRAPH_RDLOCK +static int coroutine_fn GRAPH_UNLOCKED vpc_co_create_opts(BlockDriver *drv, const char *filename, QemuOpts *opts, Error **errp) { --=20 2.40.1 From nobody Mon May 20 13:01:29 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; 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; dmarc=pass(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1683751114; cv=none; d=zohomail.com; s=zohoarc; b=FFZ6dXxN8EYMyCb5ZnllU9Vq4A6T5hq/0geNGoFnwE4lGYkv2grmqt5IYVOQcK46jn0JdRcy7WHGQl4OFSnLvtMc/MhZ/8HPytNdEpXH/cHopsyzF2u5pbNYYEWajOt1JF1eRDHtMCRQ5dqxGKWhC66AT41+S+J76DvfnY1eOc0= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1683751114; h=Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=yD72QprueAbSuOWgAgRWxGGjAq16e84Rapg38+Z4Z9g=; b=QvdJjWhSBYKSa49fBeFADTw3fzO4yKUhNsCB9V0ZGGKuDM0nlLsoNHUl8hOFf8y/LFpI8e0fkmPeBfcDWaY3qh75oy462O7rqLgGuLoyAMGFjwUoK29xL/BkFoIbEtLVLM4skoLQHeXVu9yM5ek7EjJWs3+1DAaJCYFET2IFm0U= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; 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; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1683751114404562.6282935424045; Wed, 10 May 2023 13:38:34 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1pwqY4-0005DB-Hy; Wed, 10 May 2023 16:36:32 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1pwqY2-0005AL-7I for qemu-devel@nongnu.org; Wed, 10 May 2023 16:36:30 -0400 Received: from us-smtp-delivery-124.mimecast.com ([170.10.133.124]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1pwqY0-0003K1-NI for qemu-devel@nongnu.org; Wed, 10 May 2023 16:36:29 -0400 Received: from mimecast-mx02.redhat.com (mimecast-mx02.redhat.com [66.187.233.88]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-668-1rq3FXV4NSSEq79QdghG2A-1; Wed, 10 May 2023 16:36:24 -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 mimecast-mx02.redhat.com (Postfix) with ESMTPS id 8E90880067D; Wed, 10 May 2023 20:36:24 +0000 (UTC) Received: from merkur.fritz.box (unknown [10.39.194.148]) by smtp.corp.redhat.com (Postfix) with ESMTP id E13431121314; Wed, 10 May 2023 20:36:22 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1683750988; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=yD72QprueAbSuOWgAgRWxGGjAq16e84Rapg38+Z4Z9g=; b=bETM0KMpmzVo6VU7kKFbKFFv8SB0tp0wUTr0d7TFej0UxY7c3L7z+u1PqnfM5pCtOpTzPm s1DcidBlPX6IWygTAonCwAHRjPem7oxoTcw+0CTXuRvr5G5JCHu1AxCRnm9tu66CH48q5i xh2Xqjab127ibE+K5AW9vtDBWENhZiU= X-MC-Unique: 1rq3FXV4NSSEq79QdghG2A-1 From: Kevin Wolf To: qemu-block@nongnu.org Cc: kwolf@redhat.com, hreitz@redhat.com, stefanha@redhat.com, f.ebner@proxmox.com, qemu-devel@nongnu.org Subject: [PATCH 2/8] block/export: Fix null pointer dereference in error path Date: Wed, 10 May 2023 22:35:55 +0200 Message-Id: <20230510203601.418015-3-kwolf@redhat.com> In-Reply-To: <20230510203601.418015-1-kwolf@redhat.com> References: <20230510203601.418015-1-kwolf@redhat.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Scanned-By: MIMEDefang 3.1 on 10.11.54.3 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=170.10.133.124; envelope-from=kwolf@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.001, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H2=-0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1683751116400100004 Content-Type: text/plain; charset="utf-8" There are some error paths in blk_exp_add() that jump to 'fail:' before 'exp' is even created. So we can't just unconditionally access exp->blk. Add a NULL check, and switch from exp->blk to blk, which is available earlier, just to be extra sure that we really cover all cases where BlockDevOps could have been set for it (in practice, this only happens in drv->create() today, so this part of the change isn't strictly necessary). Fixes: de79b52604e43fdeba6cee4f5af600b62169f2d2 Signed-off-by: Kevin Wolf Reviewed-by: Eric Blake Tested-by: Eric Blake --- block/export/export.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/block/export/export.c b/block/export/export.c index 62c7c22d45..a5c8f42f53 100644 --- a/block/export/export.c +++ b/block/export/export.c @@ -192,8 +192,10 @@ BlockExport *blk_exp_add(BlockExportOptions *export, E= rror **errp) return exp; =20 fail: - blk_set_dev_ops(exp->blk, NULL, NULL); - blk_unref(blk); + if (blk) { + blk_set_dev_ops(blk, NULL, NULL); + blk_unref(blk); + } aio_context_release(ctx); if (exp) { g_free(exp->id); --=20 2.40.1 From nobody Mon May 20 13:01:29 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; 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; dmarc=pass(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1683751036; cv=none; d=zohomail.com; s=zohoarc; b=ELGagWQg0amfSPYgBuxIJZvAFg0VRq8n4pHod8UEn+n/hKDdOTC/u6ucu2bUjM4DefnCxQDNbV5a5cuQGO0s5iAb9xsoSPDZut3Q2SNPy0vvbU2EvBzZyHNuSFXSAAVYv80DsdkMmGUCuOlcAstqj/5/zfF1LdYSVOyBe9pwpT4= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1683751036; h=Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=EcIuTYtOPwDAHB/h3j6Y0xZc3CIugRqzwgLuAKQ13KY=; b=TYOO6Cx7hm4JnUEBPQJ/pxV+Ee7Gg5ladTtCgCeqaXb5wBsQfj7hZq/Ehs0rFsuqUG+qyI2m4zpLpHQjTRMZ8c4fkkfvjP21HzPbWdSZujsuIFM9uxlaMquVoeP+fzwyRoZq7zvHFPXr0Meq4B5Zagb17n8NXNOH7KVNYVclknY= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; 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; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1683751036180615.0742174975694; Wed, 10 May 2023 13:37:16 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1pwqYA-0005Ez-El; Wed, 10 May 2023 16:36:38 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1pwqY7-0005EC-GK for qemu-devel@nongnu.org; Wed, 10 May 2023 16:36:35 -0400 Received: from us-smtp-delivery-124.mimecast.com ([170.10.133.124]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1pwqY5-0003Ma-BC for qemu-devel@nongnu.org; Wed, 10 May 2023 16:36:35 -0400 Received: from mimecast-mx02.redhat.com (mx3-rdu2.redhat.com [66.187.233.73]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-580-szlSdqGOOx-haVsgKAOWuw-1; Wed, 10 May 2023 16:36:26 -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 mimecast-mx02.redhat.com (Postfix) with ESMTPS id 1D0E2381D1EA; Wed, 10 May 2023 20:36:26 +0000 (UTC) Received: from merkur.fritz.box (unknown [10.39.194.148]) by smtp.corp.redhat.com (Postfix) with ESMTP id DF3261121314; Wed, 10 May 2023 20:36:24 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1683750992; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=EcIuTYtOPwDAHB/h3j6Y0xZc3CIugRqzwgLuAKQ13KY=; b=VLqx2Si7LSmWtQyhXQRKzezIUo9AQ+9HghQjpRHnrtvW+zb+Ljucaf70A7toSV70W8knGp ztgkjEIbWVoQdnaJBdrE4wpTx3UPbXPlcB4cklLYWf7cAXTPTU+g+xJCEuyt8st+4mHcXV brVDMi501ipUwtCVO2BfYcrYoA8vaUs= X-MC-Unique: szlSdqGOOx-haVsgKAOWuw-1 From: Kevin Wolf To: qemu-block@nongnu.org Cc: kwolf@redhat.com, hreitz@redhat.com, stefanha@redhat.com, f.ebner@proxmox.com, qemu-devel@nongnu.org Subject: [PATCH 3/8] qcow2: Unlock the graph in qcow2_do_open() where necessary Date: Wed, 10 May 2023 22:35:56 +0200 Message-Id: <20230510203601.418015-4-kwolf@redhat.com> In-Reply-To: <20230510203601.418015-1-kwolf@redhat.com> References: <20230510203601.418015-1-kwolf@redhat.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Scanned-By: MIMEDefang 3.1 on 10.11.54.3 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=170.10.133.124; envelope-from=kwolf@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.001, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H2=-0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=unavailable autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1683751037339100001 Content-Type: text/plain; charset="utf-8" qcow2_do_open() calls a few no_co_wrappers that wrap functions taking the graph lock internally as a writer. Therefore, it can't hold the reader lock across these calls, it causes deadlocks. Drop the lock temporarily around the calls. Signed-off-by: Kevin Wolf Reviewed-by: Eric Blake --- block/qcow2.c | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/block/qcow2.c b/block/qcow2.c index 73f36447f9..b00b4e7575 100644 --- a/block/qcow2.c +++ b/block/qcow2.c @@ -1619,9 +1619,11 @@ qcow2_do_open(BlockDriverState *bs, QDict *options, = int flags, =20 if (open_data_file) { /* Open external data file */ + bdrv_graph_co_rdunlock(); s->data_file =3D bdrv_co_open_child(NULL, options, "data-file", bs, &child_of_bds, BDRV_CHILD_DATA, true, errp); + bdrv_graph_co_rdlock(); if (*errp) { ret =3D -EINVAL; goto fail; @@ -1629,10 +1631,12 @@ qcow2_do_open(BlockDriverState *bs, QDict *options,= int flags, =20 if (s->incompatible_features & QCOW2_INCOMPAT_DATA_FILE) { if (!s->data_file && s->image_data_file) { + bdrv_graph_co_rdunlock(); s->data_file =3D bdrv_co_open_child(s->image_data_file, op= tions, "data-file", bs, &child_of_bds, BDRV_CHILD_DATA, false, = errp); + bdrv_graph_co_rdlock(); if (!s->data_file) { ret =3D -EINVAL; goto fail; @@ -1857,7 +1861,9 @@ qcow2_do_open(BlockDriverState *bs, QDict *options, i= nt flags, fail: g_free(s->image_data_file); if (open_data_file && has_data_file(bs)) { + bdrv_graph_co_rdunlock(); bdrv_unref_child(bs, s->data_file); + bdrv_graph_co_rdlock(); s->data_file =3D NULL; } g_free(s->unknown_header_fields); --=20 2.40.1 From nobody Mon May 20 13:01:29 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; 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; dmarc=pass(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1683751092; cv=none; d=zohomail.com; s=zohoarc; b=YupTHImvjHhc3C4XQnARqg31j7t0R9yTPgR9hKpWHiE+u/QWqIm97J/a2QUphELcWdMBpPDaEJnyyO6U317YojnbnJZBdml/zqpeMPQTsiS7vX71mUKBaVgRfqrRaLzFrY7V4liTqo8pgR6TzMJViETLy2+jBS7d314mFoHYaXE= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1683751092; h=Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=arGt/MnLiYPHatUBy7Jpxz/l++GTsSLMD2wbdvtEulc=; b=OKPvTLS16q85A68A/W8DXayXhBU14HG0FXZfYIPsBUnAp1M+eJqfeszw47c4znGk4MnX4LDPMeBRRv36iLoyhWhwSaAPWgfZcoKjiP8fj7QWcD+TCDrXXvmSde2IMV3ez3FzM3JEQSRRf2tN8D0EsTc6g9h3Az06Fxzs3u6jcCk= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; 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; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1683751092765266.6631843855823; Wed, 10 May 2023 13:38:12 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1pwqY8-0005EB-FW; Wed, 10 May 2023 16:36:36 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1pwqY5-0005DS-IE for qemu-devel@nongnu.org; Wed, 10 May 2023 16:36:33 -0400 Received: from us-smtp-delivery-124.mimecast.com ([170.10.133.124]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1pwqY3-0003MJ-Qd for qemu-devel@nongnu.org; Wed, 10 May 2023 16:36:32 -0400 Received: from mimecast-mx02.redhat.com (mx3-rdu2.redhat.com [66.187.233.73]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-86-_Vt7FI5INEWx5Qq0vWYSeQ-1; Wed, 10 May 2023 16:36:28 -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 mimecast-mx02.redhat.com (Postfix) with ESMTPS id 9A6231C0F2E1; Wed, 10 May 2023 20:36:27 +0000 (UTC) Received: from merkur.fritz.box (unknown [10.39.194.148]) by smtp.corp.redhat.com (Postfix) with ESMTP id 6200F1121314; Wed, 10 May 2023 20:36:26 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1683750991; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=arGt/MnLiYPHatUBy7Jpxz/l++GTsSLMD2wbdvtEulc=; b=X5ySxMU2EmbTdHJ4QkBnHCeIXQ0oUMnxatNW2j0zt/tc5yZQ1p1aQb0K3eE+p1opa1SoNs gULUVeU3aKpqXMbqjode4OAtD5kK6C8WFGd1EUAruWFz+iLJMASphfkji9voE+SyJI+tb6 8+QmpyAMelvySY0nf8ykgNpY3fWYh54= X-MC-Unique: _Vt7FI5INEWx5Qq0vWYSeQ-1 From: Kevin Wolf To: qemu-block@nongnu.org Cc: kwolf@redhat.com, hreitz@redhat.com, stefanha@redhat.com, f.ebner@proxmox.com, qemu-devel@nongnu.org Subject: [PATCH 4/8] qemu-img: Take graph lock more selectively Date: Wed, 10 May 2023 22:35:57 +0200 Message-Id: <20230510203601.418015-5-kwolf@redhat.com> In-Reply-To: <20230510203601.418015-1-kwolf@redhat.com> References: <20230510203601.418015-1-kwolf@redhat.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Scanned-By: MIMEDefang 3.1 on 10.11.54.3 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=170.10.133.124; envelope-from=kwolf@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.001, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H2=-0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=unavailable autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1683751093856100001 Content-Type: text/plain; charset="utf-8" If we take a reader lock, we can't call any functions that take a writer lock internally without causing deadlocks once the reader lock is actually enforced in the main thread, too. Take the reader lock only where it is actually needed. Signed-off-by: Kevin Wolf Reviewed-by: Eric Blake --- qemu-img.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/qemu-img.c b/qemu-img.c index 9f9f0a7629..27f48051b0 100644 --- a/qemu-img.c +++ b/qemu-img.c @@ -2938,8 +2938,6 @@ static BlockGraphInfoList *collect_image_info_list(bo= ol image_opts, } bs =3D blk_bs(blk); =20 - GRAPH_RDLOCK_GUARD_MAINLOOP(); - /* * Note that the returned BlockGraphInfo object will not have * information about this image's backing node, because we have op= ened @@ -2947,7 +2945,10 @@ static BlockGraphInfoList *collect_image_info_list(b= ool image_opts, * duplicate the backing chain information that we obtain by walki= ng * the chain manually here. */ + bdrv_graph_rdlock_main_loop(); bdrv_query_block_graph_info(bs, &info, &err); + bdrv_graph_rdunlock_main_loop(); + if (err) { error_report_err(err); blk_unref(blk); --=20 2.40.1 From nobody Mon May 20 13:01:29 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; 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; dmarc=pass(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1683751080; cv=none; d=zohomail.com; s=zohoarc; b=kEDgB2pEJk5xqcND34bC3bp3d0rF/JxQNC75Oc761lqk0Rha+lHFxL3G5nGbuUtzQ+ygpW+wadkGeCZkRFNwH5lOPfM5cTvGLq5sKUXm5aNIgUCRG0fEBMFZCmmJowzeUMxPKr7xrLh1py7McC+ex7xtPt9nZcUDyFjTnAl/kbM= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1683751080; h=Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=F3xsJyxmeHSomo74+D4aggMuwldNR5lEhLMTiDrQpX4=; b=ktCZAhF2+qXJjOBXSvq/W+syiAjDfVBmz6k1sXtsgVwPOfoA6yGgA+PisK5BIWUQ/TvQjQ6Xa46aPhd5XhLCazOFzce3PR+K0RhvwRHjqU9zZSVTsLz9d3VknLC58E9JNhXS1IpE9qMPIEmmS3eCDagANhIsYDccWuwPZn2Efxc= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; 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; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1683751080846653.9556417495985; Wed, 10 May 2023 13:38:00 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1pwqYK-0005KD-1u; Wed, 10 May 2023 16:36:48 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1pwqY8-0005EV-MF for qemu-devel@nongnu.org; Wed, 10 May 2023 16:36:37 -0400 Received: from us-smtp-delivery-124.mimecast.com ([170.10.129.124]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1pwqY5-0003MV-B7 for qemu-devel@nongnu.org; Wed, 10 May 2023 16:36:36 -0400 Received: from mimecast-mx02.redhat.com (mx3-rdu2.redhat.com [66.187.233.73]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-441-peVt73ibMGu9AjjBKAg3bw-1; Wed, 10 May 2023 16:36:29 -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 mimecast-mx02.redhat.com (Postfix) with ESMTPS id 27556381D1E4; Wed, 10 May 2023 20:36:29 +0000 (UTC) Received: from merkur.fritz.box (unknown [10.39.194.148]) by smtp.corp.redhat.com (Postfix) with ESMTP id E8A741121314; Wed, 10 May 2023 20:36:27 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1683750992; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=F3xsJyxmeHSomo74+D4aggMuwldNR5lEhLMTiDrQpX4=; b=EBcm4dcsSg3vSqOMqzlo8yCldJEMlEbaVm4awm5gHcNKNCCFgcnvxCQ9nPa/m728wj4rFC OLINC4lIr+ldUb/wNdblpoYUuDzzUd/YtGHBoDbvNDbdxkuNljfagg4L3d2t5DStvKpxwS P5L/GE3Xy++WUXsvbdEdLCeixz+P1Cs= X-MC-Unique: peVt73ibMGu9AjjBKAg3bw-1 From: Kevin Wolf To: qemu-block@nongnu.org Cc: kwolf@redhat.com, hreitz@redhat.com, stefanha@redhat.com, f.ebner@proxmox.com, qemu-devel@nongnu.org Subject: [PATCH 5/8] test-bdrv-drain: Take graph lock more selectively Date: Wed, 10 May 2023 22:35:58 +0200 Message-Id: <20230510203601.418015-6-kwolf@redhat.com> In-Reply-To: <20230510203601.418015-1-kwolf@redhat.com> References: <20230510203601.418015-1-kwolf@redhat.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Scanned-By: MIMEDefang 3.1 on 10.11.54.3 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=170.10.129.124; envelope-from=kwolf@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.001, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1683751082222100003 Content-Type: text/plain; charset="utf-8" If we take a reader lock, we can't call any functions that take a writer lock internally without causing deadlocks once the reader lock is actually enforced in the main thread, too. Take the reader lock only where it is actually needed. Signed-off-by: Kevin Wolf Reviewed-by: Eric Blake --- tests/unit/test-bdrv-drain.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tests/unit/test-bdrv-drain.c b/tests/unit/test-bdrv-drain.c index 9a4c5e59d6..ae4299ccfa 100644 --- a/tests/unit/test-bdrv-drain.c +++ b/tests/unit/test-bdrv-drain.c @@ -1004,8 +1004,6 @@ static void coroutine_fn test_co_delete_by_drain(void= *opaque) void *buffer =3D g_malloc(65536); QEMUIOVector qiov =3D QEMU_IOVEC_INIT_BUF(qiov, buffer, 65536); =20 - GRAPH_RDLOCK_GUARD(); - /* Pretend some internal write operation from parent to child. * Important: We have to read from the child, not from the parent! * Draining works by first propagating it all up the tree to the @@ -1014,7 +1012,9 @@ static void coroutine_fn test_co_delete_by_drain(void= *opaque) * everything will be drained before we go back down the tree, but * we do not want that. We want to be in the middle of draining * when this following requests returns. */ + bdrv_graph_co_rdlock(); bdrv_co_preadv(tts->wait_child, 0, 65536, &qiov, 0); + bdrv_graph_co_rdunlock(); =20 g_assert_cmpint(bs->refcnt, =3D=3D, 1); =20 --=20 2.40.1 From nobody Mon May 20 13:01:29 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; 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; dmarc=pass(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1683751114; cv=none; d=zohomail.com; s=zohoarc; b=O7DitQOaOzp1h44eSIVwL9ZCzspIlTuXqhmT/8KgsYQYEfzopUtCv+YLBiwPGfH5MLAp5NUTiyA2LjLt7jukfk6u2g6mdrOpv7E0Aj1BfJZKdLZ7ilbXBQVU/dRMDdSsWcPxWoHnWRR2DV6O2KRehNrhtG5qppQ3UiQl6ihxvkU= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1683751114; h=Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=ygZmIhLsLSHYmfIH6Wbo2LP+wRtJBgIXCzDjP+jsiJ8=; b=CPUcgjmDgEaV5phxCyN9NuD9ZoqvH9d9KQxTepaP1U6o5V+4DjK4INn355XhOKRkMRSby138d7EvZ2wrL1unRoFr3ky7pXDpZJlvm1Co1lowmgbl9VT/ofVZcu2uUWzh04hADSW6zH70A7ql3+7m2qFsr8M97YrxXy1ZsgD5OcQ= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; 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; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1683751114098797.4333226967532; Wed, 10 May 2023 13:38:34 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1pwqYG-0005IJ-1Z; Wed, 10 May 2023 16:36:44 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1pwqY9-0005Eh-QD for qemu-devel@nongnu.org; Wed, 10 May 2023 16:36:38 -0400 Received: from us-smtp-delivery-124.mimecast.com ([170.10.129.124]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1pwqY8-0003N1-Fh for qemu-devel@nongnu.org; Wed, 10 May 2023 16:36:37 -0400 Received: from mimecast-mx02.redhat.com (mx3-rdu2.redhat.com [66.187.233.73]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-167-XZBVSwrpNcucPa_lla6K4A-1; Wed, 10 May 2023 16:36:30 -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 mimecast-mx02.redhat.com (Postfix) with ESMTPS id 86A581C0F2E5; Wed, 10 May 2023 20:36:30 +0000 (UTC) Received: from merkur.fritz.box (unknown [10.39.194.148]) by smtp.corp.redhat.com (Postfix) with ESMTP id 65BF61121314; Wed, 10 May 2023 20:36:29 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1683750995; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=ygZmIhLsLSHYmfIH6Wbo2LP+wRtJBgIXCzDjP+jsiJ8=; b=SV87JygkmvdpT5WEc4tzeo+74XPuBbKXB0FF3SgwrOTqvVoProCPTaVycaAdRzjjTQpi2e tL64bVWEBU7gDo6KGjPFOJmyaXssswNozOumOiPPb40MJ6R1FKRhyWbZqzZpUSSKQ23GVT FjO8SvXjrM3k0JTXf2KTz3glWxGdlJg= X-MC-Unique: XZBVSwrpNcucPa_lla6K4A-1 From: Kevin Wolf To: qemu-block@nongnu.org Cc: kwolf@redhat.com, hreitz@redhat.com, stefanha@redhat.com, f.ebner@proxmox.com, qemu-devel@nongnu.org Subject: [PATCH 6/8] test-bdrv-drain: Call bdrv_co_unref() in coroutine context Date: Wed, 10 May 2023 22:35:59 +0200 Message-Id: <20230510203601.418015-7-kwolf@redhat.com> In-Reply-To: <20230510203601.418015-1-kwolf@redhat.com> References: <20230510203601.418015-1-kwolf@redhat.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Scanned-By: MIMEDefang 3.1 on 10.11.54.3 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=170.10.129.124; envelope-from=kwolf@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.001, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=unavailable autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1683751114927100001 Content-Type: text/plain; charset="utf-8" bdrv_unref() is a no_coroutine_fn, so calling it from coroutine context is invalid. Use bdrv_co_unref() instead. Signed-off-by: Kevin Wolf Reviewed-by: Eric Blake --- tests/unit/test-bdrv-drain.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/unit/test-bdrv-drain.c b/tests/unit/test-bdrv-drain.c index ae4299ccfa..08bb0f9984 100644 --- a/tests/unit/test-bdrv-drain.c +++ b/tests/unit/test-bdrv-drain.c @@ -1019,7 +1019,7 @@ static void coroutine_fn test_co_delete_by_drain(void= *opaque) g_assert_cmpint(bs->refcnt, =3D=3D, 1); =20 if (!dbdd->detach_instead_of_delete) { - blk_unref(blk); + blk_co_unref(blk); } else { BdrvChild *c, *next_c; QLIST_FOREACH_SAFE(c, &bs->children, next, next_c) { --=20 2.40.1 From nobody Mon May 20 13:01:29 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; 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; dmarc=pass(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1683751105; cv=none; d=zohomail.com; s=zohoarc; b=OHN33uzcoORvlL8RE4kLjy0HDnOitSr/LsuEkvQZg8kfyTQJTMj0ceWgu1TJo0/uInora0RKdqVFAsdWIz1+UN0OOFg8blKqtuyD097dQ8EBSKLB7zcNHDfFQJZgJnYQGDEEWxCiBArNRJVGWdxjnO0yj17iCGMBDqmIeGeGg6A= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1683751105; h=Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=y4DaXpKzQ0nYqby6pd0Tpizg8Luj2JNpsPJkXp72mGA=; b=jeQhIdwFCYwkXaGl805CnuAQrMoIwXLkI+nE8CjAMnZi/VSTeDwDq3oVd7WA7Tm/CgL7i/22jd7SyYSknyVzmSCGZGnquPKCuHl+5DxzwSzTAv/TYcYratk/dCkK2Xumh1D0R5S9tv3NgVjO0EXkhX4ynWK/FOVQXQ665oabKYc= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; 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; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1683751105182191.97908602202415; Wed, 10 May 2023 13:38:25 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1pwqYG-0005Id-1d; Wed, 10 May 2023 16:36:44 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1pwqYA-0005Ej-AJ for qemu-devel@nongnu.org; Wed, 10 May 2023 16:36:38 -0400 Received: from us-smtp-delivery-124.mimecast.com ([170.10.129.124]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1pwqY8-0003Mt-EX for qemu-devel@nongnu.org; Wed, 10 May 2023 16:36:38 -0400 Received: from mimecast-mx02.redhat.com (mx3-rdu2.redhat.com [66.187.233.73]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-313-5VDoi76YMQyh8cZvJqZmzA-1; Wed, 10 May 2023 16:36:32 -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 mimecast-mx02.redhat.com (Postfix) with ESMTPS id 0A35029AB3EE; Wed, 10 May 2023 20:36:32 +0000 (UTC) Received: from merkur.fritz.box (unknown [10.39.194.148]) by smtp.corp.redhat.com (Postfix) with ESMTP id D92341121314; Wed, 10 May 2023 20:36:30 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1683750995; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=y4DaXpKzQ0nYqby6pd0Tpizg8Luj2JNpsPJkXp72mGA=; b=gFU6WImwoy1gPKrb/8NayHjpMyIGeMn7a4Fj7lgK9vhigT8HbG4ssExzTNWmQb2uXsmwxe jTz+Z2jxXPOQQdcVfXRvAzLIDhAtOP5XdTgifDJZhoVKt58y4nJmFKc0Tg0mEgO3epAldR Jb8Z71SUau9jnF4mSy8wnuN/TLDaaf0= X-MC-Unique: 5VDoi76YMQyh8cZvJqZmzA-1 From: Kevin Wolf To: qemu-block@nongnu.org Cc: kwolf@redhat.com, hreitz@redhat.com, stefanha@redhat.com, f.ebner@proxmox.com, qemu-devel@nongnu.org Subject: [PATCH 7/8] blockjob: Adhere to rate limit even when reentered early Date: Wed, 10 May 2023 22:36:00 +0200 Message-Id: <20230510203601.418015-8-kwolf@redhat.com> In-Reply-To: <20230510203601.418015-1-kwolf@redhat.com> References: <20230510203601.418015-1-kwolf@redhat.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Scanned-By: MIMEDefang 3.1 on 10.11.54.3 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=170.10.129.124; envelope-from=kwolf@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.001, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1683751106360100001 Content-Type: text/plain; charset="utf-8" When jobs are sleeping, for example to enforce a given rate limit, they can be reentered early, in particular in order to get paused, to update the rate limit or to get cancelled. Before this patch, they behave in this case as if they had fully completed their rate limiting delay. This means that requests are sped up beyond their limit, violating the constraints that the user gave us. Change the block jobs to sleep in a loop until the necessary delay is completed, while still allowing cancelling them immediately as well pausing (handled by the pause point in job_sleep_ns()) and updating the rate limit. This change is also motivated by iotests cases being prone to fail because drain operations pause and unpause them so often that block jobs complete earlier than they are supposed to. In particular, the next commit would fail iotests 030 without this change. Signed-off-by: Kevin Wolf Reviewed-by: Eric Blake --- include/block/blockjob_int.h | 14 ++++++++++---- block/commit.c | 7 ++----- block/mirror.c | 23 ++++++++++------------- block/stream.c | 7 ++----- blockjob.c | 22 ++++++++++++++++++++-- 5 files changed, 44 insertions(+), 29 deletions(-) diff --git a/include/block/blockjob_int.h b/include/block/blockjob_int.h index f008446285..104824040c 100644 --- a/include/block/blockjob_int.h +++ b/include/block/blockjob_int.h @@ -126,12 +126,18 @@ void block_job_user_resume(Job *job); */ =20 /** - * block_job_ratelimit_get_delay: + * block_job_ratelimit_processed_bytes: * - * Calculate and return delay for the next request in ns. See the document= ation - * of ratelimit_calculate_delay() for details. + * To be called after some work has been done. Adjusts the delay for the n= ext + * request. See the documentation of ratelimit_calculate_delay() for detai= ls. */ -int64_t block_job_ratelimit_get_delay(BlockJob *job, uint64_t n); +void block_job_ratelimit_processed_bytes(BlockJob *job, uint64_t n); + +/** + * Put the job to sleep (assuming that it wasn't canceled) to throttle it = to the + * right speed according to its rate limiting. + */ +void block_job_ratelimit_sleep(BlockJob *job); =20 /** * block_job_error_action: diff --git a/block/commit.c b/block/commit.c index 2b20fd0fd4..aa45beb0f0 100644 --- a/block/commit.c +++ b/block/commit.c @@ -116,7 +116,6 @@ static int coroutine_fn commit_run(Job *job, Error **er= rp) { CommitBlockJob *s =3D container_of(job, CommitBlockJob, common.job); int64_t offset; - uint64_t delay_ns =3D 0; int ret =3D 0; int64_t n =3D 0; /* bytes */ QEMU_AUTO_VFREE void *buf =3D NULL; @@ -149,7 +148,7 @@ static int coroutine_fn commit_run(Job *job, Error **er= rp) /* Note that even when no rate limit is applied we need to yield * with no pending I/O here so that bdrv_drain_all() returns. */ - job_sleep_ns(&s->common.job, delay_ns); + block_job_ratelimit_sleep(&s->common); if (job_is_cancelled(&s->common.job)) { break; } @@ -184,9 +183,7 @@ static int coroutine_fn commit_run(Job *job, Error **er= rp) job_progress_update(&s->common.job, n); =20 if (copy) { - delay_ns =3D block_job_ratelimit_get_delay(&s->common, n); - } else { - delay_ns =3D 0; + block_job_ratelimit_processed_bytes(&s->common, n); } } =20 diff --git a/block/mirror.c b/block/mirror.c index 717442ca4d..b7d92d1378 100644 --- a/block/mirror.c +++ b/block/mirror.c @@ -471,12 +471,11 @@ static unsigned mirror_perform(MirrorBlockJob *s, int= 64_t offset, return bytes_handled; } =20 -static uint64_t coroutine_fn mirror_iteration(MirrorBlockJob *s) +static void coroutine_fn mirror_iteration(MirrorBlockJob *s) { BlockDriverState *source =3D s->mirror_top_bs->backing->bs; MirrorOp *pseudo_op; int64_t offset; - uint64_t delay_ns =3D 0, ret =3D 0; /* At least the first dirty chunk is mirrored in one iteration. */ int nb_chunks =3D 1; bool write_zeroes_ok =3D bdrv_can_write_zeroes_with_unmap(blk_bs(s->ta= rget)); @@ -608,16 +607,13 @@ static uint64_t coroutine_fn mirror_iteration(MirrorB= lockJob *s) assert(io_bytes); offset +=3D io_bytes; nb_chunks -=3D DIV_ROUND_UP(io_bytes, s->granularity); - delay_ns =3D block_job_ratelimit_get_delay(&s->common, io_bytes_ac= ct); + block_job_ratelimit_processed_bytes(&s->common, io_bytes_acct); } =20 - ret =3D delay_ns; fail: QTAILQ_REMOVE(&s->ops_in_flight, pseudo_op, next); qemu_co_queue_restart_all(&pseudo_op->waiting_requests); g_free(pseudo_op); - - return ret; } =20 static void mirror_free_init(MirrorBlockJob *s) @@ -1011,7 +1007,6 @@ static int coroutine_fn mirror_run(Job *job, Error **= errp) assert(!s->dbi); s->dbi =3D bdrv_dirty_iter_new(s->dirty_bitmap); for (;;) { - uint64_t delay_ns =3D 0; int64_t cnt, delta; bool should_complete; =20 @@ -1051,7 +1046,7 @@ static int coroutine_fn mirror_run(Job *job, Error **= errp) mirror_wait_for_free_in_flight_slot(s); continue; } else if (cnt !=3D 0) { - delay_ns =3D mirror_iteration(s); + mirror_iteration(s); } } =20 @@ -1114,12 +1109,14 @@ static int coroutine_fn mirror_run(Job *job, Error = **errp) } =20 if (job_is_ready(&s->common.job) && !should_complete) { - delay_ns =3D (s->in_flight =3D=3D 0 && - cnt =3D=3D 0 ? BLOCK_JOB_SLICE_TIME : 0); + if (s->in_flight =3D=3D 0 && cnt =3D=3D 0) { + trace_mirror_before_sleep(s, cnt, job_is_ready(&s->common.= job), + BLOCK_JOB_SLICE_TIME); + job_sleep_ns(&s->common.job, BLOCK_JOB_SLICE_TIME); + } + } else { + block_job_ratelimit_sleep(&s->common); } - trace_mirror_before_sleep(s, cnt, job_is_ready(&s->common.job), - delay_ns); - job_sleep_ns(&s->common.job, delay_ns); s->last_pause_ns =3D qemu_clock_get_ns(QEMU_CLOCK_REALTIME); } =20 diff --git a/block/stream.c b/block/stream.c index 7f9e1ecdbb..e522bbdec5 100644 --- a/block/stream.c +++ b/block/stream.c @@ -131,7 +131,6 @@ static int coroutine_fn stream_run(Job *job, Error **er= rp) BlockDriverState *unfiltered_bs =3D bdrv_skip_filters(s->target_bs); int64_t len; int64_t offset =3D 0; - uint64_t delay_ns =3D 0; int error =3D 0; int64_t n =3D 0; /* bytes */ =20 @@ -155,7 +154,7 @@ static int coroutine_fn stream_run(Job *job, Error **er= rp) /* Note that even when no rate limit is applied we need to yield * with no pending I/O here so that bdrv_drain_all() returns. */ - job_sleep_ns(&s->common.job, delay_ns); + block_job_ratelimit_sleep(&s->common); if (job_is_cancelled(&s->common.job)) { break; } @@ -204,9 +203,7 @@ static int coroutine_fn stream_run(Job *job, Error **er= rp) /* Publish progress */ job_progress_update(&s->common.job, n); if (copy) { - delay_ns =3D block_job_ratelimit_get_delay(&s->common, n); - } else { - delay_ns =3D 0; + block_job_ratelimit_processed_bytes(&s->common, n); } } =20 diff --git a/blockjob.c b/blockjob.c index 659c3cb9de..913da3cbf7 100644 --- a/blockjob.c +++ b/blockjob.c @@ -319,10 +319,28 @@ static bool block_job_set_speed(BlockJob *job, int64_= t speed, Error **errp) return block_job_set_speed_locked(job, speed, errp); } =20 -int64_t block_job_ratelimit_get_delay(BlockJob *job, uint64_t n) +void block_job_ratelimit_processed_bytes(BlockJob *job, uint64_t n) { IO_CODE(); - return ratelimit_calculate_delay(&job->limit, n); + ratelimit_calculate_delay(&job->limit, n); +} + +void block_job_ratelimit_sleep(BlockJob *job) +{ + uint64_t delay_ns; + + /* + * Sleep at least once. If the job is reentered early, keep waiting un= til + * we've waited for the full time that is necessary to keep the job at= the + * right speed. + * + * Make sure to recalculate the delay after each (possibly interrupted) + * sleep because the speed can change while the job has yielded. + */ + do { + delay_ns =3D ratelimit_calculate_delay(&job->limit, 0); + job_sleep_ns(&job->job, delay_ns); + } while (delay_ns && !job_is_cancelled(&job->job)); } =20 BlockJobInfo *block_job_query_locked(BlockJob *job, Error **errp) --=20 2.40.1 From nobody Mon May 20 13:01:29 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; 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; dmarc=pass(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1683751083; cv=none; d=zohomail.com; s=zohoarc; b=e4Y7HEKfkKDqZdZ698gjctFl8KLQkIP1cJ68tkIu/8aOcyPcbpv2TLxNHRcLgPd+SOW51QeWKa83eKG1Is81gQd+sPNBr6DMkm8XfnltBkMyWtVr2WgF2znLf/FEMV6zhXzNKRnau/D0AYUY6Na2LXnQ7o/pSm0Lo7taz+SKUg4= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1683751083; h=Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=N1c/27ddh+1DM1DKbHPLEkGEAW689Mmjcp7QLU92/U4=; b=SRH75nXNjqxQDfIIp80unMiCRKdj6jkGoKg7mbdgCVLQVni5WkARhSFkFULKCxfIaOzCk/BmNnxCNEnYlnvG4e4dUvvE5hWwia22ZbQXL3YHk1PHJlhanxwkkwgcpo3pGEjptZGo2XjdKDoTguO5rwCq4xrKiaaJYg9Y4oCSVkk= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; 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; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1683751083016394.8650063894047; Wed, 10 May 2023 13:38:03 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1pwqYK-0005KC-1g; Wed, 10 May 2023 16:36:48 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1pwqYB-0005FJ-AE for qemu-devel@nongnu.org; Wed, 10 May 2023 16:36:40 -0400 Received: from us-smtp-delivery-124.mimecast.com ([170.10.129.124]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1pwqY9-0003NY-Qh for qemu-devel@nongnu.org; Wed, 10 May 2023 16:36:39 -0400 Received: from mimecast-mx02.redhat.com (mimecast-mx02.redhat.com [66.187.233.88]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-447-dkwqwCdwN52ga9lji9WkYQ-1; Wed, 10 May 2023 16:36:33 -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 mimecast-mx02.redhat.com (Postfix) with ESMTPS id 829C380269A; Wed, 10 May 2023 20:36:33 +0000 (UTC) Received: from merkur.fritz.box (unknown [10.39.194.148]) by smtp.corp.redhat.com (Postfix) with ESMTP id 4E9931121314; Wed, 10 May 2023 20:36:32 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1683750997; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=N1c/27ddh+1DM1DKbHPLEkGEAW689Mmjcp7QLU92/U4=; b=M76IaXT4NC5TxHDKZ7/WTi7sxHt4pocKHWIwW5nGQ/H8a8FyUjRTSJTFmMbruq957FzGQq oACraiv2S5lSiRyORMUZp1dcZNX2iRAFiKU0R58ISy0PfPJj0Czqt6GFfflmXQJcjD8MP7 fQurpHMzNp1OJlFiGcZMLVJmylHTVKY= X-MC-Unique: dkwqwCdwN52ga9lji9WkYQ-1 From: Kevin Wolf To: qemu-block@nongnu.org Cc: kwolf@redhat.com, hreitz@redhat.com, stefanha@redhat.com, f.ebner@proxmox.com, qemu-devel@nongnu.org Subject: [PATCH 8/8] graph-lock: Honour read locks even in the main thread Date: Wed, 10 May 2023 22:36:01 +0200 Message-Id: <20230510203601.418015-9-kwolf@redhat.com> In-Reply-To: <20230510203601.418015-1-kwolf@redhat.com> References: <20230510203601.418015-1-kwolf@redhat.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Scanned-By: MIMEDefang 3.1 on 10.11.54.3 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=170.10.129.124; envelope-from=kwolf@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.001, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1683751084297100001 Content-Type: text/plain; charset="utf-8" There are some conditions under which we don't actually need to do anything for taking a reader lock: Writing the graph is only possible from the main context while holding the BQL. So if a reader is running in the main context under the BQL and knows that it won't be interrupted until the next writer runs, we don't actually need to do anything. This is the case if the reader code neither has a nested event loop (this is forbidden anyway while you hold the lock) nor is a coroutine (because a writer could run when the coroutine has yielded). These conditions are exactly what bdrv_graph_rdlock_main_loop() asserts. They are not fulfilled in bdrv_graph_co_rdlock(), which always runs in a coroutine. This deletes the shortcuts in bdrv_graph_co_rdlock() that skip taking the reader lock in the main thread. Reported-by: Fiona Ebner Signed-off-by: Kevin Wolf Reviewed-by: Eric Blake --- block/graph-lock.c | 10 ---------- 1 file changed, 10 deletions(-) diff --git a/block/graph-lock.c b/block/graph-lock.c index 377884c3a9..9c42bd9799 100644 --- a/block/graph-lock.c +++ b/block/graph-lock.c @@ -162,11 +162,6 @@ void coroutine_fn bdrv_graph_co_rdlock(void) BdrvGraphRWlock *bdrv_graph; bdrv_graph =3D qemu_get_current_aio_context()->bdrv_graph; =20 - /* Do not lock if in main thread */ - if (qemu_in_main_thread()) { - return; - } - for (;;) { qatomic_set(&bdrv_graph->reader_count, bdrv_graph->reader_count + 1); @@ -230,11 +225,6 @@ void coroutine_fn bdrv_graph_co_rdunlock(void) BdrvGraphRWlock *bdrv_graph; bdrv_graph =3D qemu_get_current_aio_context()->bdrv_graph; =20 - /* Do not lock if in main thread */ - if (qemu_in_main_thread()) { - return; - } - qatomic_store_release(&bdrv_graph->reader_count, bdrv_graph->reader_count - 1); /* make sure writer sees reader_count before we check has_writer */ --=20 2.40.1