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
241241 pci_msi_teardown_msi_irqs(dev);
242242
243243 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−
249244 list_del(&entry->list);
250245 free_msi_entry(entry);
251246 }
247+
248+ if (dev->msix_base) {
249+ iounmap(dev->msix_base);
250+ dev->msix_base = NULL;
251+ }
252252 }
253253
254254 static 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
501501 for (i = 0, curmsk = masks; i < nvec; i++) {
502502 entry = alloc_msi_entry(&dev->dev, 1, curmsk);
503503 if (!entry) {
504− if (!i)
505− iounmap(base);
506− else
507− free_msi_irqs(dev);
508504 /* No enough memory. Don't try again */
509505 ret = -ENOMEM;
510506 goto out;
@@ -602,12 +598,14 @@ static int msix_capability_init(struct pci_dev *dev, struct msix_entry *entries, · 91 unmodified lines
602598 goto out_disable;
603599 }
604600
601+ dev->msix_base = base;
602+
605603 /* Ensure that all table entries are masked. */
606604 msix_mask_all(base, tsize);
607605
608606 ret = msix_setup_entries(dev, base, entries, nvec, affd);
609607 if (ret)
610− goto out_disable;
608+ goto out_free;
611609
612610 ret = pci_msi_setup_msi_irqs(dev, nvec, PCI_CAP_ID_MSIX);
613611 if (ret)
include/linux/pci.h+1−0
@@ -473,6 +473,7 @@ struct pci_dev { · 472 unmodified lines
473473 u8 ptm_granularity;
474474 #endif
475475 #ifdef CONFIG_PCI_MSI
476+ void __iomem *msix_base;
476477 const struct attribute_group **msi_irq_groups;
477478 #endif
478479 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