From nobody Sat Jun 1 12:21:31 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=1675854746; cv=none; d=zohomail.com; s=zohoarc; b=IKUGICSjHwKvLInB8QbiZd2PxOtvdKTweoMHfvnFGSvKvO1oI95ISZg7V+t1RzVudRhDbxuTqKxgDqHnUBhxPoybOQ0oLlHJk+Kfc9VmFzSPQgoLjaIsyXncm+pNciD3+hbF5YWH3PSegtBKNdgy/8beYoS+XYzkNuUv169tsSE= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1675854746; h=Content-Transfer-Encoding:Cc:Date:From:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:Sender:Subject:To; bh=NWolw0fcXM8wivpaZz9+zd+TJnWwIr1pskJ88R2CYj8=; b=dlH8SQud+UF5qNSEyZ953XqUTkhDKQgnN71g41mmB8W198tVT+6CsQRPiT0AW6np8roOWIaaoH1QWFmuBdo0CHGdL5XUS9Knb+FZxRxGWM66vCFcE8DWxghImaRAadMzpOf3XHnFJ9MzjsE3K2XbdXMiS49OfVlp1UoXNsvwg4o= 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 167585474609476.90689304703312; Wed, 8 Feb 2023 03:12:26 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1pPiMp-0005pO-52; Wed, 08 Feb 2023 06:11:59 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1pPiMm-0005nE-1U for qemu-devel@nongnu.org; Wed, 08 Feb 2023 06:11:56 -0500 Received: from us-smtp-delivery-124.mimecast.com ([170.10.133.124]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1pPiMk-0001fv-3h for qemu-devel@nongnu.org; Wed, 08 Feb 2023 06:11:55 -0500 Received: from mimecast-mx02.redhat.com (mx3-rdu2.redhat.com [66.187.233.73]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-558-O2esOAj7MQ63m512qN31Bw-1; Wed, 08 Feb 2023 06:11:50 -0500 Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.rdu2.redhat.com [10.11.54.3]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 5BED83804500; Wed, 8 Feb 2023 11:11:50 +0000 (UTC) Received: from virtlab701.virt.lab.eng.bos.redhat.com (virtlab701.virt.lab.eng.bos.redhat.com [10.19.152.228]) by smtp.corp.redhat.com (Postfix) with ESMTP id 149731121314; Wed, 8 Feb 2023 11:11:50 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1675854711; 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; bh=NWolw0fcXM8wivpaZz9+zd+TJnWwIr1pskJ88R2CYj8=; b=PGRVjTweLSlLRBbYW8qTHZIwfAPJc08xyPUpBOfYuWAcM6Re2LBiUJATQLLscxgHpCWUty NGBOcQyMqU91rmL4FfWlqaANGO6ARReM7b6OYWDych30xP1O0Madvy4dBUV/m/MusrBeOF jjpnsTG6fX7B5bEpFvN17zoEEJ5J+uI= X-MC-Unique: O2esOAj7MQ63m512qN31Bw-1 From: Emanuele Giuseppe Esposito To: qemu-block@nongnu.org Cc: "Michael S. Tsirkin" , Stefan Hajnoczi , Kevin Wolf , Hanna Reitz , qemu-devel@nongnu.org, Emanuele Giuseppe Esposito Subject: [PATCH] virtio-blk: add missing AioContext lock Date: Wed, 8 Feb 2023 06:11:48 -0500 Message-Id: <20230208111148.1040083-1-eesposit@redhat.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Scanned-By: MIMEDefang 3.1 on 10.11.54.3 Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=170.10.133.124; envelope-from=eesposit@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.001, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H2=-0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1675854747149100001 Content-Type: text/plain; charset="utf-8" virtio_blk_update_config() calls blk_get_geometry and blk_getlength, and both functions eventually end up calling bdrv_poll_co when not running in a coroutine: - blk_getlength is a co_wrapper_mixed function - blk_get_geometry calls bdrv_get_geometry -> bdrv_nb_sectors, a co_wrapper_mixed function too Since we are not running in a coroutine, we need to take s->blk AioContext lock, otherwise bdrv_poll_co will inevitably call AIO_WAIT_WHILE and therefore try to un unlock() an AioContext lock that was never acquired. RHBZ: https://bugzilla.redhat.com/show_bug.cgi?id=3D2167838 Steps to reproduce the issue: simply boot a VM with -object '{"qom-type":"iothread","id":"iothread1"}' \ -blockdev '{"driver":"file","filename":"$QCOW2","aio":"native","node-name":= "libvirt-1-storage","cache":{"direct":true,"no-flush":false},"auto-read-onl= y":true,"discard":"unmap"}' \ -blockdev '{"node-name":"libvirt-1-format","read-only":false,"cache":{"dire= ct":true,"no-flush":false},"driver":"qcow2","file":"libvirt-1-storage"}' \ -device virtio-blk-pci,iothread=3Diothread1,drive=3Dlibvirt-1-format,id=3Dv= irtio-disk0,bootindex=3D1,write-cache=3Don and observe that it will fail not manage to boot with "qemu_mutex_unlock_im= pl: Operation not permitted" Signed-off-by: Emanuele Giuseppe Esposito Acked-by: Michael S. Tsirkin Reviewed-by: Stefan Hajnoczi Tested-by: Luk=C3=A1=C5=A1 Doktor --- hw/block/virtio-blk.c | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/hw/block/virtio-blk.c b/hw/block/virtio-blk.c index 1762517878..cefca93b31 100644 --- a/hw/block/virtio-blk.c +++ b/hw/block/virtio-blk.c @@ -894,6 +894,10 @@ static void virtio_blk_update_config(VirtIODevice *vde= v, uint8_t *config) uint64_t capacity; int64_t length; int blk_size =3D conf->logical_block_size; + AioContext *ctx; + + ctx =3D blk_get_aio_context(s->blk); + aio_context_acquire(ctx); =20 blk_get_geometry(s->blk, &capacity); memset(&blkcfg, 0, sizeof(blkcfg)); @@ -917,6 +921,7 @@ static void virtio_blk_update_config(VirtIODevice *vdev= , uint8_t *config) * per track (cylinder). */ length =3D blk_getlength(s->blk); + aio_context_release(ctx); if (length > 0 && length / conf->heads / conf->secs % blk_size) { blkcfg.geometry.sectors =3D conf->secs & ~s->sector_mask; } else { --=20 2.39.1