From nobody Mon May 6 07:52:03 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=1667834094; cv=none; d=zohomail.com; s=zohoarc; b=H3NQLD6XBqDRRYK+T0cDjseNFB0ggI85FjtTaRcFZX4k7Ue3DDBFaiyn34xp1klrwXuDcMbylB+8ES4CldTrRAaXzkwvdv5sS7u+UNqsGibD13AhkVFyVQhM+0+bPA4oZZ7TiOV1Srerm4c9vcoDfCRvIf+xB6SeiB2NlQSsOzk= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1667834094; h=Content-Type: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=m1lRj+r/gTbpNpudSw9i6+i9XWJB5nkuLpeoxy4zt4Y=; b=lyI3jGWAurUkoqJUyrLmhrcWbvZ1saQuq9jfPu2s2o/BqJQC0ugOpTOLzQz0HRZleBR38+fAxxtWYUgm+MxcIQc9HszZIaoS9Eo1qyrhyk2h/t00pGbsGpe1cg7+FmecN0t2QkJGBK8q95N2/1KDeDkIDUj+a2iGzzOMfqjOxVY= 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 1667834094473928.7163037049451; Mon, 7 Nov 2022 07:14:54 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1os3od-0001sH-Mo; Mon, 07 Nov 2022 10:13:35 -0500 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 1os3oa-0001q8-JB for qemu-devel@nongnu.org; Mon, 07 Nov 2022 10:13:32 -0500 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 1os3oX-0006el-72 for qemu-devel@nongnu.org; Mon, 07 Nov 2022 10:13:32 -0500 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-515-4EgUAimxP-6YO05K4TK-Ug-1; Mon, 07 Nov 2022 10:13:25 -0500 Received: from smtp.corp.redhat.com (int-mx08.intmail.prod.int.rdu2.redhat.com [10.11.54.8]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 1541C87B2A4; Mon, 7 Nov 2022 15:13:25 +0000 (UTC) Received: from localhost (unknown [10.39.194.227]) by smtp.corp.redhat.com (Postfix) with ESMTPS id B7707C15BB5; Mon, 7 Nov 2022 15:13:24 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1667834008; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=m1lRj+r/gTbpNpudSw9i6+i9XWJB5nkuLpeoxy4zt4Y=; b=arIETZZJWhYkbsecFCNdIqZ2BVSdCRnLyOB0GfRsP6rGZsGrhUblhOPA0ZJxfF7KYeKZRG KJ6MuuwjbF/jWVl6smnw2unqr2pmo5rr9jZ9KX4so7dNq6nUC7daHyaCjUIPA+SPZzUXOe 3+tW/VVh/z/m80tbzyo8HsOTPUxXTcQ= X-MC-Unique: 4EgUAimxP-6YO05K4TK-Ug-1 From: Hanna Reitz To: qemu-block@nongnu.org Cc: qemu-devel@nongnu.org, Hanna Reitz , Kevin Wolf , Stefan Hajnoczi Subject: [PATCH v2 1/3] block: Make bdrv_child_get_parent_aio_context I/O Date: Mon, 7 Nov 2022 16:13:19 +0100 Message-Id: <20221107151321.211175-2-hreitz@redhat.com> In-Reply-To: <20221107151321.211175-1-hreitz@redhat.com> References: <20221107151321.211175-1-hreitz@redhat.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Scanned-By: MIMEDefang 3.1 on 10.11.54.8 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=hreitz@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 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: 1667834163192100001 Content-Type: text/plain; charset="utf-8" We want to use bdrv_child_get_parent_aio_context() from bdrv_parent_drained_{begin,end}_single(), both of which are "I/O or GS" functions. Prior to 3ed4f708fe1, all the implementations were I/O code anyway. 3ed4f708fe1 has put block jobs' AioContext field under the job mutex, so to make child_job_get_parent_aio_context() work in an I/O context, we need to take that lock there. Furthermore, blk_root_get_parent_aio_context() is not marked as anything, but is safe to run in an I/O context, so mark it that way now. (blk_get_aio_context() is an I/O code function.) With that done, all implementations explicitly are I/O code, so we can mark bdrv_child_get_parent_aio_context() as I/O code, too, so callers know it is safe to run from both GS and I/O contexts. Signed-off-by: Hanna Reitz --- include/block/block-global-state.h | 1 - include/block/block-io.h | 2 ++ include/block/block_int-common.h | 4 ++-- block.c | 2 +- block/block-backend.c | 1 + blockjob.c | 3 ++- 6 files changed, 8 insertions(+), 5 deletions(-) diff --git a/include/block/block-global-state.h b/include/block/block-globa= l-state.h index bb42ed9559..c7bd4a2088 100644 --- a/include/block/block-global-state.h +++ b/include/block/block-global-state.h @@ -220,7 +220,6 @@ void coroutine_fn bdrv_co_lock(BlockDriverState *bs); */ void coroutine_fn bdrv_co_unlock(BlockDriverState *bs); =20 -AioContext *bdrv_child_get_parent_aio_context(BdrvChild *c); bool bdrv_child_change_aio_context(BdrvChild *c, AioContext *ctx, GHashTable *visited, Transaction *tran, Error **errp); diff --git a/include/block/block-io.h b/include/block/block-io.h index 770ddeb7c8..b099d7db45 100644 --- a/include/block/block-io.h +++ b/include/block/block-io.h @@ -171,6 +171,8 @@ void bdrv_debug_event(BlockDriverState *bs, BlkdebugEve= nt event); */ AioContext *bdrv_get_aio_context(BlockDriverState *bs); =20 +AioContext *bdrv_child_get_parent_aio_context(BdrvChild *c); + /** * Move the current coroutine to the AioContext of @bs and return the old * AioContext of the coroutine. Increase bs->in_flight so that draining @bs diff --git a/include/block/block_int-common.h b/include/block/block_int-com= mon.h index 5a2cc077a0..31ae91e56e 100644 --- a/include/block/block_int-common.h +++ b/include/block/block_int-common.h @@ -911,8 +911,6 @@ struct BdrvChildClass { GHashTable *visited, Transaction *tran, Error **errp); =20 - AioContext *(*get_parent_aio_context)(BdrvChild *child); - /* * I/O API functions. These functions are thread-safe. * @@ -929,6 +927,8 @@ struct BdrvChildClass { */ const char *(*get_name)(BdrvChild *child); =20 + AioContext *(*get_parent_aio_context)(BdrvChild *child); + /* * If this pair of functions is implemented, the parent doesn't issue = new * requests after returning from .drained_begin() until .drained_end()= is diff --git a/block.c b/block.c index 3bd594eb2a..2d6128d80a 100644 --- a/block.c +++ b/block.c @@ -1533,7 +1533,7 @@ const BdrvChildClass child_of_bds =3D { =20 AioContext *bdrv_child_get_parent_aio_context(BdrvChild *c) { - GLOBAL_STATE_CODE(); + IO_CODE(); return c->klass->get_parent_aio_context(c); } =20 diff --git a/block/block-backend.c b/block/block-backend.c index c0c7d56c8d..ed2f4b67a2 100644 --- a/block/block-backend.c +++ b/block/block-backend.c @@ -311,6 +311,7 @@ static void blk_root_detach(BdrvChild *child) static AioContext *blk_root_get_parent_aio_context(BdrvChild *c) { BlockBackend *blk =3D c->opaque; + IO_CODE(); =20 return blk_get_aio_context(blk); } diff --git a/blockjob.c b/blockjob.c index 2d86014fa5..f51d4e18f3 100644 --- a/blockjob.c +++ b/blockjob.c @@ -173,7 +173,8 @@ static bool child_job_change_aio_ctx(BdrvChild *c, AioC= ontext *ctx, static AioContext *child_job_get_parent_aio_context(BdrvChild *c) { BlockJob *job =3D c->opaque; - GLOBAL_STATE_CODE(); + IO_CODE(); + JOB_LOCK_GUARD(); =20 return job->job.aio_context; } --=20 2.36.1 From nobody Mon May 6 07:52:03 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=1667834093; cv=none; d=zohomail.com; s=zohoarc; b=OGCHbUhCmNf2edTkyKbKlqmIHFYQQFOIJxyMNs8gKxdJc0s0c2hd4IWLHmBK67bwsPlMGG300Q5MJVLhr+3qg+L/EDd7c0j4lL2nZdchBydD87eS+THVFVd30yvtyO+YfGPI0pUWa5fOncZB0ZtP5xvNPt3OVLANNhSM9cPRBlA= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1667834093; h=Content-Type: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=pzU0JLObee2Hbn5huwOdt/BhlzFhd9gLq2lW2XktS3E=; b=bhrcyz5NcPR/3swCeJSZiQUe2s8j44o8ss4i01mIrOpZRMZGOZ92acaMyiR8i/BGsLZ9uMtTxa/HpaVm8MA051gF0kpUMnjD7eXyH17E+DYNxqhlhkJOXG0Rr4tgEWz6XKnvj4AI4/hTmnMirELz/hy/XKNxF4aVySYR2gj+JQg= 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 1667834093856681.4912088876996; Mon, 7 Nov 2022 07:14:53 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1os3ob-0001qz-Nu; Mon, 07 Nov 2022 10:13:33 -0500 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 1os3oa-0001pw-CI for qemu-devel@nongnu.org; Mon, 07 Nov 2022 10:13:32 -0500 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 1os3oX-0006eM-0k for qemu-devel@nongnu.org; Mon, 07 Nov 2022 10:13:32 -0500 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-196-JiwijxOTNcCx2wZoMe0Syg-1; Mon, 07 Nov 2022 10:13:27 -0500 Received: from smtp.corp.redhat.com (int-mx10.intmail.prod.int.rdu2.redhat.com [10.11.54.10]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id AF5753810787; Mon, 7 Nov 2022 15:13:26 +0000 (UTC) Received: from localhost (unknown [10.39.194.227]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 5F517492B05; Mon, 7 Nov 2022 15:13:26 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1667834008; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=pzU0JLObee2Hbn5huwOdt/BhlzFhd9gLq2lW2XktS3E=; b=KtB7Zi/HNrfUl0PJrKozJcThRTXYDvP5TY97mjI8QWSwHSJSlLxmAaLSKIPTNmJg8Wjgwa 7gESYBsexgm7z1lp22cEOMRgM2gkavao1PJW5w+yjS63aMhNXTu904YzzZ+qxdJrjNYWGS 1vcGC18DZUgyhMagfMYletyGN0h2U04= X-MC-Unique: JiwijxOTNcCx2wZoMe0Syg-1 From: Hanna Reitz To: qemu-block@nongnu.org Cc: qemu-devel@nongnu.org, Hanna Reitz , Kevin Wolf , Stefan Hajnoczi Subject: [PATCH v2 2/3] block-backend: Update ctx immediately after root Date: Mon, 7 Nov 2022 16:13:20 +0100 Message-Id: <20221107151321.211175-3-hreitz@redhat.com> In-Reply-To: <20221107151321.211175-1-hreitz@redhat.com> References: <20221107151321.211175-1-hreitz@redhat.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Scanned-By: MIMEDefang 3.1 on 10.11.54.10 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=hreitz@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 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: 1667834151898100001 Content-Type: text/plain; charset="utf-8" blk_get_aio_context() asserts that blk->ctx is always equal to the root BDS's context (if there is a root BDS). Therefore, blk_do_set_aio_context() must update blk->ctx immediately after the root BDS's context has changed. Without this patch, the next patch would break iotest 238, because bdrv_drained_begin() (called by blk_do_set_aio_context()) may then invoke bdrv_child_get_parent_aio_context() on the root child, i.e. blk_get_aio_context(). However, by this point, blk->ctx would not have been updated and thus differ from the root node's context. This patch fixes that. Reviewed-by: Kevin Wolf Signed-off-by: Hanna Reitz --- block/block-backend.c | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/block/block-backend.c b/block/block-backend.c index ed2f4b67a2..b48c91f4e1 100644 --- a/block/block-backend.c +++ b/block/block-backend.c @@ -2158,6 +2158,11 @@ static int blk_do_set_aio_context(BlockBackend *blk,= AioContext *new_context, return ret; } } + /* + * Make blk->ctx consistent with the root node before we invoke any + * other operations like drain that might inquire blk->ctx + */ + blk->ctx =3D new_context; if (tgm->throttle_state) { bdrv_drained_begin(bs); throttle_group_detach_aio_context(tgm); @@ -2166,9 +2171,10 @@ static int blk_do_set_aio_context(BlockBackend *blk,= AioContext *new_context, } =20 bdrv_unref(bs); + } else { + blk->ctx =3D new_context; } =20 - blk->ctx =3D new_context; return 0; } =20 --=20 2.36.1 From nobody Mon May 6 07:52:03 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=1667834121; cv=none; d=zohomail.com; s=zohoarc; b=K0dcW2MHgXXQRKG/OUnGfYgCiIzyc19C1+e/ZWQkIUvVPJgkrvq3LJ0G7HzP6o36kLT3WPaldq1hGqPfM4dWEI5FOMZWjIsWxklOSkTlMUztR+eOa+IeFdCVJR1rT+mBG7ob6cmTDExfxNJbBYucXaM50HhqMevZZMrcqPKoRM8= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1667834121; h=Content-Type: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=Uq8qwPDvdYV9JH6DyNZb7wffdpZ/MNjI6/bR90lZT68=; b=I5F1xATuKG8UlF8HCFTOcxosh8SSnZCN+oFgn3ZtIX6VkfF2hgBLk1zY2aEMhJduCbgTrETIoLCpzydercWFMvHDvrkFZACoFvSOovLcqk74O60LcitQKGdbAbIhNVQdt1P9Y/Pv/0aSEqLS3Ru8wdEcqPfX3cKUFlatvl+Z6oI= 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 1667834121811440.634559503237; Mon, 7 Nov 2022 07:15:21 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1os3oe-0001sp-C9; Mon, 07 Nov 2022 10:13:36 -0500 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 1os3oc-0001rR-Em for qemu-devel@nongnu.org; Mon, 07 Nov 2022 10:13:34 -0500 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 1os3oa-00071K-Td for qemu-devel@nongnu.org; Mon, 07 Nov 2022 10:13:34 -0500 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-609-IiKkCnB0NMGE9Z109loMrQ-1; Mon, 07 Nov 2022 10:13:29 -0500 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 82CE6101E985; Mon, 7 Nov 2022 15:13:28 +0000 (UTC) Received: from localhost (unknown [10.39.194.227]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 2D6A51121315; Mon, 7 Nov 2022 15:13:28 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1667834012; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=Uq8qwPDvdYV9JH6DyNZb7wffdpZ/MNjI6/bR90lZT68=; b=CqkoELodp0a8q6iuB8YePtI7dV1rpgBPY+yiS7XesdibiN3z3ByY9AWtLrQQcg5hGWoboI b8Syu3TbX3wzKwikSMNafeNSzY52S93wM+45u2wiEbPiI90PITARwtoRfX1DLzSS9N2EkS G45bR6bU7wg2YHhWeiYc4QKWwYPNz8Q= X-MC-Unique: IiKkCnB0NMGE9Z109loMrQ-1 From: Hanna Reitz To: qemu-block@nongnu.org Cc: qemu-devel@nongnu.org, Hanna Reitz , Kevin Wolf , Stefan Hajnoczi Subject: [PATCH v2 3/3] block: Start/end drain on correct AioContext Date: Mon, 7 Nov 2022 16:13:21 +0100 Message-Id: <20221107151321.211175-4-hreitz@redhat.com> In-Reply-To: <20221107151321.211175-1-hreitz@redhat.com> References: <20221107151321.211175-1-hreitz@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=hreitz@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 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: 1667834183804100001 Content-Type: text/plain; charset="utf-8" bdrv_parent_drained_{begin,end}_single() are supposed to operate on the parent, not on the child, so they should not attempt to get the context to poll from the child but the parent instead. BDRV_POLL_WHILE(c->bs) does get the context from the child, so we should replace it with AIO_WAIT_WHILE() on the parent's context instead. This problem becomes apparent when bdrv_replace_child_noperm() invokes bdrv_parent_drained_end_single() after removing a child from a subgraph that is in an I/O thread. By the time bdrv_parent_drained_end_single() is called, child->bs is NULL, and so BDRV_POLL_WHILE(c->bs, ...) will poll the main loop instead of the I/O thread; but anything that bdrv_parent_drained_end_single_no_poll() may have scheduled is going to want to run in the I/O thread, but because we poll the main loop, the I/O thread is never unpaused, and nothing is run, resulting in a deadlock. Closes: https://gitlab.com/qemu-project/qemu/-/issues/1215 Reviewed-by: Kevin Wolf Signed-off-by: Hanna Reitz --- block/io.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/block/io.c b/block/io.c index 34b30e304e..b9424024f9 100644 --- a/block/io.c +++ b/block/io.c @@ -71,9 +71,10 @@ static void bdrv_parent_drained_end_single_no_poll(BdrvC= hild *c, void bdrv_parent_drained_end_single(BdrvChild *c) { int drained_end_counter =3D 0; + AioContext *ctx =3D bdrv_child_get_parent_aio_context(c); IO_OR_GS_CODE(); bdrv_parent_drained_end_single_no_poll(c, &drained_end_counter); - BDRV_POLL_WHILE(c->bs, qatomic_read(&drained_end_counter) > 0); + AIO_WAIT_WHILE(ctx, qatomic_read(&drained_end_counter) > 0); } =20 static void bdrv_parent_drained_end(BlockDriverState *bs, BdrvChild *ignor= e, @@ -116,13 +117,14 @@ static bool bdrv_parent_drained_poll(BlockDriverState= *bs, BdrvChild *ignore, =20 void bdrv_parent_drained_begin_single(BdrvChild *c, bool poll) { + AioContext *ctx =3D bdrv_child_get_parent_aio_context(c); IO_OR_GS_CODE(); c->parent_quiesce_counter++; if (c->klass->drained_begin) { c->klass->drained_begin(c); } if (poll) { - BDRV_POLL_WHILE(c->bs, bdrv_parent_drained_poll_single(c)); + AIO_WAIT_WHILE(ctx, bdrv_parent_drained_poll_single(c)); } } =20 --=20 2.36.1