All of lore.kernel.org
 help / color / mirror / Atom feed
* [Qemu-devel] [PATCH] xen_pt: fix failure of attaching & detaching a PCI device to VM repeatedly
@ 2015-12-03  3:27 ` Jianzhong,Chang
  0 siblings, 0 replies; 11+ messages in thread
From: Jianzhong,Chang @ 2015-12-03  3:27 UTC (permalink / raw)
  To: qemu-devel
  Cc: tianyu.lan, konrad.wilk, liang.z.li, xen-devel, jianzhong, Chang,
	pbonzini, stefano.stabellini

From: jianzhong,Chang <jianzhongx.chang@intel.com>

Add pci = [ '$VF_BDF', '$VF_BDF', '$VF_BDF'] in
hvm guest configuration file. After the guest boot up,
detach the VFs in sequence by "xl pci-detach $DOMID $VF_BDF",
reattach the VFs by "xl pci-attach $VF_BDF" in sequence.
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, the detection operation is moved from
xen_pt_region_update to xen_pt_region_add/del.

Signed-off-by: Jianzhong,Chang <jianzhongx.chang@intel.com>
---
 hw/xen/xen_pt.c |   23 ++++++++++++++++++++---
 1 files changed, 20 insertions(+), 3 deletions(-)

diff --git a/hw/xen/xen_pt.c b/hw/xen/xen_pt.c
index aa96288..95b4970 100644
--- a/hw/xen/xen_pt.c
+++ b/hw/xen/xen_pt.c
@@ -523,6 +523,14 @@ static int xen_pt_bar_from_region(XenPCIPassthroughState *s, MemoryRegion *mr)
     }
     return -1;
 }
+static bool xen_pt_region_in_state(XenPCIPassthroughState *s, MemoryRegion *mr)
+{
+    int bar = xen_pt_bar_from_region(s, mr);
+    if (-1 == bar && (!s->msix || &s->msix->mmio != mr)) {
+        return false;
+    }
+    return true;
+}
 
 /*
  * This function checks if an io_region overlaps an io_region from another
@@ -587,9 +595,6 @@ static void xen_pt_region_update(XenPCIPassthroughState *s,
     };
 
     bar = xen_pt_bar_from_region(s, mr);
-    if (bar == -1 && (!s->msix || &s->msix->mmio != mr)) {
-        return;
-    }
 
     if (s->msix && &s->msix->mmio == mr) {
         if (adding) {
@@ -642,6 +647,9 @@ static void xen_pt_region_add(MemoryListener *l, MemoryRegionSection *sec)
     XenPCIPassthroughState *s = container_of(l, XenPCIPassthroughState,
                                              memory_listener);
 
+    if (!xen_pt_region_in_state(s, sec->mr)) {
+        return;
+    }
     memory_region_ref(sec->mr);
     xen_pt_region_update(s, sec, true);
 }
@@ -651,6 +659,9 @@ static void xen_pt_region_del(MemoryListener *l, MemoryRegionSection *sec)
     XenPCIPassthroughState *s = container_of(l, XenPCIPassthroughState,
                                              memory_listener);
 
+    if (!xen_pt_region_in_state(s, sec->mr)) {
+        return;
+    }
     xen_pt_region_update(s, sec, false);
     memory_region_unref(sec->mr);
 }
@@ -660,6 +671,9 @@ static void xen_pt_io_region_add(MemoryListener *l, MemoryRegionSection *sec)
     XenPCIPassthroughState *s = container_of(l, XenPCIPassthroughState,
                                              io_listener);
 
+    if (!xen_pt_region_in_state(s, sec->mr)) {
+        return;
+    }
     memory_region_ref(sec->mr);
     xen_pt_region_update(s, sec, true);
 }
@@ -669,6 +683,9 @@ static void xen_pt_io_region_del(MemoryListener *l, MemoryRegionSection *sec)
     XenPCIPassthroughState *s = container_of(l, XenPCIPassthroughState,
                                              io_listener);
 
+    if (!xen_pt_region_in_state(s, sec->mr)) {
+        return;
+    }
     xen_pt_region_update(s, sec, false);
     memory_region_unref(sec->mr);
 }
-- 
1.7.1

^ permalink raw reply related	[flat|nested] 11+ messages in thread

* [PATCH] xen_pt: fix failure of attaching & detaching a PCI device to VM repeatedly
@ 2015-12-03  3:27 ` Jianzhong,Chang
  0 siblings, 0 replies; 11+ messages in thread
From: Jianzhong,Chang @ 2015-12-03  3:27 UTC (permalink / raw)
  To: qemu-devel
  Cc: tianyu.lan, liang.z.li, xen-devel, jianzhong, Chang, pbonzini,
	stefano.stabellini

From: jianzhong,Chang <jianzhongx.chang@intel.com>

Add pci = [ '$VF_BDF', '$VF_BDF', '$VF_BDF'] in
hvm guest configuration file. After the guest boot up,
detach the VFs in sequence by "xl pci-detach $DOMID $VF_BDF",
reattach the VFs by "xl pci-attach $VF_BDF" in sequence.
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, the detection operation is moved from
xen_pt_region_update to xen_pt_region_add/del.

