Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

Merge tag 'pci-v4.18-fixes-3' of git://git.kernel.org/pub/scm/linux/kernel/git/helgaas/pci

Pull PCI fixes from Bjorn Helgaas:

- Fix crashes that happen when PHY drivers are left disabled in the V3
Semiconductor, MediaTek, Faraday, Aardvark, DesignWare, Versatile,
and X-Gene host controller drivers (Sergei Shtylyov)

- Fix a NULL pointer dereference in the endpoint library configfs
support (Kishon Vijay Abraham I)

- Fix a race condition in Hyper-V IRQ handling (Dexuan Cui)

* tag 'pci-v4.18-fixes-3' of git://git.kernel.org/pub/scm/linux/kernel/git/helgaas/pci:
PCI: v3-semi: Fix I/O space page leak
PCI: mediatek: Fix I/O space page leak
PCI: faraday: Fix I/O space page leak
PCI: aardvark: Fix I/O space page leak
PCI: designware: Fix I/O space page leak
PCI: versatile: Fix I/O space page leak
PCI: xgene: Fix I/O space page leak
PCI: OF: Fix I/O space page leak
PCI: endpoint: Fix NULL pointer dereference error when CONFIGFS is disabled
PCI: hv: Disable/enable IRQs rather than BH in hv_compose_msi_msg()

