From nobody Sun May 5 11:43:48 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.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; Authentication-Results: mx.zohomail.com; spf=pass (zoho.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=redhat.com Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 15505262767591012.7682323383112; Mon, 18 Feb 2019 13:44:36 -0800 (PST) Received: from localhost ([127.0.0.1]:37045 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gvqiH-00087p-KT for importer@patchew.org; Mon, 18 Feb 2019 16:44:33 -0500 Received: from eggs.gnu.org ([209.51.188.92]:53206) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gvqgt-0007VP-SU for qemu-devel@nongnu.org; Mon, 18 Feb 2019 16:43:11 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1gvqgs-00060u-Rb for qemu-devel@nongnu.org; Mon, 18 Feb 2019 16:43:07 -0500 Received: from mx1.redhat.com ([209.132.183.28]:54080) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1gvqgn-0005ui-Ra; Mon, 18 Feb 2019 16:43:03 -0500 Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.phx2.redhat.com [10.5.11.15]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id DDBB685360; Mon, 18 Feb 2019 21:42:55 +0000 (UTC) Received: from probe.bos.redhat.com (dhcp-17-92.bos.redhat.com [10.18.17.92]) by smtp.corp.redhat.com (Postfix) with ESMTP id E34385D70E; Mon, 18 Feb 2019 21:42:54 +0000 (UTC) From: John Snow To: qemu-devel@nongnu.org, qemu-block@nongnu.org Date: Mon, 18 Feb 2019 16:42:51 -0500 Message-Id: <20190218214251.8969-2-jsnow@redhat.com> In-Reply-To: <20190218214251.8969-1-jsnow@redhat.com> References: <20190218214251.8969-1-jsnow@redhat.com> X-Scanned-By: MIMEDefang 2.79 on 10.5.11.15 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.25]); Mon, 18 Feb 2019 21:42:55 +0000 (UTC) X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 209.132.183.28 Subject: [Qemu-devel] [PATCH v4 1/1] blockdev: acquire aio_context for bitmap add/remove X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Kevin Wolf , vsementsov@virtuozzo.com, John Snow , Markus Armbruster , Max Reitz , pbonzini@redhat.com Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" When bitmaps are persistent, they may incur a disk read or write when bitma= ps are added or removed. For configurations like virtio-dataplane, failing to acquire this lock will abort QEMU when disk IO occurs. We used to acquire aio_context as part of the bitmap lookup, so re-introduce the lock for just the cases that have an IO penalty. Commit 2119882c removed these locks, and I failed to notice this when we committed fd5ae4cc, so this has been broken since persistent bitmaps were introduced. Fixes: https://bugzilla.redhat.com/show_bug.cgi?id=3D1672010 Reported-By: Aihua Liang Signed-off-by: John Snow Reviewed-by: Eric Blake --- blockdev.c | 26 ++++++++++++++++++++------ 1 file changed, 20 insertions(+), 6 deletions(-) diff --git a/blockdev.c b/blockdev.c index fb18e9c975..790b0e0ac8 100644 --- a/blockdev.c +++ b/blockdev.c @@ -2820,6 +2820,7 @@ void qmp_block_dirty_bitmap_add(const char *node, con= st char *name, { BlockDriverState *bs; BdrvDirtyBitmap *bitmap; + AioContext *aio_context =3D NULL; =20 if (!name || name[0] =3D=3D '\0') { error_setg(errp, "Bitmap name cannot be empty"); @@ -2854,15 +2855,17 @@ void qmp_block_dirty_bitmap_add(const char *node, c= onst char *name, disabled =3D false; } =20 - if (persistent && - !bdrv_can_store_new_dirty_bitmap(bs, name, granularity, errp)) - { - return; + if (persistent) { + aio_context =3D bdrv_get_aio_context(bs); + aio_context_acquire(aio_context); + if (!bdrv_can_store_new_dirty_bitmap(bs, name, granularity, errp))= { + goto out; + } } =20 bitmap =3D bdrv_create_dirty_bitmap(bs, granularity, name, errp); if (bitmap =3D=3D NULL) { - return; + goto out } =20 if (disabled) { @@ -2870,6 +2873,10 @@ void qmp_block_dirty_bitmap_add(const char *node, co= nst char *name, } =20 bdrv_dirty_bitmap_set_persistance(bitmap, persistent); + out: + if (aio_context) { + aio_context_release(aio_context); + } } =20 void qmp_block_dirty_bitmap_remove(const char *node, const char *name, @@ -2878,6 +2885,7 @@ void qmp_block_dirty_bitmap_remove(const char *node, = const char *name, BlockDriverState *bs; BdrvDirtyBitmap *bitmap; Error *local_err =3D NULL; + AioContext *aio_context =3D NULL; =20 bitmap =3D block_dirty_bitmap_lookup(node, name, &bs, errp); if (!bitmap || !bs) { @@ -2892,14 +2900,20 @@ void qmp_block_dirty_bitmap_remove(const char *node= , const char *name, } =20 if (bdrv_dirty_bitmap_get_persistance(bitmap)) { + aio_context =3D bdrv_get_aio_context(bs); + aio_context_acquire(aio_context); bdrv_remove_persistent_dirty_bitmap(bs, name, &local_err); if (local_err !=3D NULL) { error_propagate(errp, local_err); - return; + goto out; } } =20 bdrv_release_dirty_bitmap(bs, bitmap); + out: + if (aio_context) { + aio_context_release(aio_context); + } } =20 /** --=20 2.17.2