Signed-off-by: Jianzhong,Chang <jianzhongx.chang@intel.com>
---
 hw/xen/xen_pt.c |   23 ++++++++++++++++++++---
 1 files changed, 20 insertions(+), 3 deletions(-)

diff --git a/hw/xen/xen_pt.c b/hw/xen/xen_pt.c
index aa96288..95b4970 100644
--- a/hw/xen/xen_pt.c
+++ b/hw/xen/xen_pt.c
@@ -523,6 +523,14 @@ static int xen_pt_bar_from_region(XenPCIPassthroughState *s, MemoryRegion *mr)
     }
     return -1;
 }
+static bool xen_pt_region_in_state(XenPCIPassthroughState *s, MemoryRegion *mr)
+{
+    int bar = xen_pt_bar_from_region(s, mr);
+    if (-1 == bar && (!s->msix || &s->msix->mmio != mr)) {
+        return false;
+    }
+    return true;
+}
 
 /*
  * This function checks if an io_region overlaps an io_region from another
@@ -587,9 +595,6 @@ static void xen_pt_region_update(XenPCIPassthroughState *s,
     };
 
     bar = xen_pt_bar_from_region(s, mr);
-    if (bar == -1 && (!s->msix || &s->msix->mmio != mr)) {
-        return;
-    }
 
     if (s->msix && &s->msix->mmio == mr) {
         if (adding) {
@@ -642,6 +647,9 @@ static void xen_pt_region_add(MemoryListener *l, MemoryRegionSection *sec)
     XenPCIPassthroughState *s = container_of(l, XenPCIPassthroughState,
                                              memory_listener);
 
+    if (!xen_pt_region_in_state(s, sec->mr)) {
+        return;
+    }
     memory_region_ref(sec->mr);
     xen_pt_region_update(s, sec, true);
 }
@@ -651,6 +659,9 @@ static void xen_pt_region_del(MemoryListener *l, MemoryRegionSection *sec)
     XenPCIPassthroughState *s = container_of(l, XenPCIPassthroughState,
                                              memory_listener);
 
+    if (!xen_pt_region_in_state(s, sec->mr)) {
+        return;
+    }
     xen_pt_region_update(s, sec, false);
     memory_region_unref(sec->mr);
 }
@@ -660,6 +671,9 @@ static void xen_pt_io_region_add(MemoryListener *l, MemoryRegionSection *sec)
     XenPCIPassthroughState *s = container_of(l, XenPCIPassthroughState,
                                              io_listener);
 
+    if (!xen_pt_region_in_state(s, sec->mr)) {
+        return;
+    }
     memory_region_ref(sec->mr);
     xen_pt_region_update(s, sec, true);
 }
@@ -669,6 +683,9 @@ static void xen_pt_io_region_del(MemoryListener *l, MemoryRegionSection *sec)
     XenPCIPassthroughState *s = container_of(l, XenPCIPassthroughState,
                                              io_listener);
 
+    if (!xen_pt_region_in_state(s, sec->mr)) {
+        return;
+    }
     xen_pt_region_update(s, sec, false);
     memory_region_unref(sec->mr);
 }
-- 
1.7.1

^ permalink raw reply related	[flat|nested] 11+ messages in thread

* Re: [Qemu-devel] [PATCH] xen_pt: fix failure of attaching & detaching a PCI device to VM repeatedly
  2015-12-03  3:27 ` Jianzhong,Chang
  (?)
  (?)
@ 2015-12-04 15:53 ` Stefano Stabellini
  2015-12-06 15:05   ` Li, Liang Z
                     ` (3 more replies)
  -1 siblings, 4 replies; 11+ messages in thread
From: Stefano Stabellini @ 2015-12-04 15:53 UTC (permalink / raw)
  To: Jianzhong,Chang
  Cc: tianyu.lan, konrad.wilk, stefano.stabellini, liang.z.li,
	qemu-devel, xen-devel, pbonzini

On Thu, 3 Dec 2015, Jianzhong,Chang wrote:
> From: jianzhong,Chang <jianzhongx.chang@intel.com>
> 
> Add pci = [ '$VF_BDF', '$VF_BDF', '$VF_BDF'] in

This is a bit confusing: it is not actually correct to assign the same
device, even an SR_IOV VF, multiple times, so these must be all
different. More like:

pci = [ '$VF_BDF1', '$VF_BDF2', '$VF_BDF3']


> hvm guest configuration file. After the guest boot up,
> detach the VFs in sequence by "xl pci-detach $DOMID $VF_BDF",
> reattach the VFs by "xl pci-attach $VF_BDF" in sequence.

So do you mean:

xl pci-detach $DOMID $VF_BDF1
xl pci-detach $DOMID $VF_BDF2
xl pci-detach $DOMID $VF_BDF3
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, the detection operation is moved from
> xen_pt_region_update to xen_pt_region_add/del.
> 
> Signed-off-by: Jianzhong,Chang <jianzhongx.chang@intel.com>
> ---
>  hw/xen/xen_pt.c |   23 ++++++++++++++++++++---
>  1 files changed, 20 insertions(+), 3 deletions(-)
> 
> diff --git a/hw/xen/xen_pt.c b/hw/xen/xen_pt.c
> index aa96288..95b4970 100644
> --- a/hw/xen/xen_pt.c
> +++ b/hw/xen/xen_pt.c
> @@ -523,6 +523,14 @@ static int xen_pt_bar_from_region(XenPCIPassthroughState *s, MemoryRegion *mr)
>      }
>      return -1;
>  }
> +static bool xen_pt_region_in_state(XenPCIPassthroughState *s, MemoryRegion *mr)
> +{
> +    int bar = xen_pt_bar_from_region(s, mr);
> +    if (-1 == bar && (!s->msix || &s->msix->mmio != mr)) {
> +        return false;
> +    }
> +    return true;
> +}
>  
>  /*
>   * This function checks if an io_region overlaps an io_region from another
> @@ -587,9 +595,6 @@ static void xen_pt_region_update(XenPCIPassthroughState *s,
>      };
>  
>      bar = xen_pt_bar_from_region(s, mr);
> -    if (bar == -1 && (!s->msix || &s->msix->mmio != mr)) {
> -        return;
> -    }
>  
>      if (s->msix && &s->msix->mmio == mr) {
>          if (adding) {
> @@ -642,6 +647,9 @@ static void xen_pt_region_add(MemoryListener *l, MemoryRegionSection *sec)
>      XenPCIPassthroughState *s = container_of(l, XenPCIPassthroughState,
>                                               memory_listener);
>  
> +    if (!xen_pt_region_in_state(s, sec->mr)) {
> +        return;
> +    }
>      memory_region_ref(sec->mr);
>      xen_pt_region_update(s, sec, true);
>  }
> @@ -651,6 +659,9 @@ static void xen_pt_region_del(MemoryListener *l, MemoryRegionSection *sec)
>      XenPCIPassthroughState *s = container_of(l, XenPCIPassthroughState,
>                                               memory_listener);
>  
> +    if (!xen_pt_region_in_state(s, sec->mr)) {
> +        return;
> +    }
>      xen_pt_region_update(s, sec, false);
>      memory_region_unref(sec->mr);
>  }
> @@ -660,6 +671,9 @@ static void xen_pt_io_region_add(MemoryListener *l, MemoryRegionSection *sec)
>      XenPCIPassthroughState *s = container_of(l, XenPCIPassthroughState,
>                                               io_listener);
>  
> +    if (!xen_pt_region_in_state(s, sec->mr)) {
> +        return;
> +    }
>      memory_region_ref(sec->mr);
>      xen_pt_region_update(s, sec, true);
>  }
> @@ -669,6 +683,9 @@ static void xen_pt_io_region_del(MemoryListener *l, MemoryRegionSection *sec)
>      XenPCIPassthroughState *s = container_of(l, XenPCIPassthroughState,
>                                               io_listener);
>  
> +    if (!xen_pt_region_in_state(s, sec->mr)) {
> +        return;
> +    }
>      xen_pt_region_update(s, sec, false);
>      memory_region_unref(sec->mr);
>  }

Wouldn't it make more sense to move the
memory_region_ref/memory_region_unref calls inside xen_pt_region_update?

^ permalink raw reply	[flat|nested] 11+ messages in thread

* Re: [PATCH] xen_pt: fix failure of attaching & detaching a PCI device to VM repeatedly
  2015-12-03  3:27 ` Jianzhong,Chang
  (?)
@ 2015-12-04 15:53 ` Stefano Stabellini
  -1 siblings, 0 replies; 11+ messages in thread
From: Stefano Stabellini @ 2015-12-04 15:53 UTC (permalink / raw)
  To: Jianzhong,Chang
  Cc: tianyu.lan, stefano.stabellini, liang.z.li, qemu-devel,
	xen-devel, pbonzini

On Thu, 3 Dec 2015, Jianzhong,Chang wrote:
> From: jianzhong,Chang <jianzhongx.chang@intel.com>
> 
> Add pci = [ '$VF_BDF', '$VF_BDF', '$VF_BDF'] in

This is a bit confusing: it is not actually correct to assign the same
device, even an SR_IOV VF, multiple times, so these must be all
different. More like:

pci = [ '$VF_BDF1', '$VF_BDF2', '$VF_BDF3']


> hvm guest configuration file. After the guest boot up,
> detach the VFs in sequence by "xl pci-detach $DOMID $VF_BDF",
> reattach the VFs by "xl pci-attach $VF_BDF" in sequence.

So do you mean:

xl pci-detach $DOMID $VF_BDF1
xl pci-detach $DOMID $VF_BDF2
xl pci-detach $DOMID $VF_BDF3
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, the detection operation is moved from
> xen_pt_region_update to xen_pt_region_add/del.
> 
> Signed-off-by: Jianzhong,Chang <jianzhongx.chang@intel.com>
> ---
>  hw/xen/xen_pt.c |   23 ++++++++++++++++++++---
>  1 files changed, 20 insertions(+), 3 deletions(-)
> 
> diff --git a/hw/xen/xen_pt.c b/hw/xen/xen_pt.c
> index aa96288..95b4970 100644
> --- a/hw/xen/xen_pt.c
> +++ b/hw/xen/xen_pt.c
> @@ -523,6 +523,14 @@ static int xen_pt_bar_from_region(XenPCIPassthroughState *s, MemoryRegion *mr)
>      }
>      return -1;
>  }
> +static bool xen_pt_region_in_state(XenPCIPassthroughState *s, MemoryRegion *mr)
> +{
> +    int bar = xen_pt_bar_from_region(s, mr);
> +    if (-1 == bar && (!s->msix || &s->msix->mmio != mr)) {
> +        return false;
> +    }
> +    return true;
> +}
>  
>  /*
>   * This function checks if an io_region overlaps an io_region from another
> @@ -587,9 +595,6 @@ static void xen_pt_region_update(XenPCIPassthroughState *s,
>      };
>  
>      bar = xen_pt_bar_from_region(s, mr);
> -    if (bar == -1 && (!s->msix || &s->msix->mmio != mr)) {
> -        return;
> -    }
>  
>      if (s->msix && &s->msix->mmio == mr) {
>          if (adding) {
> @@ -642,6 +647,9 @@ static void xen_pt_region_add(MemoryListener *l, MemoryRegionSection *sec)
>      XenPCIPassthroughState *s = container_of(l, XenPCIPassthroughState,
>                                               memory_listener);
>  
> +    if (!xen_pt_region_in_state(s, sec->mr)) {
> +        return;
> +    }
>      memory_region_ref(sec->mr);
>      xen_pt_region_update(s, sec, true);
>  }
> @@ -651,6 +659,9 @@ static void xen_pt_region_del(MemoryListener *l, MemoryRegionSection *sec)
>      XenPCIPassthroughState *s = container_of(l, XenPCIPassthroughState,
>                                               memory_listener);
>  
> +    if (!xen_pt_region_in_state(s, sec->mr)) {
> +        return;
> +    }
>      xen_pt_region_update(s, sec, false);
>      memory_region_unref(sec->mr);
>  }
> @@ -660,6 +671,9 @@ static void xen_pt_io_region_add(MemoryListener *l, MemoryRegionSection *sec)
>      XenPCIPassthroughState *s = container_of(l, XenPCIPassthroughState,
>                                               io_listener);
>  
> +    if (!xen_pt_region_in_state(s, sec->mr)) {
> +        return;
> +    }
>      memory_region_ref(sec->mr);
>      xen_pt_region_update(s, sec, true);
>  }
> @@ -669,6 +683,9 @@ static void xen_pt_io_region_del(MemoryListener *l, MemoryRegionSection *sec)
>      XenPCIPassthroughState *s = container_of(l, XenPCIPassthroughState,
>                                               io_listener);
>  
> +    if (!xen_pt_region_in_state(s, sec->mr)) {
> +        return;
> +    }
>      xen_pt_region_update(s, sec, false);
>      memory_region_unref(sec->mr);
>  }

Wouldn't it make more sense to move the
memory_region_ref/memory_region_unref calls inside xen_pt_region_update?

^ permalink raw reply	[flat|nested] 11+ messages in thread

* Re: [Qemu-devel] [PATCH] xen_pt: fix failure of attaching & detaching a PCI device to VM repeatedly
  2015-12-04 15:53 ` [Qemu-devel] " Stefano Stabellini
@ 2015-12-06 15:05   ` Li, Liang Z
  2015-12-07  2:57     ` Chang, JianzhongX
  2015-12-07  2:57     ` Chang, JianzhongX
  2015-12-06 15:05   ` Li, Liang Z
                     ` (2 subsequent siblings)
  3 siblings, 2 replies; 11+ messages in thread
From: Li, Liang Z @ 2015-12-06 15:05 UTC (permalink / raw)
  To: Stefano Stabellini, Chang, JianzhongX
  Cc: Lan, Tianyu, pbonzini, konrad.wilk, qemu-devel, xen-devel

> > Add pci = [ '$VF_BDF', '$VF_BDF', '$VF_BDF'] in
> 
> This is a bit confusing: it is not actually correct to assign the same device, even
> an SR_IOV VF, multiple times, so these must be all different. More like:
> 
> pci = [ '$VF_BDF1', '$VF_BDF2', '$VF_BDF3']
> 
> 
> > hvm guest configuration file. After the guest boot up, detach the VFs
> > in sequence by "xl pci-detach $DOMID $VF_BDF", reattach the VFs by "xl
> > pci-attach $VF_BDF" in sequence.
> 
> So do you mean:
> 
> xl pci-detach $DOMID $VF_BDF1
> xl pci-detach $DOMID $VF_BDF2
> xl pci-detach $DOMID $VF_BDF3
> xl pci-attach $DOMID $VF_BDF1
> xl pci-attach $DOMID $VF_BDF2
> xl pci-attach $DOMID $VF_BDF3
> 
> ?

I know this bug, I had a patch to fix a similar bug,  I think Jianzhong means:

xl pci-detach $DOMID $VF_BDF1
xl pci-attach $DOMID $VF_BDF1
xl pci-detach $DOMID $VF_BDF1
xl pci-attach $DOMID $VF_BDF1
...

Liang

^ permalink raw reply	[flat|nested] 11+ messages in thread

* Re: [PATCH] xen_pt: fix failure of attaching & detaching a PCI device to VM repeatedly
  2015-12-04 15:53 ` [Qemu-devel] " Stefano Stabellini
  2015-12-06 15:05   ` Li, Liang Z
@ 2015-12-06 15:05   ` Li, Liang Z
  2015-12-07  6:28   ` Chang, JianzhongX
  2015-12-07  6:28   ` [Qemu-devel] " Chang, JianzhongX
  3 siblings, 0 replies; 11+ messages in thread
From: Li, Liang Z @ 2015-12-06 15:05 UTC (permalink / raw)
  To: Stefano Stabellini, Chang, JianzhongX
  Cc: Lan, Tianyu, pbonzini, qemu-devel, xen-devel

> > Add pci = [ '$VF_BDF', '$VF_BDF', '$VF_BDF'] in
> 
> This is a bit confusing: it is not actually correct to assign the same device, even
> an SR_IOV VF, multiple times, so these must be all different. More like:
> 
> pci = [ '$VF_BDF1', '$VF_BDF2', '$VF_BDF3']
> 
> 
> > hvm guest configuration file. After the guest boot up, detach the VFs
> > in sequence by "xl pci-detach $DOMID $VF_BDF", reattach the VFs by "xl
> > pci-attach $VF_BDF" in sequence.
> 
> So do you mean:
> 
> xl pci-detach $DOMID $VF_BDF1
> xl pci-detach $DOMID $VF_BDF2
> xl pci-detach $DOMID $VF_BDF3
> xl pci-attach $DOMID $VF_BDF1
> xl pci-attach $DOMID $VF_BDF2
> xl pci-attach $DOMID $VF_BDF3
> 
> ?

I know this bug, I had a patch to fix a similar bug,  I think Jianzhong means:

xl pci-detach $DOMID $VF_BDF1
xl pci-attach $DOMID $VF_BDF1
xl pci-detach $DOMID $VF_BDF1
xl pci-attach $DOMID $VF_BDF1
...

Liang

^ permalink raw reply	[flat|nested] 11+ messages in thread

* Re: [Qemu-devel] [PATCH] xen_pt: fix failure of attaching & detaching a PCI device to VM repeatedly
  2015-12-06 15:05   ` Li, Liang Z
@ 2015-12-07  2:57     ` Chang, JianzhongX
  2015-12-07  2:57     ` Chang, JianzhongX
  1 sibling, 0 replies; 11+ messages in thread
From: Chang, JianzhongX @ 2015-12-07  2:57 UTC (permalink / raw)
  To: Li, Liang Z, Stefano Stabellini
  Cc: Lan, Tianyu, pbonzini, konrad.wilk, qemu-devel, xen-devel

Bug url : http://bugzilla-archived.xenproject.org/bugzilla/show_bug.cgi?id=1905
Above url descripts the bug which i fix in more detail.
Add pci = [ '$VF_BDF', '$VF_BDF', '$VF_BDF'], $VF_BDFs are different.
pci = [ '$VF_BDF1', '$VF_BDF2', '$VF_BDF3'] is a more accurate description.

-----Original Message-----
From: Li, Liang Z 
Sent: Sunday, December 06, 2015 11:05 PM
To: Stefano Stabellini; Chang, JianzhongX
Cc: qemu-devel@nongnu.org; pbonzini@redhat.com; xen-devel@lists.xen.org; Lan, Tianyu; konrad.wilk@oracle.com
Subject: RE: [PATCH] xen_pt: fix failure of attaching & detaching a PCI device to VM repeatedly

> > Add pci = [ '$VF_BDF', '$VF_BDF', '$VF_BDF'] in
> 
> This is a bit confusing: it is not actually correct to assign the same 
> device, even an SR_IOV VF, multiple times, so these must be all different. More like:
> 
> pci = [ '$VF_BDF1', '$VF_BDF2', '$VF_BDF3']
> 
> 
> > hvm guest configuration file. After the guest boot up, detach the 
> > VFs in sequence by "xl pci-detach $DOMID $VF_BDF", reattach the VFs 
> > by "xl pci-attach $VF_BDF" in sequence.
> 
> So do you mean:
> 
> xl pci-detach $DOMID $VF_BDF1
> xl pci-detach $DOMID $VF_BDF2
> xl pci-detach $DOMID $VF_BDF3
> xl pci-attach $DOMID $VF_BDF1
> xl pci-attach $DOMID $VF_BDF2
> xl pci-attach $DOMID $VF_BDF3
> 
> ?

I know this bug, I had a patch to fix a similar bug,  I think Jianzhong means:

xl pci-detach $DOMID $VF_BDF1
xl pci-attach $DOMID $VF_BDF1
xl pci-detach $DOMID $VF_BDF1
xl pci-attach $DOMID $VF_BDF1
...

Liang

^ permalink raw reply	[flat|nested] 11+ messages in thread

* Re: [PATCH] xen_pt: fix failure of attaching & detaching a PCI device to VM repeatedly
  2015-12-06 15:05   ` Li, Liang Z
  2015-12-07  2:57     ` Chang, JianzhongX
@ 2015-12-07  2:57     ` Chang, JianzhongX
  1 sibling, 0 replies; 11+ messages in thread
From: Chang, JianzhongX @ 2015-12-07  2:57 UTC (permalink / raw)
  To: Li, Liang Z, Stefano Stabellini
  Cc: Lan, Tianyu, pbonzini, qemu-devel, xen-devel

Bug url : http://bugzilla-archived.xenproject.org/bugzilla/show_bug.cgi?id=1905
Above url descripts the bug which i fix in more detail.
Add pci = [ '$VF_BDF', '$VF_BDF', '$VF_BDF'], $VF_BDFs are different.
pci = [ '$VF_BDF1', '$VF_BDF2', '$VF_BDF3'] is a more accurate description.

-----Original Message-----
From: Li, Liang Z 
Sent: Sunday, December 06, 2015 11:05 PM
To: Stefano Stabellini; Chang, JianzhongX
Cc: qemu-devel@nongnu.org; pbonzini@redhat.com; xen-devel@lists.xen.org; Lan, Tianyu; konrad.wilk@oracle.com
Subject: RE: [PATCH] xen_pt: fix failure of attaching & detaching a PCI device to VM repeatedly

> > Add pci = [ '$VF_BDF', '$VF_BDF', '$VF_BDF'] in
> 
> This is a bit confusing: it is not actually correct to assign the same 
> device, even an SR_IOV VF, multiple times, so these must be all different. More like:
> 
> pci = [ '$VF_BDF1', '$VF_BDF2', '$VF_BDF3']
> 
> 
> > hvm guest configuration file. After the guest boot up, detach the 
> > VFs in sequence by "xl pci-detach $DOMID $VF_BDF", reattach the VFs 
> > by "xl pci-attach $VF_BDF" in sequence.
> 
> So do you mean:
> 
> xl pci-detach $DOMID $VF_BDF1
> xl pci-detach $DOMID $VF_BDF2
> xl pci-detach $DOMID $VF_BDF3
> xl pci-attach $DOMID $VF_BDF1
> xl pci-attach $DOMID $VF_BDF2
> xl pci-attach $DOMID $VF_BDF3
> 
> ?

I know this bug, I had a patch to fix a similar bug,  I think Jianzhong means:

xl pci-detach $DOMID $VF_BDF1
xl pci-attach $DOMID $VF_BDF1
xl pci-detach $DOMID $VF_BDF1
xl pci-attach $DOMID $VF_BDF1
...

Liang

^ permalink raw reply	[flat|nested] 11+ messages in thread

* Re: [Qemu-devel] [PATCH] xen_pt: fix failure of attaching & detaching a PCI device to VM repeatedly
  2015-12-04 15:53 ` [Qemu-devel] " Stefano Stabellini
                     ` (2 preceding siblings ...)
  2015-12-07  6:28   ` Chang, JianzhongX
@ 2015-12-07  6:28   ` Chang, JianzhongX
  3 siblings, 0 replies; 11+ messages in thread
From: Chang, JianzhongX @ 2015-12-07  6:28 UTC (permalink / raw)
  To: Stefano Stabellini
  Cc: Lan, Tianyu, konrad.wilk, Li, Liang Z, qemu-devel, xen-devel, pbonzini

>> 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, the detection operation is moved from xen_pt_region_update to 
>> xen_pt_region_add/del.
>> 
>> Signed-off-by: Jianzhong,Chang <jianzhongx.chang@intel.com>
>> ---
>>  hw/xen/xen_pt.c |   23 ++++++++++++++++++++---
>>  1 files changed, 20 insertions(+), 3 deletions(-)
>> 
>> diff --git a/hw/xen/xen_pt.c b/hw/xen/xen_pt.c index aa96288..95b4970 
>> 100644
>> --- a/hw/xen/xen_pt.c
>> +++ b/hw/xen/xen_pt.c
>> @@ -523,6 +523,14 @@ static int xen_pt_bar_from_region(XenPCIPassthroughState *s, MemoryRegion *mr)
>>      }
>>      return -1;
>>  }
>> +static bool xen_pt_region_in_state(XenPCIPassthroughState *s, 
>> +MemoryRegion *mr) {
>> +    int bar = xen_pt_bar_from_region(s, mr);
>> +    if (-1 == bar && (!s->msix || &s->msix->mmio != mr)) {
>> +        return false;
>> +    }
>> +    return true;
>> +}
>>  
>>  /*
>>   * This function checks if an io_region overlaps an io_region from 
>> another @@ -587,9 +595,6 @@ static void xen_pt_region_update(XenPCIPassthroughState *s,
>>      };
>>  
>>      bar = xen_pt_bar_from_region(s, mr);
>> -    if (bar == -1 && (!s->msix || &s->msix->mmio != mr)) {
>> -        return;
>> -    }
>>  
>>      if (s->msix && &s->msix->mmio == mr) {
>>          if (adding) {
>> @@ -642,6 +647,9 @@ static void xen_pt_region_add(MemoryListener *l, MemoryRegionSection *sec)
>>      XenPCIPassthroughState *s = container_of(l, XenPCIPassthroughState,
>>                                               memory_listener);
>>  
>> +    if (!xen_pt_region_in_state(s, sec->mr)) {
>> +        return;
>> +    }
>>      memory_region_ref(sec->mr);
>>      xen_pt_region_update(s, sec, true);  } @@ -651,6 +659,9 @@ static 
>> void xen_pt_region_del(MemoryListener *l, MemoryRegionSection *sec)
>>      XenPCIPassthroughState *s = container_of(l, XenPCIPassthroughState,
>>                                               memory_listener);
>>  
>> +    if (!xen_pt_region_in_state(s, sec->mr)) {
>> +        return;
>> +    }
>>      xen_pt_region_update(s, sec, false);
>>      memory_region_unref(sec->mr);
>>  }
>> @@ -660,6 +671,9 @@ static void xen_pt_io_region_add(MemoryListener *l, MemoryRegionSection *sec)
>>      XenPCIPassthroughState *s = container_of(l, XenPCIPassthroughState,
>>                                               io_listener);
>>  
>> +    if (!xen_pt_region_in_state(s, sec->mr)) {
>> +        return;
>> +    }
>>      memory_region_ref(sec->mr);
>>      xen_pt_region_update(s, sec, true);  } @@ -669,6 +683,9 @@ static 
>> void xen_pt_io_region_del(MemoryListener *l, MemoryRegionSection *sec)
>>      XenPCIPassthroughState *s = container_of(l, XenPCIPassthroughState,
>>                                               io_listener);
>>  
>> +    if (!xen_pt_region_in_state(s, sec->mr)) {
>> +        return;
>> +    }
>>      xen_pt_region_update(s, sec, false);
>>      memory_region_unref(sec->mr);
>>  }
>
>Wouldn't it make more sense to move the
>memory_region_ref/memory_region_unref calls inside xen_pt_region_update?

Move the operation  of mr->ref inside xen_pt_region_update can also fix this bug. 
For the convenience of maintenance, another patch can be created.

^ permalink raw reply	[flat|nested] 11+ messages in thread

* Re: [PATCH] xen_pt: fix failure of attaching & detaching a PCI device to VM repeatedly
  2015-12-04 15:53 ` [Qemu-devel] " Stefano Stabellini
  2015-12-06 15:05   ` Li, Liang Z
  2015-12-06 15:05   ` Li, Liang Z
@ 2015-12-07  6:28   ` Chang, JianzhongX
  2015-12-07  6:28   ` [Qemu-devel] " Chang, JianzhongX
  3 siblings, 0 replies; 11+ messages in thread
From: Chang, JianzhongX @ 2015-12-07  6:28 UTC (permalink / raw)
  To: Stefano Stabellini
  Cc: Lan, Tianyu, Li, Liang Z, qemu-devel, xen-devel, pbonzini

>> 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, the detection operation is moved from xen_pt_region_update to 
>> xen_pt_region_add/del.
>> 
>> Signed-off-by: Jianzhong,Chang <jianzhongx.chang@intel.com>
>> ---
>>  hw/xen/xen_pt.c |   23 ++++++++++++++++++++---
>>  1 files changed, 20 insertions(+), 3 deletions(-)
>> 
>> diff --git a/hw/xen/xen_pt.c b/hw/xen/xen_pt.c index aa96288..95b4970 
>> 100644
>> --- a/hw/xen/xen_pt.c
>> +++ b/hw/xen/xen_pt.c
>> @@ -523,6 +523,14 @@ static int xen_pt_bar_from_region(XenPCIPassthroughState *s, MemoryRegion *mr)
>>      }
>>      return -1;
>>  }
>> +static bool xen_pt_region_in_state(XenPCIPassthroughState *s, 
>> +MemoryRegion *mr) {
>> +    int bar = xen_pt_bar_from_region(s, mr);
>> +    if (-1 == bar && (!s->msix || &s->msix->mmio != mr)) {
>> +        return false;
>> +    }
>> +    return true;
>> +}
>>  
>>  /*
>>   * This function checks if an io_region overlaps an io_region from 
>> another @@ -587,9 +595,6 @@ static void xen_pt_region_update(XenPCIPassthroughState *s,
>>      };
>>  
>>      bar = xen_pt_bar_from_region(s, mr);
>> -    if (bar == -1 && (!s->msix || &s->msix->mmio != mr)) {
>> -        return;
>> -    }
>>  
>>      if (s->msix && &s->msix->mmio == mr) {
>>          if (adding) {
>> @@ -642,6 +647,9 @@ static void xen_pt_region_add(MemoryListener *l, MemoryRegionSection *sec)
>>      XenPCIPassthroughState *s = container_of(l, XenPCIPassthroughState,
>>                                               memory_listener);
>>  
>> +    if (!xen_pt_region_in_state(s, sec->mr)) {
>> +        return;
>> +    }
>>      memory_region_ref(sec->mr);
>>      xen_pt_region_update(s, sec, true);  } @@ -651,6 +659,9 @@ static 
>> void xen_pt_region_del(MemoryListener *l, MemoryRegionSection *sec)
>>      XenPCIPassthroughState *s = container_of(l, XenPCIPassthroughState,
>>                                               memory_listener);
>>  
>> +    if (!xen_pt_region_in_state(s, sec->mr)) {
>> +        return;
>> +    }
>>      xen_pt_region_update(s, sec, false);
>>      memory_region_unref(sec->mr);
>>  }
>> @@ -660,6 +671,9 @@ static void xen_pt_io_region_add(MemoryListener *l, MemoryRegionSection *sec)
>>      XenPCIPassthroughState *s = container_of(l, XenPCIPassthroughState,
>>                                               io_listener);
>>  
>> +    if (!xen_pt_region_in_state(s, sec->mr)) {
>> +        return;
>> +    }
>>      memory_region_ref(sec->mr);
>>      xen_pt_region_update(s, sec, true);  } @@ -669,6 +683,9 @@ static 
>> void xen_pt_io_region_del(MemoryListener *l, MemoryRegionSection *sec)
>>      XenPCIPassthroughState *s = container_of(l, XenPCIPassthroughState,
>>                                               io_listener);
>>  
>> +    if (!xen_pt_region_in_state(s, sec->mr)) {
>> +        return;
>> +    }
>>      xen_pt_region_update(s, sec, false);
>>      memory_region_unref(sec->mr);
>>  }
>
>Wouldn't it make more sense to move the
>memory_region_ref/memory_region_unref calls inside xen_pt_region_update?

Move the operation  of mr->ref inside xen_pt_region_update can also fix this bug. 
For the convenience of maintenance, another patch can be created.

^ permalink raw reply	[flat|nested] 11+ messages in thread

* [PATCH] xen_pt: fix failure of attaching & detaching a PCI device to VM repeatedly
@ 2015-12-09  1:40 Jianzhong,Chang
  0 siblings, 0 replies; 11+ messages in thread
From: Jianzhong,Chang @ 2015-12-09  1:40 UTC (permalink / raw)
  To: qemu-devel
  Cc: tianyu.lan, liang.z.li, xen-devel, Jianzhong, Chang, pbonzini,
	stefano.stabellini

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_BDF",
reattach the VFs by "xl pci-attach $VF_BDF" in sequence.
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 from
xen_pt_region_add/del inside xen_pt_region_update.

Signed-off-by: Jianzhong,Chang <jianzhongx.chang@intel.com>
---
 hw/xen/xen_pt.c |   10 +++++-----
 1 files changed, 5 insertions(+), 5 deletions(-)

diff --git a/hw/xen/xen_pt.c b/hw/xen/xen_pt.c
index aa96288..45d4d6c 100644
--- a/hw/xen/xen_pt.c
+++ b/hw/xen/xen_pt.c
@@ -590,7 +590,11 @@ static void xen_pt_region_update(XenPCIPassthroughState *s,
     if (bar == -1 && (!s->msix || &s->msix->mmio != mr)) {
         return;
     }
-
+    if (adding) {
+        memory_region_ref(mr);
+    } else {
+        memory_region_unref(mr);
+    }
     if (s->msix && &s->msix->mmio == mr) {
         if (adding) {
             s->msix->mmio_base_addr = sec->offset_within_address_space;
@@ -642,7 +646,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 +655,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 +662,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 +671,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

^ permalink raw reply related	[flat|nested] 11+ messages in thread

end of thread, other threads:[~2015-12-09  1:40 UTC | newest]

Thread overview: 11+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2015-12-03  3:27 [Qemu-devel] [PATCH] xen_pt: fix failure of attaching & detaching a PCI device to VM repeatedly Jianzhong,Chang
2015-12-03  3:27 ` Jianzhong,Chang
2015-12-04 15:53 ` Stefano Stabellini
2015-12-04 15:53 ` [Qemu-devel] " Stefano Stabellini
2015-12-06 15:05   ` Li, Liang Z
2015-12-07  2:57     ` Chang, JianzhongX
2015-12-07  2:57     ` Chang, JianzhongX
2015-12-06 15:05   ` Li, Liang Z
2015-12-07  6:28   ` Chang, JianzhongX
2015-12-07  6:28   ` [Qemu-devel] " Chang, JianzhongX
2015-12-09  1:40 Jianzhong,Chang

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.