libxl: do not try to detach pci device when none attached
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
Quoted 15 lines · Marek Marczykowski
# HG changeset patch
# User Marek Marczykowski <[email protected]> # Date 1307662302 -7200
# Node ID88f67b423c89f4bd604837b9eae2483dad5ebb0d# Parent4b392511ae0840fba66c40aa2788dc1ff402b6e8
libxl: do not try to detach pci device when none attachedFixes SEGV on domain destroy
Signed-off-by Marek Marczykowski <[email protected]>
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
@@ -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 ; }
Quoted 12 lines · Stefano Stabellini
Quoted 11 lines · Marek Marczykowski
# HG changeset patch
# User Marek Marczykowski <[email protected]> # Date 1307662302 -7200
# Node ID88f67b423c89f4bd604837b9eae2483dad5ebb0d# Parent4b392511ae0840fba66c40aa2788dc1ff402b6e8
libxl: do not try to detach pci device when none attachedFixes SEGV on domain destroy
Signed-off-by Marek Marczykowski <[email protected]>
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
37c77bacb52atools/libxl/libxl_pci.ctools/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
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 ID88f67b423c89f4bd604837b9eae2483dad5ebb0d# Parent4b392511ae0840fba66c40aa2788dc1ff402b6e8
libxl: do not try to detach pci device when none attachedFixes SEGV on domain destroy
Signed-off-by Marek Marczykowski <[email protected]>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_assignedexists 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.
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 ID88f67b423c89f4bd604837b9eae2483dad5ebb0d# Parent4b392511ae0840fba66c40aa2788dc1ff402b6e8
libxl: do not try to detach pci device when none attachedFixes SEGV on domain destroy
Signed-off-by Marek Marczykowski <[email protected]>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_assignedexists 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_shutdownis 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
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_shutdownis 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.
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
37c77bacb52atools/libxl/libxl_pci.ctools/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.