From patchwork Tue Jul 3 13:30:17 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Zhengui li X-Patchwork-Id: 10504109 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id 9060260325 for ; Tue, 3 Jul 2018 13:34:15 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 7B3E728AA4 for ; Tue, 3 Jul 2018 13:34:15 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 7931528B20; Tue, 3 Jul 2018 13:34:15 +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=-7.9 required=2.0 tests=BAYES_00, MAILING_LIST_MULTI, RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id BB2B628B54 for ; Tue, 3 Jul 2018 13:34:14 +0000 (UTC) Received: from localhost ([::1]:40568 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1faLRd-0005tH-Ka for patchwork-qemu-devel@patchwork.kernel.org; Tue, 03 Jul 2018 09:34:13 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:60185) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1faLQs-0005a9-Tu for qemu-devel@nongnu.org; Tue, 03 Jul 2018 09:33:28 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1faLQo-00079l-Rs for qemu-devel@nongnu.org; Tue, 03 Jul 2018 09:33:26 -0400 Received: from [45.249.212.32] (port=52555 helo=huawei.com) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1faLQn-00070N-12 for qemu-devel@nongnu.org; Tue, 03 Jul 2018 09:33:22 -0400 Received: from DGGEMS406-HUB.china.huawei.com (unknown [172.30.72.59]) by Forcepoint Email with ESMTP id 65E942AD49C8A; Tue, 3 Jul 2018 21:33:11 +0800 (CST) Received: from [127.0.0.1] (10.177.251.193) by DGGEMS406-HUB.china.huawei.com (10.3.19.206) with Microsoft SMTP Server id 14.3.382.0; Tue, 3 Jul 2018 21:33:04 +0800 To: Stefan Hajnoczi References: <86b43998-fc9e-75bf-564c-a64d72163793@huawei.com> <20180702131518.GF2155@stefanha-x1.localdomain> From: l00284672 Message-ID: <0c86fe57-ed34-f44f-83af-ecdf36f7605b@huawei.com> Date: Tue, 3 Jul 2018 21:30:17 +0800 User-Agent: Mozilla/5.0 (Windows NT 6.1; WOW64; rv:52.0) Gecko/20100101 Thunderbird/52.4.0 MIME-Version: 1.0 In-Reply-To: Content-Language: en-US X-Originating-IP: [10.177.251.193] X-CFilter-Loop: Reflected X-detected-operating-system: by eggs.gnu.org: GNU/Linux 3.x [fuzzy] X-Received-From: 45.249.212.32 Subject: Re: [Qemu-devel] question: disk missing in the guest contingently when hotplug several virtio scsi disks consecutively. 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: kwolf@redhat.com, pbonzini@redhat.com, famz@redhat.com, qemu-devel@nongnu.org, "Fangyi \(C\)" Errors-To: qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Sender: "Qemu-devel" X-Virus-Scanned: ClamAV using ClamSMTP I got a solution, the patch is below: The commit https://git.qemu.org/?p=qemu.git;a=commitdiff;h=e9447f35718439c1affdee3ef69b2fee50c8106c;hp=4c64d5b52ed5287bb31489bba39cf41628230bc introduced this problem. I  think  there should not be any IO requests brefore device is realized, but I have no idea  how to avoid it after calling virtio_scsi_push_event. On 2018/7/3 15:20, l00284672 wrote: > The disk missing due to calling scsi_probe_lun failed in guest. The > guest code is below: > static int scsi_probe_lun(struct scsi_device *sdev, unsigned char > *inq_result, >               int result_len, int *bflags) > > { > ......... >     result = scsi_execute_req(sdev,  scsi_cmd, DMA_FROM_DEVICE, >                       inq_result, try_inquiry_len, &sshdr, >                       HZ / 2 + HZ * scsi_inq_timeout, 3, >                       &resid); > > ......... > } > > The scsi inqury request from guest is cancelled by qemu. The qemu bt > is below: > > (gdb) bt > #0  scsi_req_cancel_async (req=0x7f86d00055c0, notifier=0x0) at > hw/scsi/scsi-bus.c:1825 > #1  0x000055b50ac254c7 in scsi_device_purge_requests > (sdev=sdev@entry=0x55b50f9a8990, sense=...) at hw/scsi/scsi-bus.c:1925 > #2  0x000055b50ac1d337 in scsi_disk_reset (dev=0x55b50f9a8990) at > hw/scsi/scsi-disk.c:2186 > #3  0x000055b50ab95d91 in device_set_realized (obj=, > value=, errp=0x7ffedda81898) at hw/core/qdev.c:949 > #4  0x000055b50acd167e in property_set_bool (obj=0x55b50f9a8990, > v=, name=, opaque=0x55b50f9c1b50, > errp=0x7ffedda81898) at qom/object.c:1854 > #5  0x000055b50acd5091 in object_property_set_qobject > (obj=obj@entry=0x55b50f9a8990, value=value@entry=0x55b50f997350, > name=name@entry=0x55b50ae0260b "realized", >     errp=errp@entry=0x7ffedda81898) at qom/qom-qobject.c:27 > #6  0x000055b50acd3210 in object_property_set_bool > (obj=0x55b50f9a8990, value=, name=0x55b50ae0260b > "realized", errp=0x7ffedda81898) at qom/object.c:1157 > #7  0x000055b50ab1e0b5 in qdev_device_add > (opts=opts@entry=0x55b50ceb9880, errp=errp@entry=0x7ffedda81978) at > qdev-monitor.c:627 > #8  0x000055b50ab1e68b in qmp_device_add (qdict=, > ret_data=, errp=0x7ffedda819c0) at qdev-monitor.c:807 > #9  0x000055b50ad78787 in do_qmp_dispatch (errp=0x7ffedda819b8, > request=0x55b50c9605c0) at qapi/qmp-dispatch.c:114 > #10 qmp_dispatch (request=request@entry=0x55b50d447000) at > qapi/qmp-dispatch.c:141 > #11 0x000055b50aa3a102 in handle_qmp_command (parser=, > tokens=) at > /mnt/sdb/lzg/code/UVP_2.5_CODE/qemu/monitor.c:3907 > #12 0x000055b50ad7da54 in json_message_process_token > (lexer=0x55b50c5d4458, input=0x55b50c55a6e0, type=JSON_RCURLY, x=181, > y=1449) at qobject/json-streamer.c:105 > #13 0x000055b50ad9fdfb in json_lexer_feed_char > (lexer=lexer@entry=0x55b50c5d4458, ch=125 '}', > flush=flush@entry=false) at qobject/json-lexer.c:319 > #14 0x000055b50ad9febe in json_lexer_feed (lexer=0x55b50c5d4458, > buffer=, size=) at qobject/json-lexer.c:369 > #15 0x000055b50ad7db19 in json_message_parser_feed (parser= out>, buffer=, size=) at > qobject/json-streamer.c:124 > #16 0x000055b50aa389bb in monitor_qmp_read (opaque=, > buf=, size=) at > /mnt/sdb/lzg/code/UVP_2.5_CODE/qemu/monitor.c:3937 > #17 0x000055b50ab23e26 in tcp_chr_read (chan=, > cond=, opaque=0x55b50c5d0fa0) at qemu-char.c:3253 > #18 0x00007f8754cc499a in g_main_context_dispatch () from > /usr/lib64/libglib-2.0.so.0 > #19 0x000055b50acded8c in glib_pollfds_poll () at main-loop.c:228 > #20 os_host_main_loop_wait (timeout=) at main-loop.c:273 > #21 main_loop_wait (nonblocking=) at main-loop.c:521 > #22 0x000055b50a9ff8ff in main_loop () at vl.c:2095 > > static void device_set_realized(Object *obj, bool value, Error **errp) > { >     ....... >     if (hotplug_ctrl) { >     hotplug_handler_plug(hotplug_ctrl, dev, &local_err); > } > > ....... >     if (dev->hotplugged) { >         device_reset(dev); >     } >     ...... > } > > The hotplug_handler_plug call virtio_scsi_hotplug.  If iothread handle > a request between  hotplug_handler_plug and  device_reset, the request > will be cancelled by > scsi_device_purge_requests in device_reset. > > On 2018/7/2 21:15, Stefan Hajnoczi wrote: >> On Wed, Jun 27, 2018 at 06:33:16PM +0800, l00284672 wrote: >>> Hi, I found a bug that disk missing (not all disks missing ) in the >>> guest >>> contingently when hotplug several virtio scsi disks consecutively.  >>> After >>> rebooting the guest, >> For the record, there is also a bug report here: >> >> https://bugs.launchpad.net/qemu/+bug/1779120 >> >> I plan to reproduce this issue soon. >> >> Stefan > diff --git a/hw/scsi/scsi-disk.c b/hw/scsi/scsi-disk.c index 608fb18..4cdc2bb 100644 --- a/hw/scsi/scsi-disk.c +++ b/hw/scsi/scsi-disk.c @@ -2184,7 +2184,9 @@ static void scsi_disk_reset(DeviceState *dev)      SCSIDiskState *s = DO_UPCAST(SCSIDiskState, qdev.qdev, dev);      uint64_t nb_sectors; -    scsi_device_purge_requests(&s->qdev, SENSE_CODE(RESET)); +    if (dev->realized) { +       scsi_device_purge_requests(&s->qdev, SENSE_CODE(RESET)); +    }      blk_get_geometry(s->qdev.conf.blk, &nb_sectors);      nb_sectors /= s->qdev.blocksize / 512;