[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Xen-devel] [PATCH] Cleanup of MSI code



A few cleanups of the MSI code.  There were a couple of race conditions
in the use of msi_dev_head which this patch fixes.  Use list_empty
rather than list_empty_careful since pirq_list_head is only ever
accessed under pirq_list_lock.  I removed some unused variables.

Signed-off-by: Neil Turton <nturton@xxxxxxxxxxxxxx>


diff -r 0da2e3c3ae18 -r e48832688d07 drivers/pci/msi-xen.c
--- a/drivers/pci/msi-xen.c     Thu May 08 13:44:57 2008 +0100
+++ b/drivers/pci/msi-xen.c     Fri May 09 14:13:44 2008 +0100
@@ -32,7 +32,7 @@ int msi_register(struct msi_ops *ops)
        return 0;
 }
 
-static struct list_head msi_dev_head;
+static LIST_HEAD(msi_dev_head);
 static int msi_dev_head_inited = 0;
 DEFINE_SPINLOCK(msi_dev_lock);
 
@@ -54,11 +54,6 @@ static struct msi_dev_list *get_msi_dev_
        struct msi_dev_list *msi_dev_list, *ret = NULL;
        unsigned long flags;
 
-       if (!msi_dev_head_inited) {
-               INIT_LIST_HEAD(&msi_dev_head);
-               msi_dev_head_inited = 1;
-       }
-
        spin_lock_irqsave(&msi_dev_lock, flags);
 
        list_for_each_entry(msi_dev_list, &msi_dev_head, list)
@@ -79,10 +74,10 @@ static struct msi_dev_list *get_msi_dev_
                return NULL;
        }
 
+       spin_lock_init(&ret->pirq_list_lock);
+       INIT_LIST_HEAD(&ret->pirq_list_head);
        list_add_tail(&ret->list, &msi_dev_head);
        spin_unlock_irqrestore(&msi_dev_lock, flags);
-       spin_lock_init(&ret->pirq_list_lock);
-       INIT_LIST_HEAD(&ret->pirq_list_head);
        return ret;
 }
 
@@ -304,10 +299,9 @@ int pci_save_msix_state(struct pci_dev *
        msi_dev_entry = get_msi_dev_pirq_list(dev);
 
        spin_lock_irqsave(&msi_dev_entry->pirq_list_lock, flags);
-       if (!list_empty_careful(&msi_dev_entry->pirq_list_head))
-               list_for_each_entry_safe(pirq_entry, tmp,
-                                        &msi_dev_entry->pirq_list_head, list)
-                       msi_unmap_pirq(dev, pirq_entry->pirq);
+        list_for_each_entry_safe(pirq_entry, tmp,
+                                 &msi_dev_entry->pirq_list_head, list)
+               msi_unmap_pirq(dev, pirq_entry->pirq);
        spin_unlock_irqrestore(&msi_dev_entry->pirq_list_lock, flags);
 
        disable_msi_mode(dev, pos, PCI_CAP_ID_MSIX);
@@ -394,7 +388,7 @@ static int msix_capability_init(struct p
                return -ENOMEM;
 
        spin_lock_irqsave(&msi_dev_entry->pirq_list_lock, flags);
-       if (!list_empty_careful(&msi_dev_entry->pirq_list_head))
+       if (!list_empty(&msi_dev_entry->pirq_list_head))
        {
                printk(KERN_WARNING "msix pirqs for dev %02x:%02x:%01x are not 
freed \
                       before acquire again.\n", dev->bus->number, 
PCI_SLOT(dev->devfn),
@@ -678,7 +672,7 @@ void msi_remove_pci_irq_vectors(struct p
        msi_dev_entry = get_msi_dev_pirq_list(dev);
 
        spin_lock_irqsave(&msi_dev_entry->pirq_list_lock, flags);
-       if (!list_empty_careful(&msi_dev_entry->pirq_list_head))
+       if (!list_empty(&msi_dev_entry->pirq_list_head))
        {
                printk(KERN_WARNING "msix pirqs for dev %02x:%02x:%01x are not 
freed \
                       before acquire again.\n", dev->bus->number, 
PCI_SLOT(dev->devfn),
diff -r 0da2e3c3ae18 -r e48832688d07 
drivers/xen/pciback/conf_space_capability_msi.c
--- a/drivers/xen/pciback/conf_space_capability_msi.c   Thu May 08 13:44:57 
2008 +0100
+++ b/drivers/xen/pciback/conf_space_capability_msi.c   Fri May 09 14:13:44 
2008 +0100
@@ -11,7 +11,6 @@ int pciback_enable_msi(struct pciback_de
                struct pci_dev *dev, struct xen_pci_op *op)
 {
        int otherend = pdev->xdev->otherend_id;
-       int irq;
        int status;
 
        status = pci_enable_msi(dev);
@@ -29,8 +28,6 @@ int pciback_disable_msi(struct pciback_d
 int pciback_disable_msi(struct pciback_device *pdev,
                struct pci_dev *dev, struct xen_pci_op *op)
 {
-       int old_irq = dev->irq;
-
        pci_disable_msi(dev);
 
        op->value = dev->irq;
@@ -40,7 +37,7 @@ int pciback_enable_msix(struct pciback_d
 int pciback_enable_msix(struct pciback_device *pdev,
                struct pci_dev *dev, struct xen_pci_op *op)
 {
-       int otherend = pdev->xdev->otherend_id, result, i;
+       int result;
 
        result = pci_enable_msix(dev, op->msix_entries, op->value);
 

_______________________________________________
Xen-devel mailing list
Xen-devel@xxxxxxxxxxxxxxxxxxx
http://lists.xensource.com/xen-devel

 


Rackspace

Lists.xenproject.org is hosted with RackSpace, monitoring our
servers 24x7x365 and backed by RackSpace's Fanatical Support®.