From nobody Mon Feb 9 03:15:47 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 1547477669667303.65828664131936; Mon, 14 Jan 2019 06:54:29 -0800 (PST) Received: from localhost ([127.0.0.1]:45602 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gj3dD-0000cp-Ti for importer@patchew.org; Mon, 14 Jan 2019 09:54:27 -0500 Received: from eggs.gnu.org ([209.51.188.92]:54231) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gj3At-0001jG-QZ for qemu-devel@nongnu.org; Mon, 14 Jan 2019 09:25:13 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1gj3Ao-0008VX-Dg for qemu-devel@nongnu.org; Mon, 14 Jan 2019 09:25:11 -0500 Received: from fanzine.igalia.com ([91.117.99.155]:52464) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1gj3An-0008LS-Ql; Mon, 14 Jan 2019 09:25:06 -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 1gj3AV-0002jO-Rk; Mon, 14 Jan 2019 15:24:47 +0100 Received: from berto by perseus.local with local (Exim 4.89) (envelope-from ) id 1gj39z-000380-0w; Mon, 14 Jan 2019 16:24:15 +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=B1rpo0I7gQ2eNbWZ+IneXopvQLkOTUafi3SU1162728=; b=kulWYUclw+GPHMEwHjArrTVSfIg6frW+groC864J6C3qbJpQBhxy73PQbahxwBUYfCHvjM9Z7pBqaSkEFwTZWnEZ18d72JNUaIweRU/6sdAhSouD43yKqVugwP1iPkUttxAzb7RrA/Aaot1VKGI/hF38vpBQxAQXUzfww1rVACd4W/Cg/1fe0LZU5S1oGHM3+/aK5MpLRyfBaJcs+aVDYtNDswDp4MNbhoXvP+7D/Vv4GOSZEB7Qa6SaEtPapvGN+lexo5VmpvyEjlJiO3slSOgxs2pvPOnN4CQdFwEjK63Z4xupx6/8q8w0JZNVmZk/h/ziQptLvoQOdqVyQ75nWg==; From: Alberto Garcia To: qemu-devel@nongnu.org Date: Mon, 14 Jan 2019 16:23:59 +0200 Message-Id: <5086004667e4a962e10e29ccb402705d0962dbcf.1547475602.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 v2 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 a crash when adding a virtio-blk device with a drive that is using an iothread. Test case included. Signed-off-by: Alberto Garcia --- hw/block/virtio-blk.c | 22 ++++++++----- tests/qemu-iotests/236 | 78 ++++++++++++++++++++++++++++++++++++++++++= ++++ tests/qemu-iotests/236.out | 16 ++++++++++ tests/qemu-iotests/group | 1 + 4 files changed, 110 insertions(+), 7 deletions(-) create mode 100755 tests/qemu-iotests/236 create mode 100644 tests/qemu-iotests/236.out 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) diff --git a/tests/qemu-iotests/236 b/tests/qemu-iotests/236 new file mode 100755 index 0000000000..c6a3415ffe --- /dev/null +++ b/tests/qemu-iotests/236 @@ -0,0 +1,78 @@ +#!/bin/bash +# +# Test deletion of devices that are using iothreads +# +# Copyright (C) 2019 Igalia, S.L. +# Author: Alberto Garcia +# +# 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=3Dberto@igalia.com + +seq=3D`basename $0` +echo "QA output created by $seq" + +status=3D1 # failure is the default! + +# get standard environment, filters and checks +. ./common.rc +. ./common.filter + +_supported_fmt generic +_supported_proto generic +_supported_os Linux + +do_run_qemu() +{ + echo Testing: "$@" + $QEMU -nographic -qmp stdio -serial none "$@" + echo +} + +# Remove QMP events from (pretty-printed) output. Doesn't handle +# nested dicts correctly, but we don't get any of those in this test. +_filter_qmp_events() +{ + tr '\n' '\t' | sed -e \ + 's/{\s*"timestamp":\s*{[^}]*},\s*"event":[^,}]*\(,\s*"data":\s*{[^}]*}\)\= ?\s*}\s*//g' \ + | tr '\t' '\n' +} + +run_qemu() +{ + do_run_qemu "$@" 2>&1 | _filter_qmp | _filter_qmp_events +} + +echo +echo =3D=3D=3D Try adding and removing a virtio-blk device =3D=3D=3D +echo + +run_qemu <