From nobody Mon Feb 9 04:04:32 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 1547476521364180.551480759892; Mon, 14 Jan 2019 06:35:21 -0800 (PST) Received: from localhost ([127.0.0.1]:40880 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gj3Ki-0000Xg-8z for importer@patchew.org; Mon, 14 Jan 2019 09:35:20 -0500 Received: from eggs.gnu.org ([209.51.188.92]:54223) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gj3At-0001iv-L2 for qemu-devel@nongnu.org; Mon, 14 Jan 2019 09:25:12 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1gj3Ao-0008Vp-E8 for qemu-devel@nongnu.org; Mon, 14 Jan 2019 09:25:11 -0500 Received: from fanzine.igalia.com ([91.117.99.155]:52463) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1gj3An-0008LO-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-0002jQ-Up; Mon, 14 Jan 2019 15:24:48 +0100 Received: from berto by perseus.local with local (Exim 4.89) (envelope-from ) id 1gj39z-000383-20; 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=VkAexFNG2apua1mSheMqjpENsQLKSY4KQLcRVXmJorE=; b=a0Zxqd5F8CF8npWasQLtgAJPQorGbjKuNXPcwdXfCqVi6U0QFg8erSNKBneijCO6kQLccxiNpPC3g1E4xOSrI+Xt88BS3m6V72rF0a7o0zFXoH1TR4naXTBO+t9YZAl3o8B79iM8iUd47ccMd+l0d0+bmxBiJlO6nFDrGIvG2x6CV67qWy9apibAijnLhqfNS5P4WI+98uVZYJ8TzCnbZfa590pRFN75YYjQXnVCw2nVcQbIiCYCGNK3LGRNKy34XJO/+i3LDnvwZpDQ8JJil1ez9iXx4nVjZeGouCHoiaLbUPREtI6+E8SmtRtwxkkWNSA/J4TN6a9D6Ho36hlhGw==; From: Alberto Garcia To: qemu-devel@nongnu.org Date: Mon, 14 Jan 2019 16:24:00 +0200 Message-Id: <804cf3cff9712467993929d7563b510f77c5401f.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 2/6] block: Acquire the AioContext in scsi_*_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-scsi device with a drive that is using an iothread. Test case included. Signed-off-by: Alberto Garcia --- hw/scsi/scsi-disk.c | 23 ++++++++++++++++++++--- tests/qemu-iotests/236 | 43 +++++++++++++++++++++++++++++++++++++++++++ tests/qemu-iotests/236.out | 30 ++++++++++++++++++++++++++++++ 3 files changed, 93 insertions(+), 3 deletions(-) diff --git a/hw/scsi/scsi-disk.c b/hw/scsi/scsi-disk.c index 0e9027c8f3..b049026219 100644 --- a/hw/scsi/scsi-disk.c +++ b/hw/scsi/scsi-disk.c @@ -2381,10 +2381,13 @@ static void scsi_realize(SCSIDevice *dev, Error **e= rrp) static void scsi_hd_realize(SCSIDevice *dev, Error **errp) { SCSIDiskState *s =3D DO_UPCAST(SCSIDiskState, qdev, dev); + AioContext *ctx =3D NULL; /* can happen for devices without drive. The error message for missing * backend will be issued in scsi_realize */ if (s->qdev.conf.blk) { + ctx =3D blk_get_aio_context(s->qdev.conf.blk); + aio_context_acquire(ctx); blkconf_blocksizes(&s->qdev.conf); } s->qdev.blocksize =3D s->qdev.conf.logical_block_size; @@ -2393,11 +2396,15 @@ static void scsi_hd_realize(SCSIDevice *dev, Error = **errp) s->product =3D g_strdup("QEMU HARDDISK"); } scsi_realize(&s->qdev, errp); + if (ctx) { + aio_context_release(ctx); + } } =20 static void scsi_cd_realize(SCSIDevice *dev, Error **errp) { SCSIDiskState *s =3D DO_UPCAST(SCSIDiskState, qdev, dev); + AioContext *ctx; int ret; =20 if (!dev->conf.blk) { @@ -2408,6 +2415,8 @@ static void scsi_cd_realize(SCSIDevice *dev, Error **= errp) assert(ret =3D=3D 0); } =20 + ctx =3D blk_get_aio_context(dev->conf.blk); + aio_context_acquire(ctx); s->qdev.blocksize =3D 2048; s->qdev.type =3D TYPE_ROM; s->features |=3D 1 << SCSI_DISK_F_REMOVABLE; @@ -2415,6 +2424,7 @@ static void scsi_cd_realize(SCSIDevice *dev, Error **= errp) s->product =3D g_strdup("QEMU CD-ROM"); } scsi_realize(&s->qdev, errp); + aio_context_release(ctx); } =20 static void scsi_disk_realize(SCSIDevice *dev, Error **errp) @@ -2553,6 +2563,7 @@ static int get_device_type(SCSIDiskState *s) static void scsi_block_realize(SCSIDevice *dev, Error **errp) { SCSIDiskState *s =3D DO_UPCAST(SCSIDiskState, qdev, dev); + AioContext *ctx; int sg_version; int rc; =20 @@ -2567,6 +2578,9 @@ static void scsi_block_realize(SCSIDevice *dev, Error= **errp) "be removed in a future version"); } =20 + ctx =3D blk_get_aio_context(s->qdev.conf.blk); + aio_context_acquire(ctx); + /* check we are using a driver managing SG_IO (version 3 and after) */ rc =3D blk_ioctl(s->qdev.conf.blk, SG_GET_VERSION_NUM, &sg_version); if (rc < 0) { @@ -2574,18 +2588,18 @@ static void scsi_block_realize(SCSIDevice *dev, Err= or **errp) if (rc !=3D -EPERM) { error_append_hint(errp, "Is this a SCSI device?\n"); } - return; + goto out; } if (sg_version < 30000) { error_setg(errp, "scsi generic interface too old"); - return; + goto out; } =20 /* get device type from INQUIRY data */ rc =3D get_device_type(s); if (rc < 0) { error_setg(errp, "INQUIRY failed"); - return; + goto out; } =20 /* Make a guess for the block size, we'll fix it when the guest sends. @@ -2605,6 +2619,9 @@ static void scsi_block_realize(SCSIDevice *dev, Error= **errp) =20 scsi_realize(&s->qdev, errp); scsi_generic_read_device_inquiry(&s->qdev); + +out: + aio_context_release(ctx); } =20 typedef struct SCSIBlockReq { diff --git a/tests/qemu-iotests/236 b/tests/qemu-iotests/236 index c6a3415ffe..c2bf425491 100755 --- a/tests/qemu-iotests/236 +++ b/tests/qemu-iotests/236 @@ -72,6 +72,49 @@ run_qemu <