From nobody Mon Feb 9 07:38:20 2026 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; dkim=fail; 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 Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1547132998132779.218910067069; Thu, 10 Jan 2019 07:09:58 -0800 (PST) Received: from localhost ([127.0.0.1]:45658 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ghby1-0006ru-3W for importer@patchew.org; Thu, 10 Jan 2019 10:09:57 -0500 Received: from eggs.gnu.org ([209.51.188.92]:46203) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ghbsN-00036w-Vx for qemu-devel@nongnu.org; Thu, 10 Jan 2019 10:04:13 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1ghbsG-0007OR-Gm for qemu-devel@nongnu.org; Thu, 10 Jan 2019 10:04:06 -0500 Received: from fanzine.igalia.com ([91.117.99.155]:57861) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1ghbsF-0007NK-Tl; Thu, 10 Jan 2019 10:04:00 -0500 Received: from [194.100.51.2] (helo=perseus.local) by fanzine.igalia.com with esmtpsa (Cipher TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim) id 1ghbsD-0003mU-Oi; Thu, 10 Jan 2019 16:03:57 +0100 Received: from berto by perseus.local with local (Exim 4.89) (envelope-from ) id 1ghbry-0002Bb-32; Thu, 10 Jan 2019 17:03:42 +0200 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=igalia.com; s=20170329; h=References:In-Reply-To:References:In-Reply-To:Message-Id:Date:Subject:Cc:To:From; bh=1RDoTfYk81Gj3E6of/gL7KLZOJeO382M3nMlpGpF9YU=; b=dVslm2tOWO6iBcP2yqcqIXnNyITnF2WHQ8Yy5HrV42Akzuzs+tMzpUCKMrIYF7gTGW9GPiRzTf51BXJn3zpJIe6Jyw9ltIOIghbI7uyJnQxBYPh/OIm9F3uac7MfXMJ+vA64VH3CSotl92uoBX52jTsnmdhIqUng2dRpC/ks4JPDzryYIiCNe3EHWz1xJTRaYwiB/1Qi4P5XicP27G84xbTP/h0fMaH52A31+1/rY1XYfJuREPtS0E7CFSwEjLy+LIo7wYrpl5h2LQDrGCmLqKuC/ICghz50tM2pkV8IHlvRSppRbECXpaMMRw72L49IMFrnoq0fb4ameT2z/RlwZA==; From: Alberto Garcia To: qemu-devel@nongnu.org Date: Thu, 10 Jan 2019 17:03:35 +0200 Message-Id: <4a595def20efc9d1d076850d79a2c7e6d0996ffd.1547132561.git.berto@igalia.com> X-Mailer: git-send-email 2.11.0 In-Reply-To: References: In-Reply-To: References: X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x (no timestamps) [generic] [fuzzy] X-Received-From: 91.117.99.155 Subject: [Qemu-devel] [PATCH 1/6] block: Acquire the AioContext in virtio_blk_device_realize() 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 , Alberto Garcia , qemu-block@nongnu.org, Max Reitz , Stefan Hajnoczi , Paolo Bonzini Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" This fixes the following crash: { "execute": "blockdev-add", "arguments": {"driver": "null-co", "node-name": "hd0"}} { "execute": "object-add", "arguments": {"qom-type": "iothread", "id": "iothread0"}} { "execute": "x-blockdev-set-iothread", "arguments": {"node-name": "hd0", "iothread": "iothread0"}} { "execute": "device_add", "arguments": {"id": "virtio0", "driver": "virtio-blk-pci", "drive": "hd0"}} qemu: qemu_mutex_unlock_impl: Operation not permitted Aborted Signed-off-by: Alberto Garcia --- hw/block/virtio-blk.c | 22 +++++++++++++++------- 1 file changed, 15 insertions(+), 7 deletions(-) diff --git a/hw/block/virtio-blk.c b/hw/block/virtio-blk.c index f208c6ddb9..5357da82af 100644 --- a/hw/block/virtio-blk.c +++ b/hw/block/virtio-blk.c @@ -912,6 +912,7 @@ static void virtio_blk_device_realize(DeviceState *dev,= Error **errp) VirtIODevice *vdev =3D VIRTIO_DEVICE(dev); VirtIOBlock *s =3D VIRTIO_BLK(dev); VirtIOBlkConf *conf =3D &s->conf; + AioContext *ctx; Error *err =3D NULL; unsigned i; =20 @@ -919,30 +920,34 @@ static void virtio_blk_device_realize(DeviceState *de= v, Error **errp) error_setg(errp, "drive property not set"); return; } + + ctx =3D blk_get_aio_context(conf->conf.blk); + aio_context_acquire(ctx); + if (!blk_is_inserted(conf->conf.blk)) { error_setg(errp, "Device needs media, but drive is empty"); - return; + goto out; } if (!conf->num_queues) { error_setg(errp, "num-queues property must be larger than 0"); - return; + goto out; } if (!is_power_of_2(conf->queue_size) || conf->queue_size > VIRTQUEUE_MAX_SIZE) { error_setg(errp, "invalid queue-size property (%" PRIu16 "), " "must be a power of 2 (max %d)", conf->queue_size, VIRTQUEUE_MAX_SIZE); - return; + goto out; } =20 if (!blkconf_apply_backend_options(&conf->conf, blk_is_read_only(conf->conf.blk), t= rue, errp)) { - return; + goto out; } s->original_wce =3D blk_enable_write_cache(conf->conf.blk); if (!blkconf_geometry(&conf->conf, NULL, 65535, 255, 255, errp)) { - return; + goto out; } =20 blkconf_blocksizes(&conf->conf); @@ -951,7 +956,7 @@ static void virtio_blk_device_realize(DeviceState *dev,= Error **errp) conf->conf.physical_block_size) { error_setg(errp, "logical_block_size > physical_block_size not supported= "); - return; + goto out; } =20 virtio_init(vdev, "virtio-blk", VIRTIO_ID_BLOCK, @@ -968,7 +973,7 @@ static void virtio_blk_device_realize(DeviceState *dev,= Error **errp) if (err !=3D NULL) { error_propagate(errp, err); virtio_cleanup(vdev); - return; + goto out; } =20 s->change =3D qemu_add_vm_change_state_handler(virtio_blk_dma_restart_= cb, s); @@ -976,6 +981,9 @@ static void virtio_blk_device_realize(DeviceState *dev,= Error **errp) blk_set_guest_block_size(s->blk, s->conf.conf.logical_block_size); =20 blk_iostatus_enable(s->blk); + +out: + aio_context_release(ctx); } =20 static void virtio_blk_device_unrealize(DeviceState *dev, Error **errp) --=20 2.11.0