From patchwork Wed Mar 9 10:24:35 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Jianzhong,Chang" X-Patchwork-Id: 8544961 Return-Path: X-Original-To: patchwork-xen-devel@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork1.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.136]) by patchwork1.web.kernel.org (Postfix) with ESMTP id 9AE4E9F46A for ; Wed, 9 Mar 2016 10:34:55 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id B0A3020251 for ; Wed, 9 Mar 2016 10:34:54 +0000 (UTC) Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) (using TLSv1.2 with cipher AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id C1F5520138 for ; Wed, 9 Mar 2016 10:34:53 +0000 (UTC) Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xen.org with esmtp (Exim 4.84) (envelope-from ) id 1adbPZ-0002Sw-6p; Wed, 09 Mar 2016 10:32:13 +0000 Received: from mail6.bemta5.messagelabs.com ([195.245.231.135]) by lists.xen.org with esmtp (Exim 4.84) (envelope-from ) id 1adbPY-0002Sq-KD for xen-devel@lists.xen.org; Wed, 09 Mar 2016 10:32:12 +0000 Received: from [85.158.139.211] by server-14.bemta-5.messagelabs.com id 37/F4-02716-BABFFD65; Wed, 09 Mar 2016 10:32:11 +0000 X-Env-Sender: jianzhongx.chang@intel.com X-Msg-Ref: server-8.tower-206.messagelabs.com!1457519530!27598284!1 X-Originating-IP: [192.55.52.88] X-SpamReason: No, hits=0.0 required=7.0 tests=sa_preprocessor: VHJ1c3RlZCBJUDogMTkyLjU1LjUyLjg4ID0+IDM3NDcyNQ==\n X-StarScan-Received: X-StarScan-Version: 8.11; banners=-,-,- X-VirusChecked: Checked Received: (qmail 21610 invoked from network); 9 Mar 2016 10:32:11 -0000 Received: from mga01.intel.com (HELO mga01.intel.com) (192.55.52.88) by server-8.tower-206.messagelabs.com with SMTP; 9 Mar 2016 10:32:11 -0000 Received: from fmsmga004.fm.intel.com ([10.253.24.48]) by fmsmga101.fm.intel.com with ESMTP; 09 Mar 2016 02:32:09 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.24,311,1455004800"; d="scan'208";a="62743408" Received: from unknown (HELO ivt4.sh.intel.com) ([10.239.48.11]) by fmsmga004.fm.intel.com with ESMTP; 09 Mar 2016 02:32:08 -0800 From: "Jianzhong,Chang" To: stefano.stabellini@eu.citrix.com, qemu-devel@nongnu.org, pbonzini@redhat.com, xen-devel@lists.xen.org, konrad.wilk@oracle.com Date: Wed, 9 Mar 2016 18:24:35 +0800 Message-Id: <1457519075-10658-1-git-send-email-jianzhongx.chang@intel.com> X-Mailer: git-send-email 1.7.1 Cc: "Jianzhong,Chang" Subject: [Xen-devel] [PATCH v3] xen_pt: fix failure of attaching & detaching a PCI device to VM repeatedly. X-BeenThere: xen-devel@lists.xen.org X-Mailman-Version: 2.1.18 Precedence: list List-Id: Xen developer discussion List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Errors-To: xen-devel-bounces@lists.xen.org Sender: "Xen-devel" X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00, UNPARSEABLE_RELAY autolearn=unavailable version=3.3.1 X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on mail.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP Add pci = [ '$VF_BDF1', '$VF_BDF2', '$VF_BDF3'] in hvm guest configuration file. After the guest boot up, detach the VFs in sequence by "xl pci-detach $DOMID $VF_BDF1" "xl pci-detach $DOMID $VF_BDF2" "xl pci-detach $DOMID $VF_BDF3" and reattach the VFs in sequence by "xl pci-attach $DOMID $VF_BDF1" "xl pci-attach $DOMID $VF_BDF2" "xl pci-attach $DOMID $VF_BDF3" An error message will be reported like this: "libxl: error: libxl_qmp.c:287:qmp_handle_error_response: received an error message from QMP server: Duplicate ID 'pci-pt-07_10.1' for device" When xen_pt_region_add/del() is called, MemoryRegion may not belong to the XenPCIPassthroughState. xen_pt_region_update() checks it but memory_region_ref/unref() does not. This case causes obj->ref issue and affects the release of related objects. So, memory_region_ref/unref() is moved f rom xen_pt_region_add/del to xen_pt_region_update. Signed-off-by: Jianzhong,Chang --- hw/xen/xen_pt.c | 16 +++++++++++----- 1 files changed, 11 insertions(+), 5 deletions(-) diff --git a/hw/xen/xen_pt.c b/hw/xen/xen_pt.c index aa96288..6b72ede 100644 --- a/hw/xen/xen_pt.c +++ b/hw/xen/xen_pt.c @@ -591,12 +591,16 @@ static void xen_pt_region_update(XenPCIPassthroughState *s, return; } + if (adding) { + memory_region_ref(sec->mr); + } + if (s->msix && &s->msix->mmio == mr) { if (adding) { s->msix->mmio_base_addr = sec->offset_within_address_space; rc = xen_pt_msix_update_remap(s, s->msix->bar_index); } - return; + goto out; } args.type = d->io_regions[bar].type; @@ -635,6 +639,12 @@ static void xen_pt_region_update(XenPCIPassthroughState *s, adding ? "create new" : "remove old", errno); } } + +out: + if (!adding) { + memory_region_unref(mr); + } + } static void xen_pt_region_add(MemoryListener *l, MemoryRegionSection *sec) @@ -642,7 +652,6 @@ static void xen_pt_region_add(MemoryListener *l, MemoryRegionSection *sec) XenPCIPassthroughState *s = container_of(l, XenPCIPassthroughState, memory_listener); - memory_region_ref(sec->mr); xen_pt_region_update(s, sec, true); } @@ -652,7 +661,6 @@ static void xen_pt_region_del(MemoryListener *l, MemoryRegionSection *sec) memory_listener); xen_pt_region_update(s, sec, false); - memory_region_unref(sec->mr); } static void xen_pt_io_region_add(MemoryListener *l, MemoryRegionSection *sec) @@ -660,7 +668,6 @@ static void xen_pt_io_region_add(MemoryListener *l, MemoryRegionSection *sec) XenPCIPassthroughState *s = container_of(l, XenPCIPassthroughState, io_listener); - memory_region_ref(sec->mr); xen_pt_region_update(s, sec, true); } @@ -670,7 +677,6 @@ static void xen_pt_io_region_del(MemoryListener *l, MemoryRegionSection *sec) io_listener); xen_pt_region_update(s, sec, false); - memory_region_unref(sec->mr); } static const MemoryListener xen_pt_memory_listener = {