From nobody Wed May 8 13:16:41 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) client-ip=208.118.235.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 208.118.235.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org Return-Path: Received: from lists.gnu.org (208.118.235.17 [208.118.235.17]) by mx.zohomail.com with SMTPS id 1509437095588149.64615741417992; Tue, 31 Oct 2017 01:04:55 -0700 (PDT) Received: from localhost ([::1]:44173 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1e9RXL-0001vG-Go for importer@patchew.org; Tue, 31 Oct 2017 04:04:39 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:42742) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1e9RWR-0001d6-Ti for qemu-devel@nongnu.org; Tue, 31 Oct 2017 04:03:44 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1e9RWN-0006B9-7K for qemu-devel@nongnu.org; Tue, 31 Oct 2017 04:03:43 -0400 Received: from szxga05-in.huawei.com ([45.249.212.191]:2274) by eggs.gnu.org with esmtps (TLS1.0:RSA_ARCFOUR_SHA1:16) (Exim 4.71) (envelope-from ) id 1e9RWM-00066A-L4 for qemu-devel@nongnu.org; Tue, 31 Oct 2017 04:03:39 -0400 Received: from 172.30.72.60 (EHLO DGGEMS405-HUB.china.huawei.com) ([172.30.72.60]) by dggrg05-dlp.huawei.com (MOS 4.4.6-GA FastPath queued) with ESMTP id DKE30037; Tue, 31 Oct 2017 16:03:28 +0800 (CST) Received: from localhost (10.177.131.80) by DGGEMS405-HUB.china.huawei.com (10.3.19.205) with Microsoft SMTP Server id 14.3.361.1; Tue, 31 Oct 2017 16:03:18 +0800 From: linzhecheng To: Date: Tue, 31 Oct 2017 16:03:03 +0800 Message-ID: <20171031080303.15624-1-linzhecheng@huawei.com> X-Mailer: git-send-email 2.12.2.windows.2 MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable X-Originating-IP: [10.177.131.80] X-CFilter-Loop: Reflected X-Mirapoint-Virus-RAPID-Raw: score=unknown(0), refid=str=0001.0A090203.59F82E51.00FB, ss=1, re=0.000, recu=0.000, reip=0.000, cl=1, cld=1, fgs=0, ip=0.0.0.0, so=2014-11-16 11:51:01, dmn=2013-03-21 17:37:32 X-Mirapoint-Loop-Id: 40f2ed132ed878dea1b1f0f44caf5cf0 X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.4.x-2.6.x [generic] [fuzzy] X-Received-From: 45.249.212.191 Subject: [Qemu-devel] [PATCH] fix: unrealize virtio device if we fail to hotplug it 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: linzhecheng , stefanha@redhat.com, mst@redhat.com Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail: RSF_0 Z_629925259 SPT_0 If we fail to hotplug virtio-blk device and then suspend or shutdown VM, qemu is likely to crash. Re-production steps: 1. Run VM named vm001 2. Create a virtio-blk.xml which contains wrong configurations: 3. Run command : virsh attach-device vm001 virtio-blk.xml error: Failed to attach device from blk-scsi.xml error: internal error: unable to execute QEMU command 'device_add': Please = set scsi=3Doff for virtio-blk devices in order to use virtio 1.0 it means hotplug virtio-blk device failed. 4. Suspend or shutdown VM will leads to qemu crash Problem happens in virtio_vmstate_change which is called by vm_state_notify: vdev=E2=80=99s parent_bus is NULL, so qdev_get_parent_bus(DEVICE(vdev)) wil= l crash. virtio_vmstate_change is added to the list vm_change_state_head at virtio_b= lk_device_realize(virtio_init), but after hotplug virtio-blk failed, virtio_vmstate_change will not be remo= ved from vm_change_state_head. Adding unrealize function of virtio-blk device can solve this problem. Signed-off-by: linzhecheng Reviewed-by: Stefan Hajnoczi --- hw/virtio/virtio.c | 1 + 1 file changed, 1 insertion(+) diff --git a/hw/virtio/virtio.c b/hw/virtio/virtio.c index 5884ce3480..ea532dc35f 100644 --- a/hw/virtio/virtio.c +++ b/hw/virtio/virtio.c @@ -2491,6 +2491,7 @@ static void virtio_device_realize(DeviceState *dev, E= rror **errp) virtio_bus_device_plugged(vdev, &err); if (err !=3D NULL) { error_propagate(errp, err); + vdc->unrealize(dev, NULL); return; } =20 --=20 2.12.2.windows.2