From patchwork Mon Apr 13 14:12:50 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: 460834 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 CF5D214018C for ; Tue, 14 Apr 2015 00:23:08 +1000 (AEST) Received: from localhost ([::1]:52116 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1YhfGU-0001mw-O9 for incoming@patchwork.ozlabs.org; Mon, 13 Apr 2015 10:23:06 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:55330) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1YhfGD-0001U5-Fu for qemu-devel@nongnu.org; Mon, 13 Apr 2015 10:22:50 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1YhfG9-0005Kg-Dh for qemu-devel@nongnu.org; Mon, 13 Apr 2015 10:22:49 -0400 Received: from mga14.intel.com ([192.55.52.115]:32690) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1YhfG9-0005KO-5O for qemu-devel@nongnu.org; Mon, 13 Apr 2015 10:22:45 -0400 Received: from orsmga002.jf.intel.com ([10.7.209.21]) by fmsmga103.fm.intel.com with ESMTP; 13 Apr 2015 07:22:44 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.11,570,1422950400"; d="scan'208";a="712897305" Received: from lil.sh.intel.com (HELO localhost) ([10.239.159.126]) by orsmga002.jf.intel.com with ESMTP; 13 Apr 2015 07:22:41 -0700 From: Liang Li To: qemu-devel@nongnu.org Date: Mon, 13 Apr 2015 22:12:50 +0800 Message-Id: <1428934370-29695-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: 192.55.52.115 Cc: peter.crosthwaite@xilinx.com, xen-devel@lists.xensource.com, stefano.stabellini@eu.citrix.com, Liang Li , kevin.tian@intel.com, robert.hu@intel.com, yang.z.zhang@intel.com, pbonzini@redhat.com Subject: [Qemu-devel] [PATCH] xen-pt: Fix bug cause 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 option like 'pci=[ '07:10,1', '0b:10.1', '81:10.1']' in HVM guest configuration file to assign more than one VF PCI devices to a guest, after the guest boot up, detach the VFs in sequence by 'xl pci-detach $DOM_ID $VF_BDF', and then attach the VFs by 'xl pci-attach $DOM_ID $VF_BDF' in sequence, 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-81_10.1' for device. The error message will be printed in two cases: 1. Attach and detach very quickly. The message will disappear if retry, it is expected because of the asynchronous unplug mechanism. 2. Do the attach and detach operation with a time interval. eg. 10s. The error message will not disappear if retry, in this case, it's a bug. In the 'xen_pt_region_add' and 'xen_pt_region_del', we should only care about the 'xen-pci-pt-*' memory region, this can avoid the region's reference count is not equal with the dereference count when the device is detached and prevent the device's related QemuOpts object from being released properly, and then trigger the bug when the device is re-attached. I sent a patch to fix a similar bug before, but the patch could not fix the issue completely. Signed-off-by: Liang Li --- hw/xen/xen_pt.c | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/hw/xen/xen_pt.c b/hw/xen/xen_pt.c index f2893b2..8aab769 100644 --- a/hw/xen/xen_pt.c +++ b/hw/xen/xen_pt.c @@ -61,6 +61,7 @@ #include "qemu/range.h" #include "exec/address-spaces.h" +#define XEN_PT_NAME_PREFIX "xen-pci-pt" #define XEN_PT_NR_IRQS (256) static uint8_t xen_pt_mapped_machine_irq[XEN_PT_NR_IRQS] = {0}; @@ -585,6 +586,10 @@ static void xen_pt_region_update(XenPCIPassthroughState *s, static void xen_pt_region_add(MemoryListener *l, MemoryRegionSection *sec) { + if (strncmp(sec->mr->name, XEN_PT_NAME_PREFIX, + sizeof(XEN_PT_NAME_PREFIX))) { + return; + } XenPCIPassthroughState *s = container_of(l, XenPCIPassthroughState, memory_listener); @@ -594,6 +599,11 @@ static void xen_pt_region_add(MemoryListener *l, MemoryRegionSection *sec) static void xen_pt_region_del(MemoryListener *l, MemoryRegionSection *sec) { + if (strncmp(sec->mr->name, XEN_PT_NAME_PREFIX, + sizeof(XEN_PT_NAME_PREFIX))) { + return; + } + XenPCIPassthroughState *s = container_of(l, XenPCIPassthroughState, memory_listener); @@ -603,6 +613,10 @@ static void xen_pt_region_del(MemoryListener *l, MemoryRegionSection *sec) static void xen_pt_io_region_add(MemoryListener *l, MemoryRegionSection *sec) { + if (strncmp(sec->mr->name, XEN_PT_NAME_PREFIX, + sizeof(XEN_PT_NAME_PREFIX))) { + return; + } XenPCIPassthroughState *s = container_of(l, XenPCIPassthroughState, io_listener); @@ -612,6 +626,10 @@ static void xen_pt_io_region_add(MemoryListener *l, MemoryRegionSection *sec) static void xen_pt_io_region_del(MemoryListener *l, MemoryRegionSection *sec) { + if (strncmp(sec->mr->name, XEN_PT_NAME_PREFIX, + sizeof(XEN_PT_NAME_PREFIX))) { + return; + } XenPCIPassthroughState *s = container_of(l, XenPCIPassthroughState, io_listener);