From nobody Mon May 13 18:41:58 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=1694560276; cv=none; d=zohomail.com; s=zohoarc; b=gqHgX/uE3Xb3sYcnHJOv/IZ1E1Pt3Ve588/AuwBd+ThoHqxeroMz4trDMaBAPtuGAl6Do7tba2wf1t+3llnntRytnhn7goC+60ckz0c/XRzx0KmKdDRvA208YS4Nfzcm5DbQq7pHoR/yFKer65NuViAIOqfP3D++HTekUtx8njg= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1694560276; 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=zJDwnuOpEXMdpDTk4Q7AG0iLTtiL/pwA4n7N9zt5fgw=; b=XnzE/38wPUoN63xN72xGC2ih9cXn66xnysVp4LT4Z9DXClTtD0BVqLpZ48gIDC9j+04T7ehiYTLq3SdiH2vnHaan6gVQwIMbZ0SnknbqNPtCn088Dx6j6m9OpppNpiyAo6B6ph1Olh2Gw7uPXHKcdsd4Utx63nHpoA1B3gXahp0= 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 1694560276030657.7007928292687; Tue, 12 Sep 2023 16:11:16 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1qgCWw-0001YF-MA; Tue, 12 Sep 2023 19:10:50 -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 1qgCWu-0001Xg-9c for qemu-devel@nongnu.org; Tue, 12 Sep 2023 19:10:48 -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 1qgCWr-0003Gp-Ba for qemu-devel@nongnu.org; Tue, 12 Sep 2023 19:10:47 -0400 Received: from mimecast-mx02.redhat.com (mx-ext.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-511-OWoxFU5xOFqFSe-UmIDwvA-1; Tue, 12 Sep 2023 19:10:41 -0400 Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.rdu2.redhat.com [10.11.54.2]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 099F21C060D9; Tue, 12 Sep 2023 23:10:41 +0000 (UTC) Received: from localhost (unknown [10.39.192.28]) by smtp.corp.redhat.com (Postfix) with ESMTP id 8056940C6EBF; Tue, 12 Sep 2023 23:10:40 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1694560244; 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=zJDwnuOpEXMdpDTk4Q7AG0iLTtiL/pwA4n7N9zt5fgw=; b=WghOe0Sh3TqQ3H0/iERJA9J+HMpXENAS5ivWv6lM2QOy0RoslVrnqCa24fHqLdIh+hrl+o eI23oIHgJLB/oozl/oJNtjjY6aHGCq7crvHnElRFhkvL6mBgBRRSj4d708tzH7PVRkOgt4 Yb0Y3/gf8IKTzPt+0YcgvFiDkEoKTHE= X-MC-Unique: OWoxFU5xOFqFSe-UmIDwvA-1 From: Stefan Hajnoczi To: qemu-devel@nongnu.org Cc: Klaus Jensen , kwolf@redhat.com, Cleber Rosa , John Snow , Hanna Reitz , =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= , Keith Busch , Paolo Bonzini , Peter Xu , , Stefan Hajnoczi , Vladimir Sementsov-Ogievskiy , David Hildenbrand , Fam Zheng Subject: [PATCH v3 1/5] block: remove AIOCBInfo->get_aio_context() Date: Tue, 12 Sep 2023 19:10:33 -0400 Message-ID: <20230912231037.826804-2-stefanha@redhat.com> In-Reply-To: <20230912231037.826804-1-stefanha@redhat.com> References: <20230912231037.826804-1-stefanha@redhat.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Scanned-By: MIMEDefang 3.1 on 10.11.54.2 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=stefanha@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_H4=0.001, RCVD_IN_MSPIKE_WL=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.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: 1694560276768100001 Content-Type: text/plain; charset="utf-8" The synchronous bdrv_aio_cancel() function needs the acb's AioContext so it can call aio_poll() to wait for cancellation. It turns out that all users run under the BQL in the main AioContext, so this callback is not needed. Remove the callback, mark bdrv_aio_cancel() GLOBAL_STATE_CODE just like its blk_aio_cancel() caller, and poll the main loop AioContext. The purpose of this cleanup is to identify bdrv_aio_cancel() as an API that does not work with the multi-queue block layer. Signed-off-by: Stefan Hajnoczi Reviewed-by: Eric Blake Reviewed-by: Klaus Jensen --- include/block/aio.h | 1 - include/block/block-global-state.h | 2 ++ include/block/block-io.h | 1 - block/block-backend.c | 17 ----------------- block/io.c | 23 ++++++++--------------- hw/nvme/ctrl.c | 7 ------- softmmu/dma-helpers.c | 8 -------- util/thread-pool.c | 8 -------- 8 files changed, 10 insertions(+), 57 deletions(-) diff --git a/include/block/aio.h b/include/block/aio.h index 32042e8905..bcc165c974 100644 --- a/include/block/aio.h +++ b/include/block/aio.h @@ -31,7 +31,6 @@ typedef void BlockCompletionFunc(void *opaque, int ret); =20 typedef struct AIOCBInfo { void (*cancel_async)(BlockAIOCB *acb); - AioContext *(*get_aio_context)(BlockAIOCB *acb); size_t aiocb_size; } AIOCBInfo; =20 diff --git a/include/block/block-global-state.h b/include/block/block-globa= l-state.h index f347199bff..ac2a605ef5 100644 --- a/include/block/block-global-state.h +++ b/include/block/block-global-state.h @@ -185,6 +185,8 @@ void bdrv_drain_all_begin_nopoll(void); void bdrv_drain_all_end(void); void bdrv_drain_all(void); =20 +void bdrv_aio_cancel(BlockAIOCB *acb); + int bdrv_has_zero_init_1(BlockDriverState *bs); int bdrv_has_zero_init(BlockDriverState *bs); BlockDriverState *bdrv_find_node(const char *node_name); diff --git a/include/block/block-io.h b/include/block/block-io.h index 6db48f2d35..f1c796a1ce 100644 --- a/include/block/block-io.h +++ b/include/block/block-io.h @@ -101,7 +101,6 @@ bdrv_co_delete_file_noerr(BlockDriverState *bs); =20 =20 /* async block I/O */ -void bdrv_aio_cancel(BlockAIOCB *acb); void bdrv_aio_cancel_async(BlockAIOCB *acb); =20 /* sg packet commands */ diff --git a/block/block-backend.c b/block/block-backend.c index 4009ed5fed..a77295a198 100644 --- a/block/block-backend.c +++ b/block/block-backend.c @@ -33,8 +33,6 @@ =20 #define NOT_DONE 0x7fffffff /* used while emulated sync operation in progr= ess */ =20 -static AioContext *blk_aiocb_get_aio_context(BlockAIOCB *acb); - typedef struct BlockBackendAioNotifier { void (*attached_aio_context)(AioContext *new_context, void *opaque); void (*detach_aio_context)(void *opaque); @@ -103,7 +101,6 @@ typedef struct BlockBackendAIOCB { } BlockBackendAIOCB; =20 static const AIOCBInfo block_backend_aiocb_info =3D { - .get_aio_context =3D blk_aiocb_get_aio_context, .aiocb_size =3D sizeof(BlockBackendAIOCB), }; =20 @@ -1545,16 +1542,8 @@ typedef struct BlkAioEmAIOCB { bool has_returned; } BlkAioEmAIOCB; =20 -static AioContext *blk_aio_em_aiocb_get_aio_context(BlockAIOCB *acb_) -{ - BlkAioEmAIOCB *acb =3D container_of(acb_, BlkAioEmAIOCB, common); - - return blk_get_aio_context(acb->rwco.blk); -} - static const AIOCBInfo blk_aio_em_aiocb_info =3D { .aiocb_size =3D sizeof(BlkAioEmAIOCB), - .get_aio_context =3D blk_aio_em_aiocb_get_aio_context, }; =20 static void blk_aio_complete(BlkAioEmAIOCB *acb) @@ -2434,12 +2423,6 @@ AioContext *blk_get_aio_context(BlockBackend *blk) return blk->ctx; } =20 -static AioContext *blk_aiocb_get_aio_context(BlockAIOCB *acb) -{ - BlockBackendAIOCB *blk_acb =3D DO_UPCAST(BlockBackendAIOCB, common, ac= b); - return blk_get_aio_context(blk_acb->blk); -} - int blk_set_aio_context(BlockBackend *blk, AioContext *new_context, Error **errp) { diff --git a/block/io.c b/block/io.c index ba23a9bcd3..209a6da0c8 100644 --- a/block/io.c +++ b/block/io.c @@ -2950,25 +2950,18 @@ int bdrv_load_vmstate(BlockDriverState *bs, uint8_t= *buf, /**************************************************************/ /* async I/Os */ =20 +/** + * Synchronously cancels an acb. Must be called with the BQL held and the = acb + * must be processed with the BQL held too (IOThreads are not allowed). + * + * Use bdrv_aio_cancel_async() instead when possible. + */ void bdrv_aio_cancel(BlockAIOCB *acb) { - IO_CODE(); + GLOBAL_STATE_CODE(); qemu_aio_ref(acb); bdrv_aio_cancel_async(acb); - while (acb->refcnt > 1) { - if (acb->aiocb_info->get_aio_context) { - aio_poll(acb->aiocb_info->get_aio_context(acb), true); - } else if (acb->bs) { - /* qemu_aio_ref and qemu_aio_unref are not thread-safe, so - * assert that we're not using an I/O thread. Thread-safe - * code should use bdrv_aio_cancel_async exclusively. - */ - assert(bdrv_get_aio_context(acb->bs) =3D=3D qemu_get_aio_conte= xt()); - aio_poll(bdrv_get_aio_context(acb->bs), true); - } else { - abort(); - } - } + AIO_WAIT_WHILE_UNLOCKED(NULL, acb->refcnt > 1); qemu_aio_unref(acb); } =20 diff --git a/hw/nvme/ctrl.c b/hw/nvme/ctrl.c index 539d273553..ee7273daa1 100644 --- a/hw/nvme/ctrl.c +++ b/hw/nvme/ctrl.c @@ -2130,11 +2130,6 @@ static inline bool nvme_is_write(NvmeRequest *req) rw->opcode =3D=3D NVME_CMD_WRITE_ZEROES; } =20 -static AioContext *nvme_get_aio_context(BlockAIOCB *acb) -{ - return qemu_get_aio_context(); -} - static void nvme_misc_cb(void *opaque, int ret) { NvmeRequest *req =3D opaque; @@ -3302,7 +3297,6 @@ static void nvme_flush_cancel(BlockAIOCB *acb) static const AIOCBInfo nvme_flush_aiocb_info =3D { .aiocb_size =3D sizeof(NvmeFlushAIOCB), .cancel_async =3D nvme_flush_cancel, - .get_aio_context =3D nvme_get_aio_context, }; =20 static void nvme_do_flush(NvmeFlushAIOCB *iocb); @@ -6478,7 +6472,6 @@ static void nvme_format_cancel(BlockAIOCB *aiocb) static const AIOCBInfo nvme_format_aiocb_info =3D { .aiocb_size =3D sizeof(NvmeFormatAIOCB), .cancel_async =3D nvme_format_cancel, - .get_aio_context =3D nvme_get_aio_context, }; =20 static void nvme_format_set(NvmeNamespace *ns, uint8_t lbaf, uint8_t mset, diff --git a/softmmu/dma-helpers.c b/softmmu/dma-helpers.c index 2463964805..36211acc7e 100644 --- a/softmmu/dma-helpers.c +++ b/softmmu/dma-helpers.c @@ -206,17 +206,9 @@ static void dma_aio_cancel(BlockAIOCB *acb) } } =20 -static AioContext *dma_get_aio_context(BlockAIOCB *acb) -{ - DMAAIOCB *dbs =3D container_of(acb, DMAAIOCB, common); - - return dbs->ctx; -} - static const AIOCBInfo dma_aiocb_info =3D { .aiocb_size =3D sizeof(DMAAIOCB), .cancel_async =3D dma_aio_cancel, - .get_aio_context =3D dma_get_aio_context, }; =20 BlockAIOCB *dma_blk_io(AioContext *ctx, diff --git a/util/thread-pool.c b/util/thread-pool.c index e3d8292d14..22f9ba3286 100644 --- a/util/thread-pool.c +++ b/util/thread-pool.c @@ -228,17 +228,9 @@ static void thread_pool_cancel(BlockAIOCB *acb) =20 } =20 -static AioContext *thread_pool_get_aio_context(BlockAIOCB *acb) -{ - ThreadPoolElement *elem =3D (ThreadPoolElement *)acb; - ThreadPool *pool =3D elem->pool; - return pool->ctx; -} - static const AIOCBInfo thread_pool_aiocb_info =3D { .aiocb_size =3D sizeof(ThreadPoolElement), .cancel_async =3D thread_pool_cancel, - .get_aio_context =3D thread_pool_get_aio_context, }; =20 BlockAIOCB *thread_pool_submit_aio(ThreadPoolFunc *func, void *arg, --=20 2.41.0 From nobody Mon May 13 18:41:58 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=1694560276; cv=none; d=zohomail.com; s=zohoarc; b=b+B1lLdvNRd3FT2W9E1lGf73HvojBxtA0PlNeRsBe9jQeyKoLvfXfy5CM57QeJhDUMQGZzHvIM9kxR4uXEoLfb55tBO8Lz3lTcu/hMhS4+sb7noCLLbH4y/LZwswzUldSGRAJh+rCXwFsPfqyj1X09HAF3RgASxL0s5EoTF4GhU= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1694560276; 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=897BFGJZtZGBSuUAm/0RFqaG2kWarWUrD3DLKqRGMac=; b=QEI5Cb2yR1aSAiM+8ZoBc+GQkSNH8ZcApBIXBuv1GEKez7M8yqfsmFhp8rZMnCOOEzeK+kU+QxHF7RxFdrQvdpxpQp9pFopf15Uu07/25EoiYasnRsML+mqY2uOWdoGhMnuy+5nS/Pg3wVg1g6P5RGRRZuXZkigOqGWnZNHgSCs= 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 1694560276540749.0983715738082; Tue, 12 Sep 2023 16:11:16 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1qgCWy-0001Yr-UD; Tue, 12 Sep 2023 19:10:52 -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 1qgCWx-0001YP-Mz for qemu-devel@nongnu.org; Tue, 12 Sep 2023 19:10:51 -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 1qgCWv-0003Io-BY for qemu-devel@nongnu.org; Tue, 12 Sep 2023 19:10:51 -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-130-3j7ox1ARMxanAZ1_Gzpwuw-1; Tue, 12 Sep 2023 19:10:43 -0400 Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.rdu2.redhat.com [10.11.54.6]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 0FAFB805F6B; Tue, 12 Sep 2023 23:10:43 +0000 (UTC) Received: from localhost (unknown [10.39.192.28]) by smtp.corp.redhat.com (Postfix) with ESMTP id 87E072156721; Tue, 12 Sep 2023 23:10:42 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1694560246; 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=897BFGJZtZGBSuUAm/0RFqaG2kWarWUrD3DLKqRGMac=; b=LnZ+QWIjqD+FqFTP4JBdeQxygNsq/vWQd/bxf0VbnL1uyE2OmSIHGmgBz4w9O3qka12XIW JWa5VTaZ5FPsjkxY1cDqQVeUXdrFLmaPJYV/JEb2aoLiL23vXsRi0X9/sR1t/G+uR56UhN upC8q03jmXaSSMiKDSJMHSrjkxMrWG0= X-MC-Unique: 3j7ox1ARMxanAZ1_Gzpwuw-1 From: Stefan Hajnoczi To: qemu-devel@nongnu.org Cc: Klaus Jensen , kwolf@redhat.com, Cleber Rosa , John Snow , Hanna Reitz , =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= , Keith Busch , Paolo Bonzini , Peter Xu , , Stefan Hajnoczi , Vladimir Sementsov-Ogievskiy , David Hildenbrand , Fam Zheng Subject: [PATCH v3 2/5] test-bdrv-drain: avoid race with BH in IOThread drain test Date: Tue, 12 Sep 2023 19:10:34 -0400 Message-ID: <20230912231037.826804-3-stefanha@redhat.com> In-Reply-To: <20230912231037.826804-1-stefanha@redhat.com> References: <20230912231037.826804-1-stefanha@redhat.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Scanned-By: MIMEDefang 3.1 on 10.11.54.6 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=stefanha@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_H3=0.001, RCVD_IN_MSPIKE_WL=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.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: 1694560278419100005 Content-Type: text/plain; charset="utf-8" This patch fixes a race condition in test-bdrv-drain that is difficult to reproduce. test-bdrv-drain sometimes fails without an error message on the block pull request sent by Kevin Wolf on Sep 4, 2023. I was able to reproduce it locally and found that "block-backend: process I/O in the current AioContext" (in this patch series) is the first commit where it reproduces. I do not know why "block-backend: process I/O in the current AioContext" exposes this bug. It might be related to the fact that the test's preadv request runs in the main thread instead of IOThread a after my commit. That might simply change the timing of the test. Now on to the race condition in test-bdrv-drain. The main thread schedules a BH in IOThread a and then drains the BDS: aio_bh_schedule_oneshot(ctx_a, test_iothread_main_thread_bh, &data); /* The request is running on the IOThread a. Draining its block device * will make sure that it has completed as far as the BDS is concerned, * but the drain in this thread can continue immediately after * bdrv_dec_in_flight() and aio_ret might be assigned only slightly * later. */ do_drain_begin(drain_type, bs); If the BH completes before do_drain_begin() then there is nothing to worry about. If the BH invokes bdrv_flush() before do_drain_begin(), then do_drain_begin() waits for it to complete. The problematic case is when do_drain_begin() runs before the BH enters bdrv_flush(). Then do_drain_begin() misses the BH and the drain mechanism has failed in quiescing I/O. Fix this by incrementing the in_flight counter so that do_drain_begin() waits for test_iothread_main_thread_bh(). Signed-off-by: Stefan Hajnoczi Reviewed-by: Eric Blake --- tests/unit/test-bdrv-drain.c | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/tests/unit/test-bdrv-drain.c b/tests/unit/test-bdrv-drain.c index ccc453c29e..67a79aa3f0 100644 --- a/tests/unit/test-bdrv-drain.c +++ b/tests/unit/test-bdrv-drain.c @@ -512,6 +512,7 @@ static void test_iothread_main_thread_bh(void *opaque) * executed during drain, otherwise this would deadlock. */ aio_context_acquire(bdrv_get_aio_context(data->bs)); bdrv_flush(data->bs); + bdrv_dec_in_flight(data->bs); /* incremented by test_iothread_common()= */ aio_context_release(bdrv_get_aio_context(data->bs)); } =20 @@ -583,6 +584,13 @@ static void test_iothread_common(enum drain_type drain= _type, int drain_thread) aio_context_acquire(ctx_a); } =20 + /* + * Increment in_flight so that do_drain_begin() waits for + * test_iothread_main_thread_bh(). This prevents the race between + * test_iothread_main_thread_bh() in IOThread a and do_drain_begin= () in + * this thread. test_iothread_main_thread_bh() decrements in_fligh= t. + */ + bdrv_inc_in_flight(bs); aio_bh_schedule_oneshot(ctx_a, test_iothread_main_thread_bh, &data= ); =20 /* The request is running on the IOThread a. Draining its block de= vice --=20 2.41.0 From nobody Mon May 13 18:41:58 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=1694560294; cv=none; d=zohomail.com; s=zohoarc; b=ZpurjD+GDTi70VdIp9WRbrHIZbTGbfb3RuQohsYVjHQZCIVRMOfKn/0QpO7su+b5iya+tK27pArDbxQnKxna21fuxfn0vgF3qY9Qg7y3NYkIx5AL/hxJclA/5TWDLxmvEuRRoCiPolWLNPguyjg3hxaCsUn+jjkWLEu5maUQHGQ= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1694560294; 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=CB7++GUL/YZvQw5gmnlv/Lr2xzizXGfQlkxfVa6IUuM=; b=bgsHJlP7uqrcjtTRVbUEtWpgb263PJH+GnbkD2PQUaj3Igmx5h89AtM6y8PhNTktHErMV/mLi8iRW8bMFWw2Qqs4DSVB7Mhzw/fCKJv1tOQgWCQSOD4pDvKGcl7FaVBHSjqyCu/ff28SgvrEv8TFGTueau24GzhBo3oIW/zabWM= 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 1694560294055598.6722974686537; Tue, 12 Sep 2023 16:11:34 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1qgCX0-0001Zs-JH; Tue, 12 Sep 2023 19:10:54 -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 1qgCWz-0001ZN-L8 for qemu-devel@nongnu.org; Tue, 12 Sep 2023 19:10:53 -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 1qgCWx-0003JR-7X for qemu-devel@nongnu.org; Tue, 12 Sep 2023 19:10:53 -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-83-EQnqW1HDM0Cz5TjzHThdRQ-1; Tue, 12 Sep 2023 19:10:45 -0400 Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.rdu2.redhat.com [10.11.54.6]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id D44FA181A6E0; Tue, 12 Sep 2023 23:10:44 +0000 (UTC) Received: from localhost (unknown [10.39.192.28]) by smtp.corp.redhat.com (Postfix) with ESMTP id 5B1052156722; Tue, 12 Sep 2023 23:10:44 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1694560249; 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=CB7++GUL/YZvQw5gmnlv/Lr2xzizXGfQlkxfVa6IUuM=; b=AwtnJfPj9VMgK/GmT6BKPdNBg72u4SmBEBeppesq9bmCeLhiTFbILTNEaEJyHMo2tApbP0 YPMHZRAE+0Flg16DyqE/Z6+pjed6dEwL1L0wFHNgG0EDmrgQw6Hdb81jFBycNaD0OpS6G6 68UjoFlu6wWFCUqdghfTfp+Adl7gQTg= X-MC-Unique: EQnqW1HDM0Cz5TjzHThdRQ-1 From: Stefan Hajnoczi To: qemu-devel@nongnu.org Cc: Klaus Jensen , kwolf@redhat.com, Cleber Rosa , John Snow , Hanna Reitz , =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= , Keith Busch , Paolo Bonzini , Peter Xu , , Stefan Hajnoczi , Vladimir Sementsov-Ogievskiy , David Hildenbrand , Fam Zheng Subject: [PATCH v3 3/5] block-backend: process I/O in the current AioContext Date: Tue, 12 Sep 2023 19:10:35 -0400 Message-ID: <20230912231037.826804-4-stefanha@redhat.com> In-Reply-To: <20230912231037.826804-1-stefanha@redhat.com> References: <20230912231037.826804-1-stefanha@redhat.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Scanned-By: MIMEDefang 3.1 on 10.11.54.6 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=stefanha@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_H4=0.001, RCVD_IN_MSPIKE_WL=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: 1694560295251100001 Content-Type: text/plain; charset="utf-8" Switch blk_aio_*() APIs over to multi-queue by using qemu_get_current_aio_context() instead of blk_get_aio_context(). This change will allow devices to process I/O in multiple IOThreads in the future. I audited existing blk_aio_*() callers: - migration/block.c: blk_mig_lock() protects the data accessed by the completion callback. - The remaining emulated devices and exports run with qemu_get_aio_context() =3D=3D blk_get_aio_context(). Signed-off-by: Stefan Hajnoczi Reviewed-by: Eric Blake --- block/block-backend.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/block/block-backend.c b/block/block-backend.c index a77295a198..4863be5691 100644 --- a/block/block-backend.c +++ b/block/block-backend.c @@ -1530,7 +1530,7 @@ BlockAIOCB *blk_abort_aio_request(BlockBackend *blk, acb->blk =3D blk; acb->ret =3D ret; =20 - replay_bh_schedule_oneshot_event(blk_get_aio_context(blk), + replay_bh_schedule_oneshot_event(qemu_get_current_aio_context(), error_callback_bh, acb); return &acb->common; } @@ -1584,11 +1584,11 @@ static BlockAIOCB *blk_aio_prwv(BlockBackend *blk, = int64_t offset, acb->has_returned =3D false; =20 co =3D qemu_coroutine_create(co_entry, acb); - aio_co_enter(blk_get_aio_context(blk), co); + aio_co_enter(qemu_get_current_aio_context(), co); =20 acb->has_returned =3D true; if (acb->rwco.ret !=3D NOT_DONE) { - replay_bh_schedule_oneshot_event(blk_get_aio_context(blk), + replay_bh_schedule_oneshot_event(qemu_get_current_aio_context(), blk_aio_complete_bh, acb); } =20 --=20 2.41.0 From nobody Mon May 13 18:41:58 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=1694560305; cv=none; d=zohomail.com; s=zohoarc; b=DZVzeGqUxiI4hzuBmJMCMsfoXQxmDDoJi2ZB0GMFoJzgI8yjTAGFUF6q5dp/9hVe4VNbZeW+ngmPWNtDeAIXMpF84sBwipCQBppiRQye/CR7tO7U37eF3eiYExHwN3vGaV6vlGdu5OYs4MLwj2VXny4ozqrMfUxPbHzSc4Gy1N4= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1694560305; 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=YpwmONNOzcVBwmRqXJdqeBbfcpjkCWz3pGWXhk9HVu4=; b=D30zteeKRCUbLY3fvey+cDHKNB7hOAcwGVatFAK3GOggFW7CsMQx+uHyNwHHknH45/bKtFQ7ZsssYIBfhtUC+5ntchIfqgeEz5iHxdDCx2wP3azlkYwhCMtZpUOK9uE/wedogSKQO+UY3zRsVaJKrMUrrJaJGQF+UDQpTLkC96M= 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 169456030590150.01867164915302; Tue, 12 Sep 2023 16:11:45 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1qgCX0-0001Zr-IU; Tue, 12 Sep 2023 19:10:54 -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 1qgCWz-0001ZQ-MA for qemu-devel@nongnu.org; Tue, 12 Sep 2023 19:10:53 -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 1qgCWx-0003Ja-0N for qemu-devel@nongnu.org; Tue, 12 Sep 2023 19:10:53 -0400 Received: from mimecast-mx02.redhat.com (mx-ext.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-66-_6Tm2H5vM1yw-yQwKZfFAQ-1; Tue, 12 Sep 2023 19:10:47 -0400 Received: from smtp.corp.redhat.com (int-mx01.intmail.prod.int.rdu2.redhat.com [10.11.54.1]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id AC4F33C0C880; Tue, 12 Sep 2023 23:10:46 +0000 (UTC) Received: from localhost (unknown [10.39.192.28]) by smtp.corp.redhat.com (Postfix) with ESMTP id 2B20640C2009; Tue, 12 Sep 2023 23:10:45 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1694560250; 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=YpwmONNOzcVBwmRqXJdqeBbfcpjkCWz3pGWXhk9HVu4=; b=g+1QUe3cR9NYHyfX9TKigeAjBb8czhrYL0unH2PmMEM0ZImd49Nh+NlbDRTzE5Cb8FpAcF DMW2RzJshL/BbUARoDylpUM0x1Oczsw6K7Z+3d3gZHd3VR+NWqG0xlVd3t9fo2gbHJ8LRp lNUpbJtxzC9KMbGyq6h5GTJErF4ODnA= X-MC-Unique: _6Tm2H5vM1yw-yQwKZfFAQ-1 From: Stefan Hajnoczi To: qemu-devel@nongnu.org Cc: Klaus Jensen , kwolf@redhat.com, Cleber Rosa , John Snow , Hanna Reitz , =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= , Keith Busch , Paolo Bonzini , Peter Xu , , Stefan Hajnoczi , Vladimir Sementsov-Ogievskiy , David Hildenbrand , Fam Zheng Subject: [PATCH v3 4/5] block-backend: process zoned requests in the current AioContext Date: Tue, 12 Sep 2023 19:10:36 -0400 Message-ID: <20230912231037.826804-5-stefanha@redhat.com> In-Reply-To: <20230912231037.826804-1-stefanha@redhat.com> References: <20230912231037.826804-1-stefanha@redhat.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Scanned-By: MIMEDefang 3.1 on 10.11.54.1 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=stefanha@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_H3=0.001, RCVD_IN_MSPIKE_WL=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.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: 1694560307305100001 Content-Type: text/plain; charset="utf-8" Process zoned requests in the current thread's AioContext instead of in the BlockBackend's AioContext. There is no need to use the BlockBackend's AioContext thanks to CoMutex bs->wps->colock, which protects zone metadata. Signed-off-by: Stefan Hajnoczi Reviewed-by: Eric Blake --- block/block-backend.c | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/block/block-backend.c b/block/block-backend.c index 4863be5691..427ebcc0e4 100644 --- a/block/block-backend.c +++ b/block/block-backend.c @@ -1890,11 +1890,11 @@ BlockAIOCB *blk_aio_zone_report(BlockBackend *blk, = int64_t offset, acb->has_returned =3D false; =20 co =3D qemu_coroutine_create(blk_aio_zone_report_entry, acb); - aio_co_enter(blk_get_aio_context(blk), co); + aio_co_enter(qemu_get_current_aio_context(), co); =20 acb->has_returned =3D true; if (acb->rwco.ret !=3D NOT_DONE) { - replay_bh_schedule_oneshot_event(blk_get_aio_context(blk), + replay_bh_schedule_oneshot_event(qemu_get_current_aio_context(), blk_aio_complete_bh, acb); } =20 @@ -1931,11 +1931,11 @@ BlockAIOCB *blk_aio_zone_mgmt(BlockBackend *blk, Bl= ockZoneOp op, acb->has_returned =3D false; =20 co =3D qemu_coroutine_create(blk_aio_zone_mgmt_entry, acb); - aio_co_enter(blk_get_aio_context(blk), co); + aio_co_enter(qemu_get_current_aio_context(), co); =20 acb->has_returned =3D true; if (acb->rwco.ret !=3D NOT_DONE) { - replay_bh_schedule_oneshot_event(blk_get_aio_context(blk), + replay_bh_schedule_oneshot_event(qemu_get_current_aio_context(), blk_aio_complete_bh, acb); } =20 @@ -1971,10 +1971,10 @@ BlockAIOCB *blk_aio_zone_append(BlockBackend *blk, = int64_t *offset, acb->has_returned =3D false; =20 co =3D qemu_coroutine_create(blk_aio_zone_append_entry, acb); - aio_co_enter(blk_get_aio_context(blk), co); + aio_co_enter(qemu_get_current_aio_context(), co); acb->has_returned =3D true; if (acb->rwco.ret !=3D NOT_DONE) { - replay_bh_schedule_oneshot_event(blk_get_aio_context(blk), + replay_bh_schedule_oneshot_event(qemu_get_current_aio_context(), blk_aio_complete_bh, acb); } =20 --=20 2.41.0 From nobody Mon May 13 18:41:58 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=1694560308; cv=none; d=zohomail.com; s=zohoarc; b=lxdZnuY6tmlEK7i+8qo85I1wcO7fwd2ISOU8vR7fOU0Spn+lgOdLQvb3TRGLGvn/HsepS1hEZyfOpqFAsM27Bd23MIziM/OKw/HGPtVfymS1ce0yNKd5DoFLvpTIFJ7rl0nMt734JazVO1VIKwWMzKwsPJgaC79CjxQ3kGzd60M= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1694560308; 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=C/Am5r627g6QuRUSXRfOq1ki/mlH81bZqKEnrMTBrpo=; b=K5qIWHpswvUanogP+ewldYB/hWr7pCXMwiEC2zaA2EoJW4C2VdDzkH3/cpB/JSXK6da4SeUmo3EutbZ083e3vGz7hOGxpwGEp4UYl/It+6LcCYTbLSOHXSJRzb0YFSVLLwV5XUvZ7kdQUJ28/xzhQBmKEbLgXijXpUIqOPLTvS0= 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 169456030874058.450384988986; Tue, 12 Sep 2023 16:11:48 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1qgCX3-0001cl-Iu; Tue, 12 Sep 2023 19:10:57 -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 1qgCX1-0001am-Pq for qemu-devel@nongnu.org; Tue, 12 Sep 2023 19:10:55 -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 1qgCWz-0003K3-6t for qemu-devel@nongnu.org; Tue, 12 Sep 2023 19:10:55 -0400 Received: from mimecast-mx02.redhat.com (mx-ext.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-647-CuV-VkKwMhSuyvc9-Lsa7A-1; Tue, 12 Sep 2023 19:10:49 -0400 Received: from smtp.corp.redhat.com (int-mx04.intmail.prod.int.rdu2.redhat.com [10.11.54.4]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id EEA823C0C880; Tue, 12 Sep 2023 23:10:48 +0000 (UTC) Received: from localhost (unknown [10.39.192.28]) by smtp.corp.redhat.com (Postfix) with ESMTP id 3393C2026D4B; Tue, 12 Sep 2023 23:10:48 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1694560252; 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=C/Am5r627g6QuRUSXRfOq1ki/mlH81bZqKEnrMTBrpo=; b=Wf1xuAojVfc7CYg3ZYo75e4uGno6S6mG55c48zd3oVxHnmpYrgKbNZWuHqRkYs4qO8TPID JlMOHMCH/iekgxrJ00DenRt0hoNo1/Gqb99i+YntWHb/ZPzdHGyakzNWlkO4LG5oT0hqEK XEKqnyK3TQSmHSWWPUFKU0tCM5HbcMY= X-MC-Unique: CuV-VkKwMhSuyvc9-Lsa7A-1 From: Stefan Hajnoczi To: qemu-devel@nongnu.org Cc: Klaus Jensen , kwolf@redhat.com, Cleber Rosa , John Snow , Hanna Reitz , =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= , Keith Busch , Paolo Bonzini , Peter Xu , , Stefan Hajnoczi , Vladimir Sementsov-Ogievskiy , David Hildenbrand , Fam Zheng Subject: [PATCH v3 5/5] block-coroutine-wrapper: use qemu_get_current_aio_context() Date: Tue, 12 Sep 2023 19:10:37 -0400 Message-ID: <20230912231037.826804-6-stefanha@redhat.com> In-Reply-To: <20230912231037.826804-1-stefanha@redhat.com> References: <20230912231037.826804-1-stefanha@redhat.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Scanned-By: MIMEDefang 3.1 on 10.11.54.4 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=stefanha@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_H4=0.001, RCVD_IN_MSPIKE_WL=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.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: 1694560309249100005 Content-Type: text/plain; charset="utf-8" Use qemu_get_current_aio_context() in mixed wrappers and coroutine wrappers so that code runs in the caller's AioContext instead of moving to the BlockDriverState's AioContext. This change is necessary for the multi-queue block layer where any thread can call into the block layer. Most wrappers are IO_CODE where it's safe to use the current AioContext nowadays. BlockDrivers and the core block layer use their own locks and no longer depend on the AioContext lock for thread-safety. The bdrv_create() wrapper invokes GLOBAL_STATE code. Using the current AioContext is safe because this code is only called with the BQL held from the main loop thread. The output of qemu-iotests 051 is sensitive to event loop activity. Update the output because the monitor BH runs at a different time, causing prompts to be printed differently in the output. Signed-off-by: Stefan Hajnoczi Reviewed-by: Eric Blake --- scripts/block-coroutine-wrapper.py | 6 ++---- tests/qemu-iotests/051.pc.out | 4 ++-- 2 files changed, 4 insertions(+), 6 deletions(-) diff --git a/scripts/block-coroutine-wrapper.py b/scripts/block-coroutine-w= rapper.py index d4a183db61..f93fe154c3 100644 --- a/scripts/block-coroutine-wrapper.py +++ b/scripts/block-coroutine-wrapper.py @@ -88,8 +88,6 @@ def __init__(self, wrapper_type: str, return_type: str, n= ame: str, raise ValueError(f"no_co function can't be rdlock: {self.n= ame}") self.target_name =3D f'{subsystem}_{subname}' =20 - self.ctx =3D self.gen_ctx() - self.get_result =3D 's->ret =3D ' self.ret =3D 'return s.ret;' self.co_ret =3D 'return ' @@ -162,7 +160,7 @@ def create_mixed_wrapper(func: FuncDecl) -> str: {func.co_ret}{name}({ func.gen_list('{name}') }); }} else {{ {struct_name} s =3D {{ - .poll_state.ctx =3D {func.ctx}, + .poll_state.ctx =3D qemu_get_current_aio_context(), .poll_state.in_progress =3D true, =20 { func.gen_block(' .{name} =3D {name},') } @@ -186,7 +184,7 @@ def create_co_wrapper(func: FuncDecl) -> str: {func.return_type} {func.name}({ func.gen_list('{decl}') }) {{ {struct_name} s =3D {{ - .poll_state.ctx =3D {func.ctx}, + .poll_state.ctx =3D qemu_get_current_aio_context(), .poll_state.in_progress =3D true, =20 { func.gen_block(' .{name} =3D {name},') } diff --git a/tests/qemu-iotests/051.pc.out b/tests/qemu-iotests/051.pc.out index 4d4af5a486..650cfed8e2 100644 --- a/tests/qemu-iotests/051.pc.out +++ b/tests/qemu-iotests/051.pc.out @@ -177,11 +177,11 @@ QEMU_PROG: -device virtio-blk-pci,drive=3Ddisk,share-= rw=3Don: Cannot change iothread =20 Testing: -drive file=3DTEST_DIR/t.qcow2,if=3Dnone,node-name=3Ddisk -object= iothread,id=3Dthread0 -device virtio-scsi,iothread=3Dthread0,id=3Dvirtio-s= csi0 -device scsi-hd,bus=3Dvirtio-scsi0.0,drive=3Ddisk,share-rw=3Don -devic= e lsi53c895a,id=3Dlsi0 -device scsi-hd,bus=3Dlsi0.0,drive=3Ddisk,share-rw= =3Don QEMU X.Y.Z monitor - type 'help' for more information -(qemu) QEMU_PROG: -device scsi-hd,bus=3Dlsi0.0,drive=3Ddisk,share-rw=3Don:= HBA does not support iothreads +QEMU_PROG: -device scsi-hd,bus=3Dlsi0.0,drive=3Ddisk,share-rw=3Don: HBA do= es not support iothreads =20 Testing: -drive file=3DTEST_DIR/t.qcow2,if=3Dnone,node-name=3Ddisk -object= iothread,id=3Dthread0 -device virtio-scsi,iothread=3Dthread0,id=3Dvirtio-s= csi0 -device scsi-hd,bus=3Dvirtio-scsi0.0,drive=3Ddisk,share-rw=3Don -devic= e virtio-scsi,id=3Dvirtio-scsi1 -device scsi-hd,bus=3Dvirtio-scsi1.0,drive= =3Ddisk,share-rw=3Don QEMU X.Y.Z monitor - type 'help' for more information -(qemu) QEMU_PROG: -device scsi-hd,bus=3Dvirtio-scsi1.0,drive=3Ddisk,share-= rw=3Don: Cannot change iothread of active block backend +QEMU_PROG: -device scsi-hd,bus=3Dvirtio-scsi1.0,drive=3Ddisk,share-rw=3Don= : Cannot change iothread of active block backend =20 Testing: -drive file=3DTEST_DIR/t.qcow2,if=3Dnone,node-name=3Ddisk -object= iothread,id=3Dthread0 -device virtio-scsi,iothread=3Dthread0,id=3Dvirtio-s= csi0 -device scsi-hd,bus=3Dvirtio-scsi0.0,drive=3Ddisk,share-rw=3Don -devic= e virtio-blk-pci,drive=3Ddisk,iothread=3Dthread0,share-rw=3Don QEMU X.Y.Z monitor - type 'help' for more information --=20 2.41.0