From: "Jianzhong,Chang" <jianzhongx.chang@intel.com>
To: stefano.stabellini@eu.citrix.com, qemu-devel@nongnu.org,
pbonzini@redhat.com, xen-devel@lists.xen.org,
konrad.wilk@oracle.com
Cc: "Jianzhong,Chang" <jianzhongx.chang@intel.com>
Subject: [PATCH v3] xen_pt: fix failure of attaching & detaching a PCI device to VM repeatedly.
Date: Wed, 9 Mar 2016 18:24:35 +0800 [thread overview]
Message-ID: <1457519075-10658-1-git-send-email-jianzhongx.chang__9026.52594163573$1457519608$gmane$org@intel.com> (raw)
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 <jianzhongx.chang@intel.com>
---
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 = {
--
1.7.1
_______________________________________________
Xen-devel mailing list
Xen-devel@lists.xen.org
http://lists.xen.org/xen-devel
reply other threads:[~2016-03-09 10:24 UTC|newest]
Thread overview: [no followups] expand[flat|nested] mbox.gz Atom feed
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to='1457519075-10658-1-git-send-email-jianzhongx.chang__9026.52594163573$1457519608$gmane$org@intel.com' \
--to=jianzhongx.chang@intel.com \
--cc=konrad.wilk@oracle.com \
--cc=pbonzini@redhat.com \
--cc=qemu-devel@nongnu.org \
--cc=stefano.stabellini@eu.citrix.com \
--cc=xen-devel@lists.xen.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).