From patchwork Tue Jan 13 02:40:53 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Li, Liang Z" X-Patchwork-Id: 428230 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 8F2B41401AC for ; Tue, 13 Jan 2015 13:49:58 +1100 (AEDT) Received: from localhost ([::1]:37139 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1YArYK-0008VJ-R4 for incoming@patchwork.ozlabs.org; Mon, 12 Jan 2015 21:49:56 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:36400) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1YArY5-0008Er-MD for qemu-devel@nongnu.org; Mon, 12 Jan 2015 21:49:42 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1YArY2-0005zf-FW for qemu-devel@nongnu.org; Mon, 12 Jan 2015 21:49:41 -0500 Received: from mga02.intel.com ([134.134.136.20]:29312) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1YArY2-0005xK-9t for qemu-devel@nongnu.org; Mon, 12 Jan 2015 21:49:38 -0500 Received: from orsmga003.jf.intel.com ([10.7.209.27]) by orsmga101.jf.intel.com with ESMTP; 12 Jan 2015 18:48:59 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.04,691,1406617200"; d="scan'208";a="511298690" Received: from lil.sh.intel.com (HELO localhost) ([10.239.159.167]) by orsmga003.jf.intel.com with ESMTP; 12 Jan 2015 18:42:52 -0800 From: Liang Li To: qemu-devel@nongnu.org Date: Tue, 13 Jan 2015 10:40:53 +0800 Message-Id: <1421116853-10244-1-git-send-email-liang.z.li@intel.com> X-Mailer: git-send-email 1.9.1 X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 134.134.136.20 Cc: yang.z.zhang@intel.com, pbonzini@redhat.com, kevin.tian@intel.com, Liang Li , stefano.stabellini@eu.citrix.com Subject: [Qemu-devel] [v2] xen-pt: Fix PCI devices re-attach failed 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 Use the 'xl pci-attach $DomU $BDF' command to attach more than one PCI devices to the guest, then detach the devices with 'xl pci-detach $DomU $BDF', after that, re-attach these PCI devices again, an error message will be reported like following: libxl: error: libxl_qmp.c:287:qmp_handle_error_response: receive an error message from QMP server: Duplicate ID 'pci-pt-03_10.1' for device. If using the 'address_space_memory' as the parameter of 'memory_listener_register', 'xen_pt_region_del' will not be called if the memory region's name is not 'xen-pci-pt-*' when the devices is detached. This will cause the device's related QemuOpts object not be released properly. Using the device's address space can avoid such issue, because the calling count of 'xen_pt_region_add' when attaching and the calling count of 'xen_pt_region_del' when detaching is the same, so all the memory region ref and unref by the 'xen_pt_region_add' and 'xen_pt_region_del' can be released properly. Signed-off-by: Liang Li Reviewed-by: Paolo Bonzini Reported-by: Longtao Pang --- hw/xen/xen_pt.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/hw/xen/xen_pt.c b/hw/xen/xen_pt.c index c1bf357..f2893b2 100644 --- a/hw/xen/xen_pt.c +++ b/hw/xen/xen_pt.c @@ -736,7 +736,7 @@ static int xen_pt_initfn(PCIDevice *d) } out: - memory_listener_register(&s->memory_listener, &address_space_memory); + memory_listener_register(&s->memory_listener, &s->dev.bus_master_as); memory_listener_register(&s->io_listener, &address_space_io); XEN_PT_LOG(d, "Real physical device %02x:%02x.%d registered successfully!\n",