From nobody Sat May 18 08:14:07 2024 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; 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 ARC-Seal: i=1; a=rsa-sha256; t=1563696731; cv=none; d=zoho.com; s=zohoarc; b=n/KJIddxJoOYnJT2PzEzlze4G2N2P8/BOtVrNo95UOm7ZMWqKfuaJe3C95V8/zlKUpZr/ksSchdJAatbj0lcR1PQIjqhOg8KPuEmoMEC+1ZqoZm/7m08dj6LZfoX5M7TSLP3CZelApuioyLhej5lBE06fU73di1auCUbykR6so8= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zoho.com; s=zohoarc; t=1563696731; h=Content-Type: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:ARC-Authentication-Results; bh=dK8l2lMqwMzJ2zHdhZcDebY16bZErxlMF8p5HpjHZqQ=; b=bNpUJWS5jYsX23fU+5HBhYmlJ/r4fjN5WYrIym+/32sEGe86B6kxLKFsRsxGf12bFC7kLZM0OTPq8BX1+TidjYU8+A4gCEAuZlm89MHI0IERO40lMkYy7sYLcEO6yC+ixsBWd2Zz9sr8qq1cnCMelq8GbmSsWWOYvAWlcVfEY4s= ARC-Authentication-Results: i=1; mx.zoho.com; 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 1563696731122557.9019569712789; Sun, 21 Jul 2019 01:12:11 -0700 (PDT) Received: from localhost ([::1]:55000 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.86_2) (envelope-from ) id 1hp6wx-0005sP-Qu for importer@patchew.org; Sun, 21 Jul 2019 04:12:07 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:53887) by lists.gnu.org with esmtp (Exim 4.86_2) (envelope-from ) id 1hp6wh-0005E2-7a for qemu-devel@nongnu.org; Sun, 21 Jul 2019 04:11:52 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1hp6wg-00051G-1x for qemu-devel@nongnu.org; Sun, 21 Jul 2019 04:11:51 -0400 Received: from szxga07-in.huawei.com ([45.249.212.35]:45342 helo=huawei.com) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1hp6wa-0004pD-Kd; Sun, 21 Jul 2019 04:11:45 -0400 Received: from DGGEMS403-HUB.china.huawei.com (unknown [172.30.72.58]) by Forcepoint Email with ESMTP id 62D0AFAF32EC1245CAE5; Sun, 21 Jul 2019 16:11:36 +0800 (CST) Received: from HGHY1l002846723.china.huawei.com (10.177.251.193) by DGGEMS403-HUB.china.huawei.com (10.3.19.203) with Microsoft SMTP Server id 14.3.439.0; Sun, 21 Jul 2019 16:11:28 +0800 From: l00284672 To: , Date: Sun, 21 Jul 2019 16:08:22 +0800 Message-ID: <1563696502-7972-1-git-send-email-lizhengui@huawei.com> X-Mailer: git-send-email 2.7.2.windows.1 MIME-Version: 1.0 X-Originating-IP: [10.177.251.193] X-CFilter-Loop: Reflected Content-Transfer-Encoding: quoted-printable X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 45.249.212.35 Subject: [Qemu-devel] [PATCH v2] virtio-scsi: fixed virtio_scsi_ctx_check failed when detaching scsi disk X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: lizhengui@huawei.com, qemu-block@nongnu.org, eric.fangyi@huawei.com, qemu-devel@nongnu.org, jiangyiwen@huawei.com, wangjie88@huawei.com Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" Content-Type: text/plain; charset="utf-8" commit a6f230c move blockbackend back to main AioContext on unplug. It set = the AioContext of SCSIDevice to the main AioContex, but s->ctx is still the iothread AioConte= x=EF=BC=88if the scsi controller is configure with iothread=EF=BC=89. So if there are having in-flight reque= sts during unplug, a failing assertion happend. The bt is below: (gdb) bt #0 0x0000ffff86aacbd0 in raise () from /lib64/libc.so.6 #1 0x0000ffff86aadf7c in abort () from /lib64/libc.so.6 #2 0x0000ffff86aa6124 in __assert_fail_base () from /lib64/libc.so.6 #3 0x0000ffff86aa61a4 in __assert_fail () from /lib64/libc.so.6 #4 0x0000000000529118 in virtio_scsi_ctx_check (d=3D, s=3D<= optimized out>, s=3D) at /home/qemu-4.0.0/hw/scsi/virtio-scs= i.c:246 #5 0x0000000000529ec4 in virtio_scsi_handle_cmd_req_prepare (s=3D0x2779ec0= 0, req=3D0xffff740397d0) at /home/qemu-4.0.0/hw/scsi/virtio-scsi.c:559 #6 0x000000000052a228 in virtio_scsi_handle_cmd_vq (s=3D0x2779ec00, vq=3D0= xffff7c6d7110) at /home/qemu-4.0.0/hw/scsi/virtio-scsi.c:603 #7 0x000000000052afa8 in virtio_scsi_data_plane_handle_cmd (vdev=3D, vq=3D0xffff7c6d7110) at /home/qemu-4.0.0/hw/scsi/virtio-scsi-data= plane.c:59 #8 0x000000000054d94c in virtio_queue_host_notifier_aio_poll (opaque=3D) at /home/qemu-4.0.0/hw/virtio/virtio.c:2452 assert(blk_get_aio_context(d->conf.blk) =3D=3D s->ctx) failed. To avoid assertion failed, moving the "if" after qdev_simple_device_unplug= _cb. In addition, to avoid another qemu crash below, add aio_disable_external be= fore qdev_simple_device_unplug_cb, which disable the further processing of exter= nal clients when doing qdev_simple_device_unplug_cb. (gdb) bt #0 scsi_req_unref (req=3D0xffff6802c6f0) at hw/scsi/scsi-bus.c:1283 #1 0x00000000005294a4 in virtio_scsi_handle_cmd_req_submit (req=3D, s=3D) at /home/qemu-4.0.0/hw/scsi/virtio-scsi.c:589 #2 0x000000000052a2a8 in virtio_scsi_handle_cmd_vq (s=3Ds@entry=3D0x9c90e9= 0, vq=3Dvq@entry=3D0xffff7c05f110) at /home/qemu-4.0.0/hw/scsi/virtio-scsi= .c:625 #3 0x000000000052afd8 in virtio_scsi_data_plane_handle_cmd (vdev=3D, vq=3D0xffff7c05f110) at /home/qemu-4.0.0/hw/scsi/virtio-scsi-dataplane.= c:60 #4 0x000000000054d97c in virtio_queue_host_notifier_aio_poll (opaque=3D) at /home/qemu-4.0.0/hw/virtio/virtio.c:2447 #5 0x00000000009b204c in run_poll_handlers_once (ctx=3Dctx@entry=3D0x6efea= 40, timeout=3Dtimeout@entry=3D0xffff7d7f7308) at util/aio-posix.c:521 #6 0x00000000009b2b64 in run_poll_handlers (ctx=3Dctx@entry=3D0x6efea40, max_ns=3Dmax_ns@entry=3D4000, timeout=3Dtimeout@entry=3D0xffff7d7f7308)= at util/aio-posix.c:559 #7 0x00000000009b2ca0 in try_poll_mode (ctx=3Dctx@entry=3D0x6efea40, timeo= ut=3D0xffff7d7f7308, timeout@entry=3D0xffff7d7f7348) at util/aio-posix.c:594 #8 0x00000000009b31b8 in aio_poll (ctx=3D0x6efea40, blocking=3Dblocking@en= try=3Dtrue) at util/aio-posix.c:636 #9 0x00000000006973cc in iothread_run (opaque=3D0x6ebd800) at iothread.c:75 #10 0x00000000009b592c in qemu_thread_start (args=3D0x6efef60) at util/qemu= -thread-posix.c:502 #11 0x0000ffff8057f8bc in start_thread () from /lib64/libpthread.so.0 #12 0x0000ffff804e5f8c in thread_start () from /lib64/libc.so.6 (gdb) p bus $1 =3D (SCSIBus *) 0x0 Signed-off-by: Zhengui li --- hw/scsi/virtio-scsi.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/hw/scsi/virtio-scsi.c b/hw/scsi/virtio-scsi.c index 839f120..79e555f 100644 --- a/hw/scsi/virtio-scsi.c +++ b/hw/scsi/virtio-scsi.c @@ -837,13 +837,15 @@ static void virtio_scsi_hotunplug(HotplugHandler *hot= plug_dev, DeviceState *dev, virtio_scsi_release(s); } =20 + aio_disable_external(s->ctx); + qdev_simple_device_unplug_cb(hotplug_dev, dev, errp); + aio_enable_external(s->ctx); + if (s->ctx) { virtio_scsi_acquire(s); blk_set_aio_context(sd->conf.blk, qemu_get_aio_context()); virtio_scsi_release(s); } - - qdev_simple_device_unplug_cb(hotplug_dev, dev, errp); } =20 static struct SCSIBusInfo virtio_scsi_scsi_info =3D { --=20 2.7.2.windows.1