From patchwork Tue Sep 3 12:32:53 2013 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Paolo Bonzini X-Patchwork-Id: 272216 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)) (Client did not present a certificate) by ozlabs.org (Postfix) with ESMTPS id A03882C00A4 for ; Tue, 3 Sep 2013 22:34:36 +1000 (EST) Received: from localhost ([::1]:45471 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1VGpoY-0006K0-MG for incoming@patchwork.ozlabs.org; Tue, 03 Sep 2013 08:34:34 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:52696) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1VGpnq-0006H0-B9 for qemu-devel@nongnu.org; Tue, 03 Sep 2013 08:33:58 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1VGpnh-0006Im-N0 for qemu-devel@nongnu.org; Tue, 03 Sep 2013 08:33:50 -0400 Received: from mail-ee0-x22a.google.com ([2a00:1450:4013:c00::22a]:46157) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1VGpnh-0006Hc-Gc for qemu-devel@nongnu.org; Tue, 03 Sep 2013 08:33:41 -0400 Received: by mail-ee0-f42.google.com with SMTP id b45so2968476eek.29 for ; Tue, 03 Sep 2013 05:33:40 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=sender:from:to:cc:subject:date:message-id:in-reply-to:references; bh=cpI+H09gkggwTpPB5ecCwdEFUqFl1KJnZm/h67+b0VY=; b=seTdL7hiXP8jp2jWJoNukkrljnsmf13O1818dSSjyhvZis5IoZl0OPuVMwIvpeZNbq nXdVqbBbUwlk5KrPwGqwJymUSndqiJZtvHf87QabKjIdHauPXdMjYddrN0wr/zJ8mMTU QSeH7eX1lgCqNVqMh05aMU08GEztc365ZGVFnCE1UaKC+GmrA8rjEclOY7gu3Mnxc7tv OCpXhuY/l3zp5l2ai49sUOMmwPoeXAgudqkcic9OhSOEwdwsI0g17eSxCNgUBxc97NWA kcUcBVt/bs2aESDQkX5jYliPZ8p45uW8ZVnudpIzhoCjY3G20tKWAQmQ+bCabuiOtxPe wrhw== X-Received: by 10.14.126.73 with SMTP id a49mr4650468eei.48.1378211620678; Tue, 03 Sep 2013 05:33:40 -0700 (PDT) Received: from playground.lan (net-37-117-144-28.cust.dsl.vodafone.it. [37.117.144.28]) by mx.google.com with ESMTPSA id f49sm31150419eec.7.1969.12.31.16.00.00 (version=TLSv1.2 cipher=RC4-SHA bits=128/128); Tue, 03 Sep 2013 05:33:39 -0700 (PDT) From: Paolo Bonzini To: qemu-devel@nongnu.org Date: Tue, 3 Sep 2013 14:32:53 +0200 Message-Id: <1378211609-16121-3-git-send-email-pbonzini@redhat.com> X-Mailer: git-send-email 1.8.3.1 In-Reply-To: <1378211609-16121-1-git-send-email-pbonzini@redhat.com> References: <1378211609-16121-1-git-send-email-pbonzini@redhat.com> X-detected-operating-system: by eggs.gnu.org: Error: Malformed IPv6 address (bad octet value). X-Received-From: 2a00:1450:4013:c00::22a Cc: mst@redhat.com Subject: [Qemu-devel] [PATCH 02/38] pci: split exit and finalize 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 When converting devices to use out-of-BQL memory access, destruction needs to be done in two phases. First, the device is unrealized; at this point, pending memory accesses can still be completed, but no new accesses will be started. The second part is freeing the device, which happens only after the reference count drops to zero; this means that all memory accesses are complete. Reviewed-by: Anthony Liguori Signed-off-by: Paolo Bonzini --- hw/pci/pci.c | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) diff --git a/hw/pci/pci.c b/hw/pci/pci.c index 4c004f5..bd084c7 100644 --- a/hw/pci/pci.c +++ b/hw/pci/pci.c @@ -787,6 +787,16 @@ static void pci_config_free(PCIDevice *pci_dev) g_free(pci_dev->used); } +static void pci_device_instance_finalize(Object *obj) +{ + PCIDevice *pci_dev = PCI_DEVICE(obj); + + qemu_free_irqs(pci_dev->irq); + + address_space_destroy(&pci_dev->bus_master_as); + memory_region_destroy(&pci_dev->bus_master_enable_region); +} + /* -1 for devfn means auto assign */ static PCIDevice *do_pci_register_device(PCIDevice *pci_dev, PCIBus *bus, const char *name, int devfn) @@ -875,12 +885,8 @@ static PCIDevice *do_pci_register_device(PCIDevice *pci_dev, PCIBus *bus, static void do_pci_unregister_device(PCIDevice *pci_dev) { - qemu_free_irqs(pci_dev->irq); pci_dev->bus->devices[pci_dev->devfn] = NULL; pci_config_free(pci_dev); - - address_space_destroy(&pci_dev->bus_master_as); - memory_region_destroy(&pci_dev->bus_master_enable_region); } static void pci_unregister_io_regions(PCIDevice *pci_dev) @@ -2252,6 +2258,7 @@ static const TypeInfo pci_device_type_info = { .abstract = true, .class_size = sizeof(PCIDeviceClass), .class_init = pci_device_class_init, + .instance_finalize = pci_device_instance_finalize, }; static void pci_register_types(void)