From patchwork Tue Dec 8 15:54:57 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Greg Kurz X-Patchwork-Id: 553966 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from lists.gnu.org (lists.gnu.org [IPv6:2001:4830:134:3::11]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id B62971402CD for ; Wed, 9 Dec 2015 02:55:29 +1100 (AEDT) Received: from localhost ([::1]:60474 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1a6Kbv-0008U0-Ol for incoming@patchwork.ozlabs.org; Tue, 08 Dec 2015 10:55:27 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:53364) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1a6Kbe-0008A8-5C for qemu-devel@nongnu.org; Tue, 08 Dec 2015 10:55:11 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1a6KbZ-0003Le-2W for qemu-devel@nongnu.org; Tue, 08 Dec 2015 10:55:09 -0500 Received: from e06smtp12.uk.ibm.com ([195.75.94.108]:56081) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1a6KbY-0003Jc-R1 for qemu-devel@nongnu.org; Tue, 08 Dec 2015 10:55:05 -0500 Received: from localhost by e06smtp12.uk.ibm.com with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted for from ; Tue, 8 Dec 2015 15:55:01 -0000 Received: from d06dlp02.portsmouth.uk.ibm.com (9.149.20.14) by e06smtp12.uk.ibm.com (192.168.101.142) with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted; Tue, 8 Dec 2015 15:54:59 -0000 X-IBM-Helo: d06dlp02.portsmouth.uk.ibm.com X-IBM-MailFrom: gkurz@linux.vnet.ibm.com X-IBM-RcptTo: qemu-devel@nongnu.org Received: from b06cxnps4076.portsmouth.uk.ibm.com (d06relay13.portsmouth.uk.ibm.com [9.149.109.198]) by d06dlp02.portsmouth.uk.ibm.com (Postfix) with ESMTP id CDD8B2190056 for ; Tue, 8 Dec 2015 15:54:51 +0000 (GMT) Received: from d06av05.portsmouth.uk.ibm.com (d06av05.portsmouth.uk.ibm.com [9.149.37.229]) by b06cxnps4076.portsmouth.uk.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id tB8FsxVJ9306528 for ; Tue, 8 Dec 2015 15:54:59 GMT Received: from d06av05.portsmouth.uk.ibm.com (localhost [127.0.0.1]) by d06av05.portsmouth.uk.ibm.com (8.14.4/8.14.4/NCO v10.0 AVout) with ESMTP id tB8FsxJL001777 for ; Tue, 8 Dec 2015 08:54:59 -0700 Received: from smtp.lab.toulouse-stg.fr.ibm.com (srv01.lab.toulouse-stg.fr.ibm.com [9.101.4.1]) by d06av05.portsmouth.uk.ibm.com (8.14.4/8.14.4/NCO v10.0 AVin) with ESMTP id tB8Fswhc001770; Tue, 8 Dec 2015 08:54:58 -0700 Received: from bahia.huguette.org (icon-9-167-244-173.megacenter.de.ibm.com [9.167.244.173]) by smtp.lab.toulouse-stg.fr.ibm.com (Postfix) with ESMTP id 15146220158; Tue, 8 Dec 2015 16:54:57 +0100 (CET) From: Greg Kurz To: "Michael S. Tsirkin" Date: Tue, 08 Dec 2015 16:54:57 +0100 Message-ID: <20151208155457.27775.69441.stgit@bahia.huguette.org> User-Agent: StGit/0.17.1-dirty MIME-Version: 1.0 X-TM-AS-MML: disable X-Content-Scanned: Fidelis XPS MAILER x-cbid: 15120815-0009-0000-0000-000006ED2ACA X-detected-operating-system: by eggs.gnu.org: GNU/Linux 3.x X-Received-From: 195.75.94.108 Cc: aneesh.kumar@linux.vnet.ibm.com, qemu-devel@nongnu.org, Greg Kurz Subject: [Qemu-devel] [PATCH for-2.5] virtio-9p-device: add minimal unrealize handler X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Since commit 4652f1640e029e1f2433fa77ba6af285 "virtio-9p: add savevm handlers", if the user hot-unplugs a quiescent 9p device and live migrates, the source QEMU crashes before migration completetion... This happens because virtio-9p devices have a realize handler which calls virtio_init() and register_savevm(). Both calls store pointers to the device internals, that get dereferenced during migration even if the device got unplugged. This patch simply adds an unrealize handler to perform minimal cleanup and avoid the crash. Hot unplug of non-quiescent 9p devices is still not supported in QEMU, and not supported by linux guests either. Signed-off-by: Greg Kurz Reviewed-by: Michael S. Tsirkin --- hw/9pfs/virtio-9p-device.c | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/hw/9pfs/virtio-9p-device.c b/hw/9pfs/virtio-9p-device.c index 944b5f5e9fcc..b42d3b30a027 100644 --- a/hw/9pfs/virtio-9p-device.c +++ b/hw/9pfs/virtio-9p-device.c @@ -145,6 +145,17 @@ out: v9fs_path_free(&path); } +static void virtio_9p_device_unrealize(DeviceState *dev, Error **errp) +{ + VirtIODevice *vdev = VIRTIO_DEVICE(dev); + V9fsState *s = VIRTIO_9P(dev); + + virtio_cleanup(vdev); + unregister_savevm(dev, "virtio-9p", s); + g_free(s->ctx.fs_root); + g_free(s->tag); +} + /* virtio-9p device */ static Property virtio_9p_properties[] = { @@ -161,6 +172,7 @@ static void virtio_9p_class_init(ObjectClass *klass, void *data) dc->props = virtio_9p_properties; set_bit(DEVICE_CATEGORY_STORAGE, dc->categories); vdc->realize = virtio_9p_device_realize; + vdc->unrealize = virtio_9p_device_unrealize; vdc->get_features = virtio_9p_get_features; vdc->get_config = virtio_9p_get_config; }