Skip to contentSkip to conversation

libxl: do not try to detach pci device when none attached

PATCH In review Marek Marczykowski 3 participants 7 messages Jun 9, 2011 – Jun 21, 2011

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 libxl: do not try to detach pci device when none attached

# HG changeset patch
# User Marek Marczykowski <[email protected]> # Date 1307662302 -7200
# Node ID 88f67b423c89f4bd604837b9eae2483dad5ebb0d # Parent 4b392511ae0840fba66c40aa2788dc1ff402b6e8
libxl: do not try to detach pci device when none attached

Fixes SEGV on domain destroy

tools/libxl/libxl_pci.c +2 -0
@@ -1039,6 +1039,8 @@ int libxl_device_pci_shutdown(libxl_ctx 
     rc = libxl_device_pci_list_assigned(ctx, &pcidevs, domid, &num);
     if ( rc )
         return rc;
+    if ( num == 0 )
+        return 0;
     for (i = 0; i < num; i++) {
         /* Force remove on shutdown since, on HVM, qemu will not always
          * respond to SCI interrupt because the guest kernel has shut down the
#1 lore raw
Quoted 15 lines · Marek Marczykowski

# HG changeset patch
# User Marek Marczykowski <[email protected]> # Date 1307662302 -7200
# Node ID 88f67b423c89f4bd604837b9eae2483dad5ebb0d # Parent 4b392511ae0840fba66c40aa2788dc1ff402b6e8
libxl: do not try to detach pci device when none attached

Fixes SEGV on domain destroy

tools/libxl/libxl_pci.c int libxl_device_pci_shutdown(libxl_ctx · line 1046

Quoted 8 lines
tools/libxl/libxl_pci.c +2 -0
@@ -1039,6 +1039,8 @@ int libxl_device_pci_shutdown(libxl_ctx 
     rc = libxl_device_pci_list_assigned(ctx, &pcidevs, domid, &num);
     if ( rc )
         return rc;
+    if ( num == 0 )
+        return 0;
     for (i = 0; i < num; i++) {
         /* Force remove on shutdown since, on HVM, qemu will not always
          * respond to SCI interrupt because the guest kernel has shut down the

Is the problem here that num is 0 and pcidevs is uninitialized? If so, would this patch solve the problem you are seeing?

tools/libxl/libxl_pci.c +1 -2
diff -r 37c77bacb52a tools/libxl/libxl_pci.c
@@ -1022,8 +1022,7 @@ int libxl_device_pci_list_assigned(libxl
             } while ((p = strtok_r(NULL, ",=", &saveptr)) != NULL);
         }
     }
-    if ( *num )
-        *list = pcidevs;
+    *list = pcidevs;
     libxl__free_all(&gc);
     return 0;
 }
#2 lore raw
Quoted 12 lines · Stefano Stabellini
Quoted 11 lines · Marek Marczykowski

# HG changeset patch
# User Marek Marczykowski <[email protected]> # Date 1307662302 -7200
# Node ID 88f67b423c89f4bd604837b9eae2483dad5ebb0d # Parent 4b392511ae0840fba66c40aa2788dc1ff402b6e8
libxl: do not try to detach pci device when none attached

Fixes SEGV on domain destroy

Quoted 15 lines

tools/libxl/libxl_pci.c int libxl_device_pci_shutdown(libxl_ctx · line 1046

Quoted 12 lines
tools/libxl/libxl_pci.c +2 -0
@@ -1039,6 +1039,8 @@ int libxl_device_pci_shutdown(libxl_ctx 
     rc = libxl_device_pci_list_assigned(ctx, &pcidevs, domid, &num);
     if ( rc )
         return rc;
+    if ( num == 0 )
+        return 0;
     for (i = 0; i < num; i++) {
         /* Force remove on shutdown since, on HVM, qemu will not always
          * respond to SCI interrupt because the guest kernel has shut down the

Is the problem here that num is 0 and pcidevs is uninitialized? If so, would this patch solve the problem you are seeing?

No, when there is no PCI devs, libxl_device_pci_list_assigned exists earlier - before allocating memory for pcidevs.

Quoted 13 lines

diff -r 37c77bacb52a tools/libxl/libxl_pci.c

tools/libxl/libxl_pci.c +1 -2
@@ -1022,8 +1022,7 @@ int libxl_device_pci_list_assigned(libxl
             } while ((p = strtok_r(NULL, ",=", &saveptr)) != NULL);
         }
     }
-    if ( *num )
-        *list = pcidevs;
+    *list = pcidevs;
     libxl__free_all(&gc);
     return 0;
 }
Signature · 3 lines
Pozdrawiam / Best Regards,
Marek Marczykowski         | RLU #390519
marmarek at mimuw edu pl   | xmpp:marmarek at staszic waw pl

_______________________________________________
Xen-devel mailing list
[email protected]
http://lists.xensource.com/xen-devel

#3 lore raw
Quoted 29 lines · Marek Marczykowski
Quoted 12 lines · Stefano Stabellini
Quoted 11 lines · Marek Marczykowski

# HG changeset patch
# User Marek Marczykowski <[email protected]> # Date 1307662302 -7200
# Node ID 88f67b423c89f4bd604837b9eae2483dad5ebb0d # Parent 4b392511ae0840fba66c40aa2788dc1ff402b6e8
libxl: do not try to detach pci device when none attached

Fixes SEGV on domain destroy

Quoted 15 lines

tools/libxl/libxl_pci.c int libxl_device_pci_shutdown(libxl_ctx · line 1046

Quoted 12 lines
tools/libxl/libxl_pci.c +2 -0
@@ -1039,6 +1039,8 @@ int libxl_device_pci_shutdown(libxl_ctx 
     rc = libxl_device_pci_list_assigned(ctx, &pcidevs, domid, &num);
     if ( rc )
         return rc;
+    if ( num == 0 )
+        return 0;
     for (i = 0; i < num; i++) {
         /* Force remove on shutdown since, on HVM, qemu will not always
          * respond to SCI interrupt because the guest kernel has shut down the

Is the problem here that num is 0 and pcidevs is uninitialized? If so, would this patch solve the problem you are seeing?

Quoted 2 lines

No, when there is no PCI devs, libxl_device_pci_list_assigned exists earlier - before allocating memory for pcidevs.

Sorry, but I still don't understand.

If num is 0, it won't enter the following loop anyway, the only other operation in libxl_device_pci_shutdown is free(pcidevs) and pcidevs should be NULL so nothing bad should happen.

#4 lore raw
Quoted 30 lines · Stefano Stabellini
Quoted 29 lines · Marek Marczykowski
Quoted 27 lines · Stefano Stabellini
Quoted 15 lines · Marek Marczykowski

# HG changeset patch
# User Marek Marczykowski <[email protected]> # Date 1307662302 -7200
# Node ID 88f67b423c89f4bd604837b9eae2483dad5ebb0d # Parent 4b392511ae0840fba66c40aa2788dc1ff402b6e8
libxl: do not try to detach pci device when none attached

Fixes SEGV on domain destroy

tools/libxl/libxl_pci.c int libxl_device_pci_shutdown(libxl_ctx · line 1046

Quoted 8 lines
tools/libxl/libxl_pci.c +2 -0
@@ -1039,6 +1039,8 @@ int libxl_device_pci_shutdown(libxl_ctx 
     rc = libxl_device_pci_list_assigned(ctx, &pcidevs, domid, &num);
     if ( rc )
         return rc;
+    if ( num == 0 )
+        return 0;
     for (i = 0; i < num; i++) {
         /* Force remove on shutdown since, on HVM, qemu will not always
          * respond to SCI interrupt because the guest kernel has shut down the

Is the problem here that num is 0 and pcidevs is uninitialized? If so, would this patch solve the problem you are seeing?

Quoted 8 lines
Quoted 2 lines

No, when there is no PCI devs, libxl_device_pci_list_assigned exists earlier - before allocating memory for pcidevs.

Sorry, but I still don't understand.

If num is 0, it won't enter the following loop anyway, the only other operation in libxl_device_pci_shutdown is free(pcidevs) and pcidevs should be NULL so nothing bad should happen.

Ah, ok. So your patch should also works.

Signature · 3 lines
Pozdrawiam / Best Regards,
Marek Marczykowski         | RLU #390519
marmarek at mimuw edu pl   | xmpp:marmarek at staszic waw pl

_______________________________________________
Xen-devel mailing list
[email protected]
http://lists.xensource.com/xen-devel

#5 lore raw

Marek Marczykowski writes ("Re: [Xen-devel] [PATCH] libxl: do not try to detach pci device when none attached"):

Quoted 6 lines · Stefano Stabellini
Quoted 3 lines

If num is 0, it won't enter the following loop anyway, the only other operation in libxl_device_pci_shutdown is free(pcidevs) and pcidevs should be NULL so nothing bad should happen.

Ah, ok. So your patch should also works.

I have applied Stefano's patch.

Ian.

#6 lore raw
In reply to Stefano Stabellini

Stefano Stabellini writes ("Re: [Xen-devel] [PATCH] libxl: do not try to detach pci device when none attached"):

tools/libxl/libxl_pci.c int libxl_device_pci_list_assigned(libxl · line 1025

Quoted 10 lines

diff -r 37c77bacb52a tools/libxl/libxl_pci.c

tools/libxl/libxl_pci.c +1 -2
@@ -1022,8 +1022,7 @@ int libxl_device_pci_list_assigned(libxl
             } while ((p = strtok_r(NULL, ",=", &saveptr)) != NULL);
         }
     }
-    if ( *num )
-        *list = pcidevs;
+    *list = pcidevs;

This patch looks correct to me, as far as it goes.

If n==0 then calloc is passed 0 and may return 0 willy-nilly but since there's no error check this doesn't cause other trouble :-/.

Ian.