From patchwork Thu Jan 10 15:03:36 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Alberto Garcia X-Patchwork-Id: 10756029 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 477A614DE for ; Thu, 10 Jan 2019 15:07:37 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 3639829129 for ; Thu, 10 Jan 2019 15:07:37 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 27DAF29A23; Thu, 10 Jan 2019 15:07:37 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-2.7 required=2.0 tests=BAYES_00,DKIM_INVALID, DKIM_SIGNED,MAILING_LIST_MULTI autolearn=ham version=3.3.1 Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id B2FCD29129 for ; Thu, 10 Jan 2019 15:07:36 +0000 (UTC) Received: from localhost ([127.0.0.1]:45110 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ghbvj-0005cd-Dl for patchwork-qemu-devel@patchwork.kernel.org; Thu, 10 Jan 2019 10:07:35 -0500 Received: from eggs.gnu.org ([209.51.188.92]:46113) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ghbsJ-000324-FJ for qemu-devel@nongnu.org; Thu, 10 Jan 2019 10:04:04 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1ghbsG-0007O1-EW for qemu-devel@nongnu.org; Thu, 10 Jan 2019 10:04:03 -0500 Received: from fanzine.igalia.com ([91.117.99.155]:57867) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1ghbsF-0007NE-Te; Thu, 10 Jan 2019 10:04:00 -0500 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=o4MgRiH2A9D2KlY6wfivpWdHv4L6n8VMY28b8z4DSDY=; b=fdZnFnHmLHN14kQWM7r7ICZcv9//lTYKNwBkKzylTLnN5DkE35CQF+VCYY8rtdBCJjJXxVSVKnXigdVjLmi0zyVTe1i01opUxQ9c0cHR6gL4R82ZrMyKjio8IRaP0Q1QNul2nHjEOLFz4rM7AkKO9f5zRCjco8uZajwrwlNDPu82QrC5V9rfO7SUqdpFG6Mc6Sdf9dOWsOreLdRj0gxuPBAZQpKKjni3QxymbFuCcSpbTcQQ4MTQfgMwvyTpP+NMcr3tHWk5CAUoEGyZ+bSWgocV4qlgZGPNOxC6oewQWfhtLoFmTmdY06ft52vdU7sgi2Ks5rvEvbJy4pPwBBqktg==; 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-0003mT-NJ; Thu, 10 Jan 2019 16:03:57 +0100 Received: from berto by perseus.local with local (Exim 4.89) (envelope-from ) id 1ghbry-0002Bd-4R; Thu, 10 Jan 2019 17:03:42 +0200 From: Alberto Garcia To: qemu-devel@nongnu.org Date: Thu, 10 Jan 2019 17:03:36 +0200 Message-Id: <42c8dab1efbcd608a09a1d84468fc498b612bfa1.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 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+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Sender: "Qemu-devel" X-Virus-Scanned: ClamAV using ClamSMTP 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": "scsi-pci0", "driver": "virtio-scsi-pci"}} { "execute": "device_add", "arguments": {"id": "scsi-hd0", "driver": "scsi-hd", "drive": "hd0"}} qemu: qemu_mutex_unlock_impl: Operation not permitted Aborted Signed-off-by: Alberto Garcia --- hw/scsi/scsi-disk.c | 24 +++++++++++++++++++----- 1 file changed, 19 insertions(+), 5 deletions(-) diff --git a/hw/scsi/scsi-disk.c b/hw/scsi/scsi-disk.c index 0e9027c8f3..8a22def7f3 100644 --- a/hw/scsi/scsi-disk.c +++ b/hw/scsi/scsi-disk.c @@ -2318,16 +2318,20 @@ static void scsi_disk_unit_attention_reported(SCSIDevice *dev) static void scsi_realize(SCSIDevice *dev, Error **errp) { SCSIDiskState *s = DO_UPCAST(SCSIDiskState, qdev, dev); + AioContext *ctx; if (!s->qdev.conf.blk) { error_setg(errp, "drive property not set"); return; } + ctx = blk_get_aio_context(s->qdev.conf.blk); + aio_context_acquire(ctx); + if (!(s->features & (1 << SCSI_DISK_F_REMOVABLE)) && !blk_is_inserted(s->qdev.conf.blk)) { error_setg(errp, "Device needs media, but drive is empty"); - return; + goto out; } blkconf_blocksizes(&s->qdev.conf); @@ -2336,18 +2340,18 @@ static void scsi_realize(SCSIDevice *dev, Error **errp) s->qdev.conf.physical_block_size) { error_setg(errp, "logical_block_size > physical_block_size not supported"); - return; + goto out; } if (dev->type == TYPE_DISK) { if (!blkconf_geometry(&dev->conf, NULL, 65535, 255, 255, errp)) { - return; + goto out; } } if (!blkconf_apply_backend_options(&dev->conf, blk_is_read_only(s->qdev.conf.blk), dev->type == TYPE_DISK, errp)) { - return; + goto out; } if (s->qdev.conf.discard_granularity == -1) { @@ -2364,7 +2368,7 @@ static void scsi_realize(SCSIDevice *dev, Error **errp) if (blk_is_sg(s->qdev.conf.blk)) { error_setg(errp, "unwanted /dev/sg*"); - return; + goto out; } if ((s->features & (1 << SCSI_DISK_F_REMOVABLE)) && @@ -2376,6 +2380,9 @@ static void scsi_realize(SCSIDevice *dev, Error **errp) blk_set_guest_block_size(s->qdev.conf.blk, s->qdev.blocksize); blk_iostatus_enable(s->qdev.conf.blk); + +out: + aio_context_release(ctx); } static void scsi_hd_realize(SCSIDevice *dev, Error **errp) @@ -2385,7 +2392,10 @@ static void scsi_hd_realize(SCSIDevice *dev, Error **errp) * backend will be issued in scsi_realize */ if (s->qdev.conf.blk) { + AioContext *ctx = blk_get_aio_context(s->qdev.conf.blk); + aio_context_acquire(ctx); blkconf_blocksizes(&s->qdev.conf); + aio_context_release(ctx); } s->qdev.blocksize = s->qdev.conf.logical_block_size; s->qdev.type = TYPE_DISK; @@ -2553,6 +2563,7 @@ static int get_device_type(SCSIDiskState *s) static void scsi_block_realize(SCSIDevice *dev, Error **errp) { SCSIDiskState *s = DO_UPCAST(SCSIDiskState, qdev, dev); + AioContext *ctx; int sg_version; int rc; @@ -2568,7 +2579,10 @@ static void scsi_block_realize(SCSIDevice *dev, Error **errp) } /* check we are using a driver managing SG_IO (version 3 and after) */ + ctx = blk_get_aio_context(s->qdev.conf.blk); + aio_context_acquire(ctx); rc = blk_ioctl(s->qdev.conf.blk, SG_GET_VERSION_NUM, &sg_version); + aio_context_release(ctx); if (rc < 0) { error_setg_errno(errp, -rc, "cannot get SG_IO version number"); if (rc != -EPERM) {