From nobody Sun May 5 02:58:45 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=1685531137; cv=none; d=zohomail.com; s=zohoarc; b=A7iGVOZ8+bHhj5z8NIda5bLjBBm+dMBxDfDf54BO0qY13zex9RX2rKSFxEFx81HOH8ZvF5L3JAQihzszsv3t4WrxNHnV2F9D121uNAk2XzkD57eHSrb0V629B42RmMRdxfiAawF8ABLbxCEtLnUPnmBxwKPCX8m6rOjATs85Wos= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1685531137; 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=tHveehT08bzxo9rEqWtjRYG+1BMyzRv3ibUTtU6UWxM=; b=lvwdovNoBiCZEP+rB5ihvWClhvqLpa0zDrJ0phLE2ox5PiGV51d72p2p4gTrkrMAZohNMGBjFsvRbTWX0SM1u6lV8i0PXMM37kQamwClk8br4bqdQH/Ckp0oGMppNjqh3wjdr2UZnhgDQQVuLxTaDmxyumCdRm+/wup9J9bXBPk= 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 1685531136850697.1434193464463; Wed, 31 May 2023 04:05:36 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1q4JcL-0007aj-0m; Wed, 31 May 2023 07:03: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 1q4Jby-0007Rb-FH for qemu-devel@nongnu.org; Wed, 31 May 2023 07:03:26 -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 1q4Jbu-0001en-Id for qemu-devel@nongnu.org; Wed, 31 May 2023 07:03:24 -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-502-lXen4YB7OZW08ZYGfvgAng-1; Wed, 31 May 2023 07:02:40 -0400 Received: from smtp.corp.redhat.com (int-mx04.intmail.prod.int.rdu2.redhat.com [10.11.54.4]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 28B5C185A793; Wed, 31 May 2023 11:02:40 +0000 (UTC) Received: from merkur.fritz.box (unknown [10.39.194.90]) by smtp.corp.redhat.com (Postfix) with ESMTP id 10C19200B68F; Wed, 31 May 2023 11:02:38 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1685530963; 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=tHveehT08bzxo9rEqWtjRYG+1BMyzRv3ibUTtU6UWxM=; b=ClS1McNipFFY3zDC7jgSpfBJ5JV/0sDXc3ZNpoMhd1IiOpLE4ujVlgjaD8kpwwq0vzEwez R4s5nN/NIItDYd39qusFts3YtZ5FlGd2iCbjB6CY3ABhqCTmcwWluFNUWdwUZf+i0bGL4W LgDqYTd5PvKC6G0Pbggah+3uc4dbY3U= X-MC-Unique: lXen4YB7OZW08ZYGfvgAng-1 From: Kevin Wolf To: qemu-block@nongnu.org Cc: kwolf@redhat.com, stefanha@redhat.com, hreitz@redhat.com, eblake@redhat.com, qemu-devel@nongnu.org Subject: [PATCH 01/11] iotests: Test active commit with iothread and background I/O Date: Wed, 31 May 2023 13:02:21 +0200 Message-Id: <20230531110231.262251-2-kwolf@redhat.com> In-Reply-To: <20230531110231.262251-1-kwolf@redhat.com> References: <20230531110231.262251-1-kwolf@redhat.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Scanned-By: MIMEDefang 3.1 on 10.11.54.4 Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=170.10.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.163, 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: 1685531137410100001 Content-Type: text/plain; charset="utf-8" This is a better regression test for the bugs hidden by commit 80fc5d26 ('graph-lock: Disable locking for now'). With that commit reverted, it hangs instantaneously and reliably for me. It is important to have a reliable test like this, because the following commits will set out to fix the actual root cause of the deadlocks and then finally revert commit 80fc5d26, which was only a stopgap solution. Signed-off-by: Kevin Wolf --- .../tests/iothreads-commit-active | 85 +++++++++++++++++++ .../tests/iothreads-commit-active.out | 23 +++++ 2 files changed, 108 insertions(+) create mode 100755 tests/qemu-iotests/tests/iothreads-commit-active create mode 100644 tests/qemu-iotests/tests/iothreads-commit-active.out diff --git a/tests/qemu-iotests/tests/iothreads-commit-active b/tests/qemu-= iotests/tests/iothreads-commit-active new file mode 100755 index 0000000000..4010a4871f --- /dev/null +++ b/tests/qemu-iotests/tests/iothreads-commit-active @@ -0,0 +1,85 @@ +#!/usr/bin/env python3 +# group: rw quick auto +# +# 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'], + supported_platforms=3D['linux']) +iotests.verify_virtio_scsi_pci_or_ccw() + +with iotests.FilePath('disk0.img') as img_path, \ + iotests.FilePath('disk0-snap.img') as snap_path, \ + iotests.FilePath('mirror-src.img') as src_path, \ + iotests.FilePath('mirror-dst.img') as dst_path, \ + iotests.VM() as vm: + + img_size =3D '10M' + iotests.qemu_img_create('-f', iotests.imgfmt, img_path, img_size) + iotests.qemu_img_create('-f', iotests.imgfmt, '-b', img_path, + '-F', iotests.imgfmt, snap_path) + iotests.qemu_img_create('-f', iotests.imgfmt, src_path, img_size) + iotests.qemu_img_create('-f', iotests.imgfmt, dst_path, img_size) + + iotests.qemu_io_log('-c', 'write 0 64k', img_path) + iotests.qemu_io_log('-c', 'write 1M 64k', snap_path) + iotests.qemu_io_log('-c', 'write 3M 64k', snap_path) + + iotests.qemu_io_log('-c', f'write 0 {img_size}', src_path) + + iotests.log('Launching VM...') + vm.add_object('iothread,id=3Diothread0') + vm.add_object('throttle-group,x-bps-write=3D1048576,id=3Dtg0') + vm.add_blockdev(f'file,node-name=3Ddisk0-file,filename=3D{img_path}') + vm.add_blockdev('qcow2,node-name=3Ddisk0-fmt,file=3Ddisk0-file') + vm.add_drive(snap_path, 'backing=3Ddisk0-fmt,node-name=3Ddisk0', + interface=3D'none') + vm.add_device('virtio-scsi,iothread=3Diothread0') + vm.add_device('scsi-hd,drive=3Ddrive0') + + vm.add_blockdev(f'file,filename=3D{src_path},node-name=3Dmirror-src-fi= le') + vm.add_blockdev('qcow2,file=3Dmirror-src-file,node-name=3Dmirror-src') + vm.add_blockdev(f'file,filename=3D{dst_path},node-name=3Dmirror-dst-fi= le') + vm.add_blockdev('qcow2,file=3Dmirror-dst-file,node-name=3Dmirror-dst-f= mt') + vm.add_blockdev('throttle,throttle-group=3Dtg0,file=3Dmirror-dst-fmt,' + 'node-name=3Dmirror-dst') + vm.add_device('scsi-hd,drive=3Dmirror-src') + + vm.launch() + + # The background I/O is created on unrelated nodes (so that they won't= be + # drained together with the other ones), but on the same iothread + iotests.log('Creating some background I/O...') + iotests.log(vm.qmp('blockdev-mirror', job_id=3D'job0', sync=3D'full', + device=3D'mirror-src', target=3D'mirror-dst', + auto_dismiss=3DFalse)) + + iotests.log('Starting active commit...') + iotests.log(vm.qmp('block-commit', device=3D'disk0', job_id=3D'job1', + auto_dismiss=3DFalse)) + + # Should succeed and not time out + try: + vm.run_job('job1', 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-commit-active.out b/tests/q= emu-iotests/tests/iothreads-commit-active.out new file mode 100644 index 0000000000..4afd50b8d3 --- /dev/null +++ b/tests/qemu-iotests/tests/iothreads-commit-active.out @@ -0,0 +1,23 @@ +wrote 65536/65536 bytes at offset 0 +64 KiB, X ops; XX:XX:XX.X (XXX YYY/sec and XXX ops/sec) + +wrote 65536/65536 bytes at offset 1048576 +64 KiB, X ops; XX:XX:XX.X (XXX YYY/sec and XXX ops/sec) + +wrote 65536/65536 bytes at offset 3145728 +64 KiB, X ops; XX:XX:XX.X (XXX YYY/sec and XXX ops/sec) + +wrote 10485760/10485760 bytes at offset 0 +10 MiB, X ops; XX:XX:XX.X (XXX YYY/sec and XXX ops/sec) + +Launching VM... +Creating some background I/O... +{"return": {}} +Starting active commit... +{"return": {}} +{"execute": "job-complete", "arguments": {"id": "job1"}} +{"return": {}} +{"data": {"device": "job1", "len": 131072, "offset": 131072, "speed": 0, "= type": "commit"}, "event": "BLOCK_JOB_READY", "timestamp": {"microseconds":= "USECS", "seconds": "SECS"}} +{"data": {"device": "job1", "len": 131072, "offset": 131072, "speed": 0, "= type": "commit"}, "event": "BLOCK_JOB_COMPLETED", "timestamp": {"microsecon= ds": "USECS", "seconds": "SECS"}} +{"execute": "job-dismiss", "arguments": {"id": "job1"}} +{"return": {}} --=20 2.40.1 From nobody Sun May 5 02:58:45 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=1685531172; cv=none; d=zohomail.com; s=zohoarc; b=TvzOK1ZLTHHMHwnXScpTa3I2woRWb5LB319nEqCzEb8wLGKewchtPVzj1jUjj2EcpQBo01F4Ew3KyqvmOe2JSD75zijwVIzOFdh9afA3Evzc1x/I2jmw3yQ9IjND45mzAmL0vPavcgFqo8nMjeR9e51mQ4bKwcrYxxFrH+NobIk= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1685531172; 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=IOJrNXqNGC6IPJjtQvQ91e3pVQdJqGF1iDAH9V2MKmI=; b=SFCA11b7GsR6XcYBzQNtcgwflJrXAT6jZllcYYSn1QWAcGU8O+TrAFutGn7prFAE7D0FND1isFUNrFeb4mu6JWRCBmWIKPBfuZiYrf2hfVx9PXNtLZ+LRf7SIDS7X1nenDaHubQ4sawvHgmLTy3x81aWbvQDd6qyJY9VGKAwdQA= 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 1685531172824459.6453756944678; Wed, 31 May 2023 04:06:12 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1q4JcQ-0007g1-7B; Wed, 31 May 2023 07:03: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 1q4Jbs-0007QD-Hx for qemu-devel@nongnu.org; Wed, 31 May 2023 07:03:25 -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 1q4Jbf-0001ev-CR for qemu-devel@nongnu.org; Wed, 31 May 2023 07:03:15 -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-359-Y0edXdmMPh-z5UMVX_N5-Q-1; Wed, 31 May 2023 07:02:41 -0400 Received: from smtp.corp.redhat.com (int-mx04.intmail.prod.int.rdu2.redhat.com [10.11.54.4]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 5648D1C05153; Wed, 31 May 2023 11:02:41 +0000 (UTC) Received: from merkur.fritz.box (unknown [10.39.194.90]) by smtp.corp.redhat.com (Postfix) with ESMTP id 5F0E820296C6; Wed, 31 May 2023 11:02:40 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1685530965; 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=IOJrNXqNGC6IPJjtQvQ91e3pVQdJqGF1iDAH9V2MKmI=; b=T68bzDolkmNEilhwi2mos9bVpJut6LeDIvyUlWe39sV48QXi9+nbphtAA9MIIvJrvtkhYI tT4vzMII3vrAO9J/iMgxrnND22GGm226FVCrLXFbvLdQl9rogQYU4slNPesivec1INww3n ce4CJg9+OcH1R5iVoHU+G7uEXh1JrxU= X-MC-Unique: Y0edXdmMPh-z5UMVX_N5-Q-1 From: Kevin Wolf To: qemu-block@nongnu.org Cc: kwolf@redhat.com, stefanha@redhat.com, hreitz@redhat.com, eblake@redhat.com, qemu-devel@nongnu.org Subject: [PATCH 02/11] qdev-properties-system: Lock AioContext for blk_insert_bs() Date: Wed, 31 May 2023 13:02:22 +0200 Message-Id: <20230531110231.262251-3-kwolf@redhat.com> In-Reply-To: <20230531110231.262251-1-kwolf@redhat.com> References: <20230531110231.262251-1-kwolf@redhat.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Scanned-By: MIMEDefang 3.1 on 10.11.54.4 Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=170.10.129.124; envelope-from=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.163, 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: 1685531173592100001 Content-Type: text/plain; charset="utf-8" blk_insert_bs() requires that callers hold the AioContext lock for the node that should be inserted. Take it. Signed-off-by: Kevin Wolf --- hw/core/qdev-properties-system.c | 3 +++ 1 file changed, 3 insertions(+) diff --git a/hw/core/qdev-properties-system.c b/hw/core/qdev-properties-sys= tem.c index d42493f630..7f6b14276a 100644 --- a/hw/core/qdev-properties-system.c +++ b/hw/core/qdev-properties-system.c @@ -147,7 +147,10 @@ static void set_drive_helper(Object *obj, Visitor *v, = const char *name, blk =3D blk_new(ctx, 0, BLK_PERM_ALL); blk_created =3D true; =20 + aio_context_acquire(ctx); ret =3D blk_insert_bs(blk, bs, errp); + aio_context_release(ctx); + if (ret < 0) { goto fail; } --=20 2.40.1 From nobody Sun May 5 02:58:45 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=1685531053; cv=none; d=zohomail.com; s=zohoarc; b=Ad2kejNj3ASgykhdT4UMxa033qMXMcgkbidfa1nqd1vc2c/yr3oxvJoAxPpF8Ncu0USC72MxQ/COyvydGDtYZzl1abzz3H57DF/RGzdy5eMLStEM9NmlYoJo17A4N//EOB624nJNHuzNmdZkIIn3JgeY3uFReSt7eXV1xOqy6Lo= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1685531053; 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=OAgKX9pf+aMAEQIxO3NZ4uYyinG2INC8puKoVVrBqR0=; b=L5JA1XG6y2DxvdYDHnhPmF42eEs/j00SdXQxldn1NIcURFh/LLtrMtyizla8vDoi5Ni+zisG28nKUFLK0K9HHuNwQeFAQh2A99APctpfpMrw85Z1ap4juEUsAXaua2WFl3SjtlkLooo8OGe5f+4/2JshYpl7ALZ+NuLUZh6Y0Cc= 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 1685531053025896.9153530128847; Wed, 31 May 2023 04:04:13 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1q4Jc5-0007T0-Dr; Wed, 31 May 2023 07:03:35 -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 1q4Jbr-0007QB-Il for qemu-devel@nongnu.org; Wed, 31 May 2023 07:03:25 -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 1q4JbV-0001et-Ig for qemu-devel@nongnu.org; Wed, 31 May 2023 07:03: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-271-F6rFrBTbMl6ZkYg5d9QKxQ-1; Wed, 31 May 2023 07:02:43 -0400 Received: from smtp.corp.redhat.com (int-mx04.intmail.prod.int.rdu2.redhat.com [10.11.54.4]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 9EF858027F5; Wed, 31 May 2023 11:02:42 +0000 (UTC) Received: from merkur.fritz.box (unknown [10.39.194.90]) by smtp.corp.redhat.com (Postfix) with ESMTP id 8CF2F202696C; Wed, 31 May 2023 11:02:41 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1685530964; 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=OAgKX9pf+aMAEQIxO3NZ4uYyinG2INC8puKoVVrBqR0=; b=F6tquSWGrBFKOPZB2pbKs9LPk5zTMtywqAcAzIx8p9YeOVUUVlc2P0cCNEpdsvgV2Kbp1e 0KJ5rBEzLT8qZ/0GcK0Gk+IguGGMWrhodA/flbp3CV8A80VC8hF/RpGkw6TjxkMM/QCv/N ivyYZ7Cxsikp4BzOx1Q+b3hLDfhM3Vg= X-MC-Unique: F6rFrBTbMl6ZkYg5d9QKxQ-1 From: Kevin Wolf To: qemu-block@nongnu.org Cc: kwolf@redhat.com, stefanha@redhat.com, hreitz@redhat.com, eblake@redhat.com, qemu-devel@nongnu.org Subject: [PATCH 03/11] test-block-iothread: Lock AioContext for blk_insert_bs() Date: Wed, 31 May 2023 13:02:23 +0200 Message-Id: <20230531110231.262251-4-kwolf@redhat.com> In-Reply-To: <20230531110231.262251-1-kwolf@redhat.com> References: <20230531110231.262251-1-kwolf@redhat.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Scanned-By: MIMEDefang 3.1 on 10.11.54.4 Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=170.10.129.124; envelope-from=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.163, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01, T_SPF_HELO_TEMPERROR=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: 1685531053761100003 Content-Type: text/plain; charset="utf-8" blk_insert_bs() requires that callers hold the AioContext lock for the node that should be inserted. Take it. Signed-off-by: Kevin Wolf --- tests/unit/test-block-iothread.c | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/tests/unit/test-block-iothread.c b/tests/unit/test-block-iothr= ead.c index f081c09729..d727a5fee8 100644 --- a/tests/unit/test-block-iothread.c +++ b/tests/unit/test-block-iothread.c @@ -825,6 +825,7 @@ static void test_attach_second_node(void) BlockDriverState *bs, *filter; QDict *options; =20 + aio_context_acquire(main_ctx); blk =3D blk_new(ctx, BLK_PERM_ALL, BLK_PERM_ALL); bs =3D bdrv_new_open_driver(&bdrv_test, "base", BDRV_O_RDWR, &error_ab= ort); blk_insert_bs(blk, bs, &error_abort); @@ -833,7 +834,6 @@ static void test_attach_second_node(void) qdict_put_str(options, "driver", "raw"); qdict_put_str(options, "file", "base"); =20 - aio_context_acquire(main_ctx); filter =3D bdrv_open(NULL, NULL, options, BDRV_O_RDWR, &error_abort); aio_context_release(main_ctx); =20 @@ -857,9 +857,11 @@ static void test_attach_preserve_blk_ctx(void) { IOThread *iothread =3D iothread_new(); AioContext *ctx =3D iothread_get_aio_context(iothread); + AioContext *main_ctx =3D qemu_get_aio_context(); BlockBackend *blk; BlockDriverState *bs; =20 + aio_context_acquire(main_ctx); blk =3D blk_new(ctx, BLK_PERM_ALL, BLK_PERM_ALL); bs =3D bdrv_new_open_driver(&bdrv_test, "base", BDRV_O_RDWR, &error_ab= ort); bs->total_sectors =3D 65536 / BDRV_SECTOR_SIZE; @@ -868,6 +870,7 @@ static void test_attach_preserve_blk_ctx(void) blk_insert_bs(blk, bs, &error_abort); g_assert(blk_get_aio_context(blk) =3D=3D ctx); g_assert(bdrv_get_aio_context(bs) =3D=3D ctx); + aio_context_release(main_ctx); =20 /* Remove the node again */ aio_context_acquire(ctx); @@ -877,7 +880,9 @@ static void test_attach_preserve_blk_ctx(void) g_assert(bdrv_get_aio_context(bs) =3D=3D qemu_get_aio_context()); =20 /* Re-attach the node */ + aio_context_acquire(main_ctx); blk_insert_bs(blk, bs, &error_abort); + aio_context_release(main_ctx); g_assert(blk_get_aio_context(blk) =3D=3D ctx); g_assert(bdrv_get_aio_context(bs) =3D=3D ctx); =20 --=20 2.40.1 From nobody Sun May 5 02:58:45 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=1685531115; cv=none; d=zohomail.com; s=zohoarc; b=U5Yh3TZKBDJEL7l7C2VsygCrndcwMprOgQlE2oxIGt6GH+olwi8SpyVx/ScnsCFFGkEL0HV+F/Ta56ILaTZHX+8XD0GZf9wuRHA2X4mG575T+bNC2cDnqTc/xziPiyKYyfJrDttdG9KdNyOlYBJ7nhAb9TcvE+pucnpwXd22Bg0= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1685531115; 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=6IwGvA6A66KFFU4BphP+CRoFw0sM6jkp7gZI9tsn52k=; b=QDYdBSZXE+KYr3WWvFp9+qhBglb1W0txQlIqCUrUdAylv2l9jtorc4+Vi36stMvvHZ6mxG3lJNQybSVRQAjR9FgnDLYAMrTSW/naI1YAhonFuad1dV8T+flzXX+09vXtDovuly97rfEL2+Hg0gGxemcOvUURd6OSNmbM4xIfiN4= 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 1685531115144475.850126571773; Wed, 31 May 2023 04:05:15 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1q4JcS-0007jn-HA; Wed, 31 May 2023 07:03: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 1q4Jc0-0007Sp-Mz for qemu-devel@nongnu.org; Wed, 31 May 2023 07:03: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 1q4Jbu-0001fO-Ix for qemu-devel@nongnu.org; Wed, 31 May 2023 07:03:28 -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-488-vixmxTF_PsKBsVdvdXeeEw-1; Wed, 31 May 2023 07:02:44 -0400 Received: from smtp.corp.redhat.com (int-mx04.intmail.prod.int.rdu2.redhat.com [10.11.54.4]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id EC67D801182; Wed, 31 May 2023 11:02:43 +0000 (UTC) Received: from merkur.fritz.box (unknown [10.39.194.90]) by smtp.corp.redhat.com (Postfix) with ESMTP id D4B1620296C6; Wed, 31 May 2023 11:02:42 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1685530967; 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=6IwGvA6A66KFFU4BphP+CRoFw0sM6jkp7gZI9tsn52k=; b=HjGXaZb7lBpPWWypIGvm/xZ1TOBHyWTyQAjYbZilnCRGeiC9iMk/EMU0bCyDCF4Q62z2pu DCtWjbafgwA3JhR5lsEtdugeGbEG8kGYxVjnN44zQkifOhk/8EfEDPpIiHfH+X9S+9dcd9 zTlflAjEN1WEukOif7NNHFOxDQCHhdg= X-MC-Unique: vixmxTF_PsKBsVdvdXeeEw-1 From: Kevin Wolf To: qemu-block@nongnu.org Cc: kwolf@redhat.com, stefanha@redhat.com, hreitz@redhat.com, eblake@redhat.com, qemu-devel@nongnu.org Subject: [PATCH 04/11] block: Fix AioContext locking in bdrv_open_child() Date: Wed, 31 May 2023 13:02:24 +0200 Message-Id: <20230531110231.262251-5-kwolf@redhat.com> In-Reply-To: <20230531110231.262251-1-kwolf@redhat.com> References: <20230531110231.262251-1-kwolf@redhat.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Scanned-By: MIMEDefang 3.1 on 10.11.54.4 Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=170.10.133.124; envelope-from=kwolf@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -16 X-Spam_score: -1.7 X-Spam_bar: - X-Spam_report: (-1.7 / 5.0 requ) BAYES_00=-1.9, DKIM_INVALID=0.1, DKIM_SIGNED=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=no 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: 1685531117289100003 Content-Type: text/plain; charset="utf-8" bdrv_attach_child() requires that the caller holds the AioContext lock for the new child node. Take it in bdrv_open_child() and document that the caller must not hold any AioContext apart from the main AioContext. Signed-off-by: Kevin Wolf --- block.c | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/block.c b/block.c index dae629075c..3ed943467a 100644 --- a/block.c +++ b/block.c @@ -3654,6 +3654,7 @@ done: * * The BlockdevRef will be removed from the options QDict. * + * The caller must hold the lock of the main AioContext and no other AioCo= ntext. * @parent can move to a different AioContext in this function. Callers mu= st * make sure that their AioContext locking is still correct after this. */ @@ -3665,6 +3666,8 @@ BdrvChild *bdrv_open_child(const char *filename, bool allow_none, Error **errp) { BlockDriverState *bs; + BdrvChild *child; + AioContext *ctx; =20 GLOBAL_STATE_CODE(); =20 @@ -3674,13 +3677,19 @@ BdrvChild *bdrv_open_child(const char *filename, return NULL; } =20 - return bdrv_attach_child(parent, bs, bdref_key, child_class, child_rol= e, - errp); + ctx =3D bdrv_get_aio_context(bs); + aio_context_acquire(ctx); + child =3D bdrv_attach_child(parent, bs, bdref_key, child_class, child_= role, + errp); + aio_context_release(ctx); + + return child; } =20 /* * Wrapper on bdrv_open_child() for most popular case: open primary child = of bs. * + * The caller must hold the lock of the main AioContext and no other AioCo= ntext. * @parent can move to a different AioContext in this function. Callers mu= st * make sure that their AioContext locking is still correct after this. */ --=20 2.40.1 From nobody Sun May 5 02:58:45 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=1685531060; cv=none; d=zohomail.com; s=zohoarc; b=UhG3ARUYaASMfiBY90qpYH3tYvPzWWCC+RzeljSJSmkMlPWdkmY4agSZKgN6S4mweMt/yHHazQ1Huy/9tzpvjG+IsmkB8b6at6x8f3Zo96BtCmeBntMev5bpLnOzMsAqPr+AMhoJfW5sxPT3irmyecu5uXTqZBrE/Tts3oMu/MQ= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1685531060; 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=2mKzNMaMJeH3JwSykSj+IX99QH6A36+xK3k+tagyGoI=; b=J6cLTJrTpNIbqBMn95ghouSKoZIMxblgV4bIzt6Q6x3YalYn+pJzBO9Hzak4ofxh+xMjxuNySH0H0nBhfMISG/hIVpcrAxX93YL7e2+DUtcDG5N9joP5sGr2/UGVEpA8NzpxK/azFtZkvIn1F4HHHcG+bjgTG4Duul0xLBlkrkU= 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 1685531060157532.1210838327299; Wed, 31 May 2023 04:04:20 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1q4JcQ-0007gV-H2; Wed, 31 May 2023 07:03: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 1q4Jc1-0007TD-Ff for qemu-devel@nongnu.org; Wed, 31 May 2023 07:03: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 1q4Jbu-0001fa-Ju for qemu-devel@nongnu.org; Wed, 31 May 2023 07:03:28 -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-36-on4MAxXWO1qe3UCEgFAwkQ-1; Wed, 31 May 2023 07:02:45 -0400 Received: from smtp.corp.redhat.com (int-mx04.intmail.prod.int.rdu2.redhat.com [10.11.54.4]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 77DD23C0F182; Wed, 31 May 2023 11:02:45 +0000 (UTC) Received: from merkur.fritz.box (unknown [10.39.194.90]) by smtp.corp.redhat.com (Postfix) with ESMTP id 2F6A120296C6; Wed, 31 May 2023 11:02:44 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1685530969; 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=2mKzNMaMJeH3JwSykSj+IX99QH6A36+xK3k+tagyGoI=; b=ChoyivnU6H23Rf0oxtyvvI41PupLcGviHt8ZoGhIot/zgeNZml7RWOYQv22D4s44aU1R7z 1FO1fQVmGvBz/Gzgbro3uYn1KKFhIDOa64VKPe1XPQLZBCDGP6udK5mUGwG697i3HwKZFr /xf/xi54hjqIqkHR/KmrXGqXfaEmutE= X-MC-Unique: on4MAxXWO1qe3UCEgFAwkQ-1 From: Kevin Wolf To: qemu-block@nongnu.org Cc: kwolf@redhat.com, stefanha@redhat.com, hreitz@redhat.com, eblake@redhat.com, qemu-devel@nongnu.org Subject: [PATCH 05/11] block: Fix AioContext locking in bdrv_attach_child_common() Date: Wed, 31 May 2023 13:02:25 +0200 Message-Id: <20230531110231.262251-6-kwolf@redhat.com> In-Reply-To: <20230531110231.262251-1-kwolf@redhat.com> References: <20230531110231.262251-1-kwolf@redhat.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Scanned-By: MIMEDefang 3.1 on 10.11.54.4 Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=170.10.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.163, 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: 1685531061715100003 Content-Type: text/plain; charset="utf-8" The function can move the child node to a different AioContext. In this case, it also must take the AioContext lock for the new context before calling functions that require the caller to hold the AioContext for the child node. Signed-off-by: Kevin Wolf --- block.c | 21 ++++++++++++++++++++- 1 file changed, 20 insertions(+), 1 deletion(-) diff --git a/block.c b/block.c index 3ed943467a..508e0e396b 100644 --- a/block.c +++ b/block.c @@ -2989,6 +2989,10 @@ static TransactionActionDrv bdrv_attach_child_common= _drv =3D { * Function doesn't update permissions, caller is responsible for this. * * Returns new created child. + * + * The caller must hold the AioContext lock for @child_bs. Both @parent_bs= and + * @child_bs can move to a different AioContext in this function. Callers = must + * make sure that their AioContext locking is still correct after this. */ static BdrvChild *bdrv_attach_child_common(BlockDriverState *child_bs, const char *child_name, @@ -2999,7 +3003,7 @@ static BdrvChild *bdrv_attach_child_common(BlockDrive= rState *child_bs, Transaction *tran, Error **errp) { BdrvChild *new_child; - AioContext *parent_ctx; + AioContext *parent_ctx, *new_child_ctx; AioContext *child_ctx =3D bdrv_get_aio_context(child_bs); =20 assert(child_class->get_parent_desc); @@ -3050,6 +3054,12 @@ static BdrvChild *bdrv_attach_child_common(BlockDriv= erState *child_bs, } } =20 + new_child_ctx =3D bdrv_get_aio_context(child_bs); + if (new_child_ctx !=3D child_ctx) { + aio_context_release(child_ctx); + aio_context_acquire(new_child_ctx); + } + bdrv_ref(child_bs); /* * Let every new BdrvChild start with a drained parent. Inserting the = child @@ -3079,11 +3089,20 @@ static BdrvChild *bdrv_attach_child_common(BlockDri= verState *child_bs, }; tran_add(tran, &bdrv_attach_child_common_drv, s); =20 + if (new_child_ctx !=3D child_ctx) { + aio_context_release(new_child_ctx); + aio_context_acquire(child_ctx); + } + return new_child; } =20 /* * Function doesn't update permissions, caller is responsible for this. + * + * The caller must hold the AioContext lock for @child_bs. Both @parent_bs= and + * @child_bs can move to a different AioContext in this function. Callers = must + * make sure that their AioContext locking is still correct after this. */ static BdrvChild *bdrv_attach_child_noperm(BlockDriverState *parent_bs, BlockDriverState *child_bs, --=20 2.40.1 From nobody Sun May 5 02:58:45 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=1685531132; cv=none; d=zohomail.com; s=zohoarc; b=R6fQY2nddybnQus8j95yKVgASMB4qx2TXS5Pt40E2vt/WArpILqUcmmxWcjxr5LgQfpvWXtrz/ge/YTZZghHJFj9yZi0l5baQJJmUGkT+FrE3PNQ0UQ8q72viCdjJmcHMtjxR8XCV440yUacHpLpvaZU+riBqE5NT/qvg69eybo= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1685531132; 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=ZXzk+wTY/wPTx+vScZUjOzTefhoJYcLpzD/2LCLqaO0=; b=kLGYlsosfDbkpFv+EKVVFU0mdk/Dr0ZisfjpSmypHUymTAliqsux802ZfaWN/cfPjwRN8w0hYKiGu/x2K0VQy/ImqSqvzpkS+8ZFM+B6fXDtzyjlUUc7IZgMYnpL+kmwVehxC6AQNtGNOortLPxtojMvmz0uHkwkkOBo1m/VsBs= 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 1685531132586990.6674258048344; Wed, 31 May 2023 04:05:32 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1q4JcP-0007ec-Pb; Wed, 31 May 2023 07:03: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 1q4Jby-0007Rd-GZ for qemu-devel@nongnu.org; Wed, 31 May 2023 07:03:26 -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 1q4Jbu-0001fY-J0 for qemu-devel@nongnu.org; Wed, 31 May 2023 07:03:24 -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-333-jUBVt6FUO1WwMnepTJ_msQ-1; Wed, 31 May 2023 07:02:47 -0400 Received: from smtp.corp.redhat.com (int-mx04.intmail.prod.int.rdu2.redhat.com [10.11.54.4]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 45F501C05153; Wed, 31 May 2023 11:02:47 +0000 (UTC) Received: from merkur.fritz.box (unknown [10.39.194.90]) by smtp.corp.redhat.com (Postfix) with ESMTP id AFB482029F6D; Wed, 31 May 2023 11:02:45 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1685530968; 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=ZXzk+wTY/wPTx+vScZUjOzTefhoJYcLpzD/2LCLqaO0=; b=NK+lXL9iUt51qvrckg5Qk4faeZphi+LJchnfEQ9UiOe4uM44ekniENj0u+R5qrBDqyzvbl 3adorZc0P3N6W3HoBlL9DY4QPvd71diOyeQ4HqE+ihV2i766WvPGfbB0QTqbBCYct9mlma oK/Rf3kGBH0iiWiniWBIepwcpyG1uBE= X-MC-Unique: jUBVt6FUO1WwMnepTJ_msQ-1 From: Kevin Wolf To: qemu-block@nongnu.org Cc: kwolf@redhat.com, stefanha@redhat.com, hreitz@redhat.com, eblake@redhat.com, qemu-devel@nongnu.org Subject: [PATCH 06/11] block: Fix AioContext locking in bdrv_reopen_parse_file_or_backing() Date: Wed, 31 May 2023 13:02:26 +0200 Message-Id: <20230531110231.262251-7-kwolf@redhat.com> In-Reply-To: <20230531110231.262251-1-kwolf@redhat.com> References: <20230531110231.262251-1-kwolf@redhat.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Scanned-By: MIMEDefang 3.1 on 10.11.54.4 Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=170.10.129.124; envelope-from=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.163, 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: 1685531133465100001 Content-Type: text/plain; charset="utf-8" bdrv_set_file_or_backing_noperm() requires the caller to hold the AioContext lock for the child node, but we hold the one for the parent node in bdrv_reopen_parse_file_or_backing(). Take the other one temporarily. Signed-off-by: Kevin Wolf --- block.c | 35 +++++++++++++++++++++++++++++++++-- 1 file changed, 33 insertions(+), 2 deletions(-) diff --git a/block.c b/block.c index 508e0e396b..a0793b6435 100644 --- a/block.c +++ b/block.c @@ -3366,6 +3366,10 @@ static BdrvChildRole bdrv_backing_role(BlockDriverSt= ate *bs) * callers which don't need their own reference any more must call bdrv_un= ref(). * * Function doesn't update permissions, caller is responsible for this. + * + * The caller must hold the AioContext lock for @child_bs. Both @parent_bs= and + * @child_bs can move to a different AioContext in this function. Callers = must + * make sure that their AioContext locking is still correct after this. */ static int bdrv_set_file_or_backing_noperm(BlockDriverState *parent_bs, BlockDriverState *child_bs, @@ -3454,6 +3458,11 @@ out: return 0; } =20 +/* + * The caller must hold the AioContext lock for @backing_hd. Both @bs and + * @backing_hd can move to a different AioContext in this function. Caller= s must + * make sure that their AioContext locking is still correct after this. + */ static int bdrv_set_backing_noperm(BlockDriverState *bs, BlockDriverState *backing_hd, Transaction *tran, Error **errp) @@ -4606,6 +4615,11 @@ int bdrv_reopen_set_read_only(BlockDriverState *bs, = bool read_only, * backing BlockDriverState (or NULL). * * Return 0 on success, otherwise return < 0 and set @errp. + * + * The caller must hold the AioContext lock of @reopen_state->bs. + * @reopen_state->bs can move to a different AioContext in this function. + * Callers must make sure that their AioContext locking is still correct a= fter + * this. */ static int bdrv_reopen_parse_file_or_backing(BDRVReopenState *reopen_state, bool is_backing, Transaction = *tran, @@ -4618,6 +4632,8 @@ static int bdrv_reopen_parse_file_or_backing(BDRVReop= enState *reopen_state, const char *child_name =3D is_backing ? "backing" : "file"; QObject *value; const char *str; + AioContext *ctx, *old_ctx; + int ret; =20 GLOBAL_STATE_CODE(); =20 @@ -4682,8 +4698,22 @@ static int bdrv_reopen_parse_file_or_backing(BDRVReo= penState *reopen_state, reopen_state->old_file_bs =3D old_child_bs; } =20 - return bdrv_set_file_or_backing_noperm(bs, new_child_bs, is_backing, - tran, errp); + old_ctx =3D bdrv_get_aio_context(bs); + ctx =3D bdrv_get_aio_context(new_child_bs); + if (old_ctx !=3D ctx) { + aio_context_release(old_ctx); + aio_context_acquire(ctx); + } + + ret =3D bdrv_set_file_or_backing_noperm(bs, new_child_bs, is_backing, + tran, errp); + + if (old_ctx !=3D ctx) { + aio_context_release(ctx); + aio_context_acquire(old_ctx); + } + + return ret; } =20 /* @@ -4702,6 +4732,7 @@ static int bdrv_reopen_parse_file_or_backing(BDRVReop= enState *reopen_state, * It is the responsibility of the caller to then call the abort() or * commit() for any other BDS that have been left in a prepare() state * + * The caller must hold the AioContext lock of @reopen_state->bs. */ static int bdrv_reopen_prepare(BDRVReopenState *reopen_state, BlockReopenQueue *queue, --=20 2.40.1 From nobody Sun May 5 02:58:45 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=1685531167; cv=none; d=zohomail.com; s=zohoarc; b=cJas5jgmVwgSjZEzxGmtLUAFF2uSNNfocyYAFfXcJ4jSZVBtmcQFjFo7lv9Zaw2I/3WKUXQvj28dwp/Sh7UbYkLEMNejYM+Bh7iRdaGkmYHZsgGh029MyrA9I4Ar1KcQsOWeRm2kpkZrAdIJ97WT4IHbPQWPlG2IOXQeum7XHz0= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1685531167; 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=LwbOjCEJs8O+/peU3WfjZvUeay7SQbRYnqv6qoXOGhk=; b=eUpUN9r7fAmC/9g3Y8HlhmHWgx4lzgNB9LhwZrZzcA1nIZtUdbTXYs2zoymW7EDrcgs4IclDltzc3o7FfwkCGN//wk4FiA/qTZ1ElKBr2Olopv+iwod/NaFjIPxoKkgnO4wRSCB+Kqr8yOjrWiZ7WxMkDbdOtAErXijafy2V4aI= 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 16855311677111008.5087643327813; Wed, 31 May 2023 04:06:07 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1q4JcK-0007Zm-LL; Wed, 31 May 2023 07:03:48 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1q4Jbu-0007QH-QC for qemu-devel@nongnu.org; Wed, 31 May 2023 07:03:25 -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 1q4Jbr-0001fz-4W for qemu-devel@nongnu.org; Wed, 31 May 2023 07:03:21 -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-608-RwQr5-XWNXuxwr9Ql4sH-g-1; Wed, 31 May 2023 07:02:49 -0400 Received: from smtp.corp.redhat.com (int-mx04.intmail.prod.int.rdu2.redhat.com [10.11.54.4]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 73C4485A5BB; Wed, 31 May 2023 11:02:49 +0000 (UTC) Received: from merkur.fritz.box (unknown [10.39.194.90]) by smtp.corp.redhat.com (Postfix) with ESMTP id 7CBCD2029F6D; Wed, 31 May 2023 11:02:47 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1685530973; 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=LwbOjCEJs8O+/peU3WfjZvUeay7SQbRYnqv6qoXOGhk=; b=c/Z5SHtC+UgMqsE9t50z8deIhhQ4bx+HpVBfI1jhxpYNXydlCpFufO4ScjojuIg3aBJQxb W28xmmS+3QaKg4jQmhXyoxGVbH/5Iksd8UptAVgbxL7iB9QYM2bbu+mKZ+x6/NG8DRIkYw Do6FQU0/M7Onf+faDYTLZsZ9kJZDfxs= X-MC-Unique: RwQr5-XWNXuxwr9Ql4sH-g-1 From: Kevin Wolf To: qemu-block@nongnu.org Cc: kwolf@redhat.com, stefanha@redhat.com, hreitz@redhat.com, eblake@redhat.com, qemu-devel@nongnu.org Subject: [PATCH 07/11] block: Fix AioContext locking in bdrv_open_inherit() Date: Wed, 31 May 2023 13:02:27 +0200 Message-Id: <20230531110231.262251-8-kwolf@redhat.com> In-Reply-To: <20230531110231.262251-1-kwolf@redhat.com> References: <20230531110231.262251-1-kwolf@redhat.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Scanned-By: MIMEDefang 3.1 on 10.11.54.4 Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=170.10.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.163, 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: 1685531169573100003 Content-Type: text/plain; charset="utf-8" Signed-off-by: Kevin Wolf --- block.c | 25 ++++++++++++++++++++++++- 1 file changed, 24 insertions(+), 1 deletion(-) diff --git a/block.c b/block.c index a0793b6435..954b9923d9 100644 --- a/block.c +++ b/block.c @@ -3794,6 +3794,7 @@ static BlockDriverState *bdrv_append_temp_snapshot(Bl= ockDriverState *bs, int64_t total_size; QemuOpts *opts =3D NULL; BlockDriverState *bs_snapshot =3D NULL; + AioContext *ctx =3D bdrv_get_aio_context(bs); int ret; =20 GLOBAL_STATE_CODE(); @@ -3802,7 +3803,10 @@ static BlockDriverState *bdrv_append_temp_snapshot(B= lockDriverState *bs, instead of opening 'filename' directly */ =20 /* Get the required size from the image */ + aio_context_acquire(ctx); total_size =3D bdrv_getlength(bs); + aio_context_release(ctx); + if (total_size < 0) { error_setg_errno(errp, -total_size, "Could not get image size"); goto out; @@ -3836,7 +3840,10 @@ static BlockDriverState *bdrv_append_temp_snapshot(B= lockDriverState *bs, goto out; } =20 + aio_context_acquire(ctx); ret =3D bdrv_append(bs_snapshot, bs, errp); + aio_context_release(ctx); + if (ret < 0) { bs_snapshot =3D NULL; goto out; @@ -3880,6 +3887,7 @@ bdrv_open_inherit(const char *filename, const char *r= eference, QDict *options, Error *local_err =3D NULL; QDict *snapshot_options =3D NULL; int snapshot_flags =3D 0; + AioContext *ctx =3D qemu_get_aio_context(); =20 assert(!child_class || !flags); assert(!child_class =3D=3D !parent); @@ -4017,9 +4025,13 @@ bdrv_open_inherit(const char *filename, const char *= reference, QDict *options, /* Not requesting BLK_PERM_CONSISTENT_READ because we're only * looking at the header to guess the image format. This works= even * in cases where a guest would not see a consistent state. */ - file =3D blk_new(bdrv_get_aio_context(file_bs), 0, BLK_PERM_AL= L); + ctx =3D bdrv_get_aio_context(file_bs); + aio_context_acquire(ctx); + file =3D blk_new(ctx, 0, BLK_PERM_ALL); blk_insert_bs(file, file_bs, &local_err); bdrv_unref(file_bs); + aio_context_release(ctx); + if (local_err) { goto fail; } @@ -4065,8 +4077,13 @@ bdrv_open_inherit(const char *filename, const char *= reference, QDict *options, goto fail; } =20 + /* The AioContext could have changed during bdrv_open_common() */ + ctx =3D bdrv_get_aio_context(bs); + if (file) { + aio_context_acquire(ctx); blk_unref(file); + aio_context_release(ctx); file =3D NULL; } =20 @@ -4124,13 +4141,16 @@ bdrv_open_inherit(const char *filename, const char = *reference, QDict *options, * (snapshot_bs); thus, we have to drop the strong reference to bs * (which we obtained by calling bdrv_new()). bs will not be delet= ed, * though, because the overlay still has a reference to it. */ + aio_context_acquire(ctx); bdrv_unref(bs); + aio_context_release(ctx); bs =3D snapshot_bs; } =20 return bs; =20 fail: + aio_context_acquire(ctx); blk_unref(file); qobject_unref(snapshot_options); qobject_unref(bs->explicit_options); @@ -4139,11 +4159,14 @@ fail: bs->options =3D NULL; bs->explicit_options =3D NULL; bdrv_unref(bs); + aio_context_release(ctx); error_propagate(errp, local_err); return NULL; =20 close_and_fail: + aio_context_acquire(ctx); bdrv_unref(bs); + aio_context_release(ctx); qobject_unref(snapshot_options); qobject_unref(options); error_propagate(errp, local_err); --=20 2.40.1 From nobody Sun May 5 02:58:45 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=1685531087; cv=none; d=zohomail.com; s=zohoarc; b=lBbIyfSjqRGDJn3UzbkkPPWTu2Umj/3FkSckTYAr8StHPfKkp7JvR6vPCqSlSJ1tIMPKSvCNUoyh3AHj+7jIpouUK1Z9rxJkaKMO1QeicpS89e95ESUiXuxw6hNMVu5AoxLfFjEAxol6qFJ0vyqel+M1Zbo+recyOfT4K1VmaQw= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1685531087; 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=lRNJTSSNSAXDnrhqddr90/q7AO+amHqWivhyPshnE64=; b=QFjGsTiShe8e6Bmko8Ei4dNMX6n8OCC5EAMsKPV6sSAGP6BCwcFySYTcIJ5FRibb6IzA2ge4sbY5NCGSZxtsv5/UuOj9JVoAnztYCq9kM8qqVKJkV3jKiK13f0HZxAHkix8cE69wHcwkCDu2iBt5MJMXsiUz5wvIYmZomg4/Ass= 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 1685531086870181.66715108059134; Wed, 31 May 2023 04:04:46 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1q4JcA-0007Wj-SU; Wed, 31 May 2023 07:03:42 -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 1q4Jbr-0007Q8-1P for qemu-devel@nongnu.org; Wed, 31 May 2023 07:03:25 -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 1q4JbV-0001gD-MH for qemu-devel@nongnu.org; Wed, 31 May 2023 07:02:59 -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-53-ervDNh8iOJqx9iRBSpmj3Q-1; Wed, 31 May 2023 07:02:51 -0400 Received: from smtp.corp.redhat.com (int-mx04.intmail.prod.int.rdu2.redhat.com [10.11.54.4]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id E81243801FFA; Wed, 31 May 2023 11:02:50 +0000 (UTC) Received: from merkur.fritz.box (unknown [10.39.194.90]) by smtp.corp.redhat.com (Postfix) with ESMTP id AA47D2029F6D; Wed, 31 May 2023 11:02:49 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1685530975; 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=lRNJTSSNSAXDnrhqddr90/q7AO+amHqWivhyPshnE64=; b=Ov/BUTaKNJtveqsQnVvXRyy7nMxT0VhBTmQI3oEfU8Vy/Ooax09xCVU5NOIEHXBvRrtwrf 5+UEgzS/H6i7JAc1UGeQ6uzCWFKtiBk4Dce/drq2NxzavkZL4aYAqvm/08ZCkDo7mRA4yM MhVAE20BDLCB9RecPkkbT5OvYsk513A= X-MC-Unique: ervDNh8iOJqx9iRBSpmj3Q-1 From: Kevin Wolf To: qemu-block@nongnu.org Cc: kwolf@redhat.com, stefanha@redhat.com, hreitz@redhat.com, eblake@redhat.com, qemu-devel@nongnu.org Subject: [PATCH 08/11] block: Fix AioContext locking in bdrv_open_backing_file() Date: Wed, 31 May 2023 13:02:28 +0200 Message-Id: <20230531110231.262251-9-kwolf@redhat.com> In-Reply-To: <20230531110231.262251-1-kwolf@redhat.com> References: <20230531110231.262251-1-kwolf@redhat.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Scanned-By: MIMEDefang 3.1 on 10.11.54.4 Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=170.10.129.124; envelope-from=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.163, 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: 1685531088157100003 Content-Type: text/plain; charset="utf-8" bdrv_set_backing() requires the caller to hold the AioContext lock for @backing_hd. Take it in bdrv_open_backing_file() before calling the function. Signed-off-by: Kevin Wolf --- block.c | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/block.c b/block.c index 954b9923d9..d5f8231f31 100644 --- a/block.c +++ b/block.c @@ -3526,6 +3526,7 @@ int bdrv_open_backing_file(BlockDriverState *bs, QDic= t *parent_options, int ret =3D 0; bool implicit_backing =3D false; BlockDriverState *backing_hd; + AioContext *backing_hd_ctx; QDict *options; QDict *tmp_parent_options =3D NULL; Error *local_err =3D NULL; @@ -3610,8 +3611,12 @@ int bdrv_open_backing_file(BlockDriverState *bs, QDi= ct *parent_options, =20 /* Hook up the backing file link; drop our reference, bs owns the * backing_hd reference now */ + backing_hd_ctx =3D bdrv_get_aio_context(backing_hd); + aio_context_acquire(backing_hd_ctx); ret =3D bdrv_set_backing_hd(bs, backing_hd, errp); bdrv_unref(backing_hd); + aio_context_release(backing_hd_ctx); + if (ret < 0) { goto free_exit; } --=20 2.40.1 From nobody Sun May 5 02:58:45 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=1685531065; cv=none; d=zohomail.com; s=zohoarc; b=bef+AlGpAnrKTXYdM12+m1pqpEYyS93Cat4MVMevOvJgOG02Hz4tCs/708x0XC1+MsBbiiCRZCu+ZjvNLfFk4795p3tao4P+5TFBmiyvVmlP5o5HLLN6kiib8nTo1kc2b6qtczPyDu10D/AXAF6Kwz8KCnZ35x+58NHzDPNiKB4= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1685531065; 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=jw+sVL0vSNf45fXhXNhnpmyDKEDshiUy1iXF36YCo+A=; b=AP4cKYUzOHJLfqha7YGwwoyIXxdrlfrZnzsXH+84/PhxEFGHki/VogdbY8b0DphJf9/iV3sK02JJXkBANZNFL4LqYVc3JPjVDSlWokqrW+2AmlPgadcJGMMwz9Bh/fdzE5JIbGzDi6z9kA0LEgYxmlJb8dZdw6dhQjyNI0M1Tuk= 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 1685531065232319.9676081869933; Wed, 31 May 2023 04:04:25 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1q4JcL-0007cJ-9S; Wed, 31 May 2023 07:03: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 1q4Jby-0007Rc-FI for qemu-devel@nongnu.org; Wed, 31 May 2023 07:03:26 -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 1q4Jbu-0001g7-In for qemu-devel@nongnu.org; Wed, 31 May 2023 07:03:24 -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-227-wchhDaqcMO6upvlbKiAuvA-1; Wed, 31 May 2023 07:02:52 -0400 Received: from smtp.corp.redhat.com (int-mx04.intmail.prod.int.rdu2.redhat.com [10.11.54.4]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 87A6E3801FFB; Wed, 31 May 2023 11:02:52 +0000 (UTC) Received: from merkur.fritz.box (unknown [10.39.194.90]) by smtp.corp.redhat.com (Postfix) with ESMTP id 2A8942029F6D; Wed, 31 May 2023 11:02:51 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1685530974; 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=jw+sVL0vSNf45fXhXNhnpmyDKEDshiUy1iXF36YCo+A=; b=EWSPfv9Hj/Dt2N5wBrIOtvKuxVQvtTxEnIlEHf8qHCnH2/xY6lZNph7DsOTALhxqLmzqRR MV5Uz3VkF7RBI1ptbeA0LnK3+dJMiygjpkFkuIH/gbzC1/5Bpvl+v+zKiZAH1vm57+LOvP WFAA3CrWPR2tySL6WHEPssRiAdCNazY= X-MC-Unique: wchhDaqcMO6upvlbKiAuvA-1 From: Kevin Wolf To: qemu-block@nongnu.org Cc: kwolf@redhat.com, stefanha@redhat.com, hreitz@redhat.com, eblake@redhat.com, qemu-devel@nongnu.org Subject: [PATCH 09/11] blockjob: Fix AioContext locking in block_job_add_bdrv() Date: Wed, 31 May 2023 13:02:29 +0200 Message-Id: <20230531110231.262251-10-kwolf@redhat.com> In-Reply-To: <20230531110231.262251-1-kwolf@redhat.com> References: <20230531110231.262251-1-kwolf@redhat.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Scanned-By: MIMEDefang 3.1 on 10.11.54.4 Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=170.10.129.124; envelope-from=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.163, 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: 1685531066847100003 Content-Type: text/plain; charset="utf-8" bdrv_root_attach_child() requires callers to hold the AioContext lock for child_bs. Take it in block_job_add_bdrv() before calling the function. Signed-off-by: Kevin Wolf --- blockjob.c | 17 ++++++++++++----- 1 file changed, 12 insertions(+), 5 deletions(-) diff --git a/blockjob.c b/blockjob.c index 913da3cbf7..25fe8e625d 100644 --- a/blockjob.c +++ b/blockjob.c @@ -230,20 +230,27 @@ int block_job_add_bdrv(BlockJob *job, const char *nam= e, BlockDriverState *bs, uint64_t perm, uint64_t shared_perm, Error **errp) { BdrvChild *c; + AioContext *ctx =3D bdrv_get_aio_context(bs); bool need_context_ops; GLOBAL_STATE_CODE(); =20 bdrv_ref(bs); =20 - need_context_ops =3D bdrv_get_aio_context(bs) !=3D job->job.aio_contex= t; + need_context_ops =3D ctx !=3D job->job.aio_context; =20 - if (need_context_ops && job->job.aio_context !=3D qemu_get_aio_context= ()) { - aio_context_release(job->job.aio_context); + if (need_context_ops) { + if (job->job.aio_context !=3D qemu_get_aio_context()) { + aio_context_release(job->job.aio_context); + } + aio_context_acquire(ctx); } c =3D bdrv_root_attach_child(bs, name, &child_job, 0, perm, shared_per= m, job, errp); - if (need_context_ops && job->job.aio_context !=3D qemu_get_aio_context= ()) { - aio_context_acquire(job->job.aio_context); + if (need_context_ops) { + aio_context_release(ctx); + if (job->job.aio_context !=3D qemu_get_aio_context()) { + aio_context_acquire(job->job.aio_context); + } } if (c =3D=3D NULL) { return -EPERM; --=20 2.40.1 From nobody Sun May 5 02:58:45 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=1685531053; cv=none; d=zohomail.com; s=zohoarc; b=cPcZgaocBDkYf2YR/r8Mq8F1wkKkOoXj7UWpQnMSmH2lGnGz6gQFU1hL1R8Vy6cVCsY2DW9sqB4YuzNC0zFrieJyC2v/EzTZYCPxBeBrjGOi6+nhqz5pWYSLvpfSe9JTWP1hjZll0iS9b6+LVed9o9ycbjunhEC2RqoXlcqUbzk= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1685531053; 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=eP84yjY4yh8iUNxvdcXbErwPb+zs45cUJLLBTjlwO2A=; b=dYkLuJUDtUkMQK2L7xSGvfOeu4r5JRnlmNk/sMhs8ZY11VTVh7PuS46tFm0mcuO7+Cifq1Y/ncesjxQsweuYLZe49xSYSj12MRE51c195HFOpaOtGYpSzXvr1HuwJq6vU1ssAdU+vfXfqVnPPEsW8PocWm2bQEuRj6/noFaGpTo= 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 168553105302248.409132342495695; Wed, 31 May 2023 04:04:13 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1q4JcS-0007kJ-Sd; Wed, 31 May 2023 07:03: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 1q4Jby-0007Re-H6 for qemu-devel@nongnu.org; Wed, 31 May 2023 07:03:26 -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 1q4Jbu-0001gJ-07 for qemu-devel@nongnu.org; Wed, 31 May 2023 07:03: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-249-vs171-jgO3iC_gSbuSkhAw-1; Wed, 31 May 2023 07:02:54 -0400 Received: from smtp.corp.redhat.com (int-mx04.intmail.prod.int.rdu2.redhat.com [10.11.54.4]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id B512C101A593; Wed, 31 May 2023 11:02:53 +0000 (UTC) Received: from merkur.fritz.box (unknown [10.39.194.90]) by smtp.corp.redhat.com (Postfix) with ESMTP id BE8172029F6D; Wed, 31 May 2023 11:02:52 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1685530975; 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=eP84yjY4yh8iUNxvdcXbErwPb+zs45cUJLLBTjlwO2A=; b=UYGOYj8RIt8TwydiGNcHzq8BLuZC4zW6qRwjIuGiubHHGGLV1SzwdWe7yQ1jVLZ5XtgzjF 985l8rys8Fhx45GigoPMq7bEFv+Gce/W7Xh5CrvldQLuOXGxBximE2RH+NVSxuyKm5uNV0 y6L75GAayiIQnxcXZxemKaeWLA2nfV0= X-MC-Unique: vs171-jgO3iC_gSbuSkhAw-1 From: Kevin Wolf To: qemu-block@nongnu.org Cc: kwolf@redhat.com, stefanha@redhat.com, hreitz@redhat.com, eblake@redhat.com, qemu-devel@nongnu.org Subject: [PATCH 10/11] graph-lock: Unlock the AioContext while polling Date: Wed, 31 May 2023 13:02:30 +0200 Message-Id: <20230531110231.262251-11-kwolf@redhat.com> In-Reply-To: <20230531110231.262251-1-kwolf@redhat.com> References: <20230531110231.262251-1-kwolf@redhat.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Scanned-By: MIMEDefang 3.1 on 10.11.54.4 Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=170.10.129.124; envelope-from=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.163, 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: 1685531053966100005 Content-Type: text/plain; charset="utf-8" If the caller keeps the AioContext lock for a block node in an iothread, polling in bdrv_graph_wrlock() deadlocks if the condition isn't fulfilled immediately. Now that all callers make sure to actually have the AioContext locked when they call bdrv_replace_child_noperm() like they should, we can change bdrv_graph_wrlock() to take a BlockDriverState whose AioContext lock the caller holds (NULL if it doesn't) and unlock it temporarily while polling. Signed-off-by: Kevin Wolf --- include/block/graph-lock.h | 6 ++++-- block.c | 4 ++-- block/graph-lock.c | 23 ++++++++++++++++++++++- 3 files changed, 28 insertions(+), 5 deletions(-) diff --git a/include/block/graph-lock.h b/include/block/graph-lock.h index 7574a2de5b..7e04f98ff0 100644 --- a/include/block/graph-lock.h +++ b/include/block/graph-lock.h @@ -111,10 +111,12 @@ void unregister_aiocontext(AioContext *ctx); * The wrlock can only be taken from the main loop, with BQL held, as only= the * main loop is allowed to modify the graph. * + * If @bs is non-NULL, its AioContext is temporarily released. + * * This function polls. Callers must not hold the lock of any AioContext o= ther - * than the current one. + * than the current one and the one of @bs. */ -void bdrv_graph_wrlock(void) TSA_ACQUIRE(graph_lock) TSA_NO_TSA; +void bdrv_graph_wrlock(BlockDriverState *bs) TSA_ACQUIRE(graph_lock) TSA_N= O_TSA; =20 /* * bdrv_graph_wrunlock: diff --git a/block.c b/block.c index d5f8231f31..f94cee8930 100644 --- a/block.c +++ b/block.c @@ -2854,7 +2854,7 @@ uint64_t bdrv_qapi_perm_to_blk_perm(BlockPermission q= api_perm) * Replaces the node that a BdrvChild points to without updating permissio= ns. * * If @new_bs is non-NULL, the parent of @child must already be drained th= rough - * @child. + * @child and the caller must hold the AioContext lock for @new_bs. */ static void bdrv_replace_child_noperm(BdrvChild *child, BlockDriverState *new_bs) @@ -2893,7 +2893,7 @@ static void bdrv_replace_child_noperm(BdrvChild *chil= d, } =20 /* TODO Pull this up into the callers to avoid polling here */ - bdrv_graph_wrlock(); + bdrv_graph_wrlock(new_bs); if (old_bs) { if (child->klass->detach) { child->klass->detach(child); diff --git a/block/graph-lock.c b/block/graph-lock.c index a92c6ae219..3bf2591dc4 100644 --- a/block/graph-lock.c +++ b/block/graph-lock.c @@ -110,8 +110,10 @@ static uint32_t reader_count(void) } #endif =20 -void bdrv_graph_wrlock(void) +void bdrv_graph_wrlock(BlockDriverState *bs) { + AioContext *ctx =3D NULL; + GLOBAL_STATE_CODE(); /* * TODO Some callers hold an AioContext lock when this is called, which @@ -120,7 +122,22 @@ void bdrv_graph_wrlock(void) */ #if 0 assert(!qatomic_read(&has_writer)); +#endif + + /* + * Release only non-mainloop AioContext. The mainloop often relies on = the + * BQL and doesn't lock the main AioContext before doing things. + */ + if (bs) { + ctx =3D bdrv_get_aio_context(bs); + if (ctx !=3D qemu_get_aio_context()) { + aio_context_release(ctx); + } else { + ctx =3D NULL; + } + } =20 +#if 0 /* Make sure that constantly arriving new I/O doesn't cause starvation= */ bdrv_drain_all_begin_nopoll(); =20 @@ -150,6 +167,10 @@ void bdrv_graph_wrlock(void) =20 bdrv_drain_all_end(); #endif + + if (ctx) { + aio_context_acquire(bdrv_get_aio_context(bs)); + } } =20 void bdrv_graph_wrunlock(void) --=20 2.40.1 From nobody Sun May 5 02:58:45 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=1685531198; cv=none; d=zohomail.com; s=zohoarc; b=TygDJ67mhjFbfBrp20kC0MoREkXrR0ko3mIt7F4NjeU/0ueky7L2dIYla6KR+78lc5dOS1RwSSydqilUbvNkGhF+gzHsieiPq20I4UnGHCMtnVZ/W2dny9yqW3g5P6NFBLxmjuxHffpyWMYSZbm5y1U7ZcEjtc+/+jtEBb4DvPM= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1685531198; 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=gBEA0DPzWSZSHotzqBjK5sGIr315dzasDadYZ/PEi0I=; b=Vg4aR/JHoU8pCW5KnpqbuLWSycwhAa7bAl/UaCHITGS7G83lPV5SbJmAAxsv09PyRxmAjqjw+d22HUGWQ8tqC4xW9YEhuyhDCTBkFx2SNDzpMG+N0HlLqv/AseN2ma+I6/VoYQYxfwKHDPlf029FeDP3kRKOT89YLO+DxOva6AE= 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 1685531198620615.9101457708588; Wed, 31 May 2023 04:06:38 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1q4JcQ-0007hN-Ub; Wed, 31 May 2023 07:03: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 1q4Jc2-0007Ui-Tq for qemu-devel@nongnu.org; Wed, 31 May 2023 07:03:31 -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 1q4Jbu-0001gX-JB for qemu-devel@nongnu.org; Wed, 31 May 2023 07:03:29 -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-554-dL4TJfb0OiywsA_qyswqOQ-1; Wed, 31 May 2023 07:02:56 -0400 Received: from smtp.corp.redhat.com (int-mx04.intmail.prod.int.rdu2.redhat.com [10.11.54.4]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id B46103802003; Wed, 31 May 2023 11:02:55 +0000 (UTC) Received: from merkur.fritz.box (unknown [10.39.194.90]) by smtp.corp.redhat.com (Postfix) with ESMTP id 2C05C2029F6D; Wed, 31 May 2023 11:02:54 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1685530977; 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=gBEA0DPzWSZSHotzqBjK5sGIr315dzasDadYZ/PEi0I=; b=WIxeZhA9OnVYikFRIU0MEq+oeiD0XnUa64rmleNHve8wb6liPkpdz6Ir6sx1teCEbwpChX vm3wyfKLiDFOhahsiyZj6+7ScTRPXvW8V6CljAqV+jClBLFG2+vv2N2jZnSjug/oJL6I/x Qi8HIxVbMz9yEoeYVb+ZsJKaaPkrUZE= X-MC-Unique: dL4TJfb0OiywsA_qyswqOQ-1 From: Kevin Wolf To: qemu-block@nongnu.org Cc: kwolf@redhat.com, stefanha@redhat.com, hreitz@redhat.com, eblake@redhat.com, qemu-devel@nongnu.org Subject: [PATCH 11/11] Revert "graph-lock: Disable locking for now" Date: Wed, 31 May 2023 13:02:31 +0200 Message-Id: <20230531110231.262251-12-kwolf@redhat.com> In-Reply-To: <20230531110231.262251-1-kwolf@redhat.com> References: <20230531110231.262251-1-kwolf@redhat.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Scanned-By: MIMEDefang 3.1 on 10.11.54.4 Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=170.10.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.163, 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_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01, T_SPF_HELO_TEMPERROR=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: 1685531200460100002 Content-Type: text/plain; charset="utf-8" Now that bdrv_graph_wrlock() temporarily drops the AioContext lock that its caller holds, it can poll without causing deadlocks. We can now re-enable graph locking. This reverts commit ad128dff0bf4b6f971d05eb4335a627883a19c1d. Signed-off-by: Kevin Wolf --- block/graph-lock.c | 23 ----------------------- 1 file changed, 23 deletions(-) diff --git a/block/graph-lock.c b/block/graph-lock.c index 3bf2591dc4..4c2e63ed1d 100644 --- a/block/graph-lock.c +++ b/block/graph-lock.c @@ -30,10 +30,8 @@ BdrvGraphLock graph_lock; /* Protects the list of aiocontext and orphaned_reader_count */ static QemuMutex aio_context_list_lock; =20 -#if 0 /* Written and read with atomic operations. */ static int has_writer; -#endif =20 /* * A reader coroutine could move from an AioContext to another. @@ -90,7 +88,6 @@ void unregister_aiocontext(AioContext *ctx) g_free(ctx->bdrv_graph); } =20 -#if 0 static uint32_t reader_count(void) { BdrvGraphRWlock *brdv_graph; @@ -108,21 +105,13 @@ static uint32_t reader_count(void) assert((int32_t)rd >=3D 0); return rd; } -#endif =20 void bdrv_graph_wrlock(BlockDriverState *bs) { AioContext *ctx =3D NULL; =20 GLOBAL_STATE_CODE(); - /* - * TODO Some callers hold an AioContext lock when this is called, which - * causes deadlocks. Reenable once the AioContext locking is cleaned u= p (or - * AioContext locks are gone). - */ -#if 0 assert(!qatomic_read(&has_writer)); -#endif =20 /* * Release only non-mainloop AioContext. The mainloop often relies on = the @@ -137,7 +126,6 @@ void bdrv_graph_wrlock(BlockDriverState *bs) } } =20 -#if 0 /* Make sure that constantly arriving new I/O doesn't cause starvation= */ bdrv_drain_all_begin_nopoll(); =20 @@ -166,7 +154,6 @@ void bdrv_graph_wrlock(BlockDriverState *bs) } while (reader_count() >=3D 1); =20 bdrv_drain_all_end(); -#endif =20 if (ctx) { aio_context_acquire(bdrv_get_aio_context(bs)); @@ -176,7 +163,6 @@ void bdrv_graph_wrlock(BlockDriverState *bs) void bdrv_graph_wrunlock(void) { GLOBAL_STATE_CODE(); -#if 0 QEMU_LOCK_GUARD(&aio_context_list_lock); assert(qatomic_read(&has_writer)); =20 @@ -188,13 +174,10 @@ void bdrv_graph_wrunlock(void) =20 /* Wake up all coroutine that are waiting to read the graph */ qemu_co_enter_all(&reader_queue, &aio_context_list_lock); -#endif } =20 void coroutine_fn bdrv_graph_co_rdlock(void) { - /* TODO Reenable when wrlock is reenabled */ -#if 0 BdrvGraphRWlock *bdrv_graph; bdrv_graph =3D qemu_get_current_aio_context()->bdrv_graph; =20 @@ -254,12 +237,10 @@ void coroutine_fn bdrv_graph_co_rdlock(void) qemu_co_queue_wait(&reader_queue, &aio_context_list_lock); } } -#endif } =20 void coroutine_fn bdrv_graph_co_rdunlock(void) { -#if 0 BdrvGraphRWlock *bdrv_graph; bdrv_graph =3D qemu_get_current_aio_context()->bdrv_graph; =20 @@ -277,7 +258,6 @@ void coroutine_fn bdrv_graph_co_rdunlock(void) if (qatomic_read(&has_writer)) { aio_wait_kick(); } -#endif } =20 void bdrv_graph_rdlock_main_loop(void) @@ -306,8 +286,5 @@ void assert_bdrv_graph_readable(void) void assert_bdrv_graph_writable(void) { assert(qemu_in_main_thread()); - /* TODO Reenable when wrlock is reenabled */ -#if 0 assert(qatomic_read(&has_writer)); -#endif } --=20 2.40.1