From patchwork Tue Sep 15 14:33:52 2009 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Michael S. Tsirkin" X-Patchwork-Id: 33655 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from lists.gnu.org (lists.gnu.org [199.232.76.165]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (Client did not present a certificate) by bilbo.ozlabs.org (Postfix) with ESMTPS id 0AA0FB7B72 for ; Wed, 16 Sep 2009 00:39:04 +1000 (EST) Received: from localhost ([127.0.0.1]:43185 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1MnZBM-0008R3-DJ for incoming@patchwork.ozlabs.org; Tue, 15 Sep 2009 10:39:00 -0400 Received: from mailman by lists.gnu.org with tmda-scanned (Exim 4.43) id 1MnZ8o-00082P-6r for qemu-devel@nongnu.org; Tue, 15 Sep 2009 10:36:22 -0400 Received: from exim by lists.gnu.org with spam-scanned (Exim 4.43) id 1MnZ8j-000801-Pa for qemu-devel@nongnu.org; Tue, 15 Sep 2009 10:36:21 -0400 Received: from [199.232.76.173] (port=35730 helo=monty-python.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1MnZ8j-0007zn-Cc for qemu-devel@nongnu.org; Tue, 15 Sep 2009 10:36:17 -0400 Received: from mx1.redhat.com ([209.132.183.28]:5323) by monty-python.gnu.org with esmtp (Exim 4.60) (envelope-from ) id 1MnZ8i-0002v3-TK for qemu-devel@nongnu.org; Tue, 15 Sep 2009 10:36:17 -0400 Received: from int-mx03.intmail.prod.int.phx2.redhat.com (int-mx03.intmail.prod.int.phx2.redhat.com [10.5.11.16]) by mx1.redhat.com (8.13.8/8.13.8) with ESMTP id n8FEZsIl019594; Tue, 15 Sep 2009 10:35:54 -0400 Received: from redhat.com (dhcp-0-94.tlv.redhat.com [10.35.0.94]) by int-mx03.intmail.prod.int.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id n8FEZVC7020501 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES128-SHA bits=128 verify=NO); Tue, 15 Sep 2009 10:35:37 -0400 Date: Tue, 15 Sep 2009 17:33:52 +0300 From: "Michael S. Tsirkin" To: Paul Brook , Avi Kivity , qemu-devel@nongnu.org, Carsten Otte , Christian Borntraeger , kraxel@redhat.com, markmc@redhat.com Message-ID: <20090915143352.GC24708@redhat.com> References: MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: User-Agent: Mutt/1.5.19 (2009-01-05) X-Scanned-By: MIMEDefang 2.67 on 10.5.11.16 X-detected-operating-system: by monty-python.gnu.org: Genre and OS details not recognized. Cc: Subject: [Qemu-devel] [PATCH 2/2] qemu/virtio: fix reset with device removal X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: qemu-devel.nongnu.org List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org virtio pci registers its own reset handler, but fails to unregister it, which will lead to crashes after device removal. Solve this problem by switching to qdev reset handler, which is automatically unregistered. Signed-off-by: Michael S. Tsirkin Acked-by: Gerd Hoffmann --- hw/virtio-pci.c | 14 ++++++++++---- 1 files changed, 10 insertions(+), 4 deletions(-) diff --git a/hw/virtio-pci.c b/hw/virtio-pci.c index f7a51ff..951d1dc 100644 --- a/hw/virtio-pci.c +++ b/hw/virtio-pci.c @@ -155,9 +155,8 @@ static int virtio_pci_load_queue(void * opaque, int n, QEMUFile *f) return 0; } -static void virtio_pci_reset(void *opaque) +static void virtio_pci_reset(VirtIOPCIProxy *proxy) { - VirtIOPCIProxy *proxy = opaque; virtio_reset(proxy->vdev); msix_reset(&proxy->pci_dev); } @@ -429,8 +428,6 @@ static void virtio_init_pci(VirtIOPCIProxy *proxy, VirtIODevice *vdev, pci_register_bar(&proxy->pci_dev, 0, size, PCI_ADDRESS_SPACE_IO, virtio_map); - qemu_register_reset(virtio_pci_reset, proxy); - virtio_bind_device(vdev, &virtio_pci_bindings, proxy); } @@ -514,6 +511,11 @@ static int virtio_balloon_init_pci(PCIDevice *pci_dev) return 0; } +static void virtio_reset_pci(DeviceState *d) +{ + virtio_pci_reset(container_of(d, VirtIOPCIProxy, pci_dev.qdev)); +} + static PCIDeviceInfo virtio_info[] = { { .qdev.name = "virtio-blk-pci", @@ -525,6 +527,7 @@ static PCIDeviceInfo virtio_info[] = { DEFINE_PROP_UINT32("vectors", VirtIOPCIProxy, nvectors, 2), DEFINE_PROP_END_OF_LIST(), }, + .qdev.reset = virtio_reset_pci, },{ .qdev.name = "virtio-net-pci", .qdev.size = sizeof(VirtIOPCIProxy), @@ -534,6 +537,7 @@ static PCIDeviceInfo virtio_info[] = { NIC_NVECTORS_UNSPECIFIED), DEFINE_PROP_END_OF_LIST(), }, + .qdev.reset = virtio_reset_pci, },{ .qdev.name = "virtio-console-pci", .qdev.size = sizeof(VirtIOPCIProxy), @@ -542,10 +546,12 @@ static PCIDeviceInfo virtio_info[] = { DEFINE_PROP_HEX32("class", VirtIOPCIProxy, class_code, 0), DEFINE_PROP_END_OF_LIST(), }, + .qdev.reset = virtio_reset_pci, },{ .qdev.name = "virtio-balloon-pci", .qdev.size = sizeof(VirtIOPCIProxy), .init = virtio_balloon_init_pci, + .qdev.reset = virtio_reset_pci, },{ /* end of list */ }