From nobody Mon May 20 16:32:53 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=1685464435; cv=none; d=zohomail.com; s=zohoarc; b=GPbFZlIWHQoVAfaGOMz8CDAMSvZVHjbtMi3wP+pMwxjG40kvsRKHc9wKSkljBzjt5gvF3NVaMT2wzXDtqOnfjUaZL9o8eEWge/hkJr2eA2YqKROCOKHXbhX2BmfWkWEsue9XkFxZSZza/NgHX/qrRkb50OzLuJ9DIzF86WL7TIs= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1685464435; 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=/mDLK7mC5NRaUC3H3mY9AU3fBUJ0pXzL7oiwyUyUC9w=; b=O/GR6UccChMiGlj9ubvw7NkWAjYnLdzfP+3+lFRO52gXHPBZBnXnz/nQxOXENwV4af6wOpcohudjuPkDjd9XcktIFhB522lW54/0FdqzpVCK2EAlmOibzDgiyPzH02ZDWUbDztkptjFhP6NLvc30vcYAKzZZ493coMP/40G0kyE= 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 1685464435568134.37894235089584; Tue, 30 May 2023 09:33:55 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1q42I9-0007Lk-Pm; Tue, 30 May 2023 12:33:49 -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 1q42HK-0006TO-Rn for qemu-devel@nongnu.org; Tue, 30 May 2023 12:33:00 -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 1q42HG-0008En-O0 for qemu-devel@nongnu.org; Tue, 30 May 2023 12:32:56 -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-128-mmou09xpPc6GQR4B2HKIbg-1; Tue, 30 May 2023 12:32:48 -0400 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 04FBD1C01E98; Tue, 30 May 2023 16:32:48 +0000 (UTC) Received: from merkur.redhat.com (unknown [10.39.194.4]) by smtp.corp.redhat.com (Postfix) with ESMTP id 4D4F1C15612; Tue, 30 May 2023 16:32:47 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1685464374; 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=/mDLK7mC5NRaUC3H3mY9AU3fBUJ0pXzL7oiwyUyUC9w=; b=WkXhR4PgKB75xutyyQUN+7jZAAUxztU6cpF8or0tJ8KIr5M+jXmcjJNadhXuHEz0mAPnbL PmJsivgkAIDEkSh76MMUElKBZwIaXClAdTnehj38NRVl+dO69QYUg/XWofGanamE1HIr5l uUTIiuEk16JxhjddtzOefy5ID63OH4s= X-MC-Unique: mmou09xpPc6GQR4B2HKIbg-1 From: Kevin Wolf To: qemu-block@nongnu.org Cc: kwolf@redhat.com, richard.henderson@linaro.org, qemu-devel@nongnu.org Subject: [PULL 01/32] block-coroutine-wrapper: Take AioContext lock in no_co_wrappers Date: Tue, 30 May 2023 18:32:08 +0200 Message-Id: <20230530163239.576632-2-kwolf@redhat.com> In-Reply-To: <20230530163239.576632-1-kwolf@redhat.com> References: <20230530163239.576632-1-kwolf@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.133.124; envelope-from=kwolf@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -22 X-Spam_score: -2.3 X-Spam_bar: -- X-Spam_report: (-2.3 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.167, 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: 1685464436819100003 Content-Type: text/plain; charset="utf-8" All of the functions that currently take a BlockDriverState, BdrvChild or BlockBackend as their first parameter expect the associated AioContext to be locked when they are called. In the case of no_co_wrappers, they are called from bottom halves directly in the main loop, so no other caller can be expected to take the lock for them. This can result in assertion failures because a lock that isn't taken is released in nested event loops. Looking at the first parameter is already done by co_wrappers to decide where the coroutine should run, so doing the same in no_co_wrappers is only consistent. Take the lock in the generated bottom halves to fix the problem. Signed-off-by: Kevin Wolf Message-Id: <20230525124713.401149-2-kwolf@redhat.com> Reviewed-by: Stefan Hajnoczi Signed-off-by: Kevin Wolf --- include/block/block-common.h | 3 +++ block/block-backend.c | 7 ++++++- scripts/block-coroutine-wrapper.py | 25 +++++++++++++++---------- 3 files changed, 24 insertions(+), 11 deletions(-) diff --git a/include/block/block-common.h b/include/block/block-common.h index 93196229ac..e15395f2cb 100644 --- a/include/block/block-common.h +++ b/include/block/block-common.h @@ -65,6 +65,9 @@ * scheduling a BH in the bottom half that runs the respective non-corouti= ne * function. The coroutine yields after scheduling the BH and is reentered= when * the wrapped function returns. + * + * If the first parameter of the function is a BlockDriverState, BdrvChild= or + * BlockBackend pointer, the AioContext lock for it is taken in the wrappe= r. */ #define no_co_wrapper =20 diff --git a/block/block-backend.c b/block/block-backend.c index ca537cd0ad..26447664ab 100644 --- a/block/block-backend.c +++ b/block/block-backend.c @@ -2394,9 +2394,14 @@ void blk_op_unblock_all(BlockBackend *blk, Error *re= ason) =20 AioContext *blk_get_aio_context(BlockBackend *blk) { - BlockDriverState *bs =3D blk_bs(blk); + BlockDriverState *bs; IO_CODE(); =20 + if (!blk) { + return qemu_get_aio_context(); + } + + bs =3D blk_bs(blk); if (bs) { AioContext *ctx =3D bdrv_get_aio_context(blk_bs(blk)); assert(ctx =3D=3D blk->ctx); diff --git a/scripts/block-coroutine-wrapper.py b/scripts/block-coroutine-w= rapper.py index 60e9b3107c..d4a183db61 100644 --- a/scripts/block-coroutine-wrapper.py +++ b/scripts/block-coroutine-wrapper.py @@ -88,16 +88,7 @@ def __init__(self, wrapper_type: str, return_type: str, = name: str, raise ValueError(f"no_co function can't be rdlock: {self.n= ame}") self.target_name =3D f'{subsystem}_{subname}' =20 - t =3D self.args[0].type - if t =3D=3D 'BlockDriverState *': - ctx =3D 'bdrv_get_aio_context(bs)' - elif t =3D=3D 'BdrvChild *': - ctx =3D 'bdrv_get_aio_context(child->bs)' - elif t =3D=3D 'BlockBackend *': - ctx =3D 'blk_get_aio_context(blk)' - else: - ctx =3D 'qemu_get_aio_context()' - self.ctx =3D ctx + self.ctx =3D self.gen_ctx() =20 self.get_result =3D 's->ret =3D ' self.ret =3D 'return s.ret;' @@ -109,6 +100,17 @@ def __init__(self, wrapper_type: str, return_type: str= , name: str, self.co_ret =3D '' self.return_field =3D '' =20 + def gen_ctx(self, prefix: str =3D '') -> str: + t =3D self.args[0].type + if t =3D=3D 'BlockDriverState *': + return f'bdrv_get_aio_context({prefix}bs)' + elif t =3D=3D 'BdrvChild *': + return f'bdrv_get_aio_context({prefix}child->bs)' + elif t =3D=3D 'BlockBackend *': + return f'blk_get_aio_context({prefix}blk)' + else: + return 'qemu_get_aio_context()' + def gen_list(self, format: str) -> str: return ', '.join(format.format_map(arg.__dict__) for arg in self.a= rgs) =20 @@ -262,8 +264,11 @@ def gen_no_co_wrapper(func: FuncDecl) -> str: static void {name}_bh(void *opaque) {{ {struct_name} *s =3D opaque; + AioContext *ctx =3D {func.gen_ctx('s->')}; =20 + aio_context_acquire(ctx); {func.get_result}{name}({ func.gen_list('s->{name}') }); + aio_context_release(ctx); =20 aio_co_wake(s->co); }} --=20 2.40.1 From nobody Mon May 20 16:32:53 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=1685464435; cv=none; d=zohomail.com; s=zohoarc; b=egcncg/tjwpjS4tB9ieMInkVEu4mKLfDxkWmplvRcEEPm9G9LEor5haG70vveK5T0VlxYkuwPZqWtvdkaPKA6nqiCkU+8V5Xxc4aO2I121zD4NEOeqMlBqTtwT6V6rgFJqcROsyyUpZ11Advr5m+NYoKtL6ugwZovlKBMWXB8pg= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1685464435; 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=dzhFKhskU/fSjYHhxXdldkdr3BKm2r8aQp10XT8mT9E=; b=FY6aZBnC311i36fMZzFvJVr2rR8+Sx/AisQe4jAf0Ywx8Z4TcHyBU9iyKzIM1m7VS7pHhTZr1MhOyp0r+9RXscF4+anoL4d3lkzYkXrHBMlXMeNYeCPclFx68RJK3jSXxqyREFUkG7VjeK6kYeZerJie/E80oGUpx6qPE22xtSE= 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 168546443517141.733933511875534; Tue, 30 May 2023 09:33:55 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1q42I3-0007A3-Nr; Tue, 30 May 2023 12:33:46 -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 1q42HF-0006NS-Mh for qemu-devel@nongnu.org; Tue, 30 May 2023 12:33:00 -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 1q42HE-0008Dq-5K for qemu-devel@nongnu.org; Tue, 30 May 2023 12:32:53 -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-386-KqUrSezdP0ya2L8pVUxyfQ-1; Tue, 30 May 2023 12:32:49 -0400 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 EAD8F28EC101; Tue, 30 May 2023 16:32:48 +0000 (UTC) Received: from merkur.redhat.com (unknown [10.39.194.4]) by smtp.corp.redhat.com (Postfix) with ESMTP id 3C785C154D2; Tue, 30 May 2023 16:32:48 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1685464371; 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=dzhFKhskU/fSjYHhxXdldkdr3BKm2r8aQp10XT8mT9E=; b=QGlsGOP+sXd6qm7NDJ8Q/VWlUzTaW4nNqc0r6ZYNoE0sdrsNpwPCUJNQAhPFQqH1DFyIly Vh9nB7tUNOinlKRjSGPE/ZITnkMZHSYRV12zTasPyMZfDLrSLmnvxBd3MjYUvg7BdWTq+M cJUfB618t1TYCAglUZp7B7m1rHbnRyY= X-MC-Unique: KqUrSezdP0ya2L8pVUxyfQ-1 From: Kevin Wolf To: qemu-block@nongnu.org Cc: kwolf@redhat.com, richard.henderson@linaro.org, qemu-devel@nongnu.org Subject: [PULL 02/32] block: Clarify locking rules for bdrv_open(_inherit)() Date: Tue, 30 May 2023 18:32:09 +0200 Message-Id: <20230530163239.576632-3-kwolf@redhat.com> In-Reply-To: <20230530163239.576632-1-kwolf@redhat.com> References: <20230530163239.576632-1-kwolf@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.133.124; envelope-from=kwolf@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -22 X-Spam_score: -2.3 X-Spam_bar: -- X-Spam_report: (-2.3 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.167, 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: 1685464436917100005 Content-Type: text/plain; charset="utf-8" These functions specify that the caller must hold the "@filename AioContext lock". This doesn't make sense, file names don't have an AioContext. New BlockDriverStates always start in the main AioContext, so this is what we really need here. Signed-off-by: Kevin Wolf Message-Id: <20230525124713.401149-3-kwolf@redhat.com> Reviewed-by: Stefan Hajnoczi Signed-off-by: Kevin Wolf --- block.c | 10 ++-------- 1 file changed, 2 insertions(+), 8 deletions(-) diff --git a/block.c b/block.c index a2f8d5a0c0..6ac47112fe 100644 --- a/block.c +++ b/block.c @@ -3810,9 +3810,7 @@ out: * should be opened. If specified, neither options nor a filename may be g= iven, * nor can an existing BDS be reused (that is, *pbs has to be NULL). * - * The caller must always hold @filename AioContext lock, because this - * function eventually calls bdrv_refresh_total_sectors() which polls - * when called from non-coroutine context. + * The caller must always hold the main AioContext lock. */ static BlockDriverState * no_coroutine_fn bdrv_open_inherit(const char *filename, const char *reference, QDict *opti= ons, @@ -4100,11 +4098,7 @@ close_and_fail: return NULL; } =20 -/* - * The caller must always hold @filename AioContext lock, because this - * function eventually calls bdrv_refresh_total_sectors() which polls - * when called from non-coroutine context. - */ +/* The caller must always hold the main AioContext lock. */ BlockDriverState *bdrv_open(const char *filename, const char *reference, QDict *options, int flags, Error **errp) { --=20 2.40.1 From nobody Mon May 20 16:32:53 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=1685464414; cv=none; d=zohomail.com; s=zohoarc; b=HJUfClIDlL5FlqtLjfg45+rSAKO89slsS/wuLWtbQyR+89fLdGSfETg7yxq2F1nU2Uz+F1iK3b61juN6+4f9eD5EsoNo7JxnVbfM++Soz6t6LKqd/BZeqIvhJottNoabk6zkGOkRjLKVf5TqWeHTbDFluEn6128Hbhqp8iXEQbs= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1685464414; 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=7tyzEuTfsOP1f01W0nbf8/VHn4VVJZIJjxKyB0bXOb4=; b=UYUiIz6dtiPSLn4dPqd5phOipBjKrvmECiS3+qIymN8RQPeRHKUjzCCHaeKEq9EGovmIzADZpKsUbpb/tpSUGc9Oz2yqbgPp2KqXCylLuIDbspmCH/03E+1+aNqMdvF46tVFwKeC/u8oldfjcXMffC2mKHHXWLlCSneh/tLDwOA= 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 1685464414314230.1313038976989; Tue, 30 May 2023 09:33:34 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1q42Ha-0006mD-SH; Tue, 30 May 2023 12:33:16 -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 1q42HI-0006ST-8H for qemu-devel@nongnu.org; Tue, 30 May 2023 12:33:00 -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 1q42HG-0008Ea-EF for qemu-devel@nongnu.org; Tue, 30 May 2023 12:32:55 -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-225-WHAF-ZOnMZSOB4LAM4onCw-1; Tue, 30 May 2023 12:32:50 -0400 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 DE2BB85A5AA; Tue, 30 May 2023 16:32:49 +0000 (UTC) Received: from merkur.redhat.com (unknown [10.39.194.4]) by smtp.corp.redhat.com (Postfix) with ESMTP id 2E1BCC154D2; Tue, 30 May 2023 16:32:49 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1685464373; 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=7tyzEuTfsOP1f01W0nbf8/VHn4VVJZIJjxKyB0bXOb4=; b=hhxrthfpMk293tOmo0GECq1ra+fJ1q5u7/H3Uh6CnPy4aMLoZ+pSjtEIWwlWuZW76ROo46 NsUKPwq4o9Dwn+5G+ohEiBenHEHXJA7Jqn25xeynSOjD8tTTBS/ctXWZk1gqfugtPMGXit 58dNZP82BSNupVgGN7VU3d3H2AJ29ng= X-MC-Unique: WHAF-ZOnMZSOB4LAM4onCw-1 From: Kevin Wolf To: qemu-block@nongnu.org Cc: kwolf@redhat.com, richard.henderson@linaro.org, qemu-devel@nongnu.org Subject: [PULL 03/32] block: Take main AioContext lock when calling bdrv_open() Date: Tue, 30 May 2023 18:32:10 +0200 Message-Id: <20230530163239.576632-4-kwolf@redhat.com> In-Reply-To: <20230530163239.576632-1-kwolf@redhat.com> References: <20230530163239.576632-1-kwolf@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=kwolf@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -22 X-Spam_score: -2.3 X-Spam_bar: -- X-Spam_report: (-2.3 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.167, 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: 1685464416771100001 Content-Type: text/plain; charset="utf-8" The function documentation already says that all callers must hold the main AioContext lock, but not all of them do. This can cause assertion failures when functions called by bdrv_open() try to drop the lock. Fix a few more callers to take the lock before calling bdrv_open(). Signed-off-by: Kevin Wolf Message-Id: <20230525124713.401149-4-kwolf@redhat.com> Reviewed-by: Stefan Hajnoczi Signed-off-by: Kevin Wolf --- block.c | 3 +++ block/block-backend.c | 2 ++ block/qapi-sysemu.c | 3 +++ blockdev.c | 29 +++++++++++++++++++++++------ qemu-nbd.c | 4 ++++ tests/unit/test-block-iothread.c | 3 +++ 6 files changed, 38 insertions(+), 6 deletions(-) diff --git a/block.c b/block.c index 6ac47112fe..79bc9c01de 100644 --- a/block.c +++ b/block.c @@ -7037,6 +7037,8 @@ void bdrv_img_create(const char *filename, const char= *fmt, return; } =20 + aio_context_acquire(qemu_get_aio_context()); + /* Create parameter list */ create_opts =3D qemu_opts_append(create_opts, drv->create_opts); create_opts =3D qemu_opts_append(create_opts, proto_drv->create_opts); @@ -7186,6 +7188,7 @@ out: qemu_opts_del(opts); qemu_opts_free(create_opts); error_propagate(errp, local_err); + aio_context_release(qemu_get_aio_context()); } =20 AioContext *bdrv_get_aio_context(BlockDriverState *bs) diff --git a/block/block-backend.c b/block/block-backend.c index 26447664ab..1d89fabd35 100644 --- a/block/block-backend.c +++ b/block/block-backend.c @@ -452,7 +452,9 @@ BlockBackend *blk_new_open(const char *filename, const = char *reference, } =20 blk =3D blk_new(qemu_get_aio_context(), perm, shared); + aio_context_acquire(qemu_get_aio_context()); bs =3D bdrv_open(filename, reference, options, flags, errp); + aio_context_release(qemu_get_aio_context()); if (!bs) { blk_unref(blk); return NULL; diff --git a/block/qapi-sysemu.c b/block/qapi-sysemu.c index cec3c1afb4..ef07151892 100644 --- a/block/qapi-sysemu.c +++ b/block/qapi-sysemu.c @@ -362,7 +362,10 @@ void qmp_blockdev_change_medium(const char *device, qdict_put_str(options, "driver", format); } =20 + aio_context_acquire(qemu_get_aio_context()); medium_bs =3D bdrv_open(filename, NULL, options, bdrv_flags, errp); + aio_context_release(qemu_get_aio_context()); + if (!medium_bs) { goto fail; } diff --git a/blockdev.c b/blockdev.c index 5d56b79df4..db2725fe74 100644 --- a/blockdev.c +++ b/blockdev.c @@ -662,6 +662,7 @@ err_no_opts: /* Takes the ownership of bs_opts */ BlockDriverState *bds_tree_init(QDict *bs_opts, Error **errp) { + BlockDriverState *bs; int bdrv_flags =3D 0; =20 GLOBAL_STATE_CODE(); @@ -676,7 +677,11 @@ BlockDriverState *bds_tree_init(QDict *bs_opts, Error = **errp) bdrv_flags |=3D BDRV_O_INACTIVE; } =20 - return bdrv_open(NULL, NULL, bs_opts, bdrv_flags, errp); + aio_context_acquire(qemu_get_aio_context()); + bs =3D bdrv_open(NULL, NULL, bs_opts, bdrv_flags, errp); + aio_context_release(qemu_get_aio_context()); + + return bs; } =20 void blockdev_close_all_bdrv_states(void) @@ -1480,14 +1485,20 @@ static void external_snapshot_action(TransactionAct= ion *action, } qdict_put_str(options, "driver", format); } + aio_context_release(aio_context); =20 + aio_context_acquire(qemu_get_aio_context()); state->new_bs =3D bdrv_open(new_image_file, snapshot_ref, options, fla= gs, errp); + aio_context_release(qemu_get_aio_context()); + /* We will manually add the backing_hd field to the bs later */ if (!state->new_bs) { - goto out; + return; } =20 + aio_context_acquire(aio_context); + /* * Allow attaching a backing file to an overlay that's already in use = only * if the parents don't assume that they are already seeing a valid im= age. @@ -1732,15 +1743,18 @@ static void drive_backup_action(DriveBackup *backup, if (format) { qdict_put_str(options, "driver", format); } + aio_context_release(aio_context); =20 + aio_context_acquire(qemu_get_aio_context()); target_bs =3D bdrv_open(backup->target, NULL, options, flags, errp); + aio_context_release(qemu_get_aio_context()); + if (!target_bs) { - goto out; + return; } =20 /* Honor bdrv_try_change_aio_context() context acquisition requirement= s. */ old_context =3D bdrv_get_aio_context(target_bs); - aio_context_release(aio_context); aio_context_acquire(old_context); =20 ret =3D bdrv_try_change_aio_context(target_bs, aio_context, NULL, errp= ); @@ -3066,13 +3080,17 @@ void qmp_drive_mirror(DriveMirror *arg, Error **err= p) if (format) { qdict_put_str(options, "driver", format); } + aio_context_release(aio_context); =20 /* Mirroring takes care of copy-on-write using the source's backing * file. */ + aio_context_acquire(qemu_get_aio_context()); target_bs =3D bdrv_open(arg->target, NULL, options, flags, errp); + aio_context_release(qemu_get_aio_context()); + if (!target_bs) { - goto out; + return; } =20 zero_target =3D (arg->sync =3D=3D MIRROR_SYNC_MODE_FULL && @@ -3082,7 +3100,6 @@ void qmp_drive_mirror(DriveMirror *arg, Error **errp) =20 /* Honor bdrv_try_change_aio_context() context acquisition requirement= s. */ old_context =3D bdrv_get_aio_context(target_bs); - aio_context_release(aio_context); aio_context_acquire(old_context); =20 ret =3D bdrv_try_change_aio_context(target_bs, aio_context, NULL, errp= ); diff --git a/qemu-nbd.c b/qemu-nbd.c index 6ff45308a9..4276163564 100644 --- a/qemu-nbd.c +++ b/qemu-nbd.c @@ -1071,7 +1071,11 @@ int main(int argc, char **argv) qdict_put_str(raw_opts, "driver", "raw"); qdict_put_str(raw_opts, "file", bs->node_name); qdict_put_int(raw_opts, "offset", dev_offset); + + aio_context_acquire(qemu_get_aio_context()); bs =3D bdrv_open(NULL, NULL, raw_opts, flags, &error_fatal); + aio_context_release(qemu_get_aio_context()); + blk_remove_bs(blk); blk_insert_bs(blk, bs, &error_fatal); bdrv_unref(bs); diff --git a/tests/unit/test-block-iothread.c b/tests/unit/test-block-iothr= ead.c index 3a5e1eb2c4..1b40e65bad 100644 --- a/tests/unit/test-block-iothread.c +++ b/tests/unit/test-block-iothread.c @@ -833,8 +833,11 @@ static void test_attach_second_node(void) qdict_put_str(options, "driver", "raw"); qdict_put_str(options, "file", "base"); =20 + /* FIXME raw_open() should take ctx's lock internally */ aio_context_acquire(ctx); + aio_context_acquire(main_ctx); filter =3D bdrv_open(NULL, NULL, options, BDRV_O_RDWR, &error_abort); + aio_context_release(main_ctx); aio_context_release(ctx); =20 g_assert(blk_get_aio_context(blk) =3D=3D ctx); --=20 2.40.1 From nobody Mon May 20 16:32:53 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=1685464700; cv=none; d=zohomail.com; s=zohoarc; b=bZBQr6+Lj7tQlu9nw8DlYcGXaJcOxqu0MHmU6Ep/pSwmT0BskUOHxmAa7dnuC+4w5K99CGEf0Recoc7Ti8iMBnHR2IXLVUc3u2RBu5hHR3QzNqpu7zw0d3xjl/TAetVkgFmPQ4PECyxiFv4u2wM/wmDwPEusuazm+SSl0iJVgo8= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1685464700; 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=TFmwsZj7mEJbuyFquMgG1tFmHr+v8B1z2+1WMORARnM=; b=cczYTc5t/mxy+CCkPRKNfnbMm7pRBsOv/+Ae0F0zt96tUbrvs3QS/+u5dQWvaaSdJSedfN484w3fDMuokOpDsw2wdizF5DyXUftj1F8KYfN35nAumnzCfuEVeIsf5XbVUKAOOR2gJPSpgAAHKZdL60gq6v6HTOXiT/5BO8zPHqs= 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 1685464700367347.27823888600165; Tue, 30 May 2023 09:38:20 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1q42IC-0007k8-76; Tue, 30 May 2023 12:33: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 1q42HH-0006Nx-1h for qemu-devel@nongnu.org; Tue, 30 May 2023 12:33:00 -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 1q42HF-0008EG-Al for qemu-devel@nongnu.org; Tue, 30 May 2023 12:32:54 -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-52-uU_9FGYmM8qmmJBrz1Jazg-1; Tue, 30 May 2023 12:32:51 -0400 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 D2246185A78F; Tue, 30 May 2023 16:32:50 +0000 (UTC) Received: from merkur.redhat.com (unknown [10.39.194.4]) by smtp.corp.redhat.com (Postfix) with ESMTP id 22482C154D2; Tue, 30 May 2023 16:32:50 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1685464372; 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=TFmwsZj7mEJbuyFquMgG1tFmHr+v8B1z2+1WMORARnM=; b=MsHmyt6PoIoK3i+z13x24S2c1xR2fTe74DyvudYnh5uPr2IlxYLIfv1zR8+bSdcW+nEoOv jcxQRPj43q4I2fRGbS8yTXjfDBiuXCtgdkGHl8J4Ck1Cz2U41CD1Ujc/2zwosFCay9n2IG auJALeGjToBHpRLYvbzRicqR9JIeN64= X-MC-Unique: uU_9FGYmM8qmmJBrz1Jazg-1 From: Kevin Wolf To: qemu-block@nongnu.org Cc: kwolf@redhat.com, richard.henderson@linaro.org, qemu-devel@nongnu.org Subject: [PULL 04/32] block-backend: Fix blk_new_open() for iothreads Date: Tue, 30 May 2023 18:32:11 +0200 Message-Id: <20230530163239.576632-5-kwolf@redhat.com> In-Reply-To: <20230530163239.576632-1-kwolf@redhat.com> References: <20230530163239.576632-1-kwolf@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.133.124; envelope-from=kwolf@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -22 X-Spam_score: -2.3 X-Spam_bar: -- X-Spam_report: (-2.3 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.167, 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: 1685464702396100001 Content-Type: text/plain; charset="utf-8" This fixes blk_new_open() to not assume that bs is in the main context. In particular, the BlockBackend must be created with the right AioContext because it will refuse to move to a different context afterwards. (blk->allow_aio_context_change is false.) Use this opportunity to use blk_insert_bs() instead of duplicating the bdrv_root_attach_child() call. This is consistent with what blk_new_with_bs() does. Add comments to document the locking rules. Signed-off-by: Kevin Wolf Message-Id: <20230525124713.401149-5-kwolf@redhat.com> Reviewed-by: Stefan Hajnoczi Signed-off-by: Kevin Wolf --- block/block-backend.c | 27 +++++++++++++++++++++------ 1 file changed, 21 insertions(+), 6 deletions(-) diff --git a/block/block-backend.c b/block/block-backend.c index 1d89fabd35..dde60e0f71 100644 --- a/block/block-backend.c +++ b/block/block-backend.c @@ -389,6 +389,8 @@ BlockBackend *blk_new(AioContext *ctx, uint64_t perm, u= int64_t shared_perm) * Both sets of permissions can be changed later using blk_set_perm(). * * Return the new BlockBackend on success, null on failure. + * + * Callers must hold the AioContext lock of @bs. */ BlockBackend *blk_new_with_bs(BlockDriverState *bs, uint64_t perm, uint64_t shared_perm, Error **errp) @@ -406,11 +408,15 @@ BlockBackend *blk_new_with_bs(BlockDriverState *bs, u= int64_t perm, =20 /* * Creates a new BlockBackend, opens a new BlockDriverState, and connects = both. - * The new BlockBackend is in the main AioContext. + * By default, the new BlockBackend is in the main AioContext, but if the + * parameters connect it with any existing node in a different AioContext,= it + * may end up there instead. * * Just as with bdrv_open(), after having called this function the referen= ce to * @options belongs to the block layer (even on failure). * + * Called without holding an AioContext lock. + * * TODO: Remove @filename and @flags; it should be possible to specify a w= hole * BDS tree just by specifying the @options QDict (or @reference, * alternatively). At the time of adding this function, this is not possib= le, @@ -422,6 +428,7 @@ BlockBackend *blk_new_open(const char *filename, const = char *reference, { BlockBackend *blk; BlockDriverState *bs; + AioContext *ctx; uint64_t perm =3D 0; uint64_t shared =3D BLK_PERM_ALL; =20 @@ -451,18 +458,24 @@ BlockBackend *blk_new_open(const char *filename, cons= t char *reference, shared =3D BLK_PERM_CONSISTENT_READ | BLK_PERM_WRITE_UNCHANGED; } =20 - blk =3D blk_new(qemu_get_aio_context(), perm, shared); aio_context_acquire(qemu_get_aio_context()); bs =3D bdrv_open(filename, reference, options, flags, errp); aio_context_release(qemu_get_aio_context()); if (!bs) { - blk_unref(blk); return NULL; } =20 - blk->root =3D bdrv_root_attach_child(bs, "root", &child_root, - BDRV_CHILD_FILTERED | BDRV_CHILD_PR= IMARY, - perm, shared, blk, errp); + /* bdrv_open() could have moved bs to a different AioContext */ + ctx =3D bdrv_get_aio_context(bs); + blk =3D blk_new(bdrv_get_aio_context(bs), perm, shared); + blk->perm =3D perm; + blk->shared_perm =3D shared; + + aio_context_acquire(ctx); + blk_insert_bs(blk, bs, errp); + bdrv_unref(bs); + aio_context_release(ctx); + if (!blk->root) { blk_unref(blk); return NULL; @@ -903,6 +916,8 @@ void blk_remove_bs(BlockBackend *blk) =20 /* * Associates a new BlockDriverState with @blk. + * + * Callers must hold the AioContext lock of @bs. */ int blk_insert_bs(BlockBackend *blk, BlockDriverState *bs, Error **errp) { --=20 2.40.1 From nobody Mon May 20 16:32:53 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=1685464706; cv=none; d=zohomail.com; s=zohoarc; b=E5UfhK6yVcbEzCvLgPZDbjzRCMSX63VDe40fC5fKRV0JZVoEEwz1mmcdJJPLphtWXsIhUdRJsjOd+c0s1zM1b2ZlprF9z+kX+TlA+l/RMFHUdcr5Itkv9MWi2mXDoOcZBQBzZiPuFOoA8YEHEEpRaPWVyB3xg8MKbbHFJ8nyC1M= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1685464706; 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=V7HJlzowXKR5pawe/urpsIfhEFRl6X8paocs7dzJIOI=; b=MEeFj5ewqiziiP2vm+9Y3NVNeSx0VKzHtqS9k+hvM/LW5SQhbv/2Iob21E1h4He7j2ydWnVgdPl4/po+5VaWGpfzxhGMuYWIgjD2NcHq26B3RsfAQRoc0NtGo+tMO8gcOKbeRP7nSkFhe3osTfiKIi77SensGMjf4I/qzd1OFQg= 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 1685464706128140.13078470894118; Tue, 30 May 2023 09:38:26 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1q42ID-00083n-QC; Tue, 30 May 2023 12:33:53 -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 1q42HI-0006TF-SQ for qemu-devel@nongnu.org; Tue, 30 May 2023 12:33:00 -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 1q42HG-0008Ee-EW for qemu-devel@nongnu.org; Tue, 30 May 2023 12:32:56 -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-345-RXMcfsmAPGaSq6nICiKuTg-1; Tue, 30 May 2023 12:32:52 -0400 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 C840985A5B5; Tue, 30 May 2023 16:32:51 +0000 (UTC) Received: from merkur.redhat.com (unknown [10.39.194.4]) by smtp.corp.redhat.com (Postfix) with ESMTP id 15FC3C154D2; Tue, 30 May 2023 16:32:50 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1685464373; 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=V7HJlzowXKR5pawe/urpsIfhEFRl6X8paocs7dzJIOI=; b=h6nDWM+IlxhKEc89NISXSWB7UWvqlHw8ysmlcA9Eg8tuFU3rfx0XlF60Fo8kNBIYzsYZF9 SCNk2g3QQ4G43n7DAfY2BM7Mw19IR8BDBMzfOSO1CAQ95P43OwXcojBjrw7K+TmZJXR20L R9cJ8lX9SkKus8CYG9ZQS22K+dvzQHs= X-MC-Unique: RXMcfsmAPGaSq6nICiKuTg-1 From: Kevin Wolf To: qemu-block@nongnu.org Cc: kwolf@redhat.com, richard.henderson@linaro.org, qemu-devel@nongnu.org Subject: [PULL 05/32] mirror: Hold main AioContext lock for calling bdrv_open_backing_file() Date: Tue, 30 May 2023 18:32:12 +0200 Message-Id: <20230530163239.576632-6-kwolf@redhat.com> In-Reply-To: <20230530163239.576632-1-kwolf@redhat.com> References: <20230530163239.576632-1-kwolf@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=kwolf@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -22 X-Spam_score: -2.3 X-Spam_bar: -- X-Spam_report: (-2.3 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.167, 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: 1685464706695100001 Content-Type: text/plain; charset="utf-8" bdrv_open_backing_file() calls bdrv_open_inherit(), so all callers must hold the main AioContext lock. Signed-off-by: Kevin Wolf Message-Id: <20230525124713.401149-6-kwolf@redhat.com> Reviewed-by: Stefan Hajnoczi Signed-off-by: Kevin Wolf --- block.c | 2 ++ block/mirror.c | 6 ++++++ 2 files changed, 8 insertions(+) diff --git a/block.c b/block.c index 79bc9c01de..be9ae364fb 100644 --- a/block.c +++ b/block.c @@ -3478,6 +3478,8 @@ int bdrv_set_backing_hd(BlockDriverState *bs, BlockDr= iverState *backing_hd, * itself, all options starting with "${bdref_key}." are considered part o= f the * BlockdevRef. * + * The caller must hold the main AioContext lock. + * * TODO Can this be unified with bdrv_open_image()? */ int bdrv_open_backing_file(BlockDriverState *bs, QDict *parent_options, diff --git a/block/mirror.c b/block/mirror.c index b7d92d1378..d3cacd1708 100644 --- a/block/mirror.c +++ b/block/mirror.c @@ -662,11 +662,15 @@ static int mirror_exit_common(Job *job) bool abort =3D job->ret < 0; int ret =3D 0; =20 + GLOBAL_STATE_CODE(); + if (s->prepared) { return 0; } s->prepared =3D true; =20 + aio_context_acquire(qemu_get_aio_context()); + mirror_top_bs =3D s->mirror_top_bs; bs_opaque =3D mirror_top_bs->opaque; src =3D mirror_top_bs->backing->bs; @@ -789,6 +793,8 @@ static int mirror_exit_common(Job *job) bdrv_unref(mirror_top_bs); bdrv_unref(src); =20 + aio_context_release(qemu_get_aio_context()); + return ret; } =20 --=20 2.40.1 From nobody Mon May 20 16:32:53 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=1685464732; cv=none; d=zohomail.com; s=zohoarc; b=lChknHmnb70zwkp4rQItLUeZZS5+x4R6sWSZQk6yN760O8RZIiVR9b8XdAsOaFQLF00+98IhTPkfloSo/1roMhWTYR/NiKHUDXSydPv91tCiA4eoy7tFQ+KwuLWWu90LrEB2Q6aJE6i3F9F2/X7TCaRlThqvTJSCUxT6smp2LQc= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1685464732; 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=unXlMObQwr/nXbipsntQnoRogAjP6neXdOKypzUgOjw=; b=BiFQgi/Z7H+a+AyZJReTTQXNo29/fBXrd/WLm1mIq4cedW/MUySp2FnS99TnhmvfkcRSwrrDuuo8sQvqsDLyYqkvAzPRd7PN17fjf18XhSAfAyEKSsDfUAJJBYao/4IYup5DjwzJUeCT50wjoVpPYxSzcBDoXAZ7f2q5KONBOv0= 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 1685464732728739.1594575082439; Tue, 30 May 2023 09:38:52 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1q42IC-0007jo-2W; Tue, 30 May 2023 12:33: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 1q42HO-0006Wr-GC for qemu-devel@nongnu.org; Tue, 30 May 2023 12:33:04 -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 1q42HK-0008GS-Fo for qemu-devel@nongnu.org; Tue, 30 May 2023 12:33:00 -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-423-t2DWfS0ANRWF2YyElO654g-1; Tue, 30 May 2023 12:32:53 -0400 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 B805A8032FA; Tue, 30 May 2023 16:32:52 +0000 (UTC) Received: from merkur.redhat.com (unknown [10.39.194.4]) by smtp.corp.redhat.com (Postfix) with ESMTP id 09FFFC15612; Tue, 30 May 2023 16:32:51 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1685464377; 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=unXlMObQwr/nXbipsntQnoRogAjP6neXdOKypzUgOjw=; b=hU1Mh+sJ4sDmj6TM9nnChxYftmDU1dh0RSoD8q7+anwVKvkVa4Ha5yfMTKHSxFTIdBe38+ kMlz4x/uUMMHJi16bQmu9e0i1ifRD3ESdFJc/gc8rS/KVnAfpU9pqPaSLkKecmVulV9Azn icFe+BRib65XM3EzkNMQd1UweQwSd/g= X-MC-Unique: t2DWfS0ANRWF2YyElO654g-1 From: Kevin Wolf To: qemu-block@nongnu.org Cc: kwolf@redhat.com, richard.henderson@linaro.org, qemu-devel@nongnu.org Subject: [PULL 06/32] qcow2: Fix open with 'file' in iothread Date: Tue, 30 May 2023 18:32:13 +0200 Message-Id: <20230530163239.576632-7-kwolf@redhat.com> In-Reply-To: <20230530163239.576632-1-kwolf@redhat.com> References: <20230530163239.576632-1-kwolf@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=kwolf@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -22 X-Spam_score: -2.3 X-Spam_bar: -- X-Spam_report: (-2.3 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.167, 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: 1685464734728100003 Content-Type: text/plain; charset="utf-8" qcow2_open() doesn't work correctly when opening the 'file' child moves bs to an iothread, for several reasons: - It uses BDRV_POLL_WHILE() to wait for the qcow2_open_entry() coroutine, which involves dropping the AioContext lock for bs when it is not in the main context - but we don't hold it, so this crashes. - It runs the qcow2_open_entry() coroutine in the current thread instead of the new AioContext of bs. - qcow2_open_entry() doesn't notify the main loop when it's done. This patches fixes these issues around delegating work to a coroutine. Temporarily dropping the main AioContext lock is not necessary because we know we run in the main thread. Signed-off-by: Kevin Wolf Message-Id: <20230525124713.401149-7-kwolf@redhat.com> Reviewed-by: Stefan Hajnoczi Signed-off-by: Kevin Wolf --- block.c | 6 ++++++ block/qcow2.c | 8 ++++++-- 2 files changed, 12 insertions(+), 2 deletions(-) diff --git a/block.c b/block.c index be9ae364fb..178ece2fa9 100644 --- a/block.c +++ b/block.c @@ -3646,6 +3646,9 @@ done: * BlockdevRef. * * The BlockdevRef will be removed from the options QDict. + * + * @parent can move to a different AioContext in this function. Callers mu= st + * make sure that their AioContext locking is still correct after this. */ BdrvChild *bdrv_open_child(const char *filename, QDict *options, const char *bdref_key, @@ -3670,6 +3673,9 @@ BdrvChild *bdrv_open_child(const char *filename, =20 /* * Wrapper on bdrv_open_child() for most popular case: open primary child = of bs. + * + * @parent can move to a different AioContext in this function. Callers mu= st + * make sure that their AioContext locking is still correct after this. */ int bdrv_open_file_child(const char *filename, QDict *options, const char *bdref_key, diff --git a/block/qcow2.c b/block/qcow2.c index b00b4e7575..7f3948360d 100644 --- a/block/qcow2.c +++ b/block/qcow2.c @@ -1904,6 +1904,8 @@ static void coroutine_fn qcow2_open_entry(void *opaqu= e) qoc->ret =3D qcow2_do_open(qoc->bs, qoc->options, qoc->flags, true, qoc->errp); qemu_co_mutex_unlock(&s->lock); + + aio_wait_kick(); } =20 static int qcow2_open(BlockDriverState *bs, QDict *options, int flags, @@ -1929,8 +1931,10 @@ static int qcow2_open(BlockDriverState *bs, QDict *o= ptions, int flags, =20 assert(!qemu_in_coroutine()); assert(qemu_get_current_aio_context() =3D=3D qemu_get_aio_context()); - qemu_coroutine_enter(qemu_coroutine_create(qcow2_open_entry, &qoc)); - BDRV_POLL_WHILE(bs, qoc.ret =3D=3D -EINPROGRESS); + + aio_co_enter(bdrv_get_aio_context(bs), + qemu_coroutine_create(qcow2_open_entry, &qoc)); + AIO_WAIT_WHILE_UNLOCKED(NULL, qoc.ret =3D=3D -EINPROGRESS); =20 return qoc.ret; } --=20 2.40.1 From nobody Mon May 20 16:32:53 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=1685464608; cv=none; d=zohomail.com; s=zohoarc; b=JNmxw+X/U0n8kBDHdGecl9nQfrRYqqxdGebj7uWE1gwbNZFQ3l57+y+ol+gZVZQcve1YiAtYG4s2THFT9MvN3EABDkClyfM9NsA2gDEUhtjpB3QVbmVhTYgZzJES10wPKjn1R9hdagXeMGchz9OM/YZ5dePRrpbDCZUzFXw/0Ow= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1685464608; 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=vpc8zDjMqIuzsQIO6J/QaTdJHUjH0z7XgaFZD9150hw=; b=gioMKFkLQ0sU9lqTLB2wsEqqzIbCOB0IkFz42+0AqwDP5ijJy7nISILodfR9hHC3eCKORfDmatwMfIFZEALwc3GtjKh1Bokdl+Rp2Dm1VLqmofNxQ7+/1aCp4kyz1pT/f1jDJz6m+fge8Wqm2qUNGzawruh544jkJU3EVGJdEPY= 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 168546460896017.559976538639603; Tue, 30 May 2023 09:36:48 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1q42IB-0007b7-43; Tue, 30 May 2023 12:33:51 -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 1q42HK-0006Ta-Oc for qemu-devel@nongnu.org; Tue, 30 May 2023 12:33:00 -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 1q42HI-0008FZ-Jj for qemu-devel@nongnu.org; Tue, 30 May 2023 12:32:57 -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-68-S_GokUWIM5ujo_csPOupBg-1; Tue, 30 May 2023 12:32:54 -0400 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 B2832800B2A; Tue, 30 May 2023 16:32:53 +0000 (UTC) Received: from merkur.redhat.com (unknown [10.39.194.4]) by smtp.corp.redhat.com (Postfix) with ESMTP id 019BDC154D2; Tue, 30 May 2023 16:32:52 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1685464375; 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=vpc8zDjMqIuzsQIO6J/QaTdJHUjH0z7XgaFZD9150hw=; b=dUjSDQial+5OcxEccPKKg1pp4gb2F9fRtAj7k2RdE9bFJ1he86IY0tInvt5g912Kv+sJ27 4LUfk0K3bB+X1klJ0ca0KGsZ/OJC3jl6OgLdOjTM70LWlb1SPYFIhdo1ICK1a+kQero17c 61lubUBMhWOElbptnZUO6Nju7hGy3OA= X-MC-Unique: S_GokUWIM5ujo_csPOupBg-1 From: Kevin Wolf To: qemu-block@nongnu.org Cc: kwolf@redhat.com, richard.henderson@linaro.org, qemu-devel@nongnu.org Subject: [PULL 07/32] raw-format: Fix open with 'file' in iothread Date: Tue, 30 May 2023 18:32:14 +0200 Message-Id: <20230530163239.576632-8-kwolf@redhat.com> In-Reply-To: <20230530163239.576632-1-kwolf@redhat.com> References: <20230530163239.576632-1-kwolf@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.133.124; envelope-from=kwolf@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -22 X-Spam_score: -2.3 X-Spam_bar: -- X-Spam_report: (-2.3 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.167, 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: 1685464609966100004 Content-Type: text/plain; charset="utf-8" When opening the 'file' child moves bs to an iothread, we need to hold the AioContext lock of it before we can call raw_apply_options() (and more specifically, bdrv_getlength() inside of it). Signed-off-by: Kevin Wolf Message-Id: <20230525124713.401149-8-kwolf@redhat.com> Reviewed-by: Stefan Hajnoczi Signed-off-by: Kevin Wolf --- block/raw-format.c | 5 +++++ tests/unit/test-block-iothread.c | 3 --- 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/block/raw-format.c b/block/raw-format.c index 918fe4fb7e..e4f35268e6 100644 --- a/block/raw-format.c +++ b/block/raw-format.c @@ -468,6 +468,7 @@ static int raw_open(BlockDriverState *bs, QDict *option= s, int flags, Error **errp) { BDRVRawState *s =3D bs->opaque; + AioContext *ctx; bool has_size; uint64_t offset, size; BdrvChildRole file_role; @@ -515,7 +516,11 @@ static int raw_open(BlockDriverState *bs, QDict *optio= ns, int flags, bs->file->bs->filename); } =20 + ctx =3D bdrv_get_aio_context(bs); + aio_context_acquire(ctx); ret =3D raw_apply_options(bs, s, offset, has_size, size, errp); + aio_context_release(ctx); + if (ret < 0) { return ret; } diff --git a/tests/unit/test-block-iothread.c b/tests/unit/test-block-iothr= ead.c index 1b40e65bad..f081c09729 100644 --- a/tests/unit/test-block-iothread.c +++ b/tests/unit/test-block-iothread.c @@ -833,12 +833,9 @@ static void test_attach_second_node(void) qdict_put_str(options, "driver", "raw"); qdict_put_str(options, "file", "base"); =20 - /* FIXME raw_open() should take ctx's lock internally */ - aio_context_acquire(ctx); aio_context_acquire(main_ctx); filter =3D bdrv_open(NULL, NULL, options, BDRV_O_RDWR, &error_abort); aio_context_release(main_ctx); - aio_context_release(ctx); =20 g_assert(blk_get_aio_context(blk) =3D=3D ctx); g_assert(bdrv_get_aio_context(bs) =3D=3D ctx); --=20 2.40.1 From nobody Mon May 20 16:32:53 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=1685464621; cv=none; d=zohomail.com; s=zohoarc; b=OzAFUn0sprEY+NRs9TNvjlUpO9YvpIJWFApfs+Eb5SHd31BZR9piL6E8OdDnLA5XBoQ8xbNuzuhdzCI2S1Gw4cpluzXfgyT/Kbq8luU26pzOcRHUNta8ufj7Oz3Deg0J2r+TbnjV7htQsx39XXoiHsZOdNINiPpCkRTsHfEHvmk= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1685464621; 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=9nfp1QYTgcYnCvbyCQgd9+AsYb38Acvt02na2ryMYY0=; b=KlHY5sTr+pQCS05JcME3kUyrJLx0TDmRQoU3Ft5vRfOyooE8c8WNNGt2ZFfNVLIIGIc/xAtgG4j72Ut6O8bIlNc/LylWII/WP52jd8TblAkG72f9MztW7GgvUTOvv+iNRojxaY4rOrKDvtEMRT9+ID3YeME5VAFozmy1/Z6Es6k= 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 1685464621826919.8207164052849; Tue, 30 May 2023 09:37:01 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1q42IB-0007cJ-6v; Tue, 30 May 2023 12:33:51 -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 1q42HO-0006Wq-FQ for qemu-devel@nongnu.org; Tue, 30 May 2023 12:33:04 -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 1q42HL-0008Gz-TF for qemu-devel@nongnu.org; Tue, 30 May 2023 12:33:01 -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-13-sk32MJsRPDWPgYEfMq75Ng-1; Tue, 30 May 2023 12:32:55 -0400 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 ABC972A5957F; Tue, 30 May 2023 16:32:54 +0000 (UTC) Received: from merkur.redhat.com (unknown [10.39.194.4]) by smtp.corp.redhat.com (Postfix) with ESMTP id E8FB8C0448F; Tue, 30 May 2023 16:32:53 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1685464378; 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=9nfp1QYTgcYnCvbyCQgd9+AsYb38Acvt02na2ryMYY0=; b=f4knlCEElu99lkngIL1eMXUnokgwKYLH2/5FFKWGBglstN/hCQAIpuzTaGgUlH+u4ld3mo UUPxNPX5Oy5/HcdD2692H2LIB4i55h/2UHTZBSOgdsg1dcvygJFxF0tznMNGYjab9xrPGj iPyKCWEfWA/Vhn0cLhdt2e/mOigD0xs= X-MC-Unique: sk32MJsRPDWPgYEfMq75Ng-1 From: Kevin Wolf To: qemu-block@nongnu.org Cc: kwolf@redhat.com, richard.henderson@linaro.org, qemu-devel@nongnu.org Subject: [PULL 08/32] copy-before-write: Fix open with child in iothread Date: Tue, 30 May 2023 18:32:15 +0200 Message-Id: <20230530163239.576632-9-kwolf@redhat.com> In-Reply-To: <20230530163239.576632-1-kwolf@redhat.com> References: <20230530163239.576632-1-kwolf@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=kwolf@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -22 X-Spam_score: -2.3 X-Spam_bar: -- X-Spam_report: (-2.3 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.167, 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: 1685464624064100003 Content-Type: text/plain; charset="utf-8" The AioContext lock must not be held for bdrv_open_child(), but it is necessary for the following operations, in particular those using nested event loops in coroutine wrappers. Temporarily dropping the main AioContext lock is not necessary because we know we run in the main thread. Signed-off-by: Kevin Wolf Message-Id: <20230525124713.401149-9-kwolf@redhat.com> Reviewed-by: Stefan Hajnoczi Signed-off-by: Kevin Wolf --- block/copy-before-write.c | 21 ++++++++++++++++----- 1 file changed, 16 insertions(+), 5 deletions(-) diff --git a/block/copy-before-write.c b/block/copy-before-write.c index 646d8227a4..b866e42271 100644 --- a/block/copy-before-write.c +++ b/block/copy-before-write.c @@ -412,6 +412,7 @@ static int cbw_open(BlockDriverState *bs, QDict *option= s, int flags, int64_t cluster_size; g_autoptr(BlockdevOptions) full_opts =3D NULL; BlockdevOptionsCbw *opts; + AioContext *ctx; int ret; =20 full_opts =3D cbw_parse_options(options, errp); @@ -432,11 +433,15 @@ static int cbw_open(BlockDriverState *bs, QDict *opti= ons, int flags, return -EINVAL; } =20 + ctx =3D bdrv_get_aio_context(bs); + aio_context_acquire(ctx); + if (opts->bitmap) { bitmap =3D block_dirty_bitmap_lookup(opts->bitmap->node, opts->bitmap->name, NULL, errp); if (!bitmap) { - return -EINVAL; + ret =3D -EINVAL; + goto out; } } s->on_cbw_error =3D opts->has_on_cbw_error ? opts->on_cbw_error : @@ -454,21 +459,24 @@ static int cbw_open(BlockDriverState *bs, QDict *opti= ons, int flags, s->bcs =3D block_copy_state_new(bs->file, s->target, bitmap, errp); if (!s->bcs) { error_prepend(errp, "Cannot create block-copy-state: "); - return -EINVAL; + ret =3D -EINVAL; + goto out; } =20 cluster_size =3D block_copy_cluster_size(s->bcs); =20 s->done_bitmap =3D bdrv_create_dirty_bitmap(bs, cluster_size, NULL, er= rp); if (!s->done_bitmap) { - return -EINVAL; + ret =3D -EINVAL; + goto out; } bdrv_disable_dirty_bitmap(s->done_bitmap); =20 /* s->access_bitmap starts equal to bcs bitmap */ s->access_bitmap =3D bdrv_create_dirty_bitmap(bs, cluster_size, NULL, = errp); if (!s->access_bitmap) { - return -EINVAL; + ret =3D -EINVAL; + goto out; } bdrv_disable_dirty_bitmap(s->access_bitmap); bdrv_dirty_bitmap_merge_internal(s->access_bitmap, @@ -478,7 +486,10 @@ static int cbw_open(BlockDriverState *bs, QDict *optio= ns, int flags, qemu_co_mutex_init(&s->lock); QLIST_INIT(&s->frozen_read_reqs); =20 - return 0; + ret =3D 0; +out: + aio_context_release(ctx); + return ret; } =20 static void cbw_close(BlockDriverState *bs) --=20 2.40.1 From nobody Mon May 20 16:32:53 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=1685464530; cv=none; d=zohomail.com; s=zohoarc; b=WwT5ByAI5lYjKSD98i5hClXRA7MrOh/9O44GTuGRAWxr7NpY/FzzIitGpSBX8XVJyj9DRAQSltkL91Uk5eznHxoUB7NNenoB1DKZorVl/s+RUH0RMRv+BnMh3unv0cyaNf4RFJuf2HQBry9+WbcPBZixSfaa2g88Y/0d7YBeCvA= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1685464530; 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=NjAp9tDt5hYUz1UytI76tOAKCLB67qlpuCUIJIVxJD4=; b=HgW2OfphA8dSdXVruvN+Y+vh/imiCgOSku1BTfBADAs23mo32Fjjocds1U4bT9uSBxEMWGQ2mhBdX2aQyhrInD7MBVuRkejsw+bCHx7HSl7QuyXRh1Blnb1LIcqVgto+Y12jz7lerZl7hK62LsQ7FpMusih0F/1HaJ1BON/6TMg= 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 1685464530190854.186972870352; Tue, 30 May 2023 09:35:30 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1q42IG-0008N9-9Z; Tue, 30 May 2023 12:33:56 -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 1q42HO-0006Wn-Er for qemu-devel@nongnu.org; Tue, 30 May 2023 12:33:04 -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 1q42HK-0008GZ-Ks for qemu-devel@nongnu.org; Tue, 30 May 2023 12:33:00 -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-25-5rjM1dksMYm_9aHrh9Hw-Q-1; Tue, 30 May 2023 12:32:56 -0400 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 AFEFD811E8F; Tue, 30 May 2023 16:32:55 +0000 (UTC) Received: from merkur.redhat.com (unknown [10.39.194.4]) by smtp.corp.redhat.com (Postfix) with ESMTP id E826DC15612; Tue, 30 May 2023 16:32:54 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1685464378; 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=NjAp9tDt5hYUz1UytI76tOAKCLB67qlpuCUIJIVxJD4=; b=O3jOrZbyJ9z0TBdtdEq72m4mYefc+RQwhAJ/qY5R8tukbptUGNtcSq73Zn36jZiN0uWtjs 4hUDjuoNraHWaKiVKROmGiyLZhP+vBU93HWdjInu3rOU0NRZg59THmGwbJQojg97F3r0Fy 1ghbO7pfqJV/cwpByaVeTDaxqgrB1Bc= X-MC-Unique: 5rjM1dksMYm_9aHrh9Hw-Q-1 From: Kevin Wolf To: qemu-block@nongnu.org Cc: kwolf@redhat.com, richard.henderson@linaro.org, qemu-devel@nongnu.org Subject: [PULL 09/32] block: Take AioContext lock in bdrv_open_driver() Date: Tue, 30 May 2023 18:32:16 +0200 Message-Id: <20230530163239.576632-10-kwolf@redhat.com> In-Reply-To: <20230530163239.576632-1-kwolf@redhat.com> References: <20230530163239.576632-1-kwolf@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=kwolf@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -22 X-Spam_score: -2.3 X-Spam_bar: -- X-Spam_report: (-2.3 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.167, 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: 1685464531608100003 Content-Type: text/plain; charset="utf-8" bdrv_refresh_total_sectors() and bdrv_refresh_limits() expect to be called under the AioContext lock of the node. Take the lock. Signed-off-by: Kevin Wolf Message-Id: <20230525124713.401149-10-kwolf@redhat.com> Reviewed-by: Stefan Hajnoczi Signed-off-by: Kevin Wolf --- block.c | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/block.c b/block.c index 178ece2fa9..29dea3a6a1 100644 --- a/block.c +++ b/block.c @@ -1613,6 +1613,7 @@ static int no_coroutine_fn GRAPH_UNLOCKED bdrv_open_driver(BlockDriverState *bs, BlockDriver *drv, const char *node_= name, QDict *options, int open_flags, Error **errp) { + AioContext *ctx; Error *local_err =3D NULL; int i, ret; GLOBAL_STATE_CODE(); @@ -1660,15 +1661,21 @@ bdrv_open_driver(BlockDriverState *bs, BlockDriver = *drv, const char *node_name, bs->supported_read_flags |=3D BDRV_REQ_REGISTERED_BUF; bs->supported_write_flags |=3D BDRV_REQ_REGISTERED_BUF; =20 + /* Get the context after .bdrv_open, it can change the context */ + ctx =3D bdrv_get_aio_context(bs); + aio_context_acquire(ctx); + ret =3D bdrv_refresh_total_sectors(bs, bs->total_sectors); if (ret < 0) { error_setg_errno(errp, -ret, "Could not refresh total sector count= "); + aio_context_release(ctx); return ret; } =20 bdrv_graph_rdlock_main_loop(); bdrv_refresh_limits(bs, NULL, &local_err); bdrv_graph_rdunlock_main_loop(); + aio_context_release(ctx); =20 if (local_err) { error_propagate(errp, local_err); --=20 2.40.1 From nobody Mon May 20 16:32:53 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=1685464776; cv=none; d=zohomail.com; s=zohoarc; b=hQ1JqDlfQ4Vl5au+tqDT8RCogz3yRAhf5SGCvd9IjtXll2q0DgPngvoMPMj+NAv0nScaHbvPFx7blKMNgtgJaWSmf3t9HW3l2RBQen0TDE32slCv9aoga5x1ZXFxs0/Owj8cKWFte9PNok8lHw7l+zjWcbzdLJAXSD5OO7dAgaA= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1685464776; 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=vNX5d1MVjTiz6h8ElDqn9RxFOn0J+KmMVLk3KNi4vbk=; b=V9uUj5DIMvetdycjbYRjCgy+6NKX6okXz+oGiZxpRHtxFBP5L/qCS8J8TsSJB6O3eZJgJPQzz9xjSobIS2rUs6l1KJELlD1V8IdS18U0RwIz4j7+bLysJzLx7/cvnhoXifurLfGfZKbI8q5FSCC4EGB0X899tS+biwBQUYkARQ4= 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 1685464776440423.7749348938079; Tue, 30 May 2023 09:39:36 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1q42II-0000EV-Pb; Tue, 30 May 2023 12:33:58 -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 1q42HY-0006nP-V1 for qemu-devel@nongnu.org; Tue, 30 May 2023 12:33:14 -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 1q42HU-0008M1-JG for qemu-devel@nongnu.org; Tue, 30 May 2023 12:33:12 -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-479-GvmR2AiBPf-518At2W9WkA-1; Tue, 30 May 2023 12:32:57 -0400 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 A6600800969; Tue, 30 May 2023 16:32:56 +0000 (UTC) Received: from merkur.redhat.com (unknown [10.39.194.4]) by smtp.corp.redhat.com (Postfix) with ESMTP id E9738C154D3; Tue, 30 May 2023 16:32:55 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1685464387; 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=vNX5d1MVjTiz6h8ElDqn9RxFOn0J+KmMVLk3KNi4vbk=; b=CWzbnKbP1IzwBqM+9dyMOwP0MAGCOp7czXJj2KFR1UBgHTyGCMBU6hv1slMReY8+yUbtFB ZueDx2jv9OiR06f2sGrcF3y7r9zcODZxckaYLzQSxNszdoYkkcyZOEEyPewLucrvjKqvDi hEY7moOPaTzif1Zlw1oO/ozjJgf48Fw= X-MC-Unique: GvmR2AiBPf-518At2W9WkA-1 From: Kevin Wolf To: qemu-block@nongnu.org Cc: kwolf@redhat.com, richard.henderson@linaro.org, qemu-devel@nongnu.org Subject: [PULL 10/32] block: Fix AioContext locking in bdrv_insert_node() Date: Tue, 30 May 2023 18:32:17 +0200 Message-Id: <20230530163239.576632-11-kwolf@redhat.com> In-Reply-To: <20230530163239.576632-1-kwolf@redhat.com> References: <20230530163239.576632-1-kwolf@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=kwolf@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -22 X-Spam_score: -2.3 X-Spam_bar: -- X-Spam_report: (-2.3 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.167, 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: 1685464777013100001 Content-Type: text/plain; charset="utf-8" While calling bdrv_new_open_driver_opts(), the main AioContext lock must be held, not the lock of the AioContext of the block subtree it will be added to afterwards. Signed-off-by: Kevin Wolf Message-Id: <20230525124713.401149-11-kwolf@redhat.com> Reviewed-by: Stefan Hajnoczi Signed-off-by: Kevin Wolf --- block.c | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/block.c b/block.c index 29dea3a6a1..ec65fcf732 100644 --- a/block.c +++ b/block.c @@ -5399,12 +5399,17 @@ static void bdrv_delete(BlockDriverState *bs) * empty set of options. The reference to the QDict belongs to the block l= ayer * after the call (even on failure), so if the caller intends to reuse the * dictionary, it needs to use qobject_ref() before calling bdrv_open. + * + * The caller holds the AioContext lock for @bs. It must make sure that @bs + * stays in the same AioContext, i.e. @options must not refer to nodes in a + * different AioContext. */ BlockDriverState *bdrv_insert_node(BlockDriverState *bs, QDict *options, int flags, Error **errp) { ERRP_GUARD(); int ret; + AioContext *ctx =3D bdrv_get_aio_context(bs); BlockDriverState *new_node_bs =3D NULL; const char *drvname, *node_name; BlockDriver *drv; @@ -5425,8 +5430,14 @@ BlockDriverState *bdrv_insert_node(BlockDriverState = *bs, QDict *options, =20 GLOBAL_STATE_CODE(); =20 + aio_context_release(ctx); + aio_context_acquire(qemu_get_aio_context()); new_node_bs =3D bdrv_new_open_driver_opts(drv, node_name, options, fla= gs, errp); + aio_context_release(qemu_get_aio_context()); + aio_context_acquire(ctx); + assert(bdrv_get_aio_context(bs) =3D=3D ctx); + options =3D NULL; /* bdrv_new_open_driver() eats options */ if (!new_node_bs) { error_prepend(errp, "Could not create node: "); --=20 2.40.1 From nobody Mon May 20 16:32:53 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=1685464473; cv=none; d=zohomail.com; s=zohoarc; b=Nh2HOCOVNWQSEotcfoJQKstn6N6aA8tn+eALoh7mIArpssI6V0KCEGLFeNKqJdPlmyOBT9Qvhmwab/PnuIzEayYIMoheo148J68IgJBDqqLXAzeBBJBC5zX+HG+0lmsAt9UahWSI6Hatl6MbhHCrN4gquoov4vbpMpa6WprhSO4= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1685464473; 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=eEbrIWHNsw3oAC1xjBUi+vQde6gFmeUaa662q/As5gU=; b=N8+M3AJljfIXVm8GiNI8Jxpjyndx84nS46o/xbhvFKQg5C7h6hb2aBkOoDMKgF6oVXBxmYTLnZcnvSdZelD8mmGAKMwh/t1kPC3AWSqCWnmQb8fpboA+Frns4kzDRZuvt33dSnUelguYI4fv/+enKpmZU/RvruauHPBY3gZh1zE= 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 1685464473739207.49476308602652; Tue, 30 May 2023 09:34:33 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1q42IE-0008AA-Gr; Tue, 30 May 2023 12:33: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 1q42HW-0006bL-5q for qemu-devel@nongnu.org; Tue, 30 May 2023 12:33:10 -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 1q42HO-0008HW-7M for qemu-devel@nongnu.org; Tue, 30 May 2023 12:33:09 -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-213-ObF70y9mMS-qAlCzxyZ5Hw-1; Tue, 30 May 2023 12:32:57 -0400 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 94FD3101AA44; Tue, 30 May 2023 16:32:57 +0000 (UTC) Received: from merkur.redhat.com (unknown [10.39.194.4]) by smtp.corp.redhat.com (Postfix) with ESMTP id DD985C154D2; Tue, 30 May 2023 16:32:56 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1685464381; 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=eEbrIWHNsw3oAC1xjBUi+vQde6gFmeUaa662q/As5gU=; b=IGnUvQwArTnE9ZquqavZshg4Pt6O0rwQxAIeP0zxvHB9rVPwJA3EQ0mvqk8RnAC6n3RFxL U6ldgczlBsdwMvPBhLVIE62DcNMEQK1KiUV1xJYIBYMS3u5Bm3OBN+xMQD19dRdZrF0brT C/dN1FmryfujzPm0Q7HsXGk5UGAiXaU= X-MC-Unique: ObF70y9mMS-qAlCzxyZ5Hw-1 From: Kevin Wolf To: qemu-block@nongnu.org Cc: kwolf@redhat.com, richard.henderson@linaro.org, qemu-devel@nongnu.org Subject: [PULL 11/32] iotests: Make verify_virtio_scsi_pci_or_ccw() public Date: Tue, 30 May 2023 18:32:18 +0200 Message-Id: <20230530163239.576632-12-kwolf@redhat.com> In-Reply-To: <20230530163239.576632-1-kwolf@redhat.com> References: <20230530163239.576632-1-kwolf@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=kwolf@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -22 X-Spam_score: -2.3 X-Spam_bar: -- X-Spam_report: (-2.3 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.167, 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: 1685464475135100005 Content-Type: text/plain; charset="utf-8" It has no internal callers, so its only use is being called from individual test cases. If the name starts with an underscore, it is considered private and linters warn against calling it. 256 only gets away with it currently because it's on the exception list for linters. Signed-off-by: Kevin Wolf Message-Id: <20230525124713.401149-12-kwolf@redhat.com> Reviewed-by: Stefan Hajnoczi Signed-off-by: Kevin Wolf --- tests/qemu-iotests/iotests.py | 2 +- tests/qemu-iotests/256 | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/tests/qemu-iotests/iotests.py b/tests/qemu-iotests/iotests.py index 7073579a7d..ef66fbd62b 100644 --- a/tests/qemu-iotests/iotests.py +++ b/tests/qemu-iotests/iotests.py @@ -1421,7 +1421,7 @@ def _verify_virtio_blk() -> None: if 'virtio-blk' not in out: notrun('Missing virtio-blk in QEMU binary') =20 -def _verify_virtio_scsi_pci_or_ccw() -> None: +def verify_virtio_scsi_pci_or_ccw() -> None: out =3D qemu_pipe('-M', 'none', '-device', 'help') if 'virtio-scsi-pci' not in out and 'virtio-scsi-ccw' not in out: notrun('Missing virtio-scsi-pci or virtio-scsi-ccw in QEMU binary') diff --git a/tests/qemu-iotests/256 b/tests/qemu-iotests/256 index 13666813bd..d7e67f4a05 100755 --- a/tests/qemu-iotests/256 +++ b/tests/qemu-iotests/256 @@ -24,7 +24,7 @@ import os import iotests from iotests import log =20 -iotests._verify_virtio_scsi_pci_or_ccw() +iotests.verify_virtio_scsi_pci_or_ccw() =20 iotests.script_initialize(supported_fmts=3D['qcow2']) size =3D 64 * 1024 * 1024 --=20 2.40.1 From nobody Mon May 20 16:32:53 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=1685464838; cv=none; d=zohomail.com; s=zohoarc; b=El/Tp4po5J98EaN5Y1J9M4WU924EdyTZxEoPkhm+V3rBy67GMrL/IyYhueCd/CgA++8EluSc6nGXu6k4qaLFLm2a/MeE4S+/yTbbSEAT6bHv7+oB4xulhAADZaBrTV0+3E+q8Ka037YC4jcB7qKrF0030M8wy10drxUe0/nQu1U= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1685464838; 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=Utb8Qts7FnCWvljH/Yw5u3NOCaP8JIwHs0mkMHUX4m8=; b=cDgI9Rc995bJFC13032o3+n3zARhCyoJqFHjLV7fi79JLbQ+vMZzQmuSk7H8Y/WGkCcif42mo+/lG9pousH2pEuB3Tl8xvoRq0xzHqgtbUmTDBy8rhNaJKbLecjPfEGvUW1XYU4hyUpmvh+q2SDD972dGY8q45NpSSMWM33bmcw= 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 1685464838409953.7830207208216; Tue, 30 May 2023 09:40:38 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1q42Im-0001aC-91; Tue, 30 May 2023 12:34:28 -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 1q42Hf-0006uN-0P for qemu-devel@nongnu.org; Tue, 30 May 2023 12:33:20 -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 1q42HO-0008HL-37 for qemu-devel@nongnu.org; Tue, 30 May 2023 12:33:18 -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-137-OC7sYsA2NZmPddvFTi_jYg-1; Tue, 30 May 2023 12:32:58 -0400 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 84B37101A52C; Tue, 30 May 2023 16:32:58 +0000 (UTC) Received: from merkur.redhat.com (unknown [10.39.194.4]) by smtp.corp.redhat.com (Postfix) with ESMTP id CAC5FC154D2; Tue, 30 May 2023 16:32:57 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1685464380; 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=Utb8Qts7FnCWvljH/Yw5u3NOCaP8JIwHs0mkMHUX4m8=; b=GzND/ua1yRjqDA15Vy2vEA7GZl51JvqVSth7NlDfYHqQqqThnZcELB8XRtbv+NZU1v+rHR 6iMyZ+60JqsngBxUuiiUrpGWRqYEbMuh3uT1neahUFPDCBHw4hWM/eCWw4lYCj/5jJn0uy sdpCz0YJuMUjv6q6pujJ5kj3D22XlwA= X-MC-Unique: OC7sYsA2NZmPddvFTi_jYg-1 From: Kevin Wolf To: qemu-block@nongnu.org Cc: kwolf@redhat.com, richard.henderson@linaro.org, qemu-devel@nongnu.org Subject: [PULL 12/32] iotests: Test blockdev-create in iothread Date: Tue, 30 May 2023 18:32:19 +0200 Message-Id: <20230530163239.576632-13-kwolf@redhat.com> In-Reply-To: <20230530163239.576632-1-kwolf@redhat.com> References: <20230530163239.576632-1-kwolf@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=kwolf@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -22 X-Spam_score: -2.3 X-Spam_bar: -- X-Spam_report: (-2.3 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.167, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, 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: 1685464839299100005 Content-Type: text/plain; charset="utf-8" If blockdev-create references an existing node in an iothread (e.g. as it's 'file' child), then suddenly all of the image creation code must run in that AioContext, too. Test that this actually works. Signed-off-by: Kevin Wolf Message-Id: <20230525124713.401149-13-kwolf@redhat.com> Reviewed-by: Stefan Hajnoczi Signed-off-by: Kevin Wolf --- tests/qemu-iotests/tests/iothreads-create | 67 +++++++++++++++++++ tests/qemu-iotests/tests/iothreads-create.out | 4 ++ 2 files changed, 71 insertions(+) create mode 100755 tests/qemu-iotests/tests/iothreads-create create mode 100644 tests/qemu-iotests/tests/iothreads-create.out diff --git a/tests/qemu-iotests/tests/iothreads-create b/tests/qemu-iotests= /tests/iothreads-create new file mode 100755 index 0000000000..0c862d73f2 --- /dev/null +++ b/tests/qemu-iotests/tests/iothreads-create @@ -0,0 +1,67 @@ +#!/usr/bin/env python3 +# group: rw quick +# +# Copyright (C) 2023 Red Hat, Inc. +# +# This program is free software; you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation; either version 2 of the License, or +# (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program. If not, see . +# +# Creator/Owner: Kevin Wolf + +import asyncio +import iotests + +iotests.script_initialize(supported_fmts=3D['qcow2', 'qcow', 'qed', 'vdi', + 'vmdk', 'parallels']) +iotests.verify_virtio_scsi_pci_or_ccw() + +with iotests.FilePath('disk.img') as img_path, \ + iotests.VM() as vm: + + iotests.qemu_img_create('-f', 'raw', img_path, '0') + + vm.add_object('iothread,id=3Diothread0') + vm.add_blockdev(f'file,node-name=3Dimg-file,read-only=3Don,' + f'filename=3D{img_path}') + vm.add_device('virtio-scsi,iothread=3Diothread0') + vm.add_device('scsi-hd,drive=3Dimg-file,share-rw=3Don') + + vm.launch() + + iotests.log(vm.qmp( + 'blockdev-reopen', + options=3D[{ + 'driver': 'file', + 'filename': img_path, + 'node-name': 'img-file', + 'read-only': False, + }], + )) + iotests.log(vm.qmp( + 'blockdev-create', + job_id=3D'job0', + options=3D{ + 'driver': iotests.imgfmt, + 'file': 'img-file', + 'size': 1024 * 1024, + }, + )) + + # Should succeed and not time out + try: + vm.run_job('job0', wait=3D5.0) + vm.shutdown() + except asyncio.TimeoutError: + # VM may be stuck, kill it + vm.kill() + raise diff --git a/tests/qemu-iotests/tests/iothreads-create.out b/tests/qemu-iot= ests/tests/iothreads-create.out new file mode 100644 index 0000000000..5c974ff77e --- /dev/null +++ b/tests/qemu-iotests/tests/iothreads-create.out @@ -0,0 +1,4 @@ +{"return": {}} +{"return": {}} +{"execute": "job-dismiss", "arguments": {"id": "job0"}} +{"return": {}} --=20 2.40.1 From nobody Mon May 20 16:32:53 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=1685464838; cv=none; d=zohomail.com; s=zohoarc; b=CUMhLKdiK7fixgFIrwklnC0eD2c1c+iUreeHylxwJqNXb/Ew7TaCXN8X6uImpk+CaSMzdpYAXJHKHAIMnqtqkEHPcfastQy3kdWsoiudV+dB4m1LyVuHhmFl+un7gzplkp5g/2wKfLk9BYqUqg7Wd2/Yp2N22afe4xhxnyrCEbk= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1685464838; 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=lpCFbHWdjzq3JNcz+bykK+POyiyhMHaTFyA2nD/Q4P0=; b=J5HcSyY4imWbhqZKVqm+WSBTUdgCnrG1jZb3YNPedxsC9WHvYl8kOUTRf19hOFz0JnMJvs5DchlCHV6qe1KEZqxVfmGwKPUyprdPyCKxExJDpQXnNM/GVi9T2UXJ3Ho7yexYJooaK89xWwpyE0LqFhs6FgqqUOEOgjdZGMf5JwE= 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 1685464838445437.21001794504184; Tue, 30 May 2023 09:40:38 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1q42IH-0008TN-4S; Tue, 30 May 2023 12:33: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 1q42HW-0006bM-65 for qemu-devel@nongnu.org; Tue, 30 May 2023 12:33:10 -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 1q42HQ-0008IV-4L for qemu-devel@nongnu.org; Tue, 30 May 2023 12:33:08 -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-48-xA8i8r69P_GSkRxC47NH3w-1; Tue, 30 May 2023 12:32:59 -0400 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 7A31685A5AA; Tue, 30 May 2023 16:32:59 +0000 (UTC) Received: from merkur.redhat.com (unknown [10.39.194.4]) by smtp.corp.redhat.com (Postfix) with ESMTP id BDC40C0448F; Tue, 30 May 2023 16:32:58 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1685464382; 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=lpCFbHWdjzq3JNcz+bykK+POyiyhMHaTFyA2nD/Q4P0=; b=b6+6NfjQ6zsybOAen6P+FZ0j3LVpGTr71z0fwSByzq7I5+daApYOdSBs3HSZx1dXHcicJ9 HJ+j59gfgQjoGexx5O9qIevH2pBGqV3e6Z1hHgp+NCxZKkUXdp2GdvT0IBNwSwa1O4nvlj wpEaZW4N+HY2pa9SkG3I3B/CbJLePFY= X-MC-Unique: xA8i8r69P_GSkRxC47NH3w-1 From: Kevin Wolf To: qemu-block@nongnu.org Cc: kwolf@redhat.com, richard.henderson@linaro.org, qemu-devel@nongnu.org Subject: [PULL 13/32] block-backend: split blk_do_set_aio_context() Date: Tue, 30 May 2023 18:32:20 +0200 Message-Id: <20230530163239.576632-14-kwolf@redhat.com> In-Reply-To: <20230530163239.576632-1-kwolf@redhat.com> References: <20230530163239.576632-1-kwolf@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.133.124; envelope-from=kwolf@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -22 X-Spam_score: -2.3 X-Spam_bar: -- X-Spam_report: (-2.3 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.167, 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: 1685464839385100009 Content-Type: text/plain; charset="utf-8" From: Stefan Hajnoczi blk_set_aio_context() is not fully transactional because blk_do_set_aio_context() updates blk->ctx outside the transaction. Most of the time this goes unnoticed but a BlockDevOps.drained_end() callback that invokes blk_get_aio_context() fails assert(ctx =3D=3D blk->ctx). This happens because blk->ctx is only assigned after BlockDevOps.drained_end() is called and we're in an intermediate state where BlockDrvierState nodes already have the new context and the BlockBackend still has the old context. Making blk_set_aio_context() fully transactional solves this assertion failure because the BlockBackend's context is updated as part of the transaction (before BlockDevOps.drained_end() is called). Split blk_do_set_aio_context() in order to solve this assertion failure. This helper function actually serves two different purposes: 1. It drives blk_set_aio_context(). 2. It responds to BdrvChildClass->change_aio_ctx(). Get rid of the helper function. Do #1 inside blk_set_aio_context() and do #2 inside blk_root_set_aio_ctx_commit(). This simplifies the code. The only drawback of the fully transactional approach is that blk_set_aio_context() must contend with blk_root_set_aio_ctx_commit() being invoked as part of the AioContext change propagation. This can be solved by temporarily setting blk->allow_aio_context_change to true. Future patches call blk_get_aio_context() from BlockDevOps->drained_end(), so this patch will become necessary. Signed-off-by: Stefan Hajnoczi Reviewed-by: Kevin Wolf Message-Id: <20230516190238.8401-2-stefanha@redhat.com> Signed-off-by: Kevin Wolf --- block/block-backend.c | 61 ++++++++++++++++--------------------------- 1 file changed, 23 insertions(+), 38 deletions(-) diff --git a/block/block-backend.c b/block/block-backend.c index dde60e0f71..2074ac6760 100644 --- a/block/block-backend.c +++ b/block/block-backend.c @@ -2433,52 +2433,31 @@ static AioContext *blk_aiocb_get_aio_context(BlockA= IOCB *acb) return blk_get_aio_context(blk_acb->blk); } =20 -static int blk_do_set_aio_context(BlockBackend *blk, AioContext *new_conte= xt, - bool update_root_node, Error **errp) +int blk_set_aio_context(BlockBackend *blk, AioContext *new_context, + Error **errp) { + bool old_allow_change; BlockDriverState *bs =3D blk_bs(blk); - ThrottleGroupMember *tgm =3D &blk->public.throttle_group_member; int ret; =20 - if (bs) { - bdrv_ref(bs); - - if (update_root_node) { - /* - * update_root_node MUST be false for blk_root_set_aio_ctx_com= mit(), - * as we are already in the commit function of a transaction. - */ - ret =3D bdrv_try_change_aio_context(bs, new_context, blk->root= , errp); - if (ret < 0) { - bdrv_unref(bs); - 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); - throttle_group_attach_aio_context(tgm, new_context); - bdrv_drained_end(bs); - } + GLOBAL_STATE_CODE(); =20 - bdrv_unref(bs); - } else { + if (!bs) { blk->ctx =3D new_context; + return 0; } =20 - return 0; -} + bdrv_ref(bs); =20 -int blk_set_aio_context(BlockBackend *blk, AioContext *new_context, - Error **errp) -{ - GLOBAL_STATE_CODE(); - return blk_do_set_aio_context(blk, new_context, true, errp); + old_allow_change =3D blk->allow_aio_context_change; + blk->allow_aio_context_change =3D true; + + ret =3D bdrv_try_change_aio_context(bs, new_context, NULL, errp); + + blk->allow_aio_context_change =3D old_allow_change; + + bdrv_unref(bs); + return ret; } =20 typedef struct BdrvStateBlkRootContext { @@ -2490,8 +2469,14 @@ static void blk_root_set_aio_ctx_commit(void *opaque) { BdrvStateBlkRootContext *s =3D opaque; BlockBackend *blk =3D s->blk; + AioContext *new_context =3D s->new_ctx; + ThrottleGroupMember *tgm =3D &blk->public.throttle_group_member; =20 - blk_do_set_aio_context(blk, s->new_ctx, false, &error_abort); + blk->ctx =3D new_context; + if (tgm->throttle_state) { + throttle_group_detach_aio_context(tgm); + throttle_group_attach_aio_context(tgm, new_context); + } } =20 static TransactionActionDrv set_blk_root_context =3D { --=20 2.40.1 From nobody Mon May 20 16:32:53 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=1685464749; cv=none; d=zohomail.com; s=zohoarc; b=AMpvSXpz8vh81RN8Rp5dYYLQ9/EXCOLP1sZ28QlZb89TDgkOiSYagPnajv8i+FWJV9ZQJBj2pwZCSV1vOYQLOV2sCKnivE0dGF+3gjWtaJesWZI8PWfRVa5s+CIlx2PZfUi1m4jM1IgypA8h4woR99yqi+2/T4U+gn2bsRuvtBs= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1685464749; 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=7vgb61st0O40B9bzHjNMm+O+S/R5UcWmtA8BkeR+6eA=; b=a9DiYqck8Gu0lCodzv/BHu20Sia6FJxT6gt5gZqJe9QMownlrrRa+4RQstiImgm27EXkb4b5jK6HHGM6Dc/cy0dtIVYb9nXuTR3/r7oVFS+ELuTBzyDy91ymBw0L6X6Tt0MoqjZLRnP9FsyCeMEpn4BhylMnk9mYr0N9hckcLoY= 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 1685464749740431.131760668913; Tue, 30 May 2023 09:39:09 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1q42IC-0007lU-6q; Tue, 30 May 2023 12:33: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 1q42HU-0006ap-J6 for qemu-devel@nongnu.org; Tue, 30 May 2023 12:33:10 -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 1q42HQ-0008I5-3Y for qemu-devel@nongnu.org; Tue, 30 May 2023 12:33:07 -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-540-Ksq2hTm5MTeZRQPVab4hAw-1; Tue, 30 May 2023 12:33:00 -0400 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 6EC883C17C62; Tue, 30 May 2023 16:33:00 +0000 (UTC) Received: from merkur.redhat.com (unknown [10.39.194.4]) by smtp.corp.redhat.com (Postfix) with ESMTP id B25ABC15612; Tue, 30 May 2023 16:32:59 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1685464382; 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=7vgb61st0O40B9bzHjNMm+O+S/R5UcWmtA8BkeR+6eA=; b=C4VhLNVrvH4SzrH7n5xQRWxkIn8se3V+Gev1DHkrHAzJ69RUxzd8pZl8G9gPK9g2nzajhJ n15koFylQAfqKhdDLDgc3UJHWUxk8v6c8g6UJJUUBzFhinXJEb2bsg+4GaMnAeSwlxueyf fOpxXWxVsFF89HeftqbI0gGOwWJjXPg= X-MC-Unique: Ksq2hTm5MTeZRQPVab4hAw-1 From: Kevin Wolf To: qemu-block@nongnu.org Cc: kwolf@redhat.com, richard.henderson@linaro.org, qemu-devel@nongnu.org Subject: [PULL 14/32] hw/qdev: introduce qdev_is_realized() helper Date: Tue, 30 May 2023 18:32:21 +0200 Message-Id: <20230530163239.576632-15-kwolf@redhat.com> In-Reply-To: <20230530163239.576632-1-kwolf@redhat.com> References: <20230530163239.576632-1-kwolf@redhat.com> MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" 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.133.124; envelope-from=kwolf@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -22 X-Spam_score: -2.3 X-Spam_bar: -- X-Spam_report: (-2.3 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.167, 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: 1685464750949100004 From: Stefan Hajnoczi Add a helper function to check whether the device is realized without requiring the Big QEMU Lock. The next patch adds a second caller. The goal is to avoid spreading DeviceState field accesses throughout the code. Suggested-by: Philippe Mathieu-Daud=C3=A9 Reviewed-by: Philippe Mathieu-Daud=C3=A9 Signed-off-by: Stefan Hajnoczi Reviewed-by: Kevin Wolf Message-Id: <20230516190238.8401-3-stefanha@redhat.com> Signed-off-by: Kevin Wolf --- include/hw/qdev-core.h | 17 ++++++++++++++--- hw/scsi/scsi-bus.c | 3 +-- 2 files changed, 15 insertions(+), 5 deletions(-) diff --git a/include/hw/qdev-core.h b/include/hw/qdev-core.h index 7623703943..f1070d6dc7 100644 --- a/include/hw/qdev-core.h +++ b/include/hw/qdev-core.h @@ -1,6 +1,7 @@ #ifndef QDEV_CORE_H #define QDEV_CORE_H =20 +#include "qemu/atomic.h" #include "qemu/queue.h" #include "qemu/bitmap.h" #include "qemu/rcu.h" @@ -168,9 +169,6 @@ typedef struct { =20 /** * DeviceState: - * @realized: Indicates whether the device has been fully constructed. - * When accessed outside big qemu lock, must be accessed with - * qatomic_load_acquire() * @reset: ResettableState for the device; handled by Resettable interface. * * This structure should not be accessed directly. We declare it here @@ -339,6 +337,19 @@ DeviceState *qdev_new(const char *name); */ DeviceState *qdev_try_new(const char *name); =20 +/** + * qdev_is_realized: + * @dev: The device to check. + * + * May be called outside big qemu lock. + * + * Returns: %true% if the device has been fully constructed, %false% other= wise. + */ +static inline bool qdev_is_realized(DeviceState *dev) +{ + return qatomic_load_acquire(&dev->realized); +} + /** * qdev_realize: Realize @dev. * @dev: device to realize diff --git a/hw/scsi/scsi-bus.c b/hw/scsi/scsi-bus.c index 3c20b47ad0..8857ff41f6 100644 --- a/hw/scsi/scsi-bus.c +++ b/hw/scsi/scsi-bus.c @@ -60,8 +60,7 @@ static SCSIDevice *do_scsi_device_find(SCSIBus *bus, * the user access the device. */ =20 - if (retval && !include_unrealized && - !qatomic_load_acquire(&retval->qdev.realized)) { + if (retval && !include_unrealized && !qdev_is_realized(&retval->qdev))= { retval =3D NULL; } =20 --=20 2.40.1 From nobody Mon May 20 16:32:53 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=1685464886; cv=none; d=zohomail.com; s=zohoarc; b=WKWCBhkjR9+VIrk/d31KcLvkCfCcvWl9BaZ796S1jwG74hvIEYI+h+N05hazkqm/0KtDM+KPt4ule0HQP6F4eXjwgEqitvizh2YOVSLmcDibLUE9dg35G5pQTK3MTl8GU4OlBrX3gupDJvxLSwicuKU5HKwgShhVziQl2k7f7Os= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1685464886; 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=7pk1oIYhwOuAlXZn+zTcl0HihnC4QVR7FfGm3nPys8E=; b=PTHsWJlv/0Cf0Cc2dg1wO3A9KFJlwIn6TlpkaP4flMn6tdzNmgjy/ai+WqNcAAEtgKDpxgIZfMD0z1kvHGW+mH2XJLD+WEVkV3LYHxdizdG1un3gqfGAtWb2+cI6tyKcasayosbwxVnoCqysW2+BLoVgzHr1rt+zPnSKgkJhbNo= 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 1685464886829934.7434584488515; Tue, 30 May 2023 09:41:26 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1q42IH-0008TO-6F; Tue, 30 May 2023 12:33: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 1q42HW-0006bJ-5U for qemu-devel@nongnu.org; Tue, 30 May 2023 12:33:10 -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 1q42HR-0008J6-SY for qemu-devel@nongnu.org; Tue, 30 May 2023 12:33:09 -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-41-ETG_SqauNeSMn0CE3QRFQQ-1; Tue, 30 May 2023 12:33:01 -0400 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 5FCA4800969; Tue, 30 May 2023 16:33:01 +0000 (UTC) Received: from merkur.redhat.com (unknown [10.39.194.4]) by smtp.corp.redhat.com (Postfix) with ESMTP id A5AD1C154D2; Tue, 30 May 2023 16:33:00 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1685464383; 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=7pk1oIYhwOuAlXZn+zTcl0HihnC4QVR7FfGm3nPys8E=; b=f01uw1cZWsTvGVK/YaYdpK6u+MK8gqS5L9O8pQuoz+BG5vLrnTOhlfstTW6EQqYhP5Bo/6 pb0Jjnsck8/ykzb3EXt13sOzb+QKUpDit70AXE+//yEVUaYms8a1gzzl1vI9l36+MvFx7j yD89bRIbG4OPZOjYhOD1g5kT1I+eugg= X-MC-Unique: ETG_SqauNeSMn0CE3QRFQQ-1 From: Kevin Wolf To: qemu-block@nongnu.org Cc: kwolf@redhat.com, richard.henderson@linaro.org, qemu-devel@nongnu.org Subject: [PULL 15/32] virtio-scsi: avoid race between unplug and transport event Date: Tue, 30 May 2023 18:32:22 +0200 Message-Id: <20230530163239.576632-16-kwolf@redhat.com> In-Reply-To: <20230530163239.576632-1-kwolf@redhat.com> References: <20230530163239.576632-1-kwolf@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=kwolf@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -22 X-Spam_score: -2.3 X-Spam_bar: -- X-Spam_report: (-2.3 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.167, 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: 1685464887341100001 Content-Type: text/plain; charset="utf-8" From: Stefan Hajnoczi Only report a transport reset event to the guest after the SCSIDevice has been unrealized by qdev_simple_device_unplug_cb(). qdev_simple_device_unplug_cb() sets the SCSIDevice's qdev.realized field to false so that scsi_device_find/get() no longer see it. scsi_target_emulate_report_luns() also needs to be updated to filter out SCSIDevices that are unrealized. Change virtio_scsi_push_event() to take event information as an argument instead of the SCSIDevice. This allows virtio_scsi_hotunplug() to emit a VIRTIO_SCSI_T_TRANSPORT_RESET event after the SCSIDevice has already been unrealized. These changes ensure that the guest driver does not see the SCSIDevice that's being unplugged if it responds very quickly to the transport reset event. Reviewed-by: Paolo Bonzini Reviewed-by: Michael S. Tsirkin Reviewed-by: Daniil Tatianin Signed-off-by: Stefan Hajnoczi Reviewed-by: Kevin Wolf Message-Id: <20230516190238.8401-4-stefanha@redhat.com> Signed-off-by: Kevin Wolf --- hw/scsi/scsi-bus.c | 3 +- hw/scsi/virtio-scsi.c | 86 ++++++++++++++++++++++++++++++------------- 2 files changed, 63 insertions(+), 26 deletions(-) diff --git a/hw/scsi/scsi-bus.c b/hw/scsi/scsi-bus.c index 8857ff41f6..64013c8a24 100644 --- a/hw/scsi/scsi-bus.c +++ b/hw/scsi/scsi-bus.c @@ -487,7 +487,8 @@ static bool scsi_target_emulate_report_luns(SCSITargetR= eq *r) DeviceState *qdev =3D kid->child; SCSIDevice *dev =3D SCSI_DEVICE(qdev); =20 - if (dev->channel =3D=3D channel && dev->id =3D=3D id && dev->l= un !=3D 0) { + if (dev->channel =3D=3D channel && dev->id =3D=3D id && dev->l= un !=3D 0 && + qdev_is_realized(&dev->qdev)) { store_lun(tmp, dev->lun); g_byte_array_append(buf, tmp, 8); len +=3D 8; diff --git a/hw/scsi/virtio-scsi.c b/hw/scsi/virtio-scsi.c index 612c525d9d..ae314af3de 100644 --- a/hw/scsi/virtio-scsi.c +++ b/hw/scsi/virtio-scsi.c @@ -933,13 +933,27 @@ static void virtio_scsi_reset(VirtIODevice *vdev) s->events_dropped =3D false; } =20 -static void virtio_scsi_push_event(VirtIOSCSI *s, SCSIDevice *dev, - uint32_t event, uint32_t reason) +typedef struct { + uint32_t event; + uint32_t reason; + union { + /* Used by messages specific to a device */ + struct { + uint32_t id; + uint32_t lun; + } address; + }; +} VirtIOSCSIEventInfo; + +static void virtio_scsi_push_event(VirtIOSCSI *s, + const VirtIOSCSIEventInfo *info) { VirtIOSCSICommon *vs =3D VIRTIO_SCSI_COMMON(s); VirtIOSCSIReq *req; VirtIOSCSIEvent *evt; VirtIODevice *vdev =3D VIRTIO_DEVICE(s); + uint32_t event =3D info->event; + uint32_t reason =3D info->reason; =20 if (!(vdev->status & VIRTIO_CONFIG_S_DRIVER_OK)) { return; @@ -965,27 +979,28 @@ static void virtio_scsi_push_event(VirtIOSCSI *s, SCS= IDevice *dev, memset(evt, 0, sizeof(VirtIOSCSIEvent)); evt->event =3D virtio_tswap32(vdev, event); evt->reason =3D virtio_tswap32(vdev, reason); - if (!dev) { - assert(event =3D=3D VIRTIO_SCSI_T_EVENTS_MISSED); - } else { + if (event !=3D VIRTIO_SCSI_T_EVENTS_MISSED) { evt->lun[0] =3D 1; - evt->lun[1] =3D dev->id; + evt->lun[1] =3D info->address.id; =20 /* Linux wants us to keep the same encoding we use for REPORT LUNS= . */ - if (dev->lun >=3D 256) { - evt->lun[2] =3D (dev->lun >> 8) | 0x40; + if (info->address.lun >=3D 256) { + evt->lun[2] =3D (info->address.lun >> 8) | 0x40; } - evt->lun[3] =3D dev->lun & 0xFF; + evt->lun[3] =3D info->address.lun & 0xFF; } trace_virtio_scsi_event(virtio_scsi_get_lun(evt->lun), event, reason); - =20 + virtio_scsi_complete_req(req); } =20 static void virtio_scsi_handle_event_vq(VirtIOSCSI *s, VirtQueue *vq) { if (s->events_dropped) { - virtio_scsi_push_event(s, NULL, VIRTIO_SCSI_T_NO_EVENT, 0); + VirtIOSCSIEventInfo info =3D { + .event =3D VIRTIO_SCSI_T_NO_EVENT, + }; + virtio_scsi_push_event(s, &info); } } =20 @@ -1009,9 +1024,17 @@ static void virtio_scsi_change(SCSIBus *bus, SCSIDev= ice *dev, SCSISense sense) =20 if (virtio_vdev_has_feature(vdev, VIRTIO_SCSI_F_CHANGE) && dev->type !=3D TYPE_ROM) { + VirtIOSCSIEventInfo info =3D { + .event =3D VIRTIO_SCSI_T_PARAM_CHANGE, + .reason =3D sense.asc | (sense.ascq << 8), + .address =3D { + .id =3D dev->id, + .lun =3D dev->lun, + }, + }; + virtio_scsi_acquire(s); - virtio_scsi_push_event(s, dev, VIRTIO_SCSI_T_PARAM_CHANGE, - sense.asc | (sense.ascq << 8)); + virtio_scsi_push_event(s, &info); virtio_scsi_release(s); } } @@ -1046,10 +1069,17 @@ static void virtio_scsi_hotplug(HotplugHandler *hot= plug_dev, DeviceState *dev, } =20 if (virtio_vdev_has_feature(vdev, VIRTIO_SCSI_F_HOTPLUG)) { + VirtIOSCSIEventInfo info =3D { + .event =3D VIRTIO_SCSI_T_TRANSPORT_RESET, + .reason =3D VIRTIO_SCSI_EVT_RESET_RESCAN, + .address =3D { + .id =3D sd->id, + .lun =3D sd->lun, + }, + }; + virtio_scsi_acquire(s); - virtio_scsi_push_event(s, sd, - VIRTIO_SCSI_T_TRANSPORT_RESET, - VIRTIO_SCSI_EVT_RESET_RESCAN); + virtio_scsi_push_event(s, &info); scsi_bus_set_ua(&s->bus, SENSE_CODE(REPORTED_LUNS_CHANGED)); virtio_scsi_release(s); } @@ -1062,15 +1092,14 @@ static void virtio_scsi_hotunplug(HotplugHandler *h= otplug_dev, DeviceState *dev, VirtIOSCSI *s =3D VIRTIO_SCSI(vdev); SCSIDevice *sd =3D SCSI_DEVICE(dev); AioContext *ctx =3D s->ctx ?: qemu_get_aio_context(); - - if (virtio_vdev_has_feature(vdev, VIRTIO_SCSI_F_HOTPLUG)) { - virtio_scsi_acquire(s); - virtio_scsi_push_event(s, sd, - VIRTIO_SCSI_T_TRANSPORT_RESET, - VIRTIO_SCSI_EVT_RESET_REMOVED); - scsi_bus_set_ua(&s->bus, SENSE_CODE(REPORTED_LUNS_CHANGED)); - virtio_scsi_release(s); - } + VirtIOSCSIEventInfo info =3D { + .event =3D VIRTIO_SCSI_T_TRANSPORT_RESET, + .reason =3D VIRTIO_SCSI_EVT_RESET_REMOVED, + .address =3D { + .id =3D sd->id, + .lun =3D sd->lun, + }, + }; =20 aio_disable_external(ctx); qdev_simple_device_unplug_cb(hotplug_dev, dev, errp); @@ -1082,6 +1111,13 @@ static void virtio_scsi_hotunplug(HotplugHandler *ho= tplug_dev, DeviceState *dev, blk_set_aio_context(sd->conf.blk, qemu_get_aio_context(), NULL); virtio_scsi_release(s); } + + if (virtio_vdev_has_feature(vdev, VIRTIO_SCSI_F_HOTPLUG)) { + virtio_scsi_acquire(s); + virtio_scsi_push_event(s, &info); + scsi_bus_set_ua(&s->bus, SENSE_CODE(REPORTED_LUNS_CHANGED)); + virtio_scsi_release(s); + } } =20 static struct SCSIBusInfo virtio_scsi_scsi_info =3D { --=20 2.40.1 From nobody Mon May 20 16:32:53 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=1685464506; cv=none; d=zohomail.com; s=zohoarc; b=Nd7vw510eZEGXO1bPP6vISQTg8gCTB7edJlRdRtimGpy04fXMTLtFE6NjostNLuyBGq7zpGVQjfWqHNH8h2Pn7eA4WesgauJXUCl/RQ2iLmnw5zoXIttBwPJ62+mv8CInIGDft1WAMrVoGrSxbyFQQPi/IVbI02CbbPIXyu6sps= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1685464506; 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=+7Wp8DiMjYAUrSaD97YErLoCGfd5rYj141d9403xFD4=; b=Y6yktVpj5kpUl2J75plqu4u/eandyqVFK/QDZzp3gH940T7xRqYgueZpMxM9GX5Fk8Y1cLEvRQkRv4FcnvembbEAGgDMxtFHDCIpOZGFjrtRcNaAq/DrY4WcQyA2vtaIPjEqi5+Qe5wzufhM8GhrKq+MVi4f9EXNx9XKeW785Fw= 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 1685464506348862.4622253179817; Tue, 30 May 2023 09:35:06 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1q42IF-0008MN-VM; Tue, 30 May 2023 12:33:56 -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 1q42HY-0006mQ-Gc for qemu-devel@nongnu.org; Tue, 30 May 2023 12:33:12 -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 1q42HU-0008KW-J4 for qemu-devel@nongnu.org; Tue, 30 May 2023 12:33:12 -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-344-rN0FKSf2OMOGmc_SKOwnQw-1; Tue, 30 May 2023 12:33:02 -0400 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 4F9211C01E94; Tue, 30 May 2023 16:33:02 +0000 (UTC) Received: from merkur.redhat.com (unknown [10.39.194.4]) by smtp.corp.redhat.com (Postfix) with ESMTP id 96DE4C15612; Tue, 30 May 2023 16:33:01 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1685464386; 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=+7Wp8DiMjYAUrSaD97YErLoCGfd5rYj141d9403xFD4=; b=bUwZNOEBpm3Elj1y4lL8J8A1kDuEGzB5sqIP72hUOwtnrUfbTTtbBVI4XGrtxKyFdisrZQ 7FIiTZEpKVyTB+WTDWsg7DCtfxGHa9kRwscXrpCtLQ9FdoCZ5Aulrb/B9Gd/MoScyXB7IH z3zHJaJGE7KC0NcBNPSf4GnScoxvSkw= X-MC-Unique: rN0FKSf2OMOGmc_SKOwnQw-1 From: Kevin Wolf To: qemu-block@nongnu.org Cc: kwolf@redhat.com, richard.henderson@linaro.org, qemu-devel@nongnu.org Subject: [PULL 16/32] virtio-scsi: stop using aio_disable_external() during unplug Date: Tue, 30 May 2023 18:32:23 +0200 Message-Id: <20230530163239.576632-17-kwolf@redhat.com> In-Reply-To: <20230530163239.576632-1-kwolf@redhat.com> References: <20230530163239.576632-1-kwolf@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.133.124; envelope-from=kwolf@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -22 X-Spam_score: -2.3 X-Spam_bar: -- X-Spam_report: (-2.3 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.167, 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: 1685464507454100001 Content-Type: text/plain; charset="utf-8" From: Stefan Hajnoczi This patch is part of an effort to remove the aio_disable_external() API because it does not fit in a multi-queue block layer world where many AioContexts may be submitting requests to the same disk. The SCSI emulation code is already in good shape to stop using aio_disable_external(). It was only used by commit 9c5aad84da1c ("virtio-scsi: fixed virtio_scsi_ctx_check failed when detaching scsi disk") to ensure that virtio_scsi_hotunplug() works while the guest driver is submitting I/O. Ensure virtio_scsi_hotunplug() is safe as follows: 1. qdev_simple_device_unplug_cb() -> qdev_unrealize() -> device_set_realized() calls qatomic_set(&dev->realized, false) so that future scsi_device_get() calls return NULL because they exclude SCSIDevices with realized=3Dfalse. That means virtio-scsi will reject new I/O requests to this SCSIDevice with VIRTIO_SCSI_S_BAD_TARGET even while virtio_scsi_hotunplug() is still executing. We are protected against new requests! 2. scsi_qdev_unrealize() already contains a call to scsi_device_purge_requests() so that in-flight requests are cancelled synchronously. This ensures that no in-flight requests remain once qdev_simple_device_unplug_cb() returns. Thanks to these two conditions we don't need aio_disable_external() anymore. Cc: Zhengui Li Reviewed-by: Paolo Bonzini Reviewed-by: Daniil Tatianin Signed-off-by: Stefan Hajnoczi Reviewed-by: Kevin Wolf Message-Id: <20230516190238.8401-5-stefanha@redhat.com> Signed-off-by: Kevin Wolf --- hw/scsi/virtio-scsi.c | 3 --- 1 file changed, 3 deletions(-) diff --git a/hw/scsi/virtio-scsi.c b/hw/scsi/virtio-scsi.c index ae314af3de..c1a7ea9ae2 100644 --- a/hw/scsi/virtio-scsi.c +++ b/hw/scsi/virtio-scsi.c @@ -1091,7 +1091,6 @@ static void virtio_scsi_hotunplug(HotplugHandler *hot= plug_dev, DeviceState *dev, VirtIODevice *vdev =3D VIRTIO_DEVICE(hotplug_dev); VirtIOSCSI *s =3D VIRTIO_SCSI(vdev); SCSIDevice *sd =3D SCSI_DEVICE(dev); - AioContext *ctx =3D s->ctx ?: qemu_get_aio_context(); VirtIOSCSIEventInfo info =3D { .event =3D VIRTIO_SCSI_T_TRANSPORT_RESET, .reason =3D VIRTIO_SCSI_EVT_RESET_REMOVED, @@ -1101,9 +1100,7 @@ static void virtio_scsi_hotunplug(HotplugHandler *hot= plug_dev, DeviceState *dev, }, }; =20 - aio_disable_external(ctx); qdev_simple_device_unplug_cb(hotplug_dev, dev, errp); - aio_enable_external(ctx); =20 if (s->ctx) { virtio_scsi_acquire(s); --=20 2.40.1 From nobody Mon May 20 16:32:53 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=1685464814; cv=none; d=zohomail.com; s=zohoarc; b=alpyH+VcJzjECNFIND2eZSDQwboIqrjJU8IxQDeNPqUYmD4a7mJmSV2X/eZ6d7wm5QX5yqnlsSABFM7nO20DqDHTcROOn324MVfQK8ampLYHbHpMY1UcT17R5hbk71aJPtsV1CYzsbQgFYZBkubLzHzRMeKJnye/MAQvfROE4h4= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1685464814; 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=T5y0/yLc+ucav+Qb6OYCax9Wpewd7aW5+inN3B9i6S8=; b=V5+0tTE26PrL1ZhlDtsSXtpWfCFuRFHuwH1JHuuRAXeP0edYHlCGEUCYJk7m/iF5m8yjEkr3812/bKz6XMYlNz40SQUPz0/4USoayz7tGcRku5y33ZCM6IaJRsRh0r0sjyBkJ1csazJX9YmmmvLO+UhKuBLvt89eHF8J7+ak7H0= 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 1685464814161436.2788352285271; Tue, 30 May 2023 09:40:14 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1q42II-0000EH-Pm; Tue, 30 May 2023 12:33:58 -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 1q42HW-0006bd-Cs for qemu-devel@nongnu.org; Tue, 30 May 2023 12:33:10 -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 1q42HU-0008KZ-88 for qemu-devel@nongnu.org; Tue, 30 May 2023 12:33:10 -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-591-IlgrkNufNAS8Rew3AiyaQg-1; Tue, 30 May 2023 12:33:03 -0400 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 40B3E85A5BA; Tue, 30 May 2023 16:33:03 +0000 (UTC) Received: from merkur.redhat.com (unknown [10.39.194.4]) by smtp.corp.redhat.com (Postfix) with ESMTP id 83AC0C154D2; Tue, 30 May 2023 16:33:02 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1685464386; 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=T5y0/yLc+ucav+Qb6OYCax9Wpewd7aW5+inN3B9i6S8=; b=FkqiBFHxYbO2F0ZYbC8c7Lp87qP3oW+bbmGqNznLnIkojKNVbo4FnKPjouMbLuqmdBPr/T qCFwtestiD6vusBYEXEPs+iZkokEE4wExmOXwUajJbJqEVKVZr2gMGLVQqjDLaQlmA4u0I 9WM6mg+I6jEHkGecWX0umWH8TGYPR9A= X-MC-Unique: IlgrkNufNAS8Rew3AiyaQg-1 From: Kevin Wolf To: qemu-block@nongnu.org Cc: kwolf@redhat.com, richard.henderson@linaro.org, qemu-devel@nongnu.org Subject: [PULL 17/32] util/vhost-user-server: rename refcount to in_flight counter Date: Tue, 30 May 2023 18:32:24 +0200 Message-Id: <20230530163239.576632-18-kwolf@redhat.com> In-Reply-To: <20230530163239.576632-1-kwolf@redhat.com> References: <20230530163239.576632-1-kwolf@redhat.com> MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" 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=kwolf@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -22 X-Spam_score: -2.3 X-Spam_bar: -- X-Spam_report: (-2.3 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.167, 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: 1685464815381100001 From: Stefan Hajnoczi The VuServer object has a refcount field and ref/unref APIs. The name is confusing because it's actually an in-flight request counter instead of a refcount. Normally a refcount destroys the object upon reaching zero. The VuServer counter is used to wake up the vhost-user coroutine when there are no more requests. Avoid confusing by renaming refcount and ref/unref to in_flight and inc/dec. Reviewed-by: Paolo Bonzini Reviewed-by: Philippe Mathieu-Daud=C3=A9 Signed-off-by: Stefan Hajnoczi Reviewed-by: Kevin Wolf Message-Id: <20230516190238.8401-6-stefanha@redhat.com> Signed-off-by: Kevin Wolf --- include/qemu/vhost-user-server.h | 6 +++--- block/export/vhost-user-blk-server.c | 11 +++++++---- util/vhost-user-server.c | 14 +++++++------- 3 files changed, 17 insertions(+), 14 deletions(-) diff --git a/include/qemu/vhost-user-server.h b/include/qemu/vhost-user-ser= ver.h index 25c72433ca..bc0ac9ddb6 100644 --- a/include/qemu/vhost-user-server.h +++ b/include/qemu/vhost-user-server.h @@ -41,7 +41,7 @@ typedef struct { const VuDevIface *vu_iface; =20 /* Protected by ctx lock */ - unsigned int refcount; + unsigned int in_flight; bool wait_idle; VuDev vu_dev; QIOChannel *ioc; /* The I/O channel with the client */ @@ -60,8 +60,8 @@ bool vhost_user_server_start(VuServer *server, =20 void vhost_user_server_stop(VuServer *server); =20 -void vhost_user_server_ref(VuServer *server); -void vhost_user_server_unref(VuServer *server); +void vhost_user_server_inc_in_flight(VuServer *server); +void vhost_user_server_dec_in_flight(VuServer *server); =20 void vhost_user_server_attach_aio_context(VuServer *server, AioContext *ct= x); void vhost_user_server_detach_aio_context(VuServer *server); diff --git a/block/export/vhost-user-blk-server.c b/block/export/vhost-user= -blk-server.c index e56b92f2e2..841acb36e3 100644 --- a/block/export/vhost-user-blk-server.c +++ b/block/export/vhost-user-blk-server.c @@ -50,7 +50,10 @@ static void vu_blk_req_complete(VuBlkReq *req, size_t in= _len) free(req); } =20 -/* Called with server refcount increased, must decrease before returning */ +/* + * Called with server in_flight counter increased, must decrease before + * returning. + */ static void coroutine_fn vu_blk_virtio_process_req(void *opaque) { VuBlkReq *req =3D opaque; @@ -68,12 +71,12 @@ static void coroutine_fn vu_blk_virtio_process_req(void= *opaque) in_num, out_num); if (in_len < 0) { free(req); - vhost_user_server_unref(server); + vhost_user_server_dec_in_flight(server); return; } =20 vu_blk_req_complete(req, in_len); - vhost_user_server_unref(server); + vhost_user_server_dec_in_flight(server); } =20 static void vu_blk_process_vq(VuDev *vu_dev, int idx) @@ -95,7 +98,7 @@ static void vu_blk_process_vq(VuDev *vu_dev, int idx) Coroutine *co =3D qemu_coroutine_create(vu_blk_virtio_process_req, req); =20 - vhost_user_server_ref(server); + vhost_user_server_inc_in_flight(server); qemu_coroutine_enter(co); } } diff --git a/util/vhost-user-server.c b/util/vhost-user-server.c index 5b6216069c..1622f8cfb3 100644 --- a/util/vhost-user-server.c +++ b/util/vhost-user-server.c @@ -75,16 +75,16 @@ static void panic_cb(VuDev *vu_dev, const char *buf) error_report("vu_panic: %s", buf); } =20 -void vhost_user_server_ref(VuServer *server) +void vhost_user_server_inc_in_flight(VuServer *server) { assert(!server->wait_idle); - server->refcount++; + server->in_flight++; } =20 -void vhost_user_server_unref(VuServer *server) +void vhost_user_server_dec_in_flight(VuServer *server) { - server->refcount--; - if (server->wait_idle && !server->refcount) { + server->in_flight--; + if (server->wait_idle && !server->in_flight) { aio_co_wake(server->co_trip); } } @@ -192,13 +192,13 @@ static coroutine_fn void vu_client_trip(void *opaque) /* Keep running */ } =20 - if (server->refcount) { + if (server->in_flight) { /* Wait for requests to complete before we can unmap the memory */ server->wait_idle =3D true; qemu_coroutine_yield(); server->wait_idle =3D false; } - assert(server->refcount =3D=3D 0); + assert(server->in_flight =3D=3D 0); =20 vu_deinit(vu_dev); =20 --=20 2.40.1 From nobody Mon May 20 16:32:53 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=1685464837; cv=none; d=zohomail.com; s=zohoarc; b=l9wxeWuMEwSNHD7wp+YISqHhiYnbnJBR5Bv6kZB3zgJ+Kung46hjOXobazC7MdPydyS7f8iKSVhKuGevMYBvU9Yfdhr1FCUBefzN45aA7YvYR4W+qr5PWzLHSMIn3pc6jcyGPV+BbY/LR7ZnxH40Sef7ItjGO0QL1gEgZ9jWhw0= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1685464837; 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=dWYtO63hzJuGikLX2mgXYxihjvj+ywyd+OvX6djxaX8=; b=mdnKq4PkkZuInNYwVCFTMp0PyOGDP/Gat8f+TByQxOfuvvvTVPYHurTcovER8ZT19sWOVCU91lo1UtLP/3HjG5taMt96gU/loJWUQMdOJAGBBvwghwE97+rJ34MyOi9CSTWiK0wj0gNRQJGywwfkABcViprZ1rqzx/ngTRpt68U= 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 1685464837395775.9697670189764; Tue, 30 May 2023 09:40:37 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1q42Im-0001Ru-GM; Tue, 30 May 2023 12:34:28 -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 1q42Hg-0006wX-RP for qemu-devel@nongnu.org; Tue, 30 May 2023 12:33:28 -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 1q42He-0008TB-NB for qemu-devel@nongnu.org; Tue, 30 May 2023 12:33:20 -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-428-A1rzR6SNMGKIqmDQpzlpfw-1; Tue, 30 May 2023 12:33:04 -0400 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 351CC8032FA; Tue, 30 May 2023 16:33:04 +0000 (UTC) Received: from merkur.redhat.com (unknown [10.39.194.4]) by smtp.corp.redhat.com (Postfix) with ESMTP id 78363C154D2; Tue, 30 May 2023 16:33:03 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1685464395; 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=dWYtO63hzJuGikLX2mgXYxihjvj+ywyd+OvX6djxaX8=; b=Q+ncgLLbNnL3WdsHTXgJIgwUEbUXSIq07rtpJRfVe8kN/gGgOzWMtlfkZdmelxd2OTBYVo bW7+QzV53nL0WBVlnwO2iSs33juUcq7+u0MzyT2XkYGbamfXuNu1tqZQCVOWGXDByBDXUu 2Y1Yz/KBTx7IvSzBtGvBA9wzulL5CZg= X-MC-Unique: A1rzR6SNMGKIqmDQpzlpfw-1 From: Kevin Wolf To: qemu-block@nongnu.org Cc: kwolf@redhat.com, richard.henderson@linaro.org, qemu-devel@nongnu.org Subject: [PULL 18/32] block/export: wait for vhost-user-blk requests when draining Date: Tue, 30 May 2023 18:32:25 +0200 Message-Id: <20230530163239.576632-19-kwolf@redhat.com> In-Reply-To: <20230530163239.576632-1-kwolf@redhat.com> References: <20230530163239.576632-1-kwolf@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.133.124; envelope-from=kwolf@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -22 X-Spam_score: -2.3 X-Spam_bar: -- X-Spam_report: (-2.3 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.167, 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: 1685464839378100008 Content-Type: text/plain; charset="utf-8" From: Stefan Hajnoczi Each vhost-user-blk request runs in a coroutine. When the BlockBackend enters a drained section we need to enter a quiescent state. Currently any in-flight requests race with bdrv_drained_begin() because it is unaware of vhost-user-blk requests. When blk_co_preadv/pwritev()/etc returns it wakes the bdrv_drained_begin() thread but vhost-user-blk request processing has not yet finished. The request coroutine continues executing while the main loop thread thinks it is in a drained section. One example where this is unsafe is for blk_set_aio_context() where bdrv_drained_begin() is called before .aio_context_detached() and .aio_context_attach(). If request coroutines are still running after bdrv_drained_begin(), then the AioContext could change underneath them and they race with new requests processed in the new AioContext. This could lead to virtqueue corruption, for example. (This example is theoretical, I came across this while reading the code and have not tried to reproduce it.) It's easy to make bdrv_drained_begin() wait for in-flight requests: add a .drained_poll() callback that checks the VuServer's in-flight counter. VuServer just needs an API that returns true when there are requests in flight. The in-flight counter needs to be atomic. Signed-off-by: Stefan Hajnoczi Reviewed-by: Kevin Wolf Message-Id: <20230516190238.8401-7-stefanha@redhat.com> Signed-off-by: Kevin Wolf --- include/qemu/vhost-user-server.h | 4 +++- block/export/vhost-user-blk-server.c | 13 +++++++++++++ util/vhost-user-server.c | 18 ++++++++++++------ 3 files changed, 28 insertions(+), 7 deletions(-) diff --git a/include/qemu/vhost-user-server.h b/include/qemu/vhost-user-ser= ver.h index bc0ac9ddb6..b1c1cda886 100644 --- a/include/qemu/vhost-user-server.h +++ b/include/qemu/vhost-user-server.h @@ -40,8 +40,9 @@ typedef struct { int max_queues; const VuDevIface *vu_iface; =20 + unsigned int in_flight; /* atomic */ + /* Protected by ctx lock */ - unsigned int in_flight; bool wait_idle; VuDev vu_dev; QIOChannel *ioc; /* The I/O channel with the client */ @@ -62,6 +63,7 @@ void vhost_user_server_stop(VuServer *server); =20 void vhost_user_server_inc_in_flight(VuServer *server); void vhost_user_server_dec_in_flight(VuServer *server); +bool vhost_user_server_has_in_flight(VuServer *server); =20 void vhost_user_server_attach_aio_context(VuServer *server, AioContext *ct= x); void vhost_user_server_detach_aio_context(VuServer *server); diff --git a/block/export/vhost-user-blk-server.c b/block/export/vhost-user= -blk-server.c index 841acb36e3..f51a36a14f 100644 --- a/block/export/vhost-user-blk-server.c +++ b/block/export/vhost-user-blk-server.c @@ -272,7 +272,20 @@ static void vu_blk_exp_resize(void *opaque) vu_config_change_msg(&vexp->vu_server.vu_dev); } =20 +/* + * Ensures that bdrv_drained_begin() waits until in-flight requests comple= te. + * + * Called with vexp->export.ctx acquired. + */ +static bool vu_blk_drained_poll(void *opaque) +{ + VuBlkExport *vexp =3D opaque; + + return vhost_user_server_has_in_flight(&vexp->vu_server); +} + static const BlockDevOps vu_blk_dev_ops =3D { + .drained_poll =3D vu_blk_drained_poll, .resize_cb =3D vu_blk_exp_resize, }; =20 diff --git a/util/vhost-user-server.c b/util/vhost-user-server.c index 1622f8cfb3..68c3bf162f 100644 --- a/util/vhost-user-server.c +++ b/util/vhost-user-server.c @@ -78,17 +78,23 @@ static void panic_cb(VuDev *vu_dev, const char *buf) void vhost_user_server_inc_in_flight(VuServer *server) { assert(!server->wait_idle); - server->in_flight++; + qatomic_inc(&server->in_flight); } =20 void vhost_user_server_dec_in_flight(VuServer *server) { - server->in_flight--; - if (server->wait_idle && !server->in_flight) { - aio_co_wake(server->co_trip); + if (qatomic_fetch_dec(&server->in_flight) =3D=3D 1) { + if (server->wait_idle) { + aio_co_wake(server->co_trip); + } } } =20 +bool vhost_user_server_has_in_flight(VuServer *server) +{ + return qatomic_load_acquire(&server->in_flight) > 0; +} + static bool coroutine_fn vu_message_read(VuDev *vu_dev, int conn_fd, VhostUserMsg *vmsg) { @@ -192,13 +198,13 @@ static coroutine_fn void vu_client_trip(void *opaque) /* Keep running */ } =20 - if (server->in_flight) { + if (vhost_user_server_has_in_flight(server)) { /* Wait for requests to complete before we can unmap the memory */ server->wait_idle =3D true; qemu_coroutine_yield(); server->wait_idle =3D false; } - assert(server->in_flight =3D=3D 0); + assert(!vhost_user_server_has_in_flight(server)); =20 vu_deinit(vu_dev); =20 --=20 2.40.1 From nobody Mon May 20 16:32:53 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=1685464496; cv=none; d=zohomail.com; s=zohoarc; b=GekJeAe1B1uvASioGATq+zI2IhjbmG0udpjeXEAT1yYP4Xz3TXTz9illGxmogmyQCbe+I6W+r3rbsynvTRiesF3x7eR1lz82aRCFLfEcWH2bfKkI/3y6+qD+xyrtlvpaee0aMA2aGa0Wj/yNA/XARmzc9eMDKL0aasQN2cNYsoo= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1685464496; 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=ZqktWQrLFSHZ6LXJVB3T/QJl62qVA8nRvPYAXI9WKLY=; b=hGgYGY0+IGf46eQMYmBgypQTEoDbz6Ss0SF9KKwekclp/OZ34Nhy97V+fzDrMTtcrK3ijxDJynXZF6zre9xOVr/4Nc7yjE1lmufJMM1YHVkO7/K4vNXF1MFfuEX24JLcfK1LJsbAxaubYMF0zzXoLIisZq7/NPq+hj6yDyBo9CU= 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 1685464496011641.0989032719604; Tue, 30 May 2023 09:34:56 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1q42Ii-0000sR-DQ; Tue, 30 May 2023 12:34:24 -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 1q42Hb-0006rK-6i for qemu-devel@nongnu.org; Tue, 30 May 2023 12:33:18 -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 1q42HX-0008QJ-W8 for qemu-devel@nongnu.org; Tue, 30 May 2023 12:33:14 -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-176-bjT-RugYPmqzy3SCr3QjOA-1; Tue, 30 May 2023 12:33:05 -0400 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 3084F101A53A; Tue, 30 May 2023 16:33:05 +0000 (UTC) Received: from merkur.redhat.com (unknown [10.39.194.4]) by smtp.corp.redhat.com (Postfix) with ESMTP id 745FEC154D2; Tue, 30 May 2023 16:33:04 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1685464391; 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=ZqktWQrLFSHZ6LXJVB3T/QJl62qVA8nRvPYAXI9WKLY=; b=Nn1yCIMk3RLgn7MotqKu0h01ckLCeOobhzmrLjIrSVWCAqfngM/nFbYiA/QpWL3IfddFpa wigZTZgN5cKjwJfJi5gENDoYgPRLxaA9QheJjc1ZmN17F83p1lGoZQx37ANnY+9r+mf2Nm oahiYRLmP/FpFS5q1dFdWaLfhoyJ9c8= X-MC-Unique: bjT-RugYPmqzy3SCr3QjOA-1 From: Kevin Wolf To: qemu-block@nongnu.org Cc: kwolf@redhat.com, richard.henderson@linaro.org, qemu-devel@nongnu.org Subject: [PULL 19/32] block/export: stop using is_external in vhost-user-blk server Date: Tue, 30 May 2023 18:32:26 +0200 Message-Id: <20230530163239.576632-20-kwolf@redhat.com> In-Reply-To: <20230530163239.576632-1-kwolf@redhat.com> References: <20230530163239.576632-1-kwolf@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.133.124; envelope-from=kwolf@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -22 X-Spam_score: -2.3 X-Spam_bar: -- X-Spam_report: (-2.3 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.167, 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: 1685464497337100003 Content-Type: text/plain; charset="utf-8" From: Stefan Hajnoczi vhost-user activity must be suspended during bdrv_drained_begin/end(). This prevents new requests from interfering with whatever is happening in the drained section. Previously this was done using aio_set_fd_handler()'s is_external argument. In a multi-queue block layer world the aio_disable_external() API cannot be used since multiple AioContext may be processing I/O, not just one. Switch to BlockDevOps->drained_begin/end() callbacks. Signed-off-by: Stefan Hajnoczi Reviewed-by: Kevin Wolf Message-Id: <20230516190238.8401-8-stefanha@redhat.com> Signed-off-by: Kevin Wolf --- block/export/vhost-user-blk-server.c | 28 ++++++++++++++++++++++++++-- util/vhost-user-server.c | 10 +++++----- 2 files changed, 31 insertions(+), 7 deletions(-) diff --git a/block/export/vhost-user-blk-server.c b/block/export/vhost-user= -blk-server.c index f51a36a14f..81b59761e3 100644 --- a/block/export/vhost-user-blk-server.c +++ b/block/export/vhost-user-blk-server.c @@ -212,15 +212,21 @@ static void blk_aio_attached(AioContext *ctx, void *o= paque) { VuBlkExport *vexp =3D opaque; =20 + /* + * The actual attach will happen in vu_blk_drained_end() and we just + * restore ctx here. + */ vexp->export.ctx =3D ctx; - vhost_user_server_attach_aio_context(&vexp->vu_server, ctx); } =20 static void blk_aio_detach(void *opaque) { VuBlkExport *vexp =3D opaque; =20 - vhost_user_server_detach_aio_context(&vexp->vu_server); + /* + * The actual detach already happened in vu_blk_drained_begin() but fr= om + * this point on we must not access ctx anymore. + */ vexp->export.ctx =3D NULL; } =20 @@ -272,6 +278,22 @@ static void vu_blk_exp_resize(void *opaque) vu_config_change_msg(&vexp->vu_server.vu_dev); } =20 +/* Called with vexp->export.ctx acquired */ +static void vu_blk_drained_begin(void *opaque) +{ + VuBlkExport *vexp =3D opaque; + + vhost_user_server_detach_aio_context(&vexp->vu_server); +} + +/* Called with vexp->export.blk AioContext acquired */ +static void vu_blk_drained_end(void *opaque) +{ + VuBlkExport *vexp =3D opaque; + + vhost_user_server_attach_aio_context(&vexp->vu_server, vexp->export.ct= x); +} + /* * Ensures that bdrv_drained_begin() waits until in-flight requests comple= te. * @@ -285,6 +307,8 @@ static bool vu_blk_drained_poll(void *opaque) } =20 static const BlockDevOps vu_blk_dev_ops =3D { + .drained_begin =3D vu_blk_drained_begin, + .drained_end =3D vu_blk_drained_end, .drained_poll =3D vu_blk_drained_poll, .resize_cb =3D vu_blk_exp_resize, }; diff --git a/util/vhost-user-server.c b/util/vhost-user-server.c index 68c3bf162f..a12b2d1bba 100644 --- a/util/vhost-user-server.c +++ b/util/vhost-user-server.c @@ -278,7 +278,7 @@ set_watch(VuDev *vu_dev, int fd, int vu_evt, vu_fd_watch->fd =3D fd; vu_fd_watch->cb =3D cb; qemu_socket_set_nonblock(fd); - aio_set_fd_handler(server->ioc->ctx, fd, true, kick_handler, + aio_set_fd_handler(server->ioc->ctx, fd, false, kick_handler, NULL, NULL, NULL, vu_fd_watch); vu_fd_watch->vu_dev =3D vu_dev; vu_fd_watch->pvt =3D pvt; @@ -299,7 +299,7 @@ static void remove_watch(VuDev *vu_dev, int fd) if (!vu_fd_watch) { return; } - aio_set_fd_handler(server->ioc->ctx, fd, true, + aio_set_fd_handler(server->ioc->ctx, fd, false, NULL, NULL, NULL, NULL, NULL); =20 QTAILQ_REMOVE(&server->vu_fd_watches, vu_fd_watch, next); @@ -362,7 +362,7 @@ void vhost_user_server_stop(VuServer *server) VuFdWatch *vu_fd_watch; =20 QTAILQ_FOREACH(vu_fd_watch, &server->vu_fd_watches, next) { - aio_set_fd_handler(server->ctx, vu_fd_watch->fd, true, + aio_set_fd_handler(server->ctx, vu_fd_watch->fd, false, NULL, NULL, NULL, NULL, vu_fd_watch); } =20 @@ -403,7 +403,7 @@ void vhost_user_server_attach_aio_context(VuServer *ser= ver, AioContext *ctx) qio_channel_attach_aio_context(server->ioc, ctx); =20 QTAILQ_FOREACH(vu_fd_watch, &server->vu_fd_watches, next) { - aio_set_fd_handler(ctx, vu_fd_watch->fd, true, kick_handler, NULL, + aio_set_fd_handler(ctx, vu_fd_watch->fd, false, kick_handler, NULL, NULL, NULL, vu_fd_watch); } =20 @@ -417,7 +417,7 @@ void vhost_user_server_detach_aio_context(VuServer *ser= ver) VuFdWatch *vu_fd_watch; =20 QTAILQ_FOREACH(vu_fd_watch, &server->vu_fd_watches, next) { - aio_set_fd_handler(server->ctx, vu_fd_watch->fd, true, + aio_set_fd_handler(server->ctx, vu_fd_watch->fd, false, NULL, NULL, NULL, NULL, vu_fd_watch); } =20 --=20 2.40.1 From nobody Mon May 20 16:32:53 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=1685464645; cv=none; d=zohomail.com; s=zohoarc; b=nQYNDH0S6Ui3Kmsn/voVoQYSM2fqWAFNj9SoeI/liKoaTVRjGo0rDt3EBe9yHV6ij6HG6OBJm9TFAmLdEuf9UaPOl60aR77rQFJKLLoAe8PoruJkuK25HLEoLoJwLeJvg/NeuB2ZyBWXFfmyX7PLVeRiyuzn3JdSXTiSy2CoMdA= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1685464645; 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=enE6kqXcToZmMDS/Xd19W5sqiMWZscmvZCaBAvnTUCM=; b=k21G2uxIEF+BNCQZ6TVa+CXUVX6Bm4gqJBjyjgJgVds34VEEyDBYaBrgUFAIU0j5s11mmHRUEdQ2F6wxZ7XSRi8a1B+VNRkvMumsvtlrleDMrhXEp+7DWjv4RMS+1M6y8levJOsWbCmnw8trlgKS4+o6OjD8OJzemxHC9HKaf8A= 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 1685464645736180.6614069687506; Tue, 30 May 2023 09:37:25 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1q42Ij-00011x-Ah; Tue, 30 May 2023 12:34:25 -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 1q42Hb-0006rJ-5L for qemu-devel@nongnu.org; Tue, 30 May 2023 12:33:18 -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 1q42HV-0008NR-UT for qemu-devel@nongnu.org; Tue, 30 May 2023 12:33:13 -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-214-6FfPBfhmPIiWHAE9rInPgg-1; Tue, 30 May 2023 12:33:06 -0400 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 0C60C811E8E; Tue, 30 May 2023 16:33:06 +0000 (UTC) Received: from merkur.redhat.com (unknown [10.39.194.4]) by smtp.corp.redhat.com (Postfix) with ESMTP id 67EBDC154D2; Tue, 30 May 2023 16:33:05 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1685464388; 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=enE6kqXcToZmMDS/Xd19W5sqiMWZscmvZCaBAvnTUCM=; b=PoSmubhqCBHI4Ch9qqqvQhQYttYYMjaxGSE7Wg/nmxrcfwUP+ZDiRYd3EZRaRJ1HZDYsXY 3GQICd9swB431qTLRZhCY5GrSm7j/a/XrMqXIHYLqdNANJuN3v+UxxdRyzIwLeTvKoHnrq qm1a0P/pi16qlQmMQ0uQNnuh139RZoc= X-MC-Unique: 6FfPBfhmPIiWHAE9rInPgg-1 From: Kevin Wolf To: qemu-block@nongnu.org Cc: kwolf@redhat.com, richard.henderson@linaro.org, qemu-devel@nongnu.org Subject: [PULL 20/32] hw/xen: do not use aio_set_fd_handler(is_external=true) in xen_xenstore Date: Tue, 30 May 2023 18:32:27 +0200 Message-Id: <20230530163239.576632-21-kwolf@redhat.com> In-Reply-To: <20230530163239.576632-1-kwolf@redhat.com> References: <20230530163239.576632-1-kwolf@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.133.124; envelope-from=kwolf@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -22 X-Spam_score: -2.3 X-Spam_bar: -- X-Spam_report: (-2.3 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.167, 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: 1685464646083100001 Content-Type: text/plain; charset="utf-8" From: Stefan Hajnoczi There is no need to suspend activity between aio_disable_external() and aio_enable_external(), which is mainly used for the block layer's drain operation. This is part of ongoing work to remove the aio_disable_external() API. Reviewed-by: David Woodhouse Reviewed-by: Paul Durrant Signed-off-by: Stefan Hajnoczi Reviewed-by: Kevin Wolf Message-Id: <20230516190238.8401-9-stefanha@redhat.com> Signed-off-by: Kevin Wolf --- hw/i386/kvm/xen_xenstore.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/hw/i386/kvm/xen_xenstore.c b/hw/i386/kvm/xen_xenstore.c index 900679af8a..6e81bc8791 100644 --- a/hw/i386/kvm/xen_xenstore.c +++ b/hw/i386/kvm/xen_xenstore.c @@ -133,7 +133,7 @@ static void xen_xenstore_realize(DeviceState *dev, Erro= r **errp) error_setg(errp, "Xenstore evtchn port init failed"); return; } - aio_set_fd_handler(qemu_get_aio_context(), xen_be_evtchn_fd(s->eh), tr= ue, + aio_set_fd_handler(qemu_get_aio_context(), xen_be_evtchn_fd(s->eh), fa= lse, xen_xenstore_event, NULL, NULL, NULL, s); =20 s->impl =3D xs_impl_create(xen_domid); --=20 2.40.1 From nobody Mon May 20 16:32:53 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=1685464888; cv=none; d=zohomail.com; s=zohoarc; b=FTymYGU8h+nnbDWj09HyHxpJmEVz/BqdxTp0px0QRXvSDb1IwTO0tFOwvg8G0VdbrBOGJh+MlSx2Zf2zILk2/IabmFNgBsHvhXHExyx+P4efuW8DIuo4vhbnf9ILK3tQHQjtD+axJdr12NQKNCKUpw5BA7NfQVN2qgqY9+ogPC4= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1685464888; 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=Y/GvxF/TlIRbn9E193eebjBC3x7b1gj/fk35+27OZaA=; b=XKHjAwmNimEYcGc+pzf3D5Bx4FCxu0tfoOgmKtl1Ul2OFUOzoP5VJXys+W0cSmQeRJhsY8RKhkNYc3I0yOusRNp1QWAZqiyBMzoDA4MTIoDBqT6OR5vEjF0NjDIvzDFCgp24nHvCYfD+Qk/djssDTe61zEwh+JUwV0SgdQYbtMY= 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 1685464888705273.8806541799323; Tue, 30 May 2023 09:41:28 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1q42IH-0008TP-63; Tue, 30 May 2023 12:33: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 1q42Hb-0006rL-6d for qemu-devel@nongnu.org; Tue, 30 May 2023 12:33:18 -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 1q42HW-0008P2-PK for qemu-devel@nongnu.org; Tue, 30 May 2023 12:33:13 -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-371-pUoqVFu-NQGseYiEY_S09Q-1; Tue, 30 May 2023 12:33:08 -0400 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 1197D8039AD; Tue, 30 May 2023 16:33:07 +0000 (UTC) Received: from merkur.redhat.com (unknown [10.39.194.4]) by smtp.corp.redhat.com (Postfix) with ESMTP id 4E9B9C154D3; Tue, 30 May 2023 16:33:06 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1685464390; 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=Y/GvxF/TlIRbn9E193eebjBC3x7b1gj/fk35+27OZaA=; b=B5gQK25E52h/nvI2cvzKrBhTpnTqooc8cn6grYYsbbXjHRjxY1ImXCQQSvSUpCn14HZymz K3n3I+UIW6+d6s/b+fUrszJJrHNB78GByvpyqOd3Lgo04ULTXyBSAWZCk5Vhm/PNhHK5K9 K8mYlQDjuv1CdM7shrvxcu49VC0gXtk= X-MC-Unique: pUoqVFu-NQGseYiEY_S09Q-1 From: Kevin Wolf To: qemu-block@nongnu.org Cc: kwolf@redhat.com, richard.henderson@linaro.org, qemu-devel@nongnu.org Subject: [PULL 21/32] block: add blk_in_drain() API Date: Tue, 30 May 2023 18:32:28 +0200 Message-Id: <20230530163239.576632-22-kwolf@redhat.com> In-Reply-To: <20230530163239.576632-1-kwolf@redhat.com> References: <20230530163239.576632-1-kwolf@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=kwolf@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -22 X-Spam_score: -2.3 X-Spam_bar: -- X-Spam_report: (-2.3 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.167, 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: 1685464889358100011 Content-Type: text/plain; charset="utf-8" From: Stefan Hajnoczi The BlockBackend quiesce_counter is greater than zero during drained sections. Add an API to check whether the BlockBackend is in a drained section. The next patch will use this API. Signed-off-by: Stefan Hajnoczi Reviewed-by: Kevin Wolf Message-Id: <20230516190238.8401-10-stefanha@redhat.com> Signed-off-by: Kevin Wolf --- include/sysemu/block-backend-global-state.h | 1 + block/block-backend.c | 7 +++++++ 2 files changed, 8 insertions(+) diff --git a/include/sysemu/block-backend-global-state.h b/include/sysemu/b= lock-backend-global-state.h index fa83f9389c..184e667ebd 100644 --- a/include/sysemu/block-backend-global-state.h +++ b/include/sysemu/block-backend-global-state.h @@ -81,6 +81,7 @@ void blk_activate(BlockBackend *blk, Error **errp); int blk_make_zero(BlockBackend *blk, BdrvRequestFlags flags); void blk_aio_cancel(BlockAIOCB *acb); int blk_commit_all(void); +bool blk_in_drain(BlockBackend *blk); void blk_drain(BlockBackend *blk); void blk_drain_all(void); void blk_set_on_error(BlockBackend *blk, BlockdevOnError on_read_error, diff --git a/block/block-backend.c b/block/block-backend.c index 2074ac6760..241f643507 100644 --- a/block/block-backend.c +++ b/block/block-backend.c @@ -1287,6 +1287,13 @@ blk_check_byte_request(BlockBackend *blk, int64_t of= fset, int64_t bytes) return 0; } =20 +/* Are we currently in a drained section? */ +bool blk_in_drain(BlockBackend *blk) +{ + GLOBAL_STATE_CODE(); /* change to IO_OR_GS_CODE(), if necessary */ + return qatomic_read(&blk->quiesce_counter); +} + /* To be called between exactly one pair of blk_inc/dec_in_flight() */ static void coroutine_fn blk_wait_while_drained(BlockBackend *blk) { --=20 2.40.1 From nobody Mon May 20 16:32:53 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=1685464888; cv=none; d=zohomail.com; s=zohoarc; b=YTko3dbiD+GZv1DRLY59etm+noKTYrTXLjlDrFf/kJy6kCxnWdYisUPKS3JV4gFmNol5gIOSACSq3wvrDQZkvV3k+x6fNOXV9CQfXNpt/P5VtiLveBYM6+S60KmpPgg6iGksdf6Fiva1noz5JxwvHKwtVWhhL5T5ZnC/515tVuU= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1685464888; 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=f+p6z9womlcWKNL8k7k9wu4aHeNKiXbRqBsGD/x8Ins=; b=FzMIDHTnVKRKsiVKORMuQRn09rc4cWGtyguScQp2/noQ12x4G7UkMAA2XAjHQI7r74VMHEH+cIL9CIUxMp6kccDPExUb5LZad11qH4X+3S54NM4yStlXQWlP1ysYa4Qhb2xH8ciHDCMM0jWIvGJtRW6CTs1ZmO/IiXFVUohQO/o= 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 1685464888574647.6363604943955; Tue, 30 May 2023 09:41:28 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1q42IH-00005f-UO; Tue, 30 May 2023 12:33: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 1q42Hi-0006xM-KZ for qemu-devel@nongnu.org; Tue, 30 May 2023 12:33: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 1q42He-0008UC-OV for qemu-devel@nongnu.org; Tue, 30 May 2023 12:33:22 -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-458-oPEW5R68NK288G4m0atIOw-1; Tue, 30 May 2023 12:33:08 -0400 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 031231C01E94; Tue, 30 May 2023 16:33:08 +0000 (UTC) Received: from merkur.redhat.com (unknown [10.39.194.4]) by smtp.corp.redhat.com (Postfix) with ESMTP id 48D8DC154D2; Tue, 30 May 2023 16:33:07 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1685464398; 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=f+p6z9womlcWKNL8k7k9wu4aHeNKiXbRqBsGD/x8Ins=; b=anpVMzG0b92dwv9CBffBftu4MVFGSCuAZJ9uNCtfr/2/ONf274Nvbe5jTDb82L4bXC/1lQ 0fdLerTZ76Q9soyKKa9O3W2ooCcfaUC4LghjuBPklCJb+dUkHpWz6ZD5dKustFxyQpdTby G6Jd77zjvV6dTR3ucLFQ9yxH97suCec= X-MC-Unique: oPEW5R68NK288G4m0atIOw-1 From: Kevin Wolf To: qemu-block@nongnu.org Cc: kwolf@redhat.com, richard.henderson@linaro.org, qemu-devel@nongnu.org Subject: [PULL 22/32] block: drain from main loop thread in bdrv_co_yield_to_drain() Date: Tue, 30 May 2023 18:32:29 +0200 Message-Id: <20230530163239.576632-23-kwolf@redhat.com> In-Reply-To: <20230530163239.576632-1-kwolf@redhat.com> References: <20230530163239.576632-1-kwolf@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.133.124; envelope-from=kwolf@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -22 X-Spam_score: -2.3 X-Spam_bar: -- X-Spam_report: (-2.3 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.167, 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: 1685464889369100012 Content-Type: text/plain; charset="utf-8" From: Stefan Hajnoczi For simplicity, always run BlockDevOps .drained_begin/end/poll() callbacks in the main loop thread. This makes it easier to implement the callbacks and avoids extra locks. Move the function pointer declarations from the I/O Code section to the Global State section for BlockDevOps, BdrvChildClass, and BlockDriver. Narrow IO_OR_GS_CODE() to GLOBAL_STATE_CODE() where appropriate. The test-bdrv-drain test case calls bdrv_drain() from an IOThread. This is now only allowed from coroutine context, so update the test case to run in a coroutine. Signed-off-by: Stefan Hajnoczi Reviewed-by: Kevin Wolf Message-Id: <20230516190238.8401-11-stefanha@redhat.com> Signed-off-by: Kevin Wolf --- include/block/block_int-common.h | 72 +++++++++++++-------------- include/sysemu/block-backend-common.h | 25 +++++----- block/io.c | 14 ++++-- tests/unit/test-bdrv-drain.c | 14 +++--- 4 files changed, 67 insertions(+), 58 deletions(-) diff --git a/include/block/block_int-common.h b/include/block/block_int-com= mon.h index 6492a1e538..b1cbc1e00c 100644 --- a/include/block/block_int-common.h +++ b/include/block/block_int-common.h @@ -363,6 +363,21 @@ struct BlockDriver { void (*bdrv_attach_aio_context)(BlockDriverState *bs, AioContext *new_context); =20 + /** + * bdrv_drain_begin is called if implemented in the beginning of a + * drain operation to drain and stop any internal sources of requests = in + * the driver. + * bdrv_drain_end is called if implemented at the end of the drain. + * + * They should be used by the driver to e.g. manage scheduled I/O + * requests, or toggle an internal state. After the end of the drain n= ew + * requests will continue normally. + * + * Implementations of both functions must not call aio_poll(). + */ + void (*bdrv_drain_begin)(BlockDriverState *bs); + void (*bdrv_drain_end)(BlockDriverState *bs); + /** * Try to get @bs's logical and physical block size. * On success, store them in @bsz and return zero. @@ -758,21 +773,6 @@ struct BlockDriver { void coroutine_fn GRAPH_RDLOCK_PTR (*bdrv_co_io_unplug)( BlockDriverState *bs); =20 - /** - * bdrv_drain_begin is called if implemented in the beginning of a - * drain operation to drain and stop any internal sources of requests = in - * the driver. - * bdrv_drain_end is called if implemented at the end of the drain. - * - * They should be used by the driver to e.g. manage scheduled I/O - * requests, or toggle an internal state. After the end of the drain n= ew - * requests will continue normally. - * - * Implementations of both functions must not call aio_poll(). - */ - void (*bdrv_drain_begin)(BlockDriverState *bs); - void (*bdrv_drain_end)(BlockDriverState *bs); - bool (*bdrv_supports_persistent_dirty_bitmap)(BlockDriverState *bs); =20 bool coroutine_fn GRAPH_RDLOCK_PTR (*bdrv_co_can_store_new_dirty_bitma= p)( @@ -955,6 +955,27 @@ struct BdrvChildClass { void GRAPH_WRLOCK_PTR (*attach)(BdrvChild *child); void GRAPH_WRLOCK_PTR (*detach)(BdrvChild *child); =20 + /* + * If this pair of functions is implemented, the parent doesn't issue = new + * requests after returning from .drained_begin() until .drained_end()= is + * called. + * + * These functions must not change the graph (and therefore also must = not + * call aio_poll(), which could change the graph indirectly). + * + * Note that this can be nested. If drained_begin() was called twice, = new + * I/O is allowed only after drained_end() was called twice, too. + */ + void (*drained_begin)(BdrvChild *child); + void (*drained_end)(BdrvChild *child); + + /* + * Returns whether the parent has pending requests for the child. This + * callback is polled after .drained_begin() has been called until all + * activity on the child has stopped. + */ + bool (*drained_poll)(BdrvChild *child); + /* * Notifies the parent that the filename of its child has changed (e.g. * because the direct child was removed from the backing chain), so th= at it @@ -984,27 +1005,6 @@ 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 - * called. - * - * These functions must not change the graph (and therefore also must = not - * call aio_poll(), which could change the graph indirectly). - * - * Note that this can be nested. If drained_begin() was called twice, = new - * I/O is allowed only after drained_end() was called twice, too. - */ - void (*drained_begin)(BdrvChild *child); - void (*drained_end)(BdrvChild *child); - - /* - * Returns whether the parent has pending requests for the child. This - * callback is polled after .drained_begin() has been called until all - * activity on the child has stopped. - */ - bool (*drained_poll)(BdrvChild *child); }; =20 extern const BdrvChildClass child_of_bds; diff --git a/include/sysemu/block-backend-common.h b/include/sysemu/block-b= ackend-common.h index 2391679c56..780cea7305 100644 --- a/include/sysemu/block-backend-common.h +++ b/include/sysemu/block-backend-common.h @@ -59,6 +59,19 @@ typedef struct BlockDevOps { */ bool (*is_medium_locked)(void *opaque); =20 + /* + * Runs when the backend receives a drain request. + */ + void (*drained_begin)(void *opaque); + /* + * Runs when the backend's last drain request ends. + */ + void (*drained_end)(void *opaque); + /* + * Is the device still busy? + */ + bool (*drained_poll)(void *opaque); + /* * I/O API functions. These functions are thread-safe. * @@ -76,18 +89,6 @@ typedef struct BlockDevOps { * Runs when the size changed (e.g. monitor command block_resize) */ void (*resize_cb)(void *opaque); - /* - * Runs when the backend receives a drain request. - */ - void (*drained_begin)(void *opaque); - /* - * Runs when the backend's last drain request ends. - */ - void (*drained_end)(void *opaque); - /* - * Is the device still busy? - */ - bool (*drained_poll)(void *opaque); } BlockDevOps; =20 /* diff --git a/block/io.c b/block/io.c index 4d54fda593..fece938fd0 100644 --- a/block/io.c +++ b/block/io.c @@ -60,7 +60,7 @@ static void bdrv_parent_drained_begin(BlockDriverState *b= s, BdrvChild *ignore) =20 void bdrv_parent_drained_end_single(BdrvChild *c) { - IO_OR_GS_CODE(); + GLOBAL_STATE_CODE(); =20 assert(c->quiesced_parent); c->quiesced_parent =3D false; @@ -108,7 +108,7 @@ static bool bdrv_parent_drained_poll(BlockDriverState *= bs, BdrvChild *ignore, =20 void bdrv_parent_drained_begin_single(BdrvChild *c) { - IO_OR_GS_CODE(); + GLOBAL_STATE_CODE(); =20 assert(!c->quiesced_parent); c->quiesced_parent =3D true; @@ -247,7 +247,7 @@ typedef struct { bool bdrv_drain_poll(BlockDriverState *bs, BdrvChild *ignore_parent, bool ignore_bds_parents) { - IO_OR_GS_CODE(); + GLOBAL_STATE_CODE(); =20 if (bdrv_parent_drained_poll(bs, ignore_parent, ignore_bds_parents)) { return true; @@ -334,7 +334,8 @@ static void coroutine_fn bdrv_co_yield_to_drain(BlockDr= iverState *bs, if (ctx !=3D co_ctx) { aio_context_release(ctx); } - replay_bh_schedule_oneshot_event(ctx, bdrv_co_drain_bh_cb, &data); + replay_bh_schedule_oneshot_event(qemu_get_aio_context(), + bdrv_co_drain_bh_cb, &data); =20 qemu_coroutine_yield(); /* If we are resumed from some other event (such as an aio completion = or a @@ -357,6 +358,8 @@ static void bdrv_do_drained_begin(BlockDriverState *bs,= BdrvChild *parent, return; } =20 + GLOBAL_STATE_CODE(); + /* Stop things in parent-to-child order */ if (qatomic_fetch_inc(&bs->quiesce_counter) =3D=3D 0) { aio_disable_external(bdrv_get_aio_context(bs)); @@ -399,11 +402,14 @@ static void bdrv_do_drained_end(BlockDriverState *bs,= BdrvChild *parent) { int old_quiesce_counter; =20 + IO_OR_GS_CODE(); + if (qemu_in_coroutine()) { bdrv_co_yield_to_drain(bs, false, parent, false); return; } assert(bs->quiesce_counter > 0); + GLOBAL_STATE_CODE(); =20 /* Re-enable things in child-to-parent order */ old_quiesce_counter =3D qatomic_fetch_dec(&bs->quiesce_counter); diff --git a/tests/unit/test-bdrv-drain.c b/tests/unit/test-bdrv-drain.c index 08bb0f9984..d53a633577 100644 --- a/tests/unit/test-bdrv-drain.c +++ b/tests/unit/test-bdrv-drain.c @@ -483,19 +483,19 @@ struct test_iothread_data { BlockDriverState *bs; enum drain_type drain_type; int *aio_ret; + bool co_done; }; =20 -static void test_iothread_drain_entry(void *opaque) +static void coroutine_fn test_iothread_drain_co_entry(void *opaque) { struct test_iothread_data *data =3D opaque; =20 - aio_context_acquire(bdrv_get_aio_context(data->bs)); do_drain_begin(data->drain_type, data->bs); g_assert_cmpint(*data->aio_ret, =3D=3D, 0); do_drain_end(data->drain_type, data->bs); - aio_context_release(bdrv_get_aio_context(data->bs)); =20 - qemu_event_set(&done_event); + data->co_done =3D true; + aio_wait_kick(); } =20 static void test_iothread_aio_cb(void *opaque, int ret) @@ -531,6 +531,7 @@ static void test_iothread_common(enum drain_type drain_= type, int drain_thread) BlockDriverState *bs; BDRVTestState *s; BlockAIOCB *acb; + Coroutine *co; int aio_ret; struct test_iothread_data data; =20 @@ -609,8 +610,9 @@ static void test_iothread_common(enum drain_type drain_= type, int drain_thread) } break; case 1: - aio_bh_schedule_oneshot(ctx_a, test_iothread_drain_entry, &data); - qemu_event_wait(&done_event); + co =3D qemu_coroutine_create(test_iothread_drain_co_entry, &data); + aio_co_enter(ctx_a, co); + AIO_WAIT_WHILE_UNLOCKED(NULL, !data.co_done); break; default: g_assert_not_reached(); --=20 2.40.1 From nobody Mon May 20 16:32:53 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=1685464474; cv=none; d=zohomail.com; s=zohoarc; b=dUJgUvnHtF4jgk33v7MrumdFjHWCg0FR+GoZ2XVaN/WOPxd7FzO/6wsXXrLOOWSsyGSK2ia7D+OuZd12zXjZjxJ1l4O+HWJOcxW9pMBw3ZXfVXWq5o3eGhFKVcMrjB3D2EIkUNTQ9FZZClAeiSJOMJ8TtFGSUwbeQ0gw/6XlAbQ= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1685464474; 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=E9z+FEehPz6OU7QfHraucw3bgb3i6r0OKmgXfUGJH/Q=; b=SbjVX8kGSgka9b3TC4AJsgDJRS87tdOK9GLUTYudEOuaPIulfuEUwisvPBzegIrsdOLJKQNX2cB/h1sk+FzlzM1TVjRILl1GjJF1RzTZm2PGuO6V3nwp/eBAzcuO8SRksihabruLPur0vS62rBIP9fv7tZkAHjC7kZX0ktgvM/4= 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 1685464474494115.21272713901749; Tue, 30 May 2023 09:34:34 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1q42In-0001iB-2U; Tue, 30 May 2023 12:34:29 -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 1q42Hf-0006uQ-0p for qemu-devel@nongnu.org; Tue, 30 May 2023 12:33:20 -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 1q42Hb-0008S9-2T for qemu-devel@nongnu.org; Tue, 30 May 2023 12:33:17 -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-534--yERHEfBMuaZVpHlcggJ1A-1; Tue, 30 May 2023 12:33:09 -0400 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 EF19C38149A7; Tue, 30 May 2023 16:33:08 +0000 (UTC) Received: from merkur.redhat.com (unknown [10.39.194.4]) by smtp.corp.redhat.com (Postfix) with ESMTP id 3EFB4C154D2; Tue, 30 May 2023 16:33:08 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1685464394; 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=E9z+FEehPz6OU7QfHraucw3bgb3i6r0OKmgXfUGJH/Q=; b=EDz5rrNbUlmaGy+rGM8suiQ+IxKbS0veJDgxl82vaPqoUYLAFY3GuUAixkqjKBwXvlAAsM 38AFLZOxxQqY916DEjJUwj1gWnVUQx/tcJzpnvzHX9LwXh33c0ZCDZ++I8+VPzb+0DIhp2 MuMu9RLdce+9Eyqrx8mh5Mve/EZ0dqw= X-MC-Unique: -yERHEfBMuaZVpHlcggJ1A-1 From: Kevin Wolf To: qemu-block@nongnu.org Cc: kwolf@redhat.com, richard.henderson@linaro.org, qemu-devel@nongnu.org Subject: [PULL 23/32] xen-block: implement BlockDevOps->drained_begin() Date: Tue, 30 May 2023 18:32:30 +0200 Message-Id: <20230530163239.576632-24-kwolf@redhat.com> In-Reply-To: <20230530163239.576632-1-kwolf@redhat.com> References: <20230530163239.576632-1-kwolf@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.133.124; envelope-from=kwolf@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -22 X-Spam_score: -2.3 X-Spam_bar: -- X-Spam_report: (-2.3 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.167, 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: 1685464475186100007 Content-Type: text/plain; charset="utf-8" From: Stefan Hajnoczi Detach event channels during drained sections to stop I/O submission from the ring. xen-block is no longer reliant on aio_disable_external() after this patch. This will allow us to remove the aio_disable_external() API once all other code that relies on it is converted. Extend xen_device_set_event_channel_context() to allow ctx=3DNULL. The event channel still exists but the event loop does not monitor the file descriptor. Event channel processing can resume by calling xen_device_set_event_channel_context() with a non-NULL ctx. Factor out xen_device_set_event_channel_context() calls in hw/block/dataplane/xen-block.c into attach/detach helper functions. Incidentally, these don't require the AioContext lock because aio_set_fd_handler() is thread-safe. It's safer to register BlockDevOps after the dataplane instance has been created. The BlockDevOps .drained_begin/end() callbacks depend on the dataplane instance, so move the blk_set_dev_ops() call after xen_block_dataplane_create(). Signed-off-by: Stefan Hajnoczi Reviewed-by: Kevin Wolf Message-Id: <20230516190238.8401-12-stefanha@redhat.com> Signed-off-by: Kevin Wolf --- hw/block/dataplane/xen-block.h | 2 ++ hw/block/dataplane/xen-block.c | 42 +++++++++++++++++++++++++--------- hw/block/xen-block.c | 24 ++++++++++++++++--- hw/xen/xen-bus.c | 7 ++++-- 4 files changed, 59 insertions(+), 16 deletions(-) diff --git a/hw/block/dataplane/xen-block.h b/hw/block/dataplane/xen-block.h index 76dcd51c3d..7b8e9df09f 100644 --- a/hw/block/dataplane/xen-block.h +++ b/hw/block/dataplane/xen-block.h @@ -26,5 +26,7 @@ void xen_block_dataplane_start(XenBlockDataPlane *datapla= ne, unsigned int protocol, Error **errp); void xen_block_dataplane_stop(XenBlockDataPlane *dataplane); +void xen_block_dataplane_attach(XenBlockDataPlane *dataplane); +void xen_block_dataplane_detach(XenBlockDataPlane *dataplane); =20 #endif /* HW_BLOCK_DATAPLANE_XEN_BLOCK_H */ diff --git a/hw/block/dataplane/xen-block.c b/hw/block/dataplane/xen-block.c index d8bc39d359..2597f38805 100644 --- a/hw/block/dataplane/xen-block.c +++ b/hw/block/dataplane/xen-block.c @@ -664,6 +664,30 @@ void xen_block_dataplane_destroy(XenBlockDataPlane *da= taplane) g_free(dataplane); } =20 +void xen_block_dataplane_detach(XenBlockDataPlane *dataplane) +{ + if (!dataplane || !dataplane->event_channel) { + return; + } + + /* Only reason for failure is a NULL channel */ + xen_device_set_event_channel_context(dataplane->xendev, + dataplane->event_channel, + NULL, &error_abort); +} + +void xen_block_dataplane_attach(XenBlockDataPlane *dataplane) +{ + if (!dataplane || !dataplane->event_channel) { + return; + } + + /* Only reason for failure is a NULL channel */ + xen_device_set_event_channel_context(dataplane->xendev, + dataplane->event_channel, + dataplane->ctx, &error_abort); +} + void xen_block_dataplane_stop(XenBlockDataPlane *dataplane) { XenDevice *xendev; @@ -674,13 +698,11 @@ void xen_block_dataplane_stop(XenBlockDataPlane *data= plane) =20 xendev =3D dataplane->xendev; =20 - aio_context_acquire(dataplane->ctx); - if (dataplane->event_channel) { - /* Only reason for failure is a NULL channel */ - xen_device_set_event_channel_context(xendev, dataplane->event_chan= nel, - qemu_get_aio_context(), - &error_abort); + if (!blk_in_drain(dataplane->blk)) { + xen_block_dataplane_detach(dataplane); } + + aio_context_acquire(dataplane->ctx); /* Xen doesn't have multiple users for nodes, so this can't fail */ blk_set_aio_context(dataplane->blk, qemu_get_aio_context(), &error_abo= rt); aio_context_release(dataplane->ctx); @@ -819,11 +841,9 @@ void xen_block_dataplane_start(XenBlockDataPlane *data= plane, blk_set_aio_context(dataplane->blk, dataplane->ctx, NULL); aio_context_release(old_context); =20 - /* Only reason for failure is a NULL channel */ - aio_context_acquire(dataplane->ctx); - xen_device_set_event_channel_context(xendev, dataplane->event_channel, - dataplane->ctx, &error_abort); - aio_context_release(dataplane->ctx); + if (!blk_in_drain(dataplane->blk)) { + xen_block_dataplane_attach(dataplane); + } =20 return; =20 diff --git a/hw/block/xen-block.c b/hw/block/xen-block.c index f5a744589d..f099914831 100644 --- a/hw/block/xen-block.c +++ b/hw/block/xen-block.c @@ -189,8 +189,26 @@ static void xen_block_resize_cb(void *opaque) xen_device_backend_printf(xendev, "state", "%u", state); } =20 +/* Suspend request handling */ +static void xen_block_drained_begin(void *opaque) +{ + XenBlockDevice *blockdev =3D opaque; + + xen_block_dataplane_detach(blockdev->dataplane); +} + +/* Resume request handling */ +static void xen_block_drained_end(void *opaque) +{ + XenBlockDevice *blockdev =3D opaque; + + xen_block_dataplane_attach(blockdev->dataplane); +} + static const BlockDevOps xen_block_dev_ops =3D { - .resize_cb =3D xen_block_resize_cb, + .resize_cb =3D xen_block_resize_cb, + .drained_begin =3D xen_block_drained_begin, + .drained_end =3D xen_block_drained_end, }; =20 static void xen_block_realize(XenDevice *xendev, Error **errp) @@ -242,8 +260,6 @@ static void xen_block_realize(XenDevice *xendev, Error = **errp) return; } =20 - blk_set_dev_ops(blk, &xen_block_dev_ops, blockdev); - if (conf->discard_granularity =3D=3D -1) { conf->discard_granularity =3D conf->physical_block_size; } @@ -277,6 +293,8 @@ static void xen_block_realize(XenDevice *xendev, Error = **errp) blockdev->dataplane =3D xen_block_dataplane_create(xendev, blk, conf->logical_block_size, blockdev->props.iothread); + + blk_set_dev_ops(blk, &xen_block_dev_ops, blockdev); } =20 static void xen_block_frontend_changed(XenDevice *xendev, diff --git a/hw/xen/xen-bus.c b/hw/xen/xen-bus.c index c59850b1de..b8f408c9ed 100644 --- a/hw/xen/xen-bus.c +++ b/hw/xen/xen-bus.c @@ -846,8 +846,11 @@ void xen_device_set_event_channel_context(XenDevice *x= endev, NULL, NULL, NULL, NULL, NULL); =20 channel->ctx =3D ctx; - aio_set_fd_handler(channel->ctx, qemu_xen_evtchn_fd(channel->xeh), tru= e, - xen_device_event, NULL, xen_device_poll, NULL, chan= nel); + if (ctx) { + aio_set_fd_handler(channel->ctx, qemu_xen_evtchn_fd(channel->xeh), + true, xen_device_event, NULL, xen_device_poll, = NULL, + channel); + } } =20 XenEventChannel *xen_device_bind_event_channel(XenDevice *xendev, --=20 2.40.1 From nobody Mon May 20 16:32:53 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=1685464743; cv=none; d=zohomail.com; s=zohoarc; b=XMtgunaom138xy8GJPeHrQsi5WMp4lCE4Jz5HwUDD/M4fwl+toaXYcRso2/izXXU3Cx2zbndK0DqoKx7kRXsgXPXRJzaS6iW7aCtMaFkpemmmG0BzDZEghgWBabX3fl/Y5rDd1LiZpDUXSbwXYX9PWwWIufxAwW9gp+QA5K6pJc= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1685464743; 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=ExzAkJGSgKT5OEuRFnQWS9iV88KNwjYJ5+s/1yKs2K4=; b=B4dj2useNMRVLXp31TjsRE7fE4rvdzRk+AA1oluik9Xc/4k0JYhFCvrV8HfoI9Uzgu643IgrDkbT/LxOfgXonhTlrz+2R+m2IGpmuWsDvKhvS4btPbZkVTzrYE3K3aGZpwJQZbA0LCIzpkWoMdmxLIf034zhz+VaHqDF9iBVH24= 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 16854647431258.02210411104636; Tue, 30 May 2023 09:39:03 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1q42Ij-0001Bs-W6; Tue, 30 May 2023 12:34:26 -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 1q42Hd-0006sZ-2m for qemu-devel@nongnu.org; Tue, 30 May 2023 12:33:20 -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 1q42Ha-0008Ry-SM for qemu-devel@nongnu.org; Tue, 30 May 2023 12:33:16 -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-400-e3-uDZB1MI2xnL7E8JimRw-1; Tue, 30 May 2023 12:33:10 -0400 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 DF4B6800969; Tue, 30 May 2023 16:33:09 +0000 (UTC) Received: from merkur.redhat.com (unknown [10.39.194.4]) by smtp.corp.redhat.com (Postfix) with ESMTP id 33791C154D2; Tue, 30 May 2023 16:33:09 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1685464393; 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=ExzAkJGSgKT5OEuRFnQWS9iV88KNwjYJ5+s/1yKs2K4=; b=gG8TtAMrs5dW8a3oFaov1WKqEU4/85dD62j+YB02c29grydJ/5g9zWsf8N5jm6DzkL5RG4 Dg8gWcJlWIwpSPbdKt5g7ae/69I0rqrbIUg/eeQ7LWWqIYV0+CRbE+vLAxRIx9agDBJslI mM41dJiGIwu4QAylT5AyF6AXV9vsBv8= X-MC-Unique: e3-uDZB1MI2xnL7E8JimRw-1 From: Kevin Wolf To: qemu-block@nongnu.org Cc: kwolf@redhat.com, richard.henderson@linaro.org, qemu-devel@nongnu.org Subject: [PULL 24/32] hw/xen: do not set is_external=true on evtchn fds Date: Tue, 30 May 2023 18:32:31 +0200 Message-Id: <20230530163239.576632-25-kwolf@redhat.com> In-Reply-To: <20230530163239.576632-1-kwolf@redhat.com> References: <20230530163239.576632-1-kwolf@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.133.124; envelope-from=kwolf@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -22 X-Spam_score: -2.3 X-Spam_bar: -- X-Spam_report: (-2.3 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.167, 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: 1685464744856100003 Content-Type: text/plain; charset="utf-8" From: Stefan Hajnoczi is_external=3Dtrue suspends fd handlers between aio_disable_external() and aio_enable_external(). The block layer's drain operation uses this mechanism to prevent new I/O from sneaking in between bdrv_drained_begin() and bdrv_drained_end(). The previous commit converted the xen-block device to use BlockDevOps .drained_begin/end() callbacks. It no longer relies on is_external=3Dtrue so it is safe to pass is_external=3Dfalse. This is part of ongoing work to remove the aio_disable_external() API. Signed-off-by: Stefan Hajnoczi Reviewed-by: Kevin Wolf Message-Id: <20230516190238.8401-13-stefanha@redhat.com> Signed-off-by: Kevin Wolf --- hw/xen/xen-bus.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/hw/xen/xen-bus.c b/hw/xen/xen-bus.c index b8f408c9ed..bf256d4da2 100644 --- a/hw/xen/xen-bus.c +++ b/hw/xen/xen-bus.c @@ -842,14 +842,14 @@ void xen_device_set_event_channel_context(XenDevice *= xendev, } =20 if (channel->ctx) - aio_set_fd_handler(channel->ctx, qemu_xen_evtchn_fd(channel->xeh),= true, + aio_set_fd_handler(channel->ctx, qemu_xen_evtchn_fd(channel->xeh),= false, NULL, NULL, NULL, NULL, NULL); =20 channel->ctx =3D ctx; if (ctx) { aio_set_fd_handler(channel->ctx, qemu_xen_evtchn_fd(channel->xeh), - true, xen_device_event, NULL, xen_device_poll, = NULL, - channel); + false, xen_device_event, NULL, xen_device_poll, + NULL, channel); } } =20 @@ -923,7 +923,7 @@ void xen_device_unbind_event_channel(XenDevice *xendev, =20 QLIST_REMOVE(channel, list); =20 - aio_set_fd_handler(channel->ctx, qemu_xen_evtchn_fd(channel->xeh), tru= e, + aio_set_fd_handler(channel->ctx, qemu_xen_evtchn_fd(channel->xeh), fal= se, NULL, NULL, NULL, NULL, NULL); =20 if (qemu_xen_evtchn_unbind(channel->xeh, channel->local_port) < 0) { --=20 2.40.1 From nobody Mon May 20 16:32:53 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=1685464543; cv=none; d=zohomail.com; s=zohoarc; b=DJayybSa7r5YLqPxEIDoVVhcvOhVV7ooELNIrZ3WxrF9ZE+T4Ire2fcKAH5g1um/LyxuXazeEzHdF4/E6LPUEY5v3Ho9ZUlIQU04ojXuYUAkvsGig60/M4jvXKF//zpW3BDYCHf4248RzQYsh1lW6RqGM/ZmBt917JoqQ419X5g= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1685464543; 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=sM8CqCJfymg0LztUUAinTRoTzulNqxCG6biluR1gPT8=; b=Bs/zGjNuNkaL9QGCZB2Y+C4QCRUNykgoXc8bRwm315cEtBJydI9FP+qLNMGlxgRu2u5EDnw6LdU5WwClfhee/5MGhCEkBMGnOd+vsB/kfSeqsogVJOJ5Gyf36B0Gi2xugTMOtq5TBgSAEI6nxRLrFILk91kxLLFYzQC4SFemuxY= 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 1685464543677707.3248539423997; Tue, 30 May 2023 09:35:43 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1q42IF-0008MD-VC; Tue, 30 May 2023 12:33:56 -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 1q42Hf-0006ua-H9 for qemu-devel@nongnu.org; Tue, 30 May 2023 12:33:20 -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 1q42Hc-0008TD-Nh for qemu-devel@nongnu.org; Tue, 30 May 2023 12:33:19 -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-561-eSBDAEjZNGC-hrRCvwfl-w-1; Tue, 30 May 2023 12:33:11 -0400 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 D06AE3C025C6; Tue, 30 May 2023 16:33:10 +0000 (UTC) Received: from merkur.redhat.com (unknown [10.39.194.4]) by smtp.corp.redhat.com (Postfix) with ESMTP id 228C6C154D2; Tue, 30 May 2023 16:33:10 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1685464395; 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=sM8CqCJfymg0LztUUAinTRoTzulNqxCG6biluR1gPT8=; b=CWR1HKsWXdOULtMf75LCOxIzw2A3VUU94L+Umq244mHV8zSm5pQeYmwEmsJifyGbtDwzPF bdvzhQqT03hefRzoaS9Av3kcpiGM0wSz7CgpdFYpMw1uMTDPUXGb6g8Lx14CETu6jahd9Y 1UN0LSNAXp24kPFc7lsPUACX6ezuscs= X-MC-Unique: eSBDAEjZNGC-hrRCvwfl-w-1 From: Kevin Wolf To: qemu-block@nongnu.org Cc: kwolf@redhat.com, richard.henderson@linaro.org, qemu-devel@nongnu.org Subject: [PULL 25/32] block/export: rewrite vduse-blk drain code Date: Tue, 30 May 2023 18:32:32 +0200 Message-Id: <20230530163239.576632-26-kwolf@redhat.com> In-Reply-To: <20230530163239.576632-1-kwolf@redhat.com> References: <20230530163239.576632-1-kwolf@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=kwolf@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -22 X-Spam_score: -2.3 X-Spam_bar: -- X-Spam_report: (-2.3 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.167, 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: 1685464545341100003 Content-Type: text/plain; charset="utf-8" From: Stefan Hajnoczi vduse_blk_detach_ctx() waits for in-flight requests using AIO_WAIT_WHILE(). This is not allowed according to a comment in bdrv_set_aio_context_commit(): /* * Take the old AioContex when detaching it from bs. * At this point, new_context lock is already acquired, and we are now * also taking old_context. This is safe as long as bdrv_detach_aio_conte= xt * does not call AIO_POLL_WHILE(). */ Use this opportunity to rewrite the drain code in vduse-blk: - Use the BlockExport refcount so that vduse_blk_exp_delete() is only called when there are no more requests in flight. - Implement .drained_poll() so in-flight request coroutines are stopped by the time .bdrv_detach_aio_context() is called. - Remove AIO_WAIT_WHILE() from vduse_blk_detach_ctx() to solve the .bdrv_detach_aio_context() constraint violation. It's no longer needed due to the previous changes. - Always handle the VDUSE file descriptor, even in drained sections. The VDUSE file descriptor doesn't submit I/O, so it's safe to handle it in drained sections. This ensures that the VDUSE kernel code gets a fast response. - Suspend virtqueue fd handlers in .drained_begin() and resume them in .drained_end(). This eliminates the need for the aio_set_fd_handler(is_external=3Dtrue) flag, which is being removed from QEMU. This is a long list but splitting it into individual commits would probably lead to git bisect failures - the changes are all related. Signed-off-by: Stefan Hajnoczi Reviewed-by: Kevin Wolf Message-Id: <20230516190238.8401-14-stefanha@redhat.com> Signed-off-by: Kevin Wolf --- block/export/vduse-blk.c | 132 +++++++++++++++++++++++++++------------ 1 file changed, 93 insertions(+), 39 deletions(-) diff --git a/block/export/vduse-blk.c b/block/export/vduse-blk.c index b53ef39da0..a25556fe04 100644 --- a/block/export/vduse-blk.c +++ b/block/export/vduse-blk.c @@ -31,7 +31,8 @@ typedef struct VduseBlkExport { VduseDev *dev; uint16_t num_queues; char *recon_file; - unsigned int inflight; + unsigned int inflight; /* atomic */ + bool vqs_started; } VduseBlkExport; =20 typedef struct VduseBlkReq { @@ -41,13 +42,24 @@ typedef struct VduseBlkReq { =20 static void vduse_blk_inflight_inc(VduseBlkExport *vblk_exp) { - vblk_exp->inflight++; + if (qatomic_fetch_inc(&vblk_exp->inflight) =3D=3D 0) { + /* Prevent export from being deleted */ + aio_context_acquire(vblk_exp->export.ctx); + blk_exp_ref(&vblk_exp->export); + aio_context_release(vblk_exp->export.ctx); + } } =20 static void vduse_blk_inflight_dec(VduseBlkExport *vblk_exp) { - if (--vblk_exp->inflight =3D=3D 0) { + if (qatomic_fetch_dec(&vblk_exp->inflight) =3D=3D 1) { + /* Wake AIO_WAIT_WHILE() */ aio_wait_kick(); + + /* Now the export can be deleted */ + aio_context_acquire(vblk_exp->export.ctx); + blk_exp_unref(&vblk_exp->export); + aio_context_release(vblk_exp->export.ctx); } } =20 @@ -124,8 +136,12 @@ static void vduse_blk_enable_queue(VduseDev *dev, Vdus= eVirtq *vq) { VduseBlkExport *vblk_exp =3D vduse_dev_get_priv(dev); =20 + if (!vblk_exp->vqs_started) { + return; /* vduse_blk_drained_end() will start vqs later */ + } + aio_set_fd_handler(vblk_exp->export.ctx, vduse_queue_get_fd(vq), - true, on_vduse_vq_kick, NULL, NULL, NULL, vq); + false, on_vduse_vq_kick, NULL, NULL, NULL, vq); /* Make sure we don't miss any kick afer reconnecting */ eventfd_write(vduse_queue_get_fd(vq), 1); } @@ -133,9 +149,14 @@ static void vduse_blk_enable_queue(VduseDev *dev, Vdus= eVirtq *vq) static void vduse_blk_disable_queue(VduseDev *dev, VduseVirtq *vq) { VduseBlkExport *vblk_exp =3D vduse_dev_get_priv(dev); + int fd =3D vduse_queue_get_fd(vq); =20 - aio_set_fd_handler(vblk_exp->export.ctx, vduse_queue_get_fd(vq), - true, NULL, NULL, NULL, NULL, NULL); + if (fd < 0) { + return; + } + + aio_set_fd_handler(vblk_exp->export.ctx, fd, false, + NULL, NULL, NULL, NULL, NULL); } =20 static const VduseOps vduse_blk_ops =3D { @@ -152,42 +173,19 @@ static void on_vduse_dev_kick(void *opaque) =20 static void vduse_blk_attach_ctx(VduseBlkExport *vblk_exp, AioContext *ctx) { - int i; - aio_set_fd_handler(vblk_exp->export.ctx, vduse_dev_get_fd(vblk_exp->de= v), - true, on_vduse_dev_kick, NULL, NULL, NULL, + false, on_vduse_dev_kick, NULL, NULL, NULL, vblk_exp->dev); =20 - for (i =3D 0; i < vblk_exp->num_queues; i++) { - VduseVirtq *vq =3D vduse_dev_get_queue(vblk_exp->dev, i); - int fd =3D vduse_queue_get_fd(vq); - - if (fd < 0) { - continue; - } - aio_set_fd_handler(vblk_exp->export.ctx, fd, true, - on_vduse_vq_kick, NULL, NULL, NULL, vq); - } + /* Virtqueues are handled by vduse_blk_drained_end() */ } =20 static void vduse_blk_detach_ctx(VduseBlkExport *vblk_exp) { - int i; - - for (i =3D 0; i < vblk_exp->num_queues; i++) { - VduseVirtq *vq =3D vduse_dev_get_queue(vblk_exp->dev, i); - int fd =3D vduse_queue_get_fd(vq); - - if (fd < 0) { - continue; - } - aio_set_fd_handler(vblk_exp->export.ctx, fd, - true, NULL, NULL, NULL, NULL, NULL); - } aio_set_fd_handler(vblk_exp->export.ctx, vduse_dev_get_fd(vblk_exp->de= v), - true, NULL, NULL, NULL, NULL, NULL); + false, NULL, NULL, NULL, NULL, NULL); =20 - AIO_WAIT_WHILE(vblk_exp->export.ctx, vblk_exp->inflight > 0); + /* Virtqueues are handled by vduse_blk_drained_begin() */ } =20 =20 @@ -220,8 +218,55 @@ static void vduse_blk_resize(void *opaque) (char *)&config.capacity); } =20 +static void vduse_blk_stop_virtqueues(VduseBlkExport *vblk_exp) +{ + for (uint16_t i =3D 0; i < vblk_exp->num_queues; i++) { + VduseVirtq *vq =3D vduse_dev_get_queue(vblk_exp->dev, i); + vduse_blk_disable_queue(vblk_exp->dev, vq); + } + + vblk_exp->vqs_started =3D false; +} + +static void vduse_blk_start_virtqueues(VduseBlkExport *vblk_exp) +{ + vblk_exp->vqs_started =3D true; + + for (uint16_t i =3D 0; i < vblk_exp->num_queues; i++) { + VduseVirtq *vq =3D vduse_dev_get_queue(vblk_exp->dev, i); + vduse_blk_enable_queue(vblk_exp->dev, vq); + } +} + +static void vduse_blk_drained_begin(void *opaque) +{ + BlockExport *exp =3D opaque; + VduseBlkExport *vblk_exp =3D container_of(exp, VduseBlkExport, export); + + vduse_blk_stop_virtqueues(vblk_exp); +} + +static void vduse_blk_drained_end(void *opaque) +{ + BlockExport *exp =3D opaque; + VduseBlkExport *vblk_exp =3D container_of(exp, VduseBlkExport, export); + + vduse_blk_start_virtqueues(vblk_exp); +} + +static bool vduse_blk_drained_poll(void *opaque) +{ + BlockExport *exp =3D opaque; + VduseBlkExport *vblk_exp =3D container_of(exp, VduseBlkExport, export); + + return qatomic_read(&vblk_exp->inflight) > 0; +} + static const BlockDevOps vduse_block_ops =3D { - .resize_cb =3D vduse_blk_resize, + .resize_cb =3D vduse_blk_resize, + .drained_begin =3D vduse_blk_drained_begin, + .drained_end =3D vduse_blk_drained_end, + .drained_poll =3D vduse_blk_drained_poll, }; =20 static int vduse_blk_exp_create(BlockExport *exp, BlockExportOptions *opts, @@ -268,6 +313,7 @@ static int vduse_blk_exp_create(BlockExport *exp, Block= ExportOptions *opts, vblk_exp->handler.serial =3D g_strdup(vblk_opts->serial ?: ""); vblk_exp->handler.logical_block_size =3D logical_block_size; vblk_exp->handler.writable =3D opts->writable; + vblk_exp->vqs_started =3D true; =20 config.capacity =3D cpu_to_le64(blk_getlength(exp->blk) >> VIRTIO_BLK_SECTOR_BITS); @@ -322,14 +368,20 @@ static int vduse_blk_exp_create(BlockExport *exp, Blo= ckExportOptions *opts, vduse_dev_setup_queue(vblk_exp->dev, i, queue_size); } =20 - aio_set_fd_handler(exp->ctx, vduse_dev_get_fd(vblk_exp->dev), true, + aio_set_fd_handler(exp->ctx, vduse_dev_get_fd(vblk_exp->dev), false, on_vduse_dev_kick, NULL, NULL, NULL, vblk_exp->dev); =20 blk_add_aio_context_notifier(exp->blk, blk_aio_attached, blk_aio_detac= h, vblk_exp); - blk_set_dev_ops(exp->blk, &vduse_block_ops, exp); =20 + /* + * We handle draining ourselves using an in-flight counter and by disa= bling + * virtqueue fd handlers. Do not queue BlockBackend requests, they nee= d to + * complete so the in-flight counter reaches zero. + */ + blk_set_disable_request_queuing(exp->blk, true); + return 0; err: vduse_dev_destroy(vblk_exp->dev); @@ -344,6 +396,9 @@ static void vduse_blk_exp_delete(BlockExport *exp) VduseBlkExport *vblk_exp =3D container_of(exp, VduseBlkExport, export); int ret; =20 + assert(qatomic_read(&vblk_exp->inflight) =3D=3D 0); + + vduse_blk_detach_ctx(vblk_exp); blk_remove_aio_context_notifier(exp->blk, blk_aio_attached, blk_aio_de= tach, vblk_exp); ret =3D vduse_dev_destroy(vblk_exp->dev); @@ -354,13 +409,12 @@ static void vduse_blk_exp_delete(BlockExport *exp) g_free(vblk_exp->handler.serial); } =20 +/* Called with exp->ctx acquired */ static void vduse_blk_exp_request_shutdown(BlockExport *exp) { VduseBlkExport *vblk_exp =3D container_of(exp, VduseBlkExport, export); =20 - aio_context_acquire(vblk_exp->export.ctx); - vduse_blk_detach_ctx(vblk_exp); - aio_context_acquire(vblk_exp->export.ctx); + vduse_blk_stop_virtqueues(vblk_exp); } =20 const BlockExportDriver blk_exp_vduse_blk =3D { --=20 2.40.1 From nobody Mon May 20 16:32:53 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=1685464467; cv=none; d=zohomail.com; s=zohoarc; b=eFWdf2NJfYhOOhNVYEjnGaGDsh9nsU23oWemiQ544vB+kJIRrQTy1sFvbkrZ0wM1coXo+/1hyQP2c6+uHZwSUuTpf52k8G4+jz5BhgMvyxM12DkM3IyB4X2gfl/piG+x6o7LXKGLfS/kT1zo2RxCNomTivO75Fy2KerNwqwcNfs= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1685464467; 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=wWZBE4LInGOpo4wFASMu39cjfstx1Z2V5hY1HfMK5JU=; b=XmPRtGtFbysXmL31fDJr0mUoWZjnvNBK1nXBa6e6KEWEIHZUuL9GosicSHaUko0b6l9q84yWd8JYzc4pgbKCGeGW0Joj/hAo9soDL7cIDahPnalWFupKCfbvB9Tpv9BZxFiCZGH8D9DgTRhsg7y0taSiVqtXFpsq3FHXxSbwVRk= 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 168546446777458.56729827691197; Tue, 30 May 2023 09:34:27 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1q42IE-0008CZ-PX; Tue, 30 May 2023 12:33: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 1q42Hd-0006sa-1u for qemu-devel@nongnu.org; Tue, 30 May 2023 12:33:20 -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 1q42Ha-0008Ro-Rw for qemu-devel@nongnu.org; Tue, 30 May 2023 12:33:16 -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-397-CiYiDmpSNQSZi-dSsAUoDg-1; Tue, 30 May 2023 12:33:12 -0400 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 BF2FC28EC101; Tue, 30 May 2023 16:33:11 +0000 (UTC) Received: from merkur.redhat.com (unknown [10.39.194.4]) by smtp.corp.redhat.com (Postfix) with ESMTP id 13B8DC154D2; Tue, 30 May 2023 16:33:10 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1685464393; 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=wWZBE4LInGOpo4wFASMu39cjfstx1Z2V5hY1HfMK5JU=; b=ffWpktXjd3t9RA6sJOovQOcaupzEKYnVDYGawVE/wQXNBuKPPEyemKW3ckn+mm/pjGZRfN 7UdC93ckP+lOT+3pTm8KhZ6Srslt4Z9uH5xhdX+/RIsCJ61QEBhV/+9TpejZUetbdoF+96 19EaHe/L1SmKiM5T/cb4w1333hHaGTA= X-MC-Unique: CiYiDmpSNQSZi-dSsAUoDg-1 From: Kevin Wolf To: qemu-block@nongnu.org Cc: kwolf@redhat.com, richard.henderson@linaro.org, qemu-devel@nongnu.org Subject: [PULL 26/32] block/export: don't require AioContext lock around blk_exp_ref/unref() Date: Tue, 30 May 2023 18:32:33 +0200 Message-Id: <20230530163239.576632-27-kwolf@redhat.com> In-Reply-To: <20230530163239.576632-1-kwolf@redhat.com> References: <20230530163239.576632-1-kwolf@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=kwolf@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -22 X-Spam_score: -2.3 X-Spam_bar: -- X-Spam_report: (-2.3 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.167, 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: 1685464469193100003 Content-Type: text/plain; charset="utf-8" From: Stefan Hajnoczi The FUSE export calls blk_exp_ref/unref() without the AioContext lock. Instead of fixing the FUSE export, adjust blk_exp_ref/unref() so they work without the AioContext lock. This way it's less error-prone. Suggested-by: Paolo Bonzini Signed-off-by: Stefan Hajnoczi Reviewed-by: Kevin Wolf Message-Id: <20230516190238.8401-15-stefanha@redhat.com> Signed-off-by: Kevin Wolf --- include/block/export.h | 2 ++ block/export/export.c | 13 ++++++------- block/export/vduse-blk.c | 4 ---- 3 files changed, 8 insertions(+), 11 deletions(-) diff --git a/include/block/export.h b/include/block/export.h index 7feb02e10d..f2fe0f8078 100644 --- a/include/block/export.h +++ b/include/block/export.h @@ -57,6 +57,8 @@ struct BlockExport { * Reference count for this block export. This includes strong referen= ces * both from the owner (qemu-nbd or the monitor) and clients connected= to * the export. + * + * Use atomics to access this field. */ int refcount; =20 diff --git a/block/export/export.c b/block/export/export.c index a5c8f42f53..10316b43c5 100644 --- a/block/export/export.c +++ b/block/export/export.c @@ -204,11 +204,10 @@ fail: return NULL; } =20 -/* Callers must hold exp->ctx lock */ void blk_exp_ref(BlockExport *exp) { - assert(exp->refcount > 0); - exp->refcount++; + assert(qatomic_read(&exp->refcount) > 0); + qatomic_inc(&exp->refcount); } =20 /* Runs in the main thread */ @@ -231,11 +230,10 @@ static void blk_exp_delete_bh(void *opaque) aio_context_release(aio_context); } =20 -/* Callers must hold exp->ctx lock */ void blk_exp_unref(BlockExport *exp) { - assert(exp->refcount > 0); - if (--exp->refcount =3D=3D 0) { + assert(qatomic_read(&exp->refcount) > 0); + if (qatomic_fetch_dec(&exp->refcount) =3D=3D 1) { /* Touch the block_exports list only in the main thread */ aio_bh_schedule_oneshot(qemu_get_aio_context(), blk_exp_delete_bh, exp); @@ -343,7 +341,8 @@ void qmp_block_export_del(const char *id, if (!has_mode) { mode =3D BLOCK_EXPORT_REMOVE_MODE_SAFE; } - if (mode =3D=3D BLOCK_EXPORT_REMOVE_MODE_SAFE && exp->refcount > 1) { + if (mode =3D=3D BLOCK_EXPORT_REMOVE_MODE_SAFE && + qatomic_read(&exp->refcount) > 1) { error_setg(errp, "export '%s' still in use", exp->id); error_append_hint(errp, "Use mode=3D'hard' to force client " "disconnect\n"); diff --git a/block/export/vduse-blk.c b/block/export/vduse-blk.c index a25556fe04..e0455551f9 100644 --- a/block/export/vduse-blk.c +++ b/block/export/vduse-blk.c @@ -44,9 +44,7 @@ static void vduse_blk_inflight_inc(VduseBlkExport *vblk_e= xp) { if (qatomic_fetch_inc(&vblk_exp->inflight) =3D=3D 0) { /* Prevent export from being deleted */ - aio_context_acquire(vblk_exp->export.ctx); blk_exp_ref(&vblk_exp->export); - aio_context_release(vblk_exp->export.ctx); } } =20 @@ -57,9 +55,7 @@ static void vduse_blk_inflight_dec(VduseBlkExport *vblk_e= xp) aio_wait_kick(); =20 /* Now the export can be deleted */ - aio_context_acquire(vblk_exp->export.ctx); blk_exp_unref(&vblk_exp->export); - aio_context_release(vblk_exp->export.ctx); } } =20 --=20 2.40.1 From nobody Mon May 20 16:32:53 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=1685464886; cv=none; d=zohomail.com; s=zohoarc; b=mlMGqU7kaT/1vlJ7TZMsSlSDxaAaL0+3qRvQjrvrw9v+QK0ur7B8nVtph+Dykbcx7rRC1G5KgVI2efZ9URnm7QVzm+P6HNAJDi5ZYWxC5CceaZ3fugRKSTJcic0AXqPPt7Pi5VZ3Oxt0/zywhTNQUffQ1DJhBc4izUd/jrk60lo= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1685464886; 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=V82ObSnJng8kkgMQahT0glEPa1kDj9jXvd5kuFAN8yA=; b=P5yN1KZVMR2Q3UdwyCnzGeSH7dnwH4q9hoE6k/SxfWXYKJkyQyrHRE3TYzuxnDBjWofjvzgKUYFufGPdzyQOTpkpeqRU6Z+PtDl1+wFfL2fvr9KjAgB10Dnv7ng7eB6fpUNVxBrvB97fL61Yh3mcMmkuBRa2fEuoXYia4T+4lcs= 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 1685464886891844.5996844781348; Tue, 30 May 2023 09:41:26 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1q42Iq-0002C2-Ft; Tue, 30 May 2023 12:34: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 1q42Hh-0006xF-Oz for qemu-devel@nongnu.org; Tue, 30 May 2023 12:33:28 -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 1q42He-0008Ta-OL for qemu-devel@nongnu.org; Tue, 30 May 2023 12:33:21 -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-624-ps7tSLSwMuquukPpXvDsTA-1; Tue, 30 May 2023 12:33:13 -0400 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 AEC101C01E95; Tue, 30 May 2023 16:33:12 +0000 (UTC) Received: from merkur.redhat.com (unknown [10.39.194.4]) by smtp.corp.redhat.com (Postfix) with ESMTP id 033D4C15612; Tue, 30 May 2023 16:33:11 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1685464396; 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=V82ObSnJng8kkgMQahT0glEPa1kDj9jXvd5kuFAN8yA=; b=ZFo/mDCIjrNWUH6GfxzLBfLUvPRF00QIw/lyICaPyF8J39Z8lhQf95BQAwNBRmzbNL4SV+ vgy1QYC3LHhQyWQRBDE+maquQxJHDrmh6t5i64K3GuEYD0IwVJBdQEKr1CfvOUu2ZYooWE jXwBYyM58DJ/n7OU0sSlIlIdHXmGAD0= X-MC-Unique: ps7tSLSwMuquukPpXvDsTA-1 From: Kevin Wolf To: qemu-block@nongnu.org Cc: kwolf@redhat.com, richard.henderson@linaro.org, qemu-devel@nongnu.org Subject: [PULL 27/32] block/fuse: do not set is_external=true on FUSE fd Date: Tue, 30 May 2023 18:32:34 +0200 Message-Id: <20230530163239.576632-28-kwolf@redhat.com> In-Reply-To: <20230530163239.576632-1-kwolf@redhat.com> References: <20230530163239.576632-1-kwolf@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.133.124; envelope-from=kwolf@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -22 X-Spam_score: -2.3 X-Spam_bar: -- X-Spam_report: (-2.3 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.167, 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: 1685464887716100003 Content-Type: text/plain; charset="utf-8" From: Stefan Hajnoczi This is part of ongoing work to remove the aio_disable_external() API. Use BlockDevOps .drained_begin/end/poll() instead of aio_set_fd_handler(is_external=3Dtrue). As a side-effect the FUSE export now follows AioContext changes like the other export types. Signed-off-by: Stefan Hajnoczi Reviewed-by: Kevin Wolf Message-Id: <20230516190238.8401-16-stefanha@redhat.com> Signed-off-by: Kevin Wolf --- block/export/fuse.c | 56 +++++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 54 insertions(+), 2 deletions(-) diff --git a/block/export/fuse.c b/block/export/fuse.c index 06fa41079e..adf3236b5a 100644 --- a/block/export/fuse.c +++ b/block/export/fuse.c @@ -50,6 +50,7 @@ typedef struct FuseExport { =20 struct fuse_session *fuse_session; struct fuse_buf fuse_buf; + unsigned int in_flight; /* atomic */ bool mounted, fd_handler_set_up; =20 char *mountpoint; @@ -78,6 +79,42 @@ static void read_from_fuse_export(void *opaque); static bool is_regular_file(const char *path, Error **errp); =20 =20 +static void fuse_export_drained_begin(void *opaque) +{ + FuseExport *exp =3D opaque; + + aio_set_fd_handler(exp->common.ctx, + fuse_session_fd(exp->fuse_session), false, + NULL, NULL, NULL, NULL, NULL); + exp->fd_handler_set_up =3D false; +} + +static void fuse_export_drained_end(void *opaque) +{ + FuseExport *exp =3D opaque; + + /* Refresh AioContext in case it changed */ + exp->common.ctx =3D blk_get_aio_context(exp->common.blk); + + aio_set_fd_handler(exp->common.ctx, + fuse_session_fd(exp->fuse_session), false, + read_from_fuse_export, NULL, NULL, NULL, exp); + exp->fd_handler_set_up =3D true; +} + +static bool fuse_export_drained_poll(void *opaque) +{ + FuseExport *exp =3D opaque; + + return qatomic_read(&exp->in_flight) > 0; +} + +static const BlockDevOps fuse_export_blk_dev_ops =3D { + .drained_begin =3D fuse_export_drained_begin, + .drained_end =3D fuse_export_drained_end, + .drained_poll =3D fuse_export_drained_poll, +}; + static int fuse_export_create(BlockExport *blk_exp, BlockExportOptions *blk_exp_args, Error **errp) @@ -101,6 +138,15 @@ static int fuse_export_create(BlockExport *blk_exp, } } =20 + blk_set_dev_ops(exp->common.blk, &fuse_export_blk_dev_ops, exp); + + /* + * We handle draining ourselves using an in-flight counter and by disa= bling + * the FUSE fd handler. Do not queue BlockBackend requests, they need = to + * complete so the in-flight counter reaches zero. + */ + blk_set_disable_request_queuing(exp->common.blk, true); + init_exports_table(); =20 /* @@ -224,7 +270,7 @@ static int setup_fuse_export(FuseExport *exp, const cha= r *mountpoint, g_hash_table_insert(exports, g_strdup(mountpoint), NULL); =20 aio_set_fd_handler(exp->common.ctx, - fuse_session_fd(exp->fuse_session), true, + fuse_session_fd(exp->fuse_session), false, read_from_fuse_export, NULL, NULL, NULL, exp); exp->fd_handler_set_up =3D true; =20 @@ -246,6 +292,8 @@ static void read_from_fuse_export(void *opaque) =20 blk_exp_ref(&exp->common); =20 + qatomic_inc(&exp->in_flight); + do { ret =3D fuse_session_receive_buf(exp->fuse_session, &exp->fuse_buf= ); } while (ret =3D=3D -EINTR); @@ -256,6 +304,10 @@ static void read_from_fuse_export(void *opaque) fuse_session_process_buf(exp->fuse_session, &exp->fuse_buf); =20 out: + if (qatomic_fetch_dec(&exp->in_flight) =3D=3D 1) { + aio_wait_kick(); /* wake AIO_WAIT_WHILE() */ + } + blk_exp_unref(&exp->common); } =20 @@ -268,7 +320,7 @@ static void fuse_export_shutdown(BlockExport *blk_exp) =20 if (exp->fd_handler_set_up) { aio_set_fd_handler(exp->common.ctx, - fuse_session_fd(exp->fuse_session), true, + fuse_session_fd(exp->fuse_session), false, NULL, NULL, NULL, NULL, NULL); exp->fd_handler_set_up =3D false; } --=20 2.40.1 From nobody Mon May 20 16:32:53 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=1685464609; cv=none; d=zohomail.com; s=zohoarc; b=PlS0fDSvSDxN8Cg3kb+01w40XFa5klwBufxoAg2LPMzYSIiW0daWrOPektALARFWCWT9p5EMpgAd67UW1WHHFm5JfLRJ14c0uTwIcOB+wfloxD+CCZu0+px4IKVz43ChcfY5aTFqYEkPnvBN4h7pmRCIX/FQ+B7mLT/JXE1MCAs= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1685464609; 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=nJDrUznoYCQG1PNS5ZAcf94x2p7snTAeigQtKar1joI=; b=JfEVieM2DgZWxVjhT4CHtknh2RBQ1ZcX3GxC6jNoE8r9KfSSMRYPEjInJm+xvFe2Felg11qPTM7OHVpCD5OD2LFduL5FYRSoWY/GHbzfxvqZeJBQefoKwzpSqy0w9tu/waxceazG8A6thSQQpV6a8JBvZF7aqFNTnm/rSM1kdDQ= 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 1685464609537831.7300684341479; Tue, 30 May 2023 09:36:49 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1q42Io-0001wn-KU; Tue, 30 May 2023 12:34:30 -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 1q42Hf-0006ub-O5 for qemu-devel@nongnu.org; Tue, 30 May 2023 12:33:20 -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 1q42Hb-0008T7-RY for qemu-devel@nongnu.org; Tue, 30 May 2023 12:33:19 -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-203-DAqEMwObPg2uTP60qgX55g-1; Tue, 30 May 2023 12:33:14 -0400 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 9EAE88027F5; Tue, 30 May 2023 16:33:13 +0000 (UTC) Received: from merkur.redhat.com (unknown [10.39.194.4]) by smtp.corp.redhat.com (Postfix) with ESMTP id E66D2C154D2; Tue, 30 May 2023 16:33:12 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1685464395; 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=nJDrUznoYCQG1PNS5ZAcf94x2p7snTAeigQtKar1joI=; b=SZFldM/EL3cq1iQvwHh/+/F4j0puKc+Pr/vmGHbkFqKw9mjUaJhS1JJwbI8VbYNK1ltEQ4 7VrKR+c/R4LJA1XuMrCYIJ7nWzLOZ3KkiSWwELitKSlLiuJK2kvGtphuDfBSzj7OUhwGkc 4L3UwZd8xiXczlMkDcbaaL2l3cl4FiM= X-MC-Unique: DAqEMwObPg2uTP60qgX55g-1 From: Kevin Wolf To: qemu-block@nongnu.org Cc: kwolf@redhat.com, richard.henderson@linaro.org, qemu-devel@nongnu.org Subject: [PULL 28/32] virtio: make it possible to detach host notifier from any thread Date: Tue, 30 May 2023 18:32:35 +0200 Message-Id: <20230530163239.576632-29-kwolf@redhat.com> In-Reply-To: <20230530163239.576632-1-kwolf@redhat.com> References: <20230530163239.576632-1-kwolf@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=kwolf@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -22 X-Spam_score: -2.3 X-Spam_bar: -- X-Spam_report: (-2.3 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.167, 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: 1685464609960100003 Content-Type: text/plain; charset="utf-8" From: Stefan Hajnoczi virtio_queue_aio_detach_host_notifier() does two things: 1. It removes the fd handler from the event loop. 2. It processes the virtqueue one last time. The first step can be peformed by any thread and without taking the AioContext lock. The second step may need the AioContext lock (depending on the device implementation) and runs in the thread where request processing takes place. virtio-blk and virtio-scsi therefore call virtio_queue_aio_detach_host_notifier() from a BH that is scheduled in AioContext. The next patch will introduce a .drained_begin() function that needs to call virtio_queue_aio_detach_host_notifier(). .drained_begin() functions cannot call aio_poll() to wait synchronously for the BH. It is possible for a .drained_poll() callback to asynchronously wait for the BH, but that is more complex than necessary here. Move the virtqueue processing out to the callers of virtio_queue_aio_detach_host_notifier() so that the function can be called from any thread. This is in preparation for the next patch. Signed-off-by: Stefan Hajnoczi Message-Id: <20230516190238.8401-17-stefanha@redhat.com> Signed-off-by: Kevin Wolf --- hw/block/dataplane/virtio-blk.c | 7 +++++++ hw/scsi/virtio-scsi-dataplane.c | 14 ++++++++++++++ hw/virtio/virtio.c | 3 --- 3 files changed, 21 insertions(+), 3 deletions(-) diff --git a/hw/block/dataplane/virtio-blk.c b/hw/block/dataplane/virtio-bl= k.c index af1c24c40c..4f5c7cd55f 100644 --- a/hw/block/dataplane/virtio-blk.c +++ b/hw/block/dataplane/virtio-blk.c @@ -287,8 +287,15 @@ static void virtio_blk_data_plane_stop_bh(void *opaque) =20 for (i =3D 0; i < s->conf->num_queues; i++) { VirtQueue *vq =3D virtio_get_queue(s->vdev, i); + EventNotifier *host_notifier =3D virtio_queue_get_host_notifier(vq= ); =20 virtio_queue_aio_detach_host_notifier(vq, s->ctx); + + /* + * Test and clear notifier after disabling event, in case poll cal= lback + * didn't have time to run. + */ + virtio_queue_host_notifier_read(host_notifier); } } =20 diff --git a/hw/scsi/virtio-scsi-dataplane.c b/hw/scsi/virtio-scsi-dataplan= e.c index f3214e1c57..b3a1ed21f7 100644 --- a/hw/scsi/virtio-scsi-dataplane.c +++ b/hw/scsi/virtio-scsi-dataplane.c @@ -71,12 +71,26 @@ static void virtio_scsi_dataplane_stop_bh(void *opaque) { VirtIOSCSI *s =3D opaque; VirtIOSCSICommon *vs =3D VIRTIO_SCSI_COMMON(s); + EventNotifier *host_notifier; int i; =20 virtio_queue_aio_detach_host_notifier(vs->ctrl_vq, s->ctx); + host_notifier =3D virtio_queue_get_host_notifier(vs->ctrl_vq); + + /* + * Test and clear notifier after disabling event, in case poll callback + * didn't have time to run. + */ + virtio_queue_host_notifier_read(host_notifier); + virtio_queue_aio_detach_host_notifier(vs->event_vq, s->ctx); + host_notifier =3D virtio_queue_get_host_notifier(vs->event_vq); + virtio_queue_host_notifier_read(host_notifier); + for (i =3D 0; i < vs->conf.num_queues; i++) { virtio_queue_aio_detach_host_notifier(vs->cmd_vqs[i], s->ctx); + host_notifier =3D virtio_queue_get_host_notifier(vs->cmd_vqs[i]); + virtio_queue_host_notifier_read(host_notifier); } } =20 diff --git a/hw/virtio/virtio.c b/hw/virtio/virtio.c index 272d930721..cb09cb6464 100644 --- a/hw/virtio/virtio.c +++ b/hw/virtio/virtio.c @@ -3516,9 +3516,6 @@ void virtio_queue_aio_attach_host_notifier_no_poll(Vi= rtQueue *vq, AioContext *ct void virtio_queue_aio_detach_host_notifier(VirtQueue *vq, AioContext *ctx) { aio_set_event_notifier(ctx, &vq->host_notifier, true, NULL, NULL, NULL= ); - /* Test and clear notifier before after disabling event, - * in case poll callback didn't have time to run. */ - virtio_queue_host_notifier_read(&vq->host_notifier); } =20 void virtio_queue_host_notifier_read(EventNotifier *n) --=20 2.40.1 From nobody Mon May 20 16:32:53 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=1685464613; cv=none; d=zohomail.com; s=zohoarc; b=f/CmHpvJcOJeSnTa+P8oUgXeux9M0Bd55NOtwi0pa+HK1yo3ky9EVa8hda/uSPCvd5Lp5vG8AfofysuFCUF3498ItRFC5B/Z/uMAiDQ3E7Q+98p0imjCykZEM/Aq39YEFkPO1F0EJze5oPJGhnMolM7LzUHjHLpcV/9csjBSrBA= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1685464613; 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=123E95yY9EoHHxjf4VYk1zc9vgfUknZ60ThDYikdDPw=; b=QvoPcxY3eu6ghA9e7GwbYegAH3RjckodZXHJ6Zn4Veowey2XnVc1Wqi28SjMNQ3Gq4J2wjLM31LM9A3AjA1n2t06naOXEf3Z9eyj5WAIGGWijkMhHAmmzF0nPiIiwhqDpvg/K0NhcuiXpHKa+DrprL8T8cpnmc6BvOLF/lJmUmA= 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 1685464613415842.2976396752568; Tue, 30 May 2023 09:36:53 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1q42Ip-00023n-Jm; Tue, 30 May 2023 12:34: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 1q42Hh-0006wv-2u for qemu-devel@nongnu.org; Tue, 30 May 2023 12:33:28 -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 1q42He-0008TY-NM for qemu-devel@nongnu.org; Tue, 30 May 2023 12:33:20 -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-31-2ioook0AOWCwImXyr8BJ4g-1; Tue, 30 May 2023 12:33:14 -0400 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 919FC3C17C62; Tue, 30 May 2023 16:33:14 +0000 (UTC) Received: from merkur.redhat.com (unknown [10.39.194.4]) by smtp.corp.redhat.com (Postfix) with ESMTP id D84CEC154D2; Tue, 30 May 2023 16:33:13 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1685464396; 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=123E95yY9EoHHxjf4VYk1zc9vgfUknZ60ThDYikdDPw=; b=JL2b5facbK3g+qe7HgeAcsR0/cAD+yLYuywVu+0Fz5wdmzaVctb/V6rZSf7AAcG35GgDfA aMI9III8vDGpAzopLio2NbARd1uZwkqRCWytTuQI9UqKq38gib0t8JrIxDFigrDWYWzw/p FeGLj4yVdIb9Z2tBIAmBqcx/3xGcHsc= X-MC-Unique: 2ioook0AOWCwImXyr8BJ4g-1 From: Kevin Wolf To: qemu-block@nongnu.org Cc: kwolf@redhat.com, richard.henderson@linaro.org, qemu-devel@nongnu.org Subject: [PULL 29/32] virtio-blk: implement BlockDevOps->drained_begin() Date: Tue, 30 May 2023 18:32:36 +0200 Message-Id: <20230530163239.576632-30-kwolf@redhat.com> In-Reply-To: <20230530163239.576632-1-kwolf@redhat.com> References: <20230530163239.576632-1-kwolf@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=kwolf@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -22 X-Spam_score: -2.3 X-Spam_bar: -- X-Spam_report: (-2.3 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.167, 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: 1685464613961100003 Content-Type: text/plain; charset="utf-8" From: Stefan Hajnoczi Detach ioeventfds during drained sections to stop I/O submission from the guest. virtio-blk is no longer reliant on aio_disable_external() after this patch. This will allow us to remove the aio_disable_external() API once all other code that relies on it is converted. Take extra care to avoid attaching/detaching ioeventfds if the data plane is started/stopped during a drained section. This should be rare, but maybe the mirror block job can trigger it. Signed-off-by: Stefan Hajnoczi Message-Id: <20230516190238.8401-18-stefanha@redhat.com> Signed-off-by: Kevin Wolf --- hw/block/dataplane/virtio-blk.c | 16 ++++++++------ hw/block/virtio-blk.c | 38 ++++++++++++++++++++++++++++++++- 2 files changed, 47 insertions(+), 7 deletions(-) diff --git a/hw/block/dataplane/virtio-blk.c b/hw/block/dataplane/virtio-bl= k.c index 4f5c7cd55f..b90456c08c 100644 --- a/hw/block/dataplane/virtio-blk.c +++ b/hw/block/dataplane/virtio-blk.c @@ -246,13 +246,15 @@ int virtio_blk_data_plane_start(VirtIODevice *vdev) } =20 /* Get this show started by hooking up our callbacks */ - aio_context_acquire(s->ctx); - for (i =3D 0; i < nvqs; i++) { - VirtQueue *vq =3D virtio_get_queue(s->vdev, i); + if (!blk_in_drain(s->conf->conf.blk)) { + aio_context_acquire(s->ctx); + for (i =3D 0; i < nvqs; i++) { + VirtQueue *vq =3D virtio_get_queue(s->vdev, i); =20 - virtio_queue_aio_attach_host_notifier(vq, s->ctx); + virtio_queue_aio_attach_host_notifier(vq, s->ctx); + } + aio_context_release(s->ctx); } - aio_context_release(s->ctx); return 0; =20 fail_aio_context: @@ -322,7 +324,9 @@ void virtio_blk_data_plane_stop(VirtIODevice *vdev) s->stopping =3D true; trace_virtio_blk_data_plane_stop(s); =20 - aio_wait_bh_oneshot(s->ctx, virtio_blk_data_plane_stop_bh, s); + if (!blk_in_drain(s->conf->conf.blk)) { + aio_wait_bh_oneshot(s->ctx, virtio_blk_data_plane_stop_bh, s); + } =20 aio_context_acquire(s->ctx); =20 diff --git a/hw/block/virtio-blk.c b/hw/block/virtio-blk.c index 8f65ea4659..4ca66b5860 100644 --- a/hw/block/virtio-blk.c +++ b/hw/block/virtio-blk.c @@ -1506,8 +1506,44 @@ static void virtio_blk_resize(void *opaque) aio_bh_schedule_oneshot(qemu_get_aio_context(), virtio_resize_cb, vdev= ); } =20 +/* Suspend virtqueue ioeventfd processing during drain */ +static void virtio_blk_drained_begin(void *opaque) +{ + VirtIOBlock *s =3D opaque; + VirtIODevice *vdev =3D VIRTIO_DEVICE(opaque); + AioContext *ctx =3D blk_get_aio_context(s->conf.conf.blk); + + if (!s->dataplane || !s->dataplane_started) { + return; + } + + for (uint16_t i =3D 0; i < s->conf.num_queues; i++) { + VirtQueue *vq =3D virtio_get_queue(vdev, i); + virtio_queue_aio_detach_host_notifier(vq, ctx); + } +} + +/* Resume virtqueue ioeventfd processing after drain */ +static void virtio_blk_drained_end(void *opaque) +{ + VirtIOBlock *s =3D opaque; + VirtIODevice *vdev =3D VIRTIO_DEVICE(opaque); + AioContext *ctx =3D blk_get_aio_context(s->conf.conf.blk); + + if (!s->dataplane || !s->dataplane_started) { + return; + } + + for (uint16_t i =3D 0; i < s->conf.num_queues; i++) { + VirtQueue *vq =3D virtio_get_queue(vdev, i); + virtio_queue_aio_attach_host_notifier(vq, ctx); + } +} + static const BlockDevOps virtio_block_ops =3D { - .resize_cb =3D virtio_blk_resize, + .resize_cb =3D virtio_blk_resize, + .drained_begin =3D virtio_blk_drained_begin, + .drained_end =3D virtio_blk_drained_end, }; =20 static void virtio_blk_device_realize(DeviceState *dev, Error **errp) --=20 2.40.1 From nobody Mon May 20 16:32:53 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=1685464676; cv=none; d=zohomail.com; s=zohoarc; b=S/7EfAcH4SLfyW2Ybc9fUCX7o4yliC5rAQlfCAPToTz7WhW/M+lr5gBQbOg7yAScDAtJ2+L82YPWLVBV2giDHfLeGRs8+/aLBvNpZAG1ies4WGpKn6XvHUs3sOIPtHfxFMjRqrI1tib9scrCK42YGisDyU1vGiAYd4Dj7B/j1WQ= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1685464676; 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=VMTqeHcF8RjSqsQQucIDOo4omtP972aWT9e/Ekg6/88=; b=HLJIMhvItK+F4vaTiUTFaTEbSAtsMJ7x4nzvgt2MZLLLLvjP0lacbpdrUTAWTWAP0x3oPt9SgvnrwAtluLdc6CCFWXHo8rAoNmlQIbzQkStVNtivZxTpKptKBTCkQ2lu0lKs25PNyNlZOCdgN00WKTd6/B4NsKY1BofY9qxKf8E= 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 1685464676036152.9063034625616; Tue, 30 May 2023 09:37:56 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1q42Io-0001rd-8G; Tue, 30 May 2023 12:34:30 -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 1q42Hi-0006xI-BX for qemu-devel@nongnu.org; Tue, 30 May 2023 12:33:28 -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 1q42He-0008U9-OK for qemu-devel@nongnu.org; Tue, 30 May 2023 12:33:22 -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-609-7-qbEELAOxm5z6DDZ3scnQ-1; Tue, 30 May 2023 12:33:15 -0400 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 81ABC8032FA; Tue, 30 May 2023 16:33:15 +0000 (UTC) Received: from merkur.redhat.com (unknown [10.39.194.4]) by smtp.corp.redhat.com (Postfix) with ESMTP id C89DAC154D2; Tue, 30 May 2023 16:33:14 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1685464397; 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=VMTqeHcF8RjSqsQQucIDOo4omtP972aWT9e/Ekg6/88=; b=cAyRJIOP4jqGYOX6p1ESv09qwU78d6vozi/GzE06bftMHHCSHYD0sT+CpIhqukEum6+NRu 9GRDCMob68V2XC3NRRhodoTULl+n7xJWuTnPaBiDOAfdQB6sXJTBRxaacSKMz8PeaUKXxz hxG0OCrTv7UVPS6LH6WD/J9hkkY8xoQ= X-MC-Unique: 7-qbEELAOxm5z6DDZ3scnQ-1 From: Kevin Wolf To: qemu-block@nongnu.org Cc: kwolf@redhat.com, richard.henderson@linaro.org, qemu-devel@nongnu.org Subject: [PULL 30/32] virtio-scsi: implement BlockDevOps->drained_begin() Date: Tue, 30 May 2023 18:32:37 +0200 Message-Id: <20230530163239.576632-31-kwolf@redhat.com> In-Reply-To: <20230530163239.576632-1-kwolf@redhat.com> References: <20230530163239.576632-1-kwolf@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=kwolf@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -22 X-Spam_score: -2.3 X-Spam_bar: -- X-Spam_report: (-2.3 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.167, 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: 1685464676256100001 Content-Type: text/plain; charset="utf-8" From: Stefan Hajnoczi The virtio-scsi Host Bus Adapter provides access to devices on a SCSI bus. Those SCSI devices typically have a BlockBackend. When the BlockBackend enters a drained section, the SCSI device must temporarily stop submitting new I/O requests. Implement this behavior by temporarily stopping virtio-scsi virtqueue processing when one of the SCSI devices enters a drained section. The new scsi_device_drained_begin() API allows scsi-disk to message the virtio-scsi HBA. scsi_device_drained_begin() uses a drain counter so that multiple SCSI devices can have overlapping drained sections. The HBA only sees one pair of .drained_begin/end() calls. After this commit, virtio-scsi no longer depends on hw/virtio's ioeventfd aio_set_event_notifier(is_external=3Dtrue). This commit is a step towards removing the aio_disable_external() API. Signed-off-by: Stefan Hajnoczi Message-Id: <20230516190238.8401-19-stefanha@redhat.com> Signed-off-by: Kevin Wolf --- include/hw/scsi/scsi.h | 14 ++++++++++++ hw/scsi/scsi-bus.c | 40 +++++++++++++++++++++++++++++++++ hw/scsi/scsi-disk.c | 27 +++++++++++++++++----- hw/scsi/virtio-scsi-dataplane.c | 18 +++++++++------ hw/scsi/virtio-scsi.c | 38 +++++++++++++++++++++++++++++++ hw/scsi/trace-events | 2 ++ 6 files changed, 127 insertions(+), 12 deletions(-) diff --git a/include/hw/scsi/scsi.h b/include/hw/scsi/scsi.h index 6f23a7a73e..e2bb1a2fbf 100644 --- a/include/hw/scsi/scsi.h +++ b/include/hw/scsi/scsi.h @@ -133,6 +133,16 @@ struct SCSIBusInfo { void (*save_request)(QEMUFile *f, SCSIRequest *req); void *(*load_request)(QEMUFile *f, SCSIRequest *req); void (*free_request)(SCSIBus *bus, void *priv); + + /* + * Temporarily stop submitting new requests between drained_begin() and + * drained_end(). Called from the main loop thread with the BQL held. + * + * Implement these callbacks if request processing is triggered by a f= ile + * descriptor like an EventNotifier. Otherwise set them to NULL. + */ + void (*drained_begin)(SCSIBus *bus); + void (*drained_end)(SCSIBus *bus); }; =20 #define TYPE_SCSI_BUS "SCSI" @@ -144,6 +154,8 @@ struct SCSIBus { =20 SCSISense unit_attention; const SCSIBusInfo *info; + + int drain_count; /* protected by BQL */ }; =20 /** @@ -213,6 +225,8 @@ void scsi_req_cancel_complete(SCSIRequest *req); void scsi_req_cancel(SCSIRequest *req); void scsi_req_cancel_async(SCSIRequest *req, Notifier *notifier); void scsi_req_retry(SCSIRequest *req); +void scsi_device_drained_begin(SCSIDevice *sdev); +void scsi_device_drained_end(SCSIDevice *sdev); void scsi_device_purge_requests(SCSIDevice *sdev, SCSISense sense); void scsi_device_set_ua(SCSIDevice *sdev, SCSISense sense); void scsi_device_report_change(SCSIDevice *dev, SCSISense sense); diff --git a/hw/scsi/scsi-bus.c b/hw/scsi/scsi-bus.c index 64013c8a24..f80f4cb4fc 100644 --- a/hw/scsi/scsi-bus.c +++ b/hw/scsi/scsi-bus.c @@ -1669,6 +1669,46 @@ void scsi_device_purge_requests(SCSIDevice *sdev, SC= SISense sense) scsi_device_set_ua(sdev, sense); } =20 +void scsi_device_drained_begin(SCSIDevice *sdev) +{ + SCSIBus *bus =3D DO_UPCAST(SCSIBus, qbus, sdev->qdev.parent_bus); + if (!bus) { + return; + } + + assert(qemu_get_current_aio_context() =3D=3D qemu_get_aio_context()); + assert(bus->drain_count < INT_MAX); + + /* + * Multiple BlockBackends can be on a SCSIBus and each may begin/end + * draining at any time. Keep a counter so HBAs only see begin/end onc= e. + */ + if (bus->drain_count++ =3D=3D 0) { + trace_scsi_bus_drained_begin(bus, sdev); + if (bus->info->drained_begin) { + bus->info->drained_begin(bus); + } + } +} + +void scsi_device_drained_end(SCSIDevice *sdev) +{ + SCSIBus *bus =3D DO_UPCAST(SCSIBus, qbus, sdev->qdev.parent_bus); + if (!bus) { + return; + } + + assert(qemu_get_current_aio_context() =3D=3D qemu_get_aio_context()); + assert(bus->drain_count > 0); + + if (bus->drain_count-- =3D=3D 1) { + trace_scsi_bus_drained_end(bus, sdev); + if (bus->info->drained_end) { + bus->info->drained_end(bus); + } + } +} + static char *scsibus_get_dev_path(DeviceState *dev) { SCSIDevice *d =3D SCSI_DEVICE(dev); diff --git a/hw/scsi/scsi-disk.c b/hw/scsi/scsi-disk.c index 97c9b1c8cd..e0d79c7966 100644 --- a/hw/scsi/scsi-disk.c +++ b/hw/scsi/scsi-disk.c @@ -2360,6 +2360,20 @@ static void scsi_disk_reset(DeviceState *dev) s->qdev.scsi_version =3D s->qdev.default_scsi_version; } =20 +static void scsi_disk_drained_begin(void *opaque) +{ + SCSIDiskState *s =3D opaque; + + scsi_device_drained_begin(&s->qdev); +} + +static void scsi_disk_drained_end(void *opaque) +{ + SCSIDiskState *s =3D opaque; + + scsi_device_drained_end(&s->qdev); +} + static void scsi_disk_resize_cb(void *opaque) { SCSIDiskState *s =3D opaque; @@ -2414,16 +2428,19 @@ static bool scsi_cd_is_medium_locked(void *opaque) } =20 static const BlockDevOps scsi_disk_removable_block_ops =3D { - .change_media_cb =3D scsi_cd_change_media_cb, + .change_media_cb =3D scsi_cd_change_media_cb, + .drained_begin =3D scsi_disk_drained_begin, + .drained_end =3D scsi_disk_drained_end, .eject_request_cb =3D scsi_cd_eject_request_cb, - .is_tray_open =3D scsi_cd_is_tray_open, .is_medium_locked =3D scsi_cd_is_medium_locked, - - .resize_cb =3D scsi_disk_resize_cb, + .is_tray_open =3D scsi_cd_is_tray_open, + .resize_cb =3D scsi_disk_resize_cb, }; =20 static const BlockDevOps scsi_disk_block_ops =3D { - .resize_cb =3D scsi_disk_resize_cb, + .drained_begin =3D scsi_disk_drained_begin, + .drained_end =3D scsi_disk_drained_end, + .resize_cb =3D scsi_disk_resize_cb, }; =20 static void scsi_disk_unit_attention_reported(SCSIDevice *dev) diff --git a/hw/scsi/virtio-scsi-dataplane.c b/hw/scsi/virtio-scsi-dataplan= e.c index b3a1ed21f7..d55de4c8ca 100644 --- a/hw/scsi/virtio-scsi-dataplane.c +++ b/hw/scsi/virtio-scsi-dataplane.c @@ -158,14 +158,16 @@ int virtio_scsi_dataplane_start(VirtIODevice *vdev) s->dataplane_starting =3D false; s->dataplane_started =3D true; =20 - aio_context_acquire(s->ctx); - virtio_queue_aio_attach_host_notifier(vs->ctrl_vq, s->ctx); - virtio_queue_aio_attach_host_notifier_no_poll(vs->event_vq, s->ctx); + if (s->bus.drain_count =3D=3D 0) { + aio_context_acquire(s->ctx); + virtio_queue_aio_attach_host_notifier(vs->ctrl_vq, s->ctx); + virtio_queue_aio_attach_host_notifier_no_poll(vs->event_vq, s->ctx= ); =20 - for (i =3D 0; i < vs->conf.num_queues; i++) { - virtio_queue_aio_attach_host_notifier(vs->cmd_vqs[i], s->ctx); + for (i =3D 0; i < vs->conf.num_queues; i++) { + virtio_queue_aio_attach_host_notifier(vs->cmd_vqs[i], s->ctx); + } + aio_context_release(s->ctx); } - aio_context_release(s->ctx); return 0; =20 fail_host_notifiers: @@ -211,7 +213,9 @@ void virtio_scsi_dataplane_stop(VirtIODevice *vdev) } s->dataplane_stopping =3D true; =20 - aio_wait_bh_oneshot(s->ctx, virtio_scsi_dataplane_stop_bh, s); + if (s->bus.drain_count =3D=3D 0) { + aio_wait_bh_oneshot(s->ctx, virtio_scsi_dataplane_stop_bh, s); + } =20 blk_drain_all(); /* ensure there are no in-flight requests */ =20 diff --git a/hw/scsi/virtio-scsi.c b/hw/scsi/virtio-scsi.c index c1a7ea9ae2..4a8849cc7e 100644 --- a/hw/scsi/virtio-scsi.c +++ b/hw/scsi/virtio-scsi.c @@ -1117,6 +1117,42 @@ static void virtio_scsi_hotunplug(HotplugHandler *ho= tplug_dev, DeviceState *dev, } } =20 +/* Suspend virtqueue ioeventfd processing during drain */ +static void virtio_scsi_drained_begin(SCSIBus *bus) +{ + VirtIOSCSI *s =3D container_of(bus, VirtIOSCSI, bus); + VirtIODevice *vdev =3D VIRTIO_DEVICE(s); + uint32_t total_queues =3D VIRTIO_SCSI_VQ_NUM_FIXED + + s->parent_obj.conf.num_queues; + + if (!s->dataplane_started) { + return; + } + + for (uint32_t i =3D 0; i < total_queues; i++) { + VirtQueue *vq =3D virtio_get_queue(vdev, i); + virtio_queue_aio_detach_host_notifier(vq, s->ctx); + } +} + +/* Resume virtqueue ioeventfd processing after drain */ +static void virtio_scsi_drained_end(SCSIBus *bus) +{ + VirtIOSCSI *s =3D container_of(bus, VirtIOSCSI, bus); + VirtIODevice *vdev =3D VIRTIO_DEVICE(s); + uint32_t total_queues =3D VIRTIO_SCSI_VQ_NUM_FIXED + + s->parent_obj.conf.num_queues; + + if (!s->dataplane_started) { + return; + } + + for (uint32_t i =3D 0; i < total_queues; i++) { + VirtQueue *vq =3D virtio_get_queue(vdev, i); + virtio_queue_aio_attach_host_notifier(vq, s->ctx); + } +} + static struct SCSIBusInfo virtio_scsi_scsi_info =3D { .tcq =3D true, .max_channel =3D VIRTIO_SCSI_MAX_CHANNEL, @@ -1131,6 +1167,8 @@ static struct SCSIBusInfo virtio_scsi_scsi_info =3D { .get_sg_list =3D virtio_scsi_get_sg_list, .save_request =3D virtio_scsi_save_request, .load_request =3D virtio_scsi_load_request, + .drained_begin =3D virtio_scsi_drained_begin, + .drained_end =3D virtio_scsi_drained_end, }; =20 void virtio_scsi_common_realize(DeviceState *dev, diff --git a/hw/scsi/trace-events b/hw/scsi/trace-events index ab238293f0..bdd4e2c7c7 100644 --- a/hw/scsi/trace-events +++ b/hw/scsi/trace-events @@ -6,6 +6,8 @@ scsi_req_cancel(int target, int lun, int tag) "target %d lu= n %d tag %d" scsi_req_data(int target, int lun, int tag, int len) "target %d lun %d tag= %d len %d" scsi_req_data_canceled(int target, int lun, int tag, int len) "target %d l= un %d tag %d len %d" scsi_req_dequeue(int target, int lun, int tag) "target %d lun %d tag %d" +scsi_bus_drained_begin(void *bus, void *sdev) "bus %p sdev %p" +scsi_bus_drained_end(void *bus, void *sdev) "bus %p sdev %p" scsi_req_continue(int target, int lun, int tag) "target %d lun %d tag %d" scsi_req_continue_canceled(int target, int lun, int tag) "target %d lun %d= tag %d" scsi_req_parsed(int target, int lun, int tag, int cmd, int mode, int xfer)= "target %d lun %d tag %d command %d dir %d length %d" --=20 2.40.1 From nobody Mon May 20 16:32:53 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=1685464565; cv=none; d=zohomail.com; s=zohoarc; b=kSER2pworUpLgRltWoCH7wpfs87u8n637A2Fqz9HwjBc3moAp6l2Dut+dNL+uIS/WFRb32GRZ8OlPd5aVAfUVxuPPEJiPw27yF4y2gkqP5PcFTFHLMth9tADcdwOo+3jHVgxNx+f+P+38q0jMvx5CnW0CxmXoUOkbbpfRs3qyPs= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1685464565; 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=ORMxaB7LiQ5yr4u/kXEFuDR+l8a9PEdRdpdItmlyfqA=; b=HtSTbxmDsE3/Z6bsPYcqiRWCEJQgglznEnG4H/qFsQk5V1yhQY0M96THWNkxg+tNQYPQSE/z56JmnwbgTv1earfVf3zHM2KV5uxEg3m/HM6Zy7jcu+O+jR37z3bO/T20vgOKueQsM6N8Rl5G0mQFY5wJ52tu/7FDYIhvAkZd+0o= 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 1685464565258110.47797792747224; Tue, 30 May 2023 09:36:05 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1q42Io-0001vw-BI; Tue, 30 May 2023 12:34:30 -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 1q42Hk-0006xX-0q for qemu-devel@nongnu.org; Tue, 30 May 2023 12:33:29 -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 1q42Hg-0008VV-W9 for qemu-devel@nongnu.org; Tue, 30 May 2023 12:33:23 -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-159-BYaT7_HHM0Ku1BseVcYsTA-1; Tue, 30 May 2023 12:33:16 -0400 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 721B2811E8F; Tue, 30 May 2023 16:33:16 +0000 (UTC) Received: from merkur.redhat.com (unknown [10.39.194.4]) by smtp.corp.redhat.com (Postfix) with ESMTP id B9AE1C154D2; Tue, 30 May 2023 16:33:15 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1685464400; 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=ORMxaB7LiQ5yr4u/kXEFuDR+l8a9PEdRdpdItmlyfqA=; b=Rhceda1wHG7cxHCaJP9SB7KcUc/d9gkT6VTp29Bhq8dHpEq4p5I3K90clf2E95IdIgg5yu Ap7bBT8h54DQteQr3109HLex/fChEFGgWG4F+/W0IBysg1z94ut6kRE1eYv+6dMbO50cGr DBjf6vV+B2vtWLlGtyt9bMnbr88bEGA= X-MC-Unique: BYaT7_HHM0Ku1BseVcYsTA-1 From: Kevin Wolf To: qemu-block@nongnu.org Cc: kwolf@redhat.com, richard.henderson@linaro.org, qemu-devel@nongnu.org Subject: [PULL 31/32] virtio: do not set is_external=true on host notifiers Date: Tue, 30 May 2023 18:32:38 +0200 Message-Id: <20230530163239.576632-32-kwolf@redhat.com> In-Reply-To: <20230530163239.576632-1-kwolf@redhat.com> References: <20230530163239.576632-1-kwolf@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=kwolf@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -22 X-Spam_score: -2.3 X-Spam_bar: -- X-Spam_report: (-2.3 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.167, 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: 1685464565736100001 Content-Type: text/plain; charset="utf-8" From: Stefan Hajnoczi Host notifiers can now use is_external=3Dfalse since virtio-blk and virtio-scsi no longer rely on is_external=3Dtrue for drained sections. Signed-off-by: Stefan Hajnoczi Message-Id: <20230516190238.8401-20-stefanha@redhat.com> Signed-off-by: Kevin Wolf --- hw/virtio/virtio.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/hw/virtio/virtio.c b/hw/virtio/virtio.c index cb09cb6464..08011be8dc 100644 --- a/hw/virtio/virtio.c +++ b/hw/virtio/virtio.c @@ -3491,7 +3491,7 @@ static void virtio_queue_host_notifier_aio_poll_end(E= ventNotifier *n) =20 void virtio_queue_aio_attach_host_notifier(VirtQueue *vq, AioContext *ctx) { - aio_set_event_notifier(ctx, &vq->host_notifier, true, + aio_set_event_notifier(ctx, &vq->host_notifier, false, virtio_queue_host_notifier_read, virtio_queue_host_notifier_aio_poll, virtio_queue_host_notifier_aio_poll_ready); @@ -3508,14 +3508,14 @@ void virtio_queue_aio_attach_host_notifier(VirtQueu= e *vq, AioContext *ctx) */ void virtio_queue_aio_attach_host_notifier_no_poll(VirtQueue *vq, AioConte= xt *ctx) { - aio_set_event_notifier(ctx, &vq->host_notifier, true, + aio_set_event_notifier(ctx, &vq->host_notifier, false, virtio_queue_host_notifier_read, NULL, NULL); } =20 void virtio_queue_aio_detach_host_notifier(VirtQueue *vq, AioContext *ctx) { - aio_set_event_notifier(ctx, &vq->host_notifier, true, NULL, NULL, NULL= ); + aio_set_event_notifier(ctx, &vq->host_notifier, false, NULL, NULL, NUL= L); } =20 void virtio_queue_host_notifier_read(EventNotifier *n) --=20 2.40.1 From nobody Mon May 20 16:32:53 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=1685464837; cv=none; d=zohomail.com; s=zohoarc; b=CY0tP5mkmxxVoH8VNhtMeNXOAEBCkYWTMNvpGrDoGHIoWQBbcz4ZN/MTcE6PPk7RUovo1MxXqeL67d4g9NXBDk9nJZ2TmCcKyhN78DZULbAFc9NhbmVNGcHEgUmp65hI9haJGNF7z0GSFRxWP9gjgcC92d+/BP3tjuJG8hmLb4w= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1685464837; 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=qqRRaEOfRP9T8DxPT2M6qnZE8Em0V5/14IMawfSR+nM=; b=ECtEPDGj6P1THHz6wj8g/ji0RY5asjRhYZ4ldRp91oPa8/cRJnzTxJdFmYby/YnjhJQniVUNvsqmScv1KWxXxVI30py064ymJPGuzjYDyKevhZF9PsWd+F7QPe+uhgthQas59aVtig/p81mMHb0p+tNpux24uWk5ZWS5HAChL8E= 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 168546483786429.047034462548368; Tue, 30 May 2023 09:40:37 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1q42Iq-0002Cp-N1; Tue, 30 May 2023 12:34: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 1q42Hn-0006yj-Ng for qemu-devel@nongnu.org; Tue, 30 May 2023 12:33:29 -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 1q42Hh-0008W2-Dp for qemu-devel@nongnu.org; Tue, 30 May 2023 12:33:27 -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-587-NC26rG1sOrmMP_Sxf4nsog-1; Tue, 30 May 2023 12:33:18 -0400 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 825EA38149A4; Tue, 30 May 2023 16:33:17 +0000 (UTC) Received: from merkur.redhat.com (unknown [10.39.194.4]) by smtp.corp.redhat.com (Postfix) with ESMTP id AD608C154DD; Tue, 30 May 2023 16:33:16 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1685464400; 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=qqRRaEOfRP9T8DxPT2M6qnZE8Em0V5/14IMawfSR+nM=; b=WWmN6zwxavXKliMUut7oZcjw40GK86FEQ/fiAeKU72STAFWW9rCnHY9X43zusPC0OCgYRe Lefx1kOJfi7PD47RwFO46PQbNVoIRCoQXs0WEq+urIO0JtUvx9kd8A/dTjwzfUq+nSyGr6 /IyA5EPv4vZe/rATQ0/RSix+h07Exy4= X-MC-Unique: NC26rG1sOrmMP_Sxf4nsog-1 From: Kevin Wolf To: qemu-block@nongnu.org Cc: kwolf@redhat.com, richard.henderson@linaro.org, qemu-devel@nongnu.org Subject: [PULL 32/32] aio: remove aio_disable_external() API Date: Tue, 30 May 2023 18:32:39 +0200 Message-Id: <20230530163239.576632-33-kwolf@redhat.com> In-Reply-To: <20230530163239.576632-1-kwolf@redhat.com> References: <20230530163239.576632-1-kwolf@redhat.com> MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" 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=kwolf@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -22 X-Spam_score: -2.3 X-Spam_bar: -- X-Spam_report: (-2.3 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.167, 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: 1685464839345100006 From: Stefan Hajnoczi All callers now pass is_external=3Dfalse to aio_set_fd_handler() and aio_set_event_notifier(). The aio_disable_external() API that temporarily disables fd handlers that were registered is_external=3Dtrue is therefore dead code. Remove aio_disable_external(), aio_enable_external(), and the is_external arguments to aio_set_fd_handler() and aio_set_event_notifier(). The entire test-fdmon-epoll test is removed because its sole purpose was testing aio_disable_external(). Parts of this patch were generated using the following coccinelle (https://coccinelle.lip6.fr/) semantic patch: @@ expression ctx, fd, is_external, io_read, io_write, io_poll, io_poll_read= y, opaque; @@ - aio_set_fd_handler(ctx, fd, is_external, io_read, io_write, io_poll, io= _poll_ready, opaque) + aio_set_fd_handler(ctx, fd, io_read, io_write, io_poll, io_poll_ready, = opaque) @@ expression ctx, notifier, is_external, io_read, io_poll, io_poll_ready; @@ - aio_set_event_notifier(ctx, notifier, is_external, io_read, io_poll, io= _poll_ready) + aio_set_event_notifier(ctx, notifier, io_read, io_poll, io_poll_ready) Reviewed-by: Juan Quintela Reviewed-by: Philippe Mathieu-Daud=C3=A9 Signed-off-by: Stefan Hajnoczi Message-Id: <20230516190238.8401-21-stefanha@redhat.com> Signed-off-by: Kevin Wolf --- include/block/aio.h | 57 ------------------------ util/aio-posix.h | 1 - block.c | 7 --- block/blkio.c | 15 +++---- block/curl.c | 10 ++--- block/export/fuse.c | 8 ++-- block/export/vduse-blk.c | 10 ++--- block/io.c | 2 - block/io_uring.c | 4 +- block/iscsi.c | 3 +- block/linux-aio.c | 4 +- block/nfs.c | 5 +-- block/nvme.c | 8 ++-- block/ssh.c | 4 +- block/win32-aio.c | 6 +-- hw/i386/kvm/xen_xenstore.c | 2 +- hw/virtio/virtio.c | 6 +-- hw/xen/xen-bus.c | 8 ++-- io/channel-command.c | 6 +-- io/channel-file.c | 3 +- io/channel-socket.c | 3 +- migration/rdma.c | 16 +++---- tests/unit/test-aio.c | 27 +----------- tests/unit/test-bdrv-drain.c | 1 - tests/unit/test-fdmon-epoll.c | 73 ------------------------------- tests/unit/test-nested-aio-poll.c | 9 ++-- util/aio-posix.c | 20 +++------ util/aio-win32.c | 8 +--- util/async.c | 3 +- util/fdmon-epoll.c | 10 ----- util/fdmon-io_uring.c | 8 +--- util/fdmon-poll.c | 3 +- util/main-loop.c | 7 ++- util/qemu-coroutine-io.c | 7 ++- util/vhost-user-server.c | 11 +++-- tests/unit/meson.build | 3 -- 36 files changed, 80 insertions(+), 298 deletions(-) delete mode 100644 tests/unit/test-fdmon-epoll.c diff --git a/include/block/aio.h b/include/block/aio.h index 89bbc536f9..32042e8905 100644 --- a/include/block/aio.h +++ b/include/block/aio.h @@ -225,8 +225,6 @@ struct AioContext { */ QEMUTimerListGroup tlg; =20 - int external_disable_cnt; - /* Number of AioHandlers without .io_poll() */ int poll_disable_cnt; =20 @@ -481,7 +479,6 @@ bool aio_poll(AioContext *ctx, bool blocking); */ void aio_set_fd_handler(AioContext *ctx, int fd, - bool is_external, IOHandler *io_read, IOHandler *io_write, AioPollFn *io_poll, @@ -497,7 +494,6 @@ void aio_set_fd_handler(AioContext *ctx, */ void aio_set_event_notifier(AioContext *ctx, EventNotifier *notifier, - bool is_external, EventNotifierHandler *io_read, AioPollFn *io_poll, EventNotifierHandler *io_poll_ready); @@ -626,59 +622,6 @@ static inline void aio_timer_init(AioContext *ctx, */ int64_t aio_compute_timeout(AioContext *ctx); =20 -/** - * aio_disable_external: - * @ctx: the aio context - * - * Disable the further processing of external clients. - */ -static inline void aio_disable_external(AioContext *ctx) -{ - qatomic_inc(&ctx->external_disable_cnt); -} - -/** - * aio_enable_external: - * @ctx: the aio context - * - * Enable the processing of external clients. - */ -static inline void aio_enable_external(AioContext *ctx) -{ - int old; - - old =3D qatomic_fetch_dec(&ctx->external_disable_cnt); - assert(old > 0); - if (old =3D=3D 1) { - /* Kick event loop so it re-arms file descriptors */ - aio_notify(ctx); - } -} - -/** - * aio_external_disabled: - * @ctx: the aio context - * - * Return true if the external clients are disabled. - */ -static inline bool aio_external_disabled(AioContext *ctx) -{ - return qatomic_read(&ctx->external_disable_cnt); -} - -/** - * aio_node_check: - * @ctx: the aio context - * @is_external: Whether or not the checked node is an external event sour= ce. - * - * Check if the node's is_external flag is okay to be polled by the ctx at= this - * moment. True means green light. - */ -static inline bool aio_node_check(AioContext *ctx, bool is_external) -{ - return !is_external || !qatomic_read(&ctx->external_disable_cnt); -} - /** * aio_co_schedule: * @ctx: the aio context diff --git a/util/aio-posix.h b/util/aio-posix.h index 80b927c7f4..4264c518be 100644 --- a/util/aio-posix.h +++ b/util/aio-posix.h @@ -38,7 +38,6 @@ struct AioHandler { #endif int64_t poll_idle_timeout; /* when to stop userspace polling */ bool poll_ready; /* has polling detected an event? */ - bool is_external; }; =20 /* Add a handler to a ready list */ diff --git a/block.c b/block.c index ec65fcf732..dae629075c 100644 --- a/block.c +++ b/block.c @@ -7305,9 +7305,6 @@ static void bdrv_detach_aio_context(BlockDriverState = *bs) bs->drv->bdrv_detach_aio_context(bs); } =20 - if (bs->quiesce_counter) { - aio_enable_external(bs->aio_context); - } bs->aio_context =3D NULL; } =20 @@ -7317,10 +7314,6 @@ static void bdrv_attach_aio_context(BlockDriverState= *bs, BdrvAioNotifier *ban, *ban_tmp; GLOBAL_STATE_CODE(); =20 - if (bs->quiesce_counter) { - aio_disable_external(new_context); - } - bs->aio_context =3D new_context; =20 if (bs->drv && bs->drv->bdrv_attach_aio_context) { diff --git a/block/blkio.c b/block/blkio.c index 0cdc99a729..72117fa005 100644 --- a/block/blkio.c +++ b/block/blkio.c @@ -306,23 +306,18 @@ static void blkio_attach_aio_context(BlockDriverState= *bs, { BDRVBlkioState *s =3D bs->opaque; =20 - aio_set_fd_handler(new_context, - s->completion_fd, - false, - blkio_completion_fd_read, - NULL, + aio_set_fd_handler(new_context, s->completion_fd, + blkio_completion_fd_read, NULL, blkio_completion_fd_poll, - blkio_completion_fd_poll_ready, - bs); + blkio_completion_fd_poll_ready, bs); } =20 static void blkio_detach_aio_context(BlockDriverState *bs) { BDRVBlkioState *s =3D bs->opaque; =20 - aio_set_fd_handler(bdrv_get_aio_context(bs), - s->completion_fd, - false, NULL, NULL, NULL, NULL, NULL); + aio_set_fd_handler(bdrv_get_aio_context(bs), s->completion_fd, NULL, N= ULL, + NULL, NULL, NULL); } =20 /* Call with s->blkio_lock held to submit I/O after enqueuing a new reques= t */ diff --git a/block/curl.c b/block/curl.c index 8bb39a134e..0fc42d03d7 100644 --- a/block/curl.c +++ b/block/curl.c @@ -132,7 +132,7 @@ static gboolean curl_drop_socket(void *key, void *value= , void *opaque) CURLSocket *socket =3D value; BDRVCURLState *s =3D socket->s; =20 - aio_set_fd_handler(s->aio_context, socket->fd, false, + aio_set_fd_handler(s->aio_context, socket->fd, NULL, NULL, NULL, NULL, NULL); return true; } @@ -180,20 +180,20 @@ static int curl_sock_cb(CURL *curl, curl_socket_t fd,= int action, trace_curl_sock_cb(action, (int)fd); switch (action) { case CURL_POLL_IN: - aio_set_fd_handler(s->aio_context, fd, false, + aio_set_fd_handler(s->aio_context, fd, curl_multi_do, NULL, NULL, NULL, socket); break; case CURL_POLL_OUT: - aio_set_fd_handler(s->aio_context, fd, false, + aio_set_fd_handler(s->aio_context, fd, NULL, curl_multi_do, NULL, NULL, socket); break; case CURL_POLL_INOUT: - aio_set_fd_handler(s->aio_context, fd, false, + aio_set_fd_handler(s->aio_context, fd, curl_multi_do, curl_multi_do, NULL, NULL, socket); break; case CURL_POLL_REMOVE: - aio_set_fd_handler(s->aio_context, fd, false, + aio_set_fd_handler(s->aio_context, fd, NULL, NULL, NULL, NULL, NULL); break; } diff --git a/block/export/fuse.c b/block/export/fuse.c index adf3236b5a..3307b64089 100644 --- a/block/export/fuse.c +++ b/block/export/fuse.c @@ -84,7 +84,7 @@ static void fuse_export_drained_begin(void *opaque) FuseExport *exp =3D opaque; =20 aio_set_fd_handler(exp->common.ctx, - fuse_session_fd(exp->fuse_session), false, + fuse_session_fd(exp->fuse_session), NULL, NULL, NULL, NULL, NULL); exp->fd_handler_set_up =3D false; } @@ -97,7 +97,7 @@ static void fuse_export_drained_end(void *opaque) exp->common.ctx =3D blk_get_aio_context(exp->common.blk); =20 aio_set_fd_handler(exp->common.ctx, - fuse_session_fd(exp->fuse_session), false, + fuse_session_fd(exp->fuse_session), read_from_fuse_export, NULL, NULL, NULL, exp); exp->fd_handler_set_up =3D true; } @@ -270,7 +270,7 @@ static int setup_fuse_export(FuseExport *exp, const cha= r *mountpoint, g_hash_table_insert(exports, g_strdup(mountpoint), NULL); =20 aio_set_fd_handler(exp->common.ctx, - fuse_session_fd(exp->fuse_session), false, + fuse_session_fd(exp->fuse_session), read_from_fuse_export, NULL, NULL, NULL, exp); exp->fd_handler_set_up =3D true; =20 @@ -320,7 +320,7 @@ static void fuse_export_shutdown(BlockExport *blk_exp) =20 if (exp->fd_handler_set_up) { aio_set_fd_handler(exp->common.ctx, - fuse_session_fd(exp->fuse_session), false, + fuse_session_fd(exp->fuse_session), NULL, NULL, NULL, NULL, NULL); exp->fd_handler_set_up =3D false; } diff --git a/block/export/vduse-blk.c b/block/export/vduse-blk.c index e0455551f9..83b05548e7 100644 --- a/block/export/vduse-blk.c +++ b/block/export/vduse-blk.c @@ -137,7 +137,7 @@ static void vduse_blk_enable_queue(VduseDev *dev, Vduse= Virtq *vq) } =20 aio_set_fd_handler(vblk_exp->export.ctx, vduse_queue_get_fd(vq), - false, on_vduse_vq_kick, NULL, NULL, NULL, vq); + on_vduse_vq_kick, NULL, NULL, NULL, vq); /* Make sure we don't miss any kick afer reconnecting */ eventfd_write(vduse_queue_get_fd(vq), 1); } @@ -151,7 +151,7 @@ static void vduse_blk_disable_queue(VduseDev *dev, Vdus= eVirtq *vq) return; } =20 - aio_set_fd_handler(vblk_exp->export.ctx, fd, false, + aio_set_fd_handler(vblk_exp->export.ctx, fd, NULL, NULL, NULL, NULL, NULL); } =20 @@ -170,7 +170,7 @@ static void on_vduse_dev_kick(void *opaque) static void vduse_blk_attach_ctx(VduseBlkExport *vblk_exp, AioContext *ctx) { aio_set_fd_handler(vblk_exp->export.ctx, vduse_dev_get_fd(vblk_exp->de= v), - false, on_vduse_dev_kick, NULL, NULL, NULL, + on_vduse_dev_kick, NULL, NULL, NULL, vblk_exp->dev); =20 /* Virtqueues are handled by vduse_blk_drained_end() */ @@ -179,7 +179,7 @@ static void vduse_blk_attach_ctx(VduseBlkExport *vblk_e= xp, AioContext *ctx) static void vduse_blk_detach_ctx(VduseBlkExport *vblk_exp) { aio_set_fd_handler(vblk_exp->export.ctx, vduse_dev_get_fd(vblk_exp->de= v), - false, NULL, NULL, NULL, NULL, NULL); + NULL, NULL, NULL, NULL, NULL); =20 /* Virtqueues are handled by vduse_blk_drained_begin() */ } @@ -364,7 +364,7 @@ static int vduse_blk_exp_create(BlockExport *exp, Block= ExportOptions *opts, vduse_dev_setup_queue(vblk_exp->dev, i, queue_size); } =20 - aio_set_fd_handler(exp->ctx, vduse_dev_get_fd(vblk_exp->dev), false, + aio_set_fd_handler(exp->ctx, vduse_dev_get_fd(vblk_exp->dev), on_vduse_dev_kick, NULL, NULL, NULL, vblk_exp->dev); =20 blk_add_aio_context_notifier(exp->blk, blk_aio_attached, blk_aio_detac= h, diff --git a/block/io.c b/block/io.c index fece938fd0..540bf8d26d 100644 --- a/block/io.c +++ b/block/io.c @@ -362,7 +362,6 @@ static void bdrv_do_drained_begin(BlockDriverState *bs,= BdrvChild *parent, =20 /* Stop things in parent-to-child order */ if (qatomic_fetch_inc(&bs->quiesce_counter) =3D=3D 0) { - aio_disable_external(bdrv_get_aio_context(bs)); bdrv_parent_drained_begin(bs, parent); if (bs->drv && bs->drv->bdrv_drain_begin) { bs->drv->bdrv_drain_begin(bs); @@ -418,7 +417,6 @@ static void bdrv_do_drained_end(BlockDriverState *bs, B= drvChild *parent) bs->drv->bdrv_drain_end(bs); } bdrv_parent_drained_end(bs, parent); - aio_enable_external(bdrv_get_aio_context(bs)); } } =20 diff --git a/block/io_uring.c b/block/io_uring.c index 82cab6a5bd..3a77480e16 100644 --- a/block/io_uring.c +++ b/block/io_uring.c @@ -410,7 +410,7 @@ int coroutine_fn luring_co_submit(BlockDriverState *bs,= int fd, uint64_t offset, =20 void luring_detach_aio_context(LuringState *s, AioContext *old_context) { - aio_set_fd_handler(old_context, s->ring.ring_fd, false, + aio_set_fd_handler(old_context, s->ring.ring_fd, NULL, NULL, NULL, NULL, s); qemu_bh_delete(s->completion_bh); s->aio_context =3D NULL; @@ -420,7 +420,7 @@ void luring_attach_aio_context(LuringState *s, AioConte= xt *new_context) { s->aio_context =3D new_context; s->completion_bh =3D aio_bh_new(new_context, qemu_luring_completion_bh= , s); - aio_set_fd_handler(s->aio_context, s->ring.ring_fd, false, + aio_set_fd_handler(s->aio_context, s->ring.ring_fd, qemu_luring_completion_cb, NULL, qemu_luring_poll_cb, qemu_luring_poll_ready, s); } diff --git a/block/iscsi.c b/block/iscsi.c index 9fc0bed90b..34f97ab646 100644 --- a/block/iscsi.c +++ b/block/iscsi.c @@ -363,7 +363,6 @@ iscsi_set_events(IscsiLun *iscsilun) =20 if (ev !=3D iscsilun->events) { aio_set_fd_handler(iscsilun->aio_context, iscsi_get_fd(iscsi), - false, (ev & POLLIN) ? iscsi_process_read : NULL, (ev & POLLOUT) ? iscsi_process_write : NULL, NULL, NULL, @@ -1540,7 +1539,7 @@ static void iscsi_detach_aio_context(BlockDriverState= *bs) IscsiLun *iscsilun =3D bs->opaque; =20 aio_set_fd_handler(iscsilun->aio_context, iscsi_get_fd(iscsilun->iscsi= ), - false, NULL, NULL, NULL, NULL, NULL); + NULL, NULL, NULL, NULL, NULL); iscsilun->events =3D 0; =20 if (iscsilun->nop_timer) { diff --git a/block/linux-aio.c b/block/linux-aio.c index 442c86209b..916f001e32 100644 --- a/block/linux-aio.c +++ b/block/linux-aio.c @@ -446,7 +446,7 @@ int coroutine_fn laio_co_submit(int fd, uint64_t offset= , QEMUIOVector *qiov, =20 void laio_detach_aio_context(LinuxAioState *s, AioContext *old_context) { - aio_set_event_notifier(old_context, &s->e, false, NULL, NULL, NULL); + aio_set_event_notifier(old_context, &s->e, NULL, NULL, NULL); qemu_bh_delete(s->completion_bh); s->aio_context =3D NULL; } @@ -455,7 +455,7 @@ void laio_attach_aio_context(LinuxAioState *s, AioConte= xt *new_context) { s->aio_context =3D new_context; s->completion_bh =3D aio_bh_new(new_context, qemu_laio_completion_bh, = s); - aio_set_event_notifier(new_context, &s->e, false, + aio_set_event_notifier(new_context, &s->e, qemu_laio_completion_cb, qemu_laio_poll_cb, qemu_laio_poll_ready); diff --git a/block/nfs.c b/block/nfs.c index 006045d71a..8f89ece69f 100644 --- a/block/nfs.c +++ b/block/nfs.c @@ -195,7 +195,6 @@ static void nfs_set_events(NFSClient *client) int ev =3D nfs_which_events(client->context); if (ev !=3D client->events) { aio_set_fd_handler(client->aio_context, nfs_get_fd(client->context= ), - false, (ev & POLLIN) ? nfs_process_read : NULL, (ev & POLLOUT) ? nfs_process_write : NULL, NULL, NULL, client); @@ -373,7 +372,7 @@ static void nfs_detach_aio_context(BlockDriverState *bs) NFSClient *client =3D bs->opaque; =20 aio_set_fd_handler(client->aio_context, nfs_get_fd(client->context), - false, NULL, NULL, NULL, NULL, NULL); + NULL, NULL, NULL, NULL, NULL); client->events =3D 0; } =20 @@ -391,7 +390,7 @@ static void nfs_client_close(NFSClient *client) if (client->context) { qemu_mutex_lock(&client->mutex); aio_set_fd_handler(client->aio_context, nfs_get_fd(client->context= ), - false, NULL, NULL, NULL, NULL, NULL); + NULL, NULL, NULL, NULL, NULL); qemu_mutex_unlock(&client->mutex); if (client->fh) { nfs_close(client->context, client->fh); diff --git a/block/nvme.c b/block/nvme.c index 5b744c2bda..17937d398d 100644 --- a/block/nvme.c +++ b/block/nvme.c @@ -862,7 +862,7 @@ static int nvme_init(BlockDriverState *bs, const char *= device, int namespace, } aio_set_event_notifier(bdrv_get_aio_context(bs), &s->irq_notifier[MSIX_SHARED_IRQ_IDX], - false, nvme_handle_event, nvme_poll_cb, + nvme_handle_event, nvme_poll_cb, nvme_poll_ready); =20 if (!nvme_identify(bs, namespace, errp)) { @@ -948,7 +948,7 @@ static void nvme_close(BlockDriverState *bs) g_free(s->queues); aio_set_event_notifier(bdrv_get_aio_context(bs), &s->irq_notifier[MSIX_SHARED_IRQ_IDX], - false, NULL, NULL, NULL); + NULL, NULL, NULL); event_notifier_cleanup(&s->irq_notifier[MSIX_SHARED_IRQ_IDX]); qemu_vfio_pci_unmap_bar(s->vfio, 0, s->bar0_wo_map, 0, sizeof(NvmeBar) + NVME_DOORBELL_SIZE); @@ -1546,7 +1546,7 @@ static void nvme_detach_aio_context(BlockDriverState = *bs) =20 aio_set_event_notifier(bdrv_get_aio_context(bs), &s->irq_notifier[MSIX_SHARED_IRQ_IDX], - false, NULL, NULL, NULL); + NULL, NULL, NULL); } =20 static void nvme_attach_aio_context(BlockDriverState *bs, @@ -1556,7 +1556,7 @@ static void nvme_attach_aio_context(BlockDriverState = *bs, =20 s->aio_context =3D new_context; aio_set_event_notifier(new_context, &s->irq_notifier[MSIX_SHARED_IRQ_I= DX], - false, nvme_handle_event, nvme_poll_cb, + nvme_handle_event, nvme_poll_cb, nvme_poll_ready); =20 for (unsigned i =3D 0; i < s->queue_count; i++) { diff --git a/block/ssh.c b/block/ssh.c index b3b3352075..2748253d4a 100644 --- a/block/ssh.c +++ b/block/ssh.c @@ -1019,7 +1019,7 @@ static void restart_coroutine(void *opaque) AioContext *ctx =3D bdrv_get_aio_context(bs); =20 trace_ssh_restart_coroutine(restart->co); - aio_set_fd_handler(ctx, s->sock, false, NULL, NULL, NULL, NULL, NULL); + aio_set_fd_handler(ctx, s->sock, NULL, NULL, NULL, NULL, NULL); =20 aio_co_wake(restart->co); } @@ -1049,7 +1049,7 @@ static coroutine_fn void co_yield(BDRVSSHState *s, Bl= ockDriverState *bs) trace_ssh_co_yield(s->sock, rd_handler, wr_handler); =20 aio_set_fd_handler(bdrv_get_aio_context(bs), s->sock, - false, rd_handler, wr_handler, NULL, NULL, &restart= ); + rd_handler, wr_handler, NULL, NULL, &restart); qemu_coroutine_yield(); trace_ssh_co_yield_back(s->sock); } diff --git a/block/win32-aio.c b/block/win32-aio.c index ee87d6048f..6327861e1d 100644 --- a/block/win32-aio.c +++ b/block/win32-aio.c @@ -174,7 +174,7 @@ int win32_aio_attach(QEMUWin32AIOState *aio, HANDLE hfi= le) void win32_aio_detach_aio_context(QEMUWin32AIOState *aio, AioContext *old_context) { - aio_set_event_notifier(old_context, &aio->e, false, NULL, NULL, NULL); + aio_set_event_notifier(old_context, &aio->e, NULL, NULL, NULL); aio->aio_ctx =3D NULL; } =20 @@ -182,8 +182,8 @@ void win32_aio_attach_aio_context(QEMUWin32AIOState *ai= o, AioContext *new_context) { aio->aio_ctx =3D new_context; - aio_set_event_notifier(new_context, &aio->e, false, - win32_aio_completion_cb, NULL, NULL); + aio_set_event_notifier(new_context, &aio->e, win32_aio_completion_cb, + NULL, NULL); } =20 QEMUWin32AIOState *win32_aio_init(void) diff --git a/hw/i386/kvm/xen_xenstore.c b/hw/i386/kvm/xen_xenstore.c index 6e81bc8791..0b189c6ab8 100644 --- a/hw/i386/kvm/xen_xenstore.c +++ b/hw/i386/kvm/xen_xenstore.c @@ -133,7 +133,7 @@ static void xen_xenstore_realize(DeviceState *dev, Erro= r **errp) error_setg(errp, "Xenstore evtchn port init failed"); return; } - aio_set_fd_handler(qemu_get_aio_context(), xen_be_evtchn_fd(s->eh), fa= lse, + aio_set_fd_handler(qemu_get_aio_context(), xen_be_evtchn_fd(s->eh), xen_xenstore_event, NULL, NULL, NULL, s); =20 s->impl =3D xs_impl_create(xen_domid); diff --git a/hw/virtio/virtio.c b/hw/virtio/virtio.c index 08011be8dc..295a603e58 100644 --- a/hw/virtio/virtio.c +++ b/hw/virtio/virtio.c @@ -3491,7 +3491,7 @@ static void virtio_queue_host_notifier_aio_poll_end(E= ventNotifier *n) =20 void virtio_queue_aio_attach_host_notifier(VirtQueue *vq, AioContext *ctx) { - aio_set_event_notifier(ctx, &vq->host_notifier, false, + aio_set_event_notifier(ctx, &vq->host_notifier, virtio_queue_host_notifier_read, virtio_queue_host_notifier_aio_poll, virtio_queue_host_notifier_aio_poll_ready); @@ -3508,14 +3508,14 @@ void virtio_queue_aio_attach_host_notifier(VirtQueu= e *vq, AioContext *ctx) */ void virtio_queue_aio_attach_host_notifier_no_poll(VirtQueue *vq, AioConte= xt *ctx) { - aio_set_event_notifier(ctx, &vq->host_notifier, false, + aio_set_event_notifier(ctx, &vq->host_notifier, virtio_queue_host_notifier_read, NULL, NULL); } =20 void virtio_queue_aio_detach_host_notifier(VirtQueue *vq, AioContext *ctx) { - aio_set_event_notifier(ctx, &vq->host_notifier, false, NULL, NULL, NUL= L); + aio_set_event_notifier(ctx, &vq->host_notifier, NULL, NULL, NULL); } =20 void virtio_queue_host_notifier_read(EventNotifier *n) diff --git a/hw/xen/xen-bus.c b/hw/xen/xen-bus.c index bf256d4da2..1e08cf027a 100644 --- a/hw/xen/xen-bus.c +++ b/hw/xen/xen-bus.c @@ -842,14 +842,14 @@ void xen_device_set_event_channel_context(XenDevice *= xendev, } =20 if (channel->ctx) - aio_set_fd_handler(channel->ctx, qemu_xen_evtchn_fd(channel->xeh),= false, + aio_set_fd_handler(channel->ctx, qemu_xen_evtchn_fd(channel->xeh), NULL, NULL, NULL, NULL, NULL); =20 channel->ctx =3D ctx; if (ctx) { aio_set_fd_handler(channel->ctx, qemu_xen_evtchn_fd(channel->xeh), - false, xen_device_event, NULL, xen_device_poll, - NULL, channel); + xen_device_event, NULL, xen_device_poll, NULL, + channel); } } =20 @@ -923,7 +923,7 @@ void xen_device_unbind_event_channel(XenDevice *xendev, =20 QLIST_REMOVE(channel, list); =20 - aio_set_fd_handler(channel->ctx, qemu_xen_evtchn_fd(channel->xeh), fal= se, + aio_set_fd_handler(channel->ctx, qemu_xen_evtchn_fd(channel->xeh), NULL, NULL, NULL, NULL, NULL); =20 if (qemu_xen_evtchn_unbind(channel->xeh, channel->local_port) < 0) { diff --git a/io/channel-command.c b/io/channel-command.c index e7edd091af..7ed726c802 100644 --- a/io/channel-command.c +++ b/io/channel-command.c @@ -337,10 +337,8 @@ static void qio_channel_command_set_aio_fd_handler(QIO= Channel *ioc, void *opaque) { QIOChannelCommand *cioc =3D QIO_CHANNEL_COMMAND(ioc); - aio_set_fd_handler(ctx, cioc->readfd, false, - io_read, NULL, NULL, NULL, opaque); - aio_set_fd_handler(ctx, cioc->writefd, false, - NULL, io_write, NULL, NULL, opaque); + aio_set_fd_handler(ctx, cioc->readfd, io_read, NULL, NULL, NULL, opaqu= e); + aio_set_fd_handler(ctx, cioc->writefd, NULL, io_write, NULL, NULL, opa= que); } =20 =20 diff --git a/io/channel-file.c b/io/channel-file.c index d76663e6ae..8b5821f452 100644 --- a/io/channel-file.c +++ b/io/channel-file.c @@ -198,8 +198,7 @@ static void qio_channel_file_set_aio_fd_handler(QIOChan= nel *ioc, void *opaque) { QIOChannelFile *fioc =3D QIO_CHANNEL_FILE(ioc); - aio_set_fd_handler(ctx, fioc->fd, false, io_read, io_write, - NULL, NULL, opaque); + aio_set_fd_handler(ctx, fioc->fd, io_read, io_write, NULL, NULL, opaqu= e); } =20 static GSource *qio_channel_file_create_watch(QIOChannel *ioc, diff --git a/io/channel-socket.c b/io/channel-socket.c index b0ea7d48b3..d99945ebec 100644 --- a/io/channel-socket.c +++ b/io/channel-socket.c @@ -899,8 +899,7 @@ static void qio_channel_socket_set_aio_fd_handler(QIOCh= annel *ioc, void *opaque) { QIOChannelSocket *sioc =3D QIO_CHANNEL_SOCKET(ioc); - aio_set_fd_handler(ctx, sioc->fd, false, - io_read, io_write, NULL, NULL, opaque); + aio_set_fd_handler(ctx, sioc->fd, io_read, io_write, NULL, NULL, opaqu= e); } =20 static GSource *qio_channel_socket_create_watch(QIOChannel *ioc, diff --git a/migration/rdma.c b/migration/rdma.c index 2e4dcff1c9..dd1c039e6c 100644 --- a/migration/rdma.c +++ b/migration/rdma.c @@ -3110,15 +3110,15 @@ static void qio_channel_rdma_set_aio_fd_handler(QIO= Channel *ioc, { QIOChannelRDMA *rioc =3D QIO_CHANNEL_RDMA(ioc); if (io_read) { - aio_set_fd_handler(ctx, rioc->rdmain->recv_comp_channel->fd, - false, io_read, io_write, NULL, NULL, opaque); - aio_set_fd_handler(ctx, rioc->rdmain->send_comp_channel->fd, - false, io_read, io_write, NULL, NULL, opaque); + aio_set_fd_handler(ctx, rioc->rdmain->recv_comp_channel->fd, io_re= ad, + io_write, NULL, NULL, opaque); + aio_set_fd_handler(ctx, rioc->rdmain->send_comp_channel->fd, io_re= ad, + io_write, NULL, NULL, opaque); } else { - aio_set_fd_handler(ctx, rioc->rdmaout->recv_comp_channel->fd, - false, io_read, io_write, NULL, NULL, opaque); - aio_set_fd_handler(ctx, rioc->rdmaout->send_comp_channel->fd, - false, io_read, io_write, NULL, NULL, opaque); + aio_set_fd_handler(ctx, rioc->rdmaout->recv_comp_channel->fd, io_r= ead, + io_write, NULL, NULL, opaque); + aio_set_fd_handler(ctx, rioc->rdmaout->send_comp_channel->fd, io_r= ead, + io_write, NULL, NULL, opaque); } } =20 diff --git a/tests/unit/test-aio.c b/tests/unit/test-aio.c index 321d7ab01a..519440eed3 100644 --- a/tests/unit/test-aio.c +++ b/tests/unit/test-aio.c @@ -130,7 +130,7 @@ static void *test_acquire_thread(void *opaque) static void set_event_notifier(AioContext *ctx, EventNotifier *notifier, EventNotifierHandler *handler) { - aio_set_event_notifier(ctx, notifier, false, handler, NULL, NULL); + aio_set_event_notifier(ctx, notifier, handler, NULL, NULL); } =20 static void dummy_notifier_read(EventNotifier *n) @@ -383,30 +383,6 @@ static void test_flush_event_notifier(void) event_notifier_cleanup(&data.e); } =20 -static void test_aio_external_client(void) -{ - int i, j; - - for (i =3D 1; i < 3; i++) { - EventNotifierTestData data =3D { .n =3D 0, .active =3D 10, .auto_s= et =3D true }; - event_notifier_init(&data.e, false); - aio_set_event_notifier(ctx, &data.e, true, event_ready_cb, NULL, N= ULL); - event_notifier_set(&data.e); - for (j =3D 0; j < i; j++) { - aio_disable_external(ctx); - } - for (j =3D 0; j < i; j++) { - assert(!aio_poll(ctx, false)); - assert(event_notifier_test_and_clear(&data.e)); - event_notifier_set(&data.e); - aio_enable_external(ctx); - } - assert(aio_poll(ctx, false)); - set_event_notifier(ctx, &data.e, NULL); - event_notifier_cleanup(&data.e); - } -} - static void test_wait_event_notifier_noflush(void) { EventNotifierTestData data =3D { .n =3D 0 }; @@ -935,7 +911,6 @@ int main(int argc, char **argv) g_test_add_func("/aio/event/wait", test_wait_event_notifi= er); g_test_add_func("/aio/event/wait/no-flush-cb", test_wait_event_notifi= er_noflush); g_test_add_func("/aio/event/flush", test_flush_event_notif= ier); - g_test_add_func("/aio/external-client", test_aio_external_clie= nt); g_test_add_func("/aio/timer/schedule", test_timer_schedule); =20 g_test_add_func("/aio/coroutine/queue-chaining", test_queue_chaining); diff --git a/tests/unit/test-bdrv-drain.c b/tests/unit/test-bdrv-drain.c index d53a633577..ccc453c29e 100644 --- a/tests/unit/test-bdrv-drain.c +++ b/tests/unit/test-bdrv-drain.c @@ -473,7 +473,6 @@ static void test_graph_change_drain_all(void) =20 g_assert_cmpint(bs_b->quiesce_counter, =3D=3D, 0); g_assert_cmpint(b_s->drain_count, =3D=3D, 0); - g_assert_cmpint(qemu_get_aio_context()->external_disable_cnt, =3D=3D, = 0); =20 bdrv_unref(bs_b); blk_unref(blk_b); diff --git a/tests/unit/test-fdmon-epoll.c b/tests/unit/test-fdmon-epoll.c deleted file mode 100644 index ef5a856d09..0000000000 --- a/tests/unit/test-fdmon-epoll.c +++ /dev/null @@ -1,73 +0,0 @@ -/* SPDX-License-Identifier: GPL-2.0-or-later */ -/* - * fdmon-epoll tests - * - * Copyright (c) 2020 Red Hat, Inc. - */ - -#include "qemu/osdep.h" -#include "block/aio.h" -#include "qapi/error.h" -#include "qemu/main-loop.h" - -static AioContext *ctx; - -static void dummy_fd_handler(EventNotifier *notifier) -{ - event_notifier_test_and_clear(notifier); -} - -static void add_event_notifiers(EventNotifier *notifiers, size_t n) -{ - for (size_t i =3D 0; i < n; i++) { - event_notifier_init(¬ifiers[i], false); - aio_set_event_notifier(ctx, ¬ifiers[i], false, - dummy_fd_handler, NULL, NULL); - } -} - -static void remove_event_notifiers(EventNotifier *notifiers, size_t n) -{ - for (size_t i =3D 0; i < n; i++) { - aio_set_event_notifier(ctx, ¬ifiers[i], false, NULL, NULL, NULL= ); - event_notifier_cleanup(¬ifiers[i]); - } -} - -/* Check that fd handlers work when external clients are disabled */ -static void test_external_disabled(void) -{ - EventNotifier notifiers[100]; - - /* fdmon-epoll is only enabled when many fd handlers are registered */ - add_event_notifiers(notifiers, G_N_ELEMENTS(notifiers)); - - event_notifier_set(¬ifiers[0]); - assert(aio_poll(ctx, true)); - - aio_disable_external(ctx); - event_notifier_set(¬ifiers[0]); - assert(aio_poll(ctx, true)); - aio_enable_external(ctx); - - remove_event_notifiers(notifiers, G_N_ELEMENTS(notifiers)); -} - -int main(int argc, char **argv) -{ - /* - * This code relies on the fact that fdmon-io_uring disables itself wh= en - * the glib main loop is in use. The main loop uses fdmon-poll and upg= rades - * to fdmon-epoll when the number of fds exceeds a threshold. - */ - qemu_init_main_loop(&error_fatal); - ctx =3D qemu_get_aio_context(); - - while (g_main_context_iteration(NULL, false)) { - /* Do nothing */ - } - - g_test_init(&argc, &argv, NULL); - g_test_add_func("/fdmon-epoll/external-disabled", test_external_disabl= ed); - return g_test_run(); -} diff --git a/tests/unit/test-nested-aio-poll.c b/tests/unit/test-nested-aio= -poll.c index 9bbe18b839..db33742af3 100644 --- a/tests/unit/test-nested-aio-poll.c +++ b/tests/unit/test-nested-aio-poll.c @@ -91,12 +91,12 @@ static void test(void) =20 /* Make the event notifier active (set) right away */ event_notifier_init(&td.poll_notifier, 1); - aio_set_event_notifier(td.ctx, &td.poll_notifier, false, + aio_set_event_notifier(td.ctx, &td.poll_notifier, io_read, io_poll_true, io_poll_ready); =20 /* This event notifier will be used later */ event_notifier_init(&td.dummy_notifier, 0); - aio_set_event_notifier(td.ctx, &td.dummy_notifier, false, + aio_set_event_notifier(td.ctx, &td.dummy_notifier, io_read, io_poll_false, io_poll_never_ready); =20 /* Consume aio_notify() */ @@ -114,9 +114,8 @@ static void test(void) /* Run io_poll()/io_poll_ready() one more time to show it keeps workin= g */ g_assert(aio_poll(td.ctx, true)); =20 - aio_set_event_notifier(td.ctx, &td.dummy_notifier, false, - NULL, NULL, NULL); - aio_set_event_notifier(td.ctx, &td.poll_notifier, false, NULL, NULL, N= ULL); + aio_set_event_notifier(td.ctx, &td.dummy_notifier, NULL, NULL, NULL); + aio_set_event_notifier(td.ctx, &td.poll_notifier, NULL, NULL, NULL); event_notifier_cleanup(&td.dummy_notifier); event_notifier_cleanup(&td.poll_notifier); aio_context_unref(td.ctx); diff --git a/util/aio-posix.c b/util/aio-posix.c index 34bc2a64d8..7f2c99729d 100644 --- a/util/aio-posix.c +++ b/util/aio-posix.c @@ -99,7 +99,6 @@ static bool aio_remove_fd_handler(AioContext *ctx, AioHan= dler *node) =20 void aio_set_fd_handler(AioContext *ctx, int fd, - bool is_external, IOHandler *io_read, IOHandler *io_write, AioPollFn *io_poll, @@ -144,7 +143,6 @@ void aio_set_fd_handler(AioContext *ctx, new_node->io_poll =3D io_poll; new_node->io_poll_ready =3D io_poll_ready; new_node->opaque =3D opaque; - new_node->is_external =3D is_external; =20 if (is_new) { new_node->pfd.fd =3D fd; @@ -196,12 +194,11 @@ static void aio_set_fd_poll(AioContext *ctx, int fd, =20 void aio_set_event_notifier(AioContext *ctx, EventNotifier *notifier, - bool is_external, EventNotifierHandler *io_read, AioPollFn *io_poll, EventNotifierHandler *io_poll_ready) { - aio_set_fd_handler(ctx, event_notifier_get_fd(notifier), is_external, + aio_set_fd_handler(ctx, event_notifier_get_fd(notifier), (IOHandler *)io_read, NULL, io_poll, (IOHandler *)io_poll_ready, notifier); } @@ -285,13 +282,11 @@ bool aio_pending(AioContext *ctx) =20 /* TODO should this check poll ready? */ revents =3D node->pfd.revents & node->pfd.events; - if (revents & (G_IO_IN | G_IO_HUP | G_IO_ERR) && node->io_read && - aio_node_check(ctx, node->is_external)) { + if (revents & (G_IO_IN | G_IO_HUP | G_IO_ERR) && node->io_read) { result =3D true; break; } - if (revents & (G_IO_OUT | G_IO_ERR) && node->io_write && - aio_node_check(ctx, node->is_external)) { + if (revents & (G_IO_OUT | G_IO_ERR) && node->io_write) { result =3D true; break; } @@ -350,9 +345,7 @@ static bool aio_dispatch_handler(AioContext *ctx, AioHa= ndler *node) QLIST_INSERT_HEAD(&ctx->poll_aio_handlers, node, node_poll); } if (!QLIST_IS_INSERTED(node, node_deleted) && - poll_ready && revents =3D=3D 0 && - aio_node_check(ctx, node->is_external) && - node->io_poll_ready) { + poll_ready && revents =3D=3D 0 && node->io_poll_ready) { /* * Remove temporarily to avoid infinite loops when ->io_poll_ready= () * calls aio_poll() before clearing the condition that made the po= ll @@ -375,7 +368,6 @@ static bool aio_dispatch_handler(AioContext *ctx, AioHa= ndler *node) =20 if (!QLIST_IS_INSERTED(node, node_deleted) && (revents & (G_IO_IN | G_IO_HUP | G_IO_ERR)) && - aio_node_check(ctx, node->is_external) && node->io_read) { node->io_read(node->opaque); =20 @@ -386,7 +378,6 @@ static bool aio_dispatch_handler(AioContext *ctx, AioHa= ndler *node) } if (!QLIST_IS_INSERTED(node, node_deleted) && (revents & (G_IO_OUT | G_IO_ERR)) && - aio_node_check(ctx, node->is_external) && node->io_write) { node->io_write(node->opaque); progress =3D true; @@ -447,8 +438,7 @@ static bool run_poll_handlers_once(AioContext *ctx, AioHandler *tmp; =20 QLIST_FOREACH_SAFE(node, &ctx->poll_aio_handlers, node_poll, tmp) { - if (aio_node_check(ctx, node->is_external) && - node->io_poll(node->opaque)) { + if (node->io_poll(node->opaque)) { aio_add_poll_ready_handler(ready_list, node); =20 node->poll_idle_timeout =3D now + POLL_IDLE_INTERVAL_NS; diff --git a/util/aio-win32.c b/util/aio-win32.c index 6bded009a4..948ef47a4d 100644 --- a/util/aio-win32.c +++ b/util/aio-win32.c @@ -32,7 +32,6 @@ struct AioHandler { GPollFD pfd; int deleted; void *opaque; - bool is_external; QLIST_ENTRY(AioHandler) node; }; =20 @@ -64,7 +63,6 @@ static void aio_remove_fd_handler(AioContext *ctx, AioHan= dler *node) =20 void aio_set_fd_handler(AioContext *ctx, int fd, - bool is_external, IOHandler *io_read, IOHandler *io_write, AioPollFn *io_poll, @@ -111,7 +109,6 @@ void aio_set_fd_handler(AioContext *ctx, node->opaque =3D opaque; node->io_read =3D io_read; node->io_write =3D io_write; - node->is_external =3D is_external; =20 if (io_read) { bitmask |=3D FD_READ | FD_ACCEPT | FD_CLOSE; @@ -135,7 +132,6 @@ void aio_set_fd_handler(AioContext *ctx, =20 void aio_set_event_notifier(AioContext *ctx, EventNotifier *e, - bool is_external, EventNotifierHandler *io_notify, AioPollFn *io_poll, EventNotifierHandler *io_poll_ready) @@ -161,7 +157,6 @@ void aio_set_event_notifier(AioContext *ctx, node->e =3D e; node->pfd.fd =3D (uintptr_t)event_notifier_get_handle(e); node->pfd.events =3D G_IO_IN; - node->is_external =3D is_external; QLIST_INSERT_HEAD_RCU(&ctx->aio_handlers, node, node); =20 g_source_add_poll(&ctx->source, &node->pfd); @@ -368,8 +363,7 @@ bool aio_poll(AioContext *ctx, bool blocking) /* fill fd sets */ count =3D 0; QLIST_FOREACH_RCU(node, &ctx->aio_handlers, node) { - if (!node->deleted && node->io_notify - && aio_node_check(ctx, node->is_external)) { + if (!node->deleted && node->io_notify) { assert(count < MAXIMUM_WAIT_OBJECTS); events[count++] =3D event_notifier_get_handle(node->e); } diff --git a/util/async.c b/util/async.c index 055070ffbd..8f90ddc304 100644 --- a/util/async.c +++ b/util/async.c @@ -409,7 +409,7 @@ aio_ctx_finalize(GSource *source) g_free(bh); } =20 - aio_set_event_notifier(ctx, &ctx->notifier, false, NULL, NULL, NULL); + aio_set_event_notifier(ctx, &ctx->notifier, NULL, NULL, NULL); event_notifier_cleanup(&ctx->notifier); qemu_rec_mutex_destroy(&ctx->lock); qemu_lockcnt_destroy(&ctx->list_lock); @@ -593,7 +593,6 @@ AioContext *aio_context_new(Error **errp) QSLIST_INIT(&ctx->scheduled_coroutines); =20 aio_set_event_notifier(ctx, &ctx->notifier, - false, aio_context_notifier_cb, aio_context_notifier_poll, aio_context_notifier_poll_ready); diff --git a/util/fdmon-epoll.c b/util/fdmon-epoll.c index 1683aa1105..c6413cb18f 100644 --- a/util/fdmon-epoll.c +++ b/util/fdmon-epoll.c @@ -64,11 +64,6 @@ static int fdmon_epoll_wait(AioContext *ctx, AioHandlerL= ist *ready_list, int i, ret =3D 0; struct epoll_event events[128]; =20 - /* Fall back while external clients are disabled */ - if (qatomic_read(&ctx->external_disable_cnt)) { - return fdmon_poll_ops.wait(ctx, ready_list, timeout); - } - if (timeout > 0) { ret =3D qemu_poll_ns(&pfd, 1, timeout); if (ret > 0) { @@ -133,11 +128,6 @@ bool fdmon_epoll_try_upgrade(AioContext *ctx, unsigned= npfd) return false; } =20 - /* Do not upgrade while external clients are disabled */ - if (qatomic_read(&ctx->external_disable_cnt)) { - return false; - } - if (npfd < EPOLL_ENABLE_THRESHOLD) { return false; } diff --git a/util/fdmon-io_uring.c b/util/fdmon-io_uring.c index ab43052dd7..17ec18b7bd 100644 --- a/util/fdmon-io_uring.c +++ b/util/fdmon-io_uring.c @@ -276,11 +276,6 @@ static int fdmon_io_uring_wait(AioContext *ctx, AioHan= dlerList *ready_list, unsigned wait_nr =3D 1; /* block until at least one cqe is ready */ int ret; =20 - /* Fall back while external clients are disabled */ - if (qatomic_read(&ctx->external_disable_cnt)) { - return fdmon_poll_ops.wait(ctx, ready_list, timeout); - } - if (timeout =3D=3D 0) { wait_nr =3D 0; /* non-blocking */ } else if (timeout > 0) { @@ -315,8 +310,7 @@ static bool fdmon_io_uring_need_wait(AioContext *ctx) return true; } =20 - /* Are we falling back to fdmon-poll? */ - return qatomic_read(&ctx->external_disable_cnt); + return false; } =20 static const FDMonOps fdmon_io_uring_ops =3D { diff --git a/util/fdmon-poll.c b/util/fdmon-poll.c index 5fe3b47865..17df917cf9 100644 --- a/util/fdmon-poll.c +++ b/util/fdmon-poll.c @@ -65,8 +65,7 @@ static int fdmon_poll_wait(AioContext *ctx, AioHandlerLis= t *ready_list, assert(npfd =3D=3D 0); =20 QLIST_FOREACH_RCU(node, &ctx->aio_handlers, node) { - if (!QLIST_IS_INSERTED(node, node_deleted) && node->pfd.events - && aio_node_check(ctx, node->is_external)) { + if (!QLIST_IS_INSERTED(node, node_deleted) && node->pfd.events) { add_pollfd(node); } } diff --git a/util/main-loop.c b/util/main-loop.c index 7022f02ef8..014c795916 100644 --- a/util/main-loop.c +++ b/util/main-loop.c @@ -644,14 +644,13 @@ void qemu_set_fd_handler(int fd, void *opaque) { iohandler_init(); - aio_set_fd_handler(iohandler_ctx, fd, false, - fd_read, fd_write, NULL, NULL, opaque); + aio_set_fd_handler(iohandler_ctx, fd, fd_read, fd_write, NULL, NULL, + opaque); } =20 void event_notifier_set_handler(EventNotifier *e, EventNotifierHandler *handler) { iohandler_init(); - aio_set_event_notifier(iohandler_ctx, e, false, - handler, NULL, NULL); + aio_set_event_notifier(iohandler_ctx, e, handler, NULL, NULL); } diff --git a/util/qemu-coroutine-io.c b/util/qemu-coroutine-io.c index d791932d63..364f4d5abf 100644 --- a/util/qemu-coroutine-io.c +++ b/util/qemu-coroutine-io.c @@ -74,8 +74,7 @@ typedef struct { static void fd_coroutine_enter(void *opaque) { FDYieldUntilData *data =3D opaque; - aio_set_fd_handler(data->ctx, data->fd, false, - NULL, NULL, NULL, NULL, NULL); + aio_set_fd_handler(data->ctx, data->fd, NULL, NULL, NULL, NULL, NULL); qemu_coroutine_enter(data->co); } =20 @@ -87,7 +86,7 @@ void coroutine_fn yield_until_fd_readable(int fd) data.ctx =3D qemu_get_current_aio_context(); data.co =3D qemu_coroutine_self(); data.fd =3D fd; - aio_set_fd_handler( - data.ctx, fd, false, fd_coroutine_enter, NULL, NULL, NULL, &data); + aio_set_fd_handler(data.ctx, fd, fd_coroutine_enter, NULL, NULL, NULL, + &data); qemu_coroutine_yield(); } diff --git a/util/vhost-user-server.c b/util/vhost-user-server.c index a12b2d1bba..cd17fb5326 100644 --- a/util/vhost-user-server.c +++ b/util/vhost-user-server.c @@ -278,7 +278,7 @@ set_watch(VuDev *vu_dev, int fd, int vu_evt, vu_fd_watch->fd =3D fd; vu_fd_watch->cb =3D cb; qemu_socket_set_nonblock(fd); - aio_set_fd_handler(server->ioc->ctx, fd, false, kick_handler, + aio_set_fd_handler(server->ioc->ctx, fd, kick_handler, NULL, NULL, NULL, vu_fd_watch); vu_fd_watch->vu_dev =3D vu_dev; vu_fd_watch->pvt =3D pvt; @@ -299,8 +299,7 @@ static void remove_watch(VuDev *vu_dev, int fd) if (!vu_fd_watch) { return; } - aio_set_fd_handler(server->ioc->ctx, fd, false, - NULL, NULL, NULL, NULL, NULL); + aio_set_fd_handler(server->ioc->ctx, fd, NULL, NULL, NULL, NULL, NULL); =20 QTAILQ_REMOVE(&server->vu_fd_watches, vu_fd_watch, next); g_free(vu_fd_watch); @@ -362,7 +361,7 @@ void vhost_user_server_stop(VuServer *server) VuFdWatch *vu_fd_watch; =20 QTAILQ_FOREACH(vu_fd_watch, &server->vu_fd_watches, next) { - aio_set_fd_handler(server->ctx, vu_fd_watch->fd, false, + aio_set_fd_handler(server->ctx, vu_fd_watch->fd, NULL, NULL, NULL, NULL, vu_fd_watch); } =20 @@ -403,7 +402,7 @@ void vhost_user_server_attach_aio_context(VuServer *ser= ver, AioContext *ctx) qio_channel_attach_aio_context(server->ioc, ctx); =20 QTAILQ_FOREACH(vu_fd_watch, &server->vu_fd_watches, next) { - aio_set_fd_handler(ctx, vu_fd_watch->fd, false, kick_handler, NULL, + aio_set_fd_handler(ctx, vu_fd_watch->fd, kick_handler, NULL, NULL, NULL, vu_fd_watch); } =20 @@ -417,7 +416,7 @@ void vhost_user_server_detach_aio_context(VuServer *ser= ver) VuFdWatch *vu_fd_watch; =20 QTAILQ_FOREACH(vu_fd_watch, &server->vu_fd_watches, next) { - aio_set_fd_handler(server->ctx, vu_fd_watch->fd, false, + aio_set_fd_handler(server->ctx, vu_fd_watch->fd, NULL, NULL, NULL, NULL, vu_fd_watch); } =20 diff --git a/tests/unit/meson.build b/tests/unit/meson.build index 3a6314269b..93977cc32d 100644 --- a/tests/unit/meson.build +++ b/tests/unit/meson.build @@ -125,9 +125,6 @@ if have_block if nettle.found() or gcrypt.found() tests +=3D {'test-crypto-pbkdf': [io]} endif - if config_host_data.get('CONFIG_EPOLL_CREATE1') - tests +=3D {'test-fdmon-epoll': [testblock]} - endif endif =20 if have_system --=20 2.40.1