From patchwork Mon Jul 20 15:14:58 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Lin Ma X-Patchwork-Id: 497762 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 2BF3014076A for ; Tue, 21 Jul 2015 01:16:36 +1000 (AEST) Received: from localhost ([::1]:55807 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ZHCny-0005sl-6H for incoming@patchwork.ozlabs.org; Mon, 20 Jul 2015 11:16:34 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:37364) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ZHCnh-0005bB-Jm for qemu-devel@nongnu.org; Mon, 20 Jul 2015 11:16:18 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1ZHCne-00030v-Db for qemu-devel@nongnu.org; Mon, 20 Jul 2015 11:16:17 -0400 Received: from smtp2.provo.novell.com ([137.65.250.81]:38467) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ZHCne-00030J-6Y for qemu-devel@nongnu.org; Mon, 20 Jul 2015 11:16:14 -0400 Received: from linux-wc25.site (prv-ext-foundry1int.gns.novell.com [137.65.251.240]) by smtp2.provo.novell.com with ESMTP (TLS encrypted); Mon, 20 Jul 2015 09:16:01 -0600 Message-ID: <55AD1072.7030706@suse.com> Date: Mon, 20 Jul 2015 23:14:58 +0800 From: Lin Ma User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:31.0) Gecko/20100101 Thunderbird/31.2.0 MIME-Version: 1.0 To: mst@redhat.com, "kraxel@redhat.com >> Gerd Hoffmann" X-detected-operating-system: by eggs.gnu.org: GNU/Linux 3.x X-Received-From: 137.65.250.81 Cc: "qemu-devel@nongnu.org Developers" Subject: [Qemu-devel] [RFC PATCH] Fix hotplug/hotunplug issue about virtio 1.0 devices X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.14 Precedence: list Reply-To: lma@suse.com 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 Hi Michael and Gerd, I found an hotplug/hotunplug issue about virtio 1.0 devices and trying to fix it. The bug description is: (qemu) device_add virtio-gpu-pci,id=gpu0 (qemu) device_del gpu0 (qemu) device_add virtio-gpu-pci,id=gpu0 Duplicate ID 'gpu0' for device Try "help device_add" for more information My fix looks like this: { @@ -1584,6 +1590,16 @@ static void virtio_pci_exit(PCIDevice *pci_dev) msix_uninit_exclusive_bar(pci_dev); address_space_destroy(&proxy->modern_as); + object_unparent(OBJECT(&proxy->modern_cfg)); + + bool modern = !(proxy->flags & VIRTIO_PCI_FLAG_DISABLE_MODERN); + if (modern) { + virtio_pci_modern_region_unmap(proxy, &proxy->common); + virtio_pci_modern_region_unmap(proxy, &proxy->isr); + virtio_pci_modern_region_unmap(proxy, &proxy->device); + virtio_pci_modern_region_unmap(proxy, &proxy->notify); + } + memory_region_unref(&proxy->modern_bar); } static void virtio_pci_reset(DeviceState *qdev) But after applying the fix, I got the following errors: (qemu) device_add virtio-gpu-pci,id=gpu0 (qemu) device_del gpu0 (qemu) ** ERROR:qom/object.c:825:object_unref: assertion failed: (obj->ref > 0) ...... I think because of the grace period of rcu, the function memory_region_unref(as->root) in do_address_space_destroy isn't performed immediately, The do_address_space_destroy is always performed after virtio_pci_exit, That caused 'assertion failed: (obj->ref > 0)'. I have no idea whether my guess is correct or in correct, and don't know how to avoid this assertion failure in this situation. Does my fix make sense ? May I have your ideas or suggestions? Thanks! Lin diff --git a/hw/virtio/virtio-pci.c b/hw/virtio/virtio-pci.c index 283401a..098fc83 100644 --- a/hw/virtio/virtio-pci.c +++ b/hw/virtio/virtio-pci.c @@ -1413,6 +1413,12 @@ static void virtio_pci_modern_region_map(VirtIOPCIProxy *proxy, virtio_pci_add_mem_cap(proxy, cap); } +static void virtio_pci_modern_region_unmap(VirtIOPCIProxy *proxy, + VirtIOPCIRegion *region) +{ + memory_region_del_subregion(&proxy->modern_bar, ®ion->mr); +} + /* This is called by virtio-bus just after the device is plugged. */ static void virtio_pci_device_plugged(DeviceState *d, Error **errp)