+97 -30
+2 -1
drivers/pci/controller/dwc/pcie-designware-host.c
··· 363 363 resource_list_for_each_entry_safe(win, tmp, &bridge->windows) { 364 364 switch (resource_type(win->res)) { 365 365 case IORESOURCE_IO: 366 - ret = pci_remap_iospace(win->res, pp->io_base); 366 + ret = devm_pci_remap_iospace(dev, win->res, 367 + pp->io_base); 367 368 if (ret) { 368 369 dev_warn(dev, "Error %d: failed to map resource %pR\n", 369 370 ret, win->res);
+1 -1
drivers/pci/controller/pci-aardvark.c
··· 849 849 0, 0xF8000000, 0, 850 850 lower_32_bits(res->start), 851 851 OB_PCIE_IO); 852 - err = pci_remap_iospace(res, iobase); 852 + err = devm_pci_remap_iospace(dev, res, iobase); 853 853 if (err) { 854 854 dev_warn(dev, "error %d: failed to map resource %pR\n", 855 855 err, res);
+1 -1
drivers/pci/controller/pci-ftpci100.c
··· 503 503 dev_err(dev, "illegal IO mem size\n"); 504 504 return -EINVAL; 505 505 } 506 - ret = pci_remap_iospace(io, io_base); 506 + ret = devm_pci_remap_iospace(dev, io, io_base); 507 507 if (ret) { 508 508 dev_warn(dev, "error %d: failed to map resource %pR\n", 509 509 ret, io);
+5 -3
drivers/pci/controller/pci-hyperv.c
··· 1073 1073 struct pci_bus *pbus; 1074 1074 struct pci_dev *pdev; 1075 1075 struct cpumask *dest; 1076 + unsigned long flags; 1076 1077 struct compose_comp_ctxt comp; 1077 1078 struct tran_int_desc *int_desc; 1078 1079 struct { ··· 1165 1164 * the channel callback directly when channel->target_cpu is 1166 1165 * the current CPU. When the higher level interrupt code 1167 1166 * calls us with interrupt enabled, let's add the 1168 - * local_bh_disable()/enable() to avoid race. 1167 + * local_irq_save()/restore() to avoid race: 1168 + * hv_pci_onchannelcallback() can also run in tasklet. 1169 1169 */ 1170 - local_bh_disable(); 1170 + local_irq_save(flags); 1171 1171 1172 1172 if (hbus->hdev->channel->target_cpu == smp_processor_id()) 1173 1173 hv_pci_onchannelcallback(hbus); 1174 1174 1175 - local_bh_enable(); 1175 + local_irq_restore(flags); 1176 1176 1177 1177 if (hpdev->state == hv_pcichild_ejecting) { 1178 1178 dev_err_once(&hbus->hdev->device,
+1 -1
drivers/pci/controller/pci-v3-semi.c
··· 537 537 v3->io_bus_addr = io->start - win->offset; 538 538 dev_dbg(dev, "I/O window %pR, bus addr %pap\n", 539 539 io, &v3->io_bus_addr); 540 - ret = pci_remap_iospace(io, io_base); 540 + ret = devm_pci_remap_iospace(dev, io, io_base); 541 541 if (ret) { 542 542 dev_warn(dev, 543 543 "error %d: failed to map resource %pR\n",
+1 -1
drivers/pci/controller/pci-versatile.c
··· 82 82 83 83 switch (resource_type(res)) { 84 84 case IORESOURCE_IO: 85 - err = pci_remap_iospace(res, iobase); 85 + err = devm_pci_remap_iospace(dev, res, iobase); 86 86 if (err) { 87 87 dev_warn(dev, "error %d: failed to map resource %pR\n", 88 88 err, res);
+1 -1
drivers/pci/controller/pci-xgene.c
··· 423 423 case IORESOURCE_IO: 424 424 xgene_pcie_setup_ob_reg(port, res, OMR3BARL, io_base, 425 425 res->start - window->offset); 426 - ret = pci_remap_iospace(res, io_base); 426 + ret = devm_pci_remap_iospace(dev, res, io_base); 427 427 if (ret < 0) 428 428 return ret; 429 429 break;
+1 -1
drivers/pci/controller/pcie-mediatek.c
··· 1109 1109 if (err < 0) 1110 1110 return err; 1111 1111 1112 - pci_remap_iospace(&pcie->pio, pcie->io.start); 1112 + devm_pci_remap_iospace(dev, &pcie->pio, pcie->io.start); 1113 1113 1114 1114 return 0; 1115 1115 }
+43 -19
drivers/pci/endpoint/pci-epf-core.c
··· 137 137 } 138 138 EXPORT_SYMBOL_GPL(pci_epf_alloc_space); 139 139 140 + static void pci_epf_remove_cfs(struct pci_epf_driver *driver) 141 + { 142 + struct config_group *group, *tmp; 143 + 144 + if (!IS_ENABLED(CONFIG_PCI_ENDPOINT_CONFIGFS)) 145 + return; 146 + 147 + mutex_lock(&pci_epf_mutex); 148 + list_for_each_entry_safe(group, tmp, &driver->epf_group, group_entry) 149 + pci_ep_cfs_remove_epf_group(group); 150 + list_del(&driver->epf_group); 151 + mutex_unlock(&pci_epf_mutex); 152 + } 153 + 140 154 /** 141 155 * pci_epf_unregister_driver() - unregister the PCI EPF driver 142 156 * @driver: the PCI EPF driver that has to be unregistered ··· 159 145 */ 160 146 void pci_epf_unregister_driver(struct pci_epf_driver *driver) 161 147 { 162 - struct config_group *group, *tmp; 163 - 164 - mutex_lock(&pci_epf_mutex); 165 - list_for_each_entry_safe(group, tmp, &driver->epf_group, group_entry) 166 - pci_ep_cfs_remove_epf_group(group); 167 - list_del(&driver->epf_group); 168 - mutex_unlock(&pci_epf_mutex); 148 + pci_epf_remove_cfs(driver); 169 149 driver_unregister(&driver->driver); 170 150 } 171 151 EXPORT_SYMBOL_GPL(pci_epf_unregister_driver); 152 + 153 + static int pci_epf_add_cfs(struct pci_epf_driver *driver) 154 + { 155 + struct config_group *group; 156 + const struct pci_epf_device_id *id; 157 + 158 + if (!IS_ENABLED(CONFIG_PCI_ENDPOINT_CONFIGFS)) 159 + return 0; 160 + 161 + INIT_LIST_HEAD(&driver->epf_group); 162 + 163 + id = driver->id_table; 164 + while (id->name[0]) { 165 + group = pci_ep_cfs_add_epf_group(id->name); 166 + if (IS_ERR(group)) { 167 + pci_epf_remove_cfs(driver); 168 + return PTR_ERR(group); 169 + } 170 + 171 + mutex_lock(&pci_epf_mutex); 172 + list_add_tail(&group->group_entry, &driver->epf_group); 173 + mutex_unlock(&pci_epf_mutex); 174 + id++; 175 + } 176 + 177 + return 0; 178 + } 172 179 173 180 /** 174 181 * __pci_epf_register_driver() - register a new PCI EPF driver ··· 202 167 struct module *owner) 203 168 { 204 169 int ret; 205 - struct config_group *group; 206 - const struct pci_epf_device_id *id; 207 170 208 171 if (!driver->ops) 209 172 return -EINVAL; ··· 216 183 if (ret) 217 184 return ret; 218 185 219 - INIT_LIST_HEAD(&driver->epf_group); 220 - 221 - id = driver->id_table; 222 - while (id->name[0]) { 223 - group = pci_ep_cfs_add_epf_group(id->name); 224 - mutex_lock(&pci_epf_mutex); 225 - list_add_tail(&group->group_entry, &driver->epf_group); 226 - mutex_unlock(&pci_epf_mutex); 227 - id++; 228 - } 186 + pci_epf_add_cfs(driver); 229 187 230 188 return 0; 231 189 }
+1 -1
drivers/pci/of.c
··· 612 612 613 613 switch (resource_type(res)) { 614 614 case IORESOURCE_IO: 615 - err = pci_remap_iospace(res, iobase); 615 + err = devm_pci_remap_iospace(dev, res, iobase); 616 616 if (err) { 617 617 dev_warn(dev, "error %d: failed to map resource %pR\n", 618 618 err, res);
+38
drivers/pci/pci.c
··· 3579 3579 } 3580 3580 EXPORT_SYMBOL(pci_unmap_iospace); 3581 3581 3582 + static void devm_pci_unmap_iospace(struct device *dev, void *ptr) 3583 + { 3584 + struct resource **res = ptr; 3585 + 3586 + pci_unmap_iospace(*res); 3587 + } 3588 + 3589 + /** 3590 + * devm_pci_remap_iospace - Managed pci_remap_iospace() 3591 + * @dev: Generic device to remap IO address for 3592 + * @res: Resource describing the I/O space 3593 + * @phys_addr: physical address of range to be mapped 3594 + * 3595 + * Managed pci_remap_iospace(). Map is automatically unmapped on driver 3596 + * detach. 3597 + */ 3598 + int devm_pci_remap_iospace(struct device *dev, const struct resource *res, 3599 + phys_addr_t phys_addr) 3600 + { 3601 + const struct resource **ptr; 3602 + int error; 3603 + 3604 + ptr = devres_alloc(devm_pci_unmap_iospace, sizeof(*ptr), GFP_KERNEL); 3605 + if (!ptr) 3606 + return -ENOMEM; 3607 + 3608 + error = pci_remap_iospace(res, phys_addr); 3609 + if (error) { 3610 + devres_free(ptr); 3611 + } else { 3612 + *ptr = res; 3613 + devres_add(dev, ptr); 3614 + } 3615 + 3616 + return error; 3617 + } 3618 + EXPORT_SYMBOL(devm_pci_remap_iospace); 3619 + 3582 3620 /** 3583 3621 * devm_pci_remap_cfgspace - Managed pci_remap_cfgspace() 3584 3622 * @dev: Generic device to remap IO address for
+2
include/linux/pci.h
··· 1240 1240 unsigned long pci_address_to_pio(phys_addr_t addr); 1241 1241 phys_addr_t pci_pio_to_address(unsigned long pio); 1242 1242 int pci_remap_iospace(const struct resource *res, phys_addr_t phys_addr); 1243 + int devm_pci_remap_iospace(struct device *dev, const struct resource *res, 1244 + phys_addr_t phys_addr); 1243 1245 void pci_unmap_iospace(struct resource *res); 1244 1246 void __iomem *devm_pci_remap_cfgspace(struct device *dev, 1245 1247 resource_size_t offset,