Skip to contentSkip to conversation

pci_remove_device: fix linked list discipline

PATCH In review Tim Deegan 2 participants 4 messages May 18, 2011 – May 23, 2011

lore
Share & tools
lore

Tim Deegan

author
#0 lore raw

PATCH 1/1 pci_remove_device: fix linked list discipline

# HG changeset patch
# User Tim Deegan <[email protected]> # Date 1305708740 -3600
# Node ID 7b12c46b18777655c8a5f8290286f5699c77c335 # Parent f531ed84b0661aa6863dc86d5e5638642bc47301
pci_remove_device: fix linked list discipline

xen/drivers/passthrough/pci.c +2 -2
diff -r f531ed84b066 -r 7b12c46b1877 xen/drivers/passthrough/pci.c
@@ -173,11 +173,11 @@ out:
 
 int pci_remove_device(u8 bus, u8 devfn)
 {
-    struct pci_dev *pdev;
+    struct pci_dev *pdev, *tmp;
     int ret = -ENODEV;
 
     spin_lock(&pcidevs_lock);
-    list_for_each_entry ( pdev, &alldevs_list, alldevs_list )
+    list_for_each_entry_safe ( pdev, tmp, &alldevs_list, alldevs_list )
         if ( pdev->bus == bus && pdev->devfn == devfn )
         {
             ret = iommu_remove_device(pdev);
#1 lore raw
Quoted 14 lines
Quoted 1 line
Quoted 1 line · Tim Deegan

# HG changeset patch
# User Tim Deegan <[email protected]> # Date 1305708740 -3600
# Node ID 7b12c46b18777655c8a5f8290286f5699c77c335 # Parent f531ed84b0661aa6863dc86d5e5638642bc47301
pci_remove_device: fix linked list discipline

diff -r f531ed84b066 -r 7b12c46b1877 xen/drivers/passthrough/pci.c

xen/drivers/passthrough/pci.c out: · line 180

Quoted 10 lines
xen/drivers/passthrough/pci.c +2 -2
@@ -173,11 +173,11 @@ out:
 
 int pci_remove_device(u8 bus, u8 devfn)
 {
-    struct pci_dev *pdev;
+    struct pci_dev *pdev, *tmp;
     int ret = -ENODEV;
 
     spin_lock(&pcidevs_lock);
-    list_for_each_entry ( pdev, &alldevs_list, alldevs_list )
+    list_for_each_entry_safe ( pdev, tmp, &alldevs_list, alldevs_list )

Somehow I overlooked this patch when it was sent - looking at the code it modifies I can't see why the ..._safe() variant is necessary here, as there's a break statement following the list deletion.

Jan

Quoted 8 lines
xen/drivers/passthrough/pci.c +0 -0
         if ( pdev->bus == bus && pdev->devfn == devfn )
         {
             ret = iommu_remove_device(pdev);

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

author
#2 lore raw
Quoted 11 lines · Jan Beulich
Quoted 11 lines

diff -r f531ed84b066 -r 7b12c46b1877 xen/drivers/passthrough/pci.c

xen/drivers/passthrough/pci.c +1 -1
@@ -173,11 +173,11 @@ out:
 
 int pci_remove_device(u8 bus, u8 devfn)
 {
-    struct pci_dev *pdev;
+    struct pci_dev *pdev, *tmp;
     int ret = -ENODEV;
 
Quoted 7 lines

xen/drivers/passthrough/pci.c out: · line 180

Quoted 3 lines
xen/drivers/passthrough/pci.c +1 -1
     spin_lock(&pcidevs_lock);
-    list_for_each_entry ( pdev, &alldevs_list, alldevs_list )
+    list_for_each_entry_safe ( pdev, tmp, &alldevs_list, alldevs_list )

Somehow I overlooked this patch when it was sent - looking at the code it modifies I can't see why the ..._safe() variant is necessary here, as there's a break statement following the list deletion.

Ah - good point. I'll go back to the crash report I thought this fixed and take another look. :)

Cheers,

Tim.

Signature · 3 lines
Tim Deegan <[email protected]>
Principal Software Engineer, Xen Platform Team
Citrix Systems UK Ltd.  (Company #02937203, SL9 0BG)
author
#3 lore raw
Quoted 6 lines · Tim Deegan
Quoted 3 lines

Somehow I overlooked this patch when it was sent - looking at the code it modifies I can't see why the ..._safe() variant is necessary here, as there's a break statement following the list deletion.

Ah - good point. I'll go back to the crash report I thought this fixed and take another look. :)

The attached patch is a more likely candidate. That will teach me to debug crash reports without getting hold of proper debug symbols. :)

Keir, can you apply this and revert 23352:ea48976517af ?

Cheers,

Tim.

Signature · 3 lines
Tim Deegan <[email protected]>
Principal Software Engineer, Xen Platform Team
Citrix Systems UK Ltd.  (Company #02937203, SL9 0BG)

# HG changeset patch
# User Tim Deegan <[email protected]>
# Date 1306154800 -3600
# Node ID d585903eb8bce83d7d365a4c94bbf0176283c3e9 # Parent 0f670f5146c858ffdc743176d4e22aef4bfe12da drivers/passthrough: fix error paths in pci_add_device*()

When a device can't be allocated to dom0 by the IOMMU, don't leave dom0 in the "domain" field. It causes pci_remove_device() to crash trying to remove the dev from the domain's list of devices (and was probably the wrong thing to do anyway).

xen/drivers/passthrough/pci.c +6 -0
diff -r 0f670f5146c8 -r d585903eb8bc xen/drivers/passthrough/pci.c
@@ -158,7 +158,10 @@ int pci_add_device(u8 bus, u8 devfn)
         pdev->domain = dom0;
         ret = iommu_add_device(pdev);
         if ( ret )
+        {
+            pdev->domain = NULL;
             goto out;
+        }
 
         list_add(&pdev->domain_list, &dom0->arch.pdev_list);
         pci_enable_acs(pdev);
@@ -222,7 +225,10 @@ int pci_add_device_ext(u8 bus, u8 devfn,
         pdev->domain = dom0;
         ret = iommu_add_device(pdev);
         if ( ret )
+        {
+            pdev->domain = NULL;
             goto out;
+        }
 
         list_add(&pdev->domain_list, &dom0->arch.pdev_list);
         pci_enable_acs(pdev);

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