Skip to content

Commit ce45dc4

Browse files
l1kkwilczynski
authored andcommitted
PCI: Limit visibility of match_driver flag to PCI core
Since commit 58d9a38 ("PCI: Skip attaching driver in device_add()"), PCI enumeration is split into two steps: In the first step, all devices are published in sysfs with device_add(). In the second step, drivers are bound to the devices with device_attach(). To delay driver binding until the second step, a "bool match_driver" in struct pci_dev is used. Instead of a bool, use a bit in the "unsigned long priv_flags" to shrink struct pci_dev a little and prevent use of the bool outside the PCI core (as has happened with commit cbbc00b ("iommu/amd: Prevent binding other PCI drivers to IOMMU PCI devices")). Signed-off-by: Lukas Wunner <lukas@wunner.de> Signed-off-by: Bjorn Helgaas <bhelgaas@google.com> Signed-off-by: Krzysztof Wilczyński <kwilczynski@kernel.org> Link: https://patch.msgid.link/d22a9e5b81d6bd8dd1837607d6156679b3b1199c.1745572340.git.lukas@wunner.de
1 parent 3be5fa2 commit ce45dc4

File tree

5 files changed

+15
-5
lines changed

5 files changed

+15
-5
lines changed

drivers/pci/bus.c

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -369,7 +369,9 @@ void pci_bus_add_device(struct pci_dev *dev)
369369
pdev->name);
370370
}
371371

372-
dev->match_driver = !dn || of_device_is_available(dn);
372+
if (!dn || of_device_is_available(dn))
373+
pci_dev_allow_binding(dev);
374+
373375
retval = device_attach(&dev->dev);
374376
if (retval < 0 && retval != -EPROBE_DEFER)
375377
pci_warn(dev, "device attach failed (%d)\n", retval);

drivers/pci/pci-driver.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1507,7 +1507,7 @@ static int pci_bus_match(struct device *dev, const struct device_driver *drv)
15071507
struct pci_driver *pci_drv;
15081508
const struct pci_device_id *found_id;
15091509

1510-
if (!pci_dev->match_driver)
1510+
if (pci_dev_binding_disallowed(pci_dev))
15111511
return 0;
15121512

15131513
pci_drv = (struct pci_driver *)to_pci_driver(drv);

drivers/pci/pci.h

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -557,6 +557,7 @@ static inline int pci_dev_set_disconnected(struct pci_dev *dev, void *unused)
557557
#define PCI_DPC_RECOVERED 1
558558
#define PCI_DPC_RECOVERING 2
559559
#define PCI_DEV_REMOVED 3
560+
#define PCI_DEV_ALLOW_BINDING 7
560561

561562
static inline void pci_dev_assign_added(struct pci_dev *dev)
562563
{
@@ -580,6 +581,16 @@ static inline bool pci_dev_test_and_set_removed(struct pci_dev *dev)
580581
return test_and_set_bit(PCI_DEV_REMOVED, &dev->priv_flags);
581582
}
582583

584+
static inline void pci_dev_allow_binding(struct pci_dev *dev)
585+
{
586+
set_bit(PCI_DEV_ALLOW_BINDING, &dev->priv_flags);
587+
}
588+
589+
static inline bool pci_dev_binding_disallowed(struct pci_dev *dev)
590+
{
591+
return !test_bit(PCI_DEV_ALLOW_BINDING, &dev->priv_flags);
592+
}
593+
583594
#ifdef CONFIG_PCIEAER
584595
#include <linux/aer.h>
585596

drivers/pci/probe.c

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2711,7 +2711,6 @@ void pci_device_add(struct pci_dev *dev, struct pci_bus *bus)
27112711
pci_set_msi_domain(dev);
27122712

27132713
/* Notifier could use PCI capabilities */
2714-
dev->match_driver = false;
27152714
ret = device_add(&dev->dev);
27162715
WARN_ON(ret < 0);
27172716

include/linux/pci.h

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -423,8 +423,6 @@ struct pci_dev {
423423
struct resource resource[DEVICE_COUNT_RESOURCE]; /* I/O and memory regions + expansion ROMs */
424424
struct resource driver_exclusive_resource; /* driver exclusive resource ranges */
425425

426-
bool match_driver; /* Skip attaching driver */
427-
428426
unsigned int transparent:1; /* Subtractive decode bridge */
429427
unsigned int io_window:1; /* Bridge has I/O window */
430428
unsigned int pref_window:1; /* Bridge has pref mem window */

0 commit comments

Comments
 (0)