History

PCI/MSI: Sanitize MSI-X table map handling

Unmapping the MSI-X base mapping in the loops which allocate/free MSI descriptors is daft and in the way of allowing runtime expansion of MSI-X descriptors. Store the mapping in struct pci_dev and free it after freeing the MSI-X descriptors.

Thomas Gleixner committed 4 years ago

Commit 85aa6071 parent aa423ac2 files · +9 −10Browse files

Unified · Split

2 files
  1. drivers/pci/msi/msi.c +8 −10
  2. include/linux/pci.h +1 −0
drivers/pci/msi/msi.c+8−10
@@ -241,14 +241,14 @@ static void free_msi_irqs(struct pci_dev *dev) · 240 unmodified lines
241 pci_msi_teardown_msi_irqs(dev);241 pci_msi_teardown_msi_irqs(dev);
242 242
243 list_for_each_entry_safe(entry, tmp, msi_list, list) {243 list_for_each_entry_safe(entry, tmp, msi_list, list) {
244 if (entry->pci.msi_attrib.is_msix) {
245 if (list_is_last(&entry->list, msi_list))
246 iounmap(entry->pci.mask_base);
247 }
248
249 list_del(&entry->list);244 list_del(&entry->list);
250 free_msi_entry(entry);245 free_msi_entry(entry);
251 }246 }
247
248 if (dev->msix_base) {
249 iounmap(dev->msix_base);
250 dev->msix_base = NULL;
251 }
252}252}
253 253
254static void pci_intx_for_msi(struct pci_dev *dev, int enable)254static void pci_intx_for_msi(struct pci_dev *dev, int enable)
@@ -501,10 +501,6 @@ static int msix_setup_entries(struct pci_dev *dev, void __iomem *base, · 246 unmodified lines
501 for (i = 0, curmsk = masks; i < nvec; i++) {501 for (i = 0, curmsk = masks; i < nvec; i++) {
502 entry = alloc_msi_entry(&dev->dev, 1, curmsk);502 entry = alloc_msi_entry(&dev->dev, 1, curmsk);
503 if (!entry) {503 if (!entry) {
504 if (!i)
505 iounmap(base);
506 else
507 free_msi_irqs(dev);
508 /* No enough memory. Don't try again */504 /* No enough memory. Don't try again */
509 ret = -ENOMEM;505 ret = -ENOMEM;
510 goto out;506 goto out;
@@ -602,12 +598,14 @@ static int msix_capability_init(struct pci_dev *dev, struct msix_entry *entries, · 91 unmodified lines
602 goto out_disable;598 goto out_disable;
603 }599 }
604 600
601 dev->msix_base = base;
602
605 /* Ensure that all table entries are masked. */603 /* Ensure that all table entries are masked. */
606 msix_mask_all(base, tsize);604 msix_mask_all(base, tsize);
607 605
608 ret = msix_setup_entries(dev, base, entries, nvec, affd);606 ret = msix_setup_entries(dev, base, entries, nvec, affd);
609 if (ret)607 if (ret)
610 goto out_disable;608 goto out_free;
611 609
612 ret = pci_msi_setup_msi_irqs(dev, nvec, PCI_CAP_ID_MSIX);610 ret = pci_msi_setup_msi_irqs(dev, nvec, PCI_CAP_ID_MSIX);
613 if (ret)611 if (ret)
include/linux/pci.h+1−0
@@ -473,6 +473,7 @@ struct pci_dev { · 472 unmodified lines
473 u8 ptm_granularity;473 u8 ptm_granularity;
474#endif474#endif
475#ifdef CONFIG_PCI_MSI475#ifdef CONFIG_PCI_MSI
476 void __iomem *msix_base;
476 const struct attribute_group **msi_irq_groups;477 const struct attribute_group **msi_irq_groups;
477#endif478#endif
478 struct pci_vpd vpd;479 struct pci_vpd vpd;

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t