public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
* [PATCH] PCI: Check drivers_autoprobe for all added devices
@ 2025-10-01 15:15 Vincent Liu
  2025-10-02  5:55 ` Greg Kroah-Hartman
                   ` (3 more replies)
  0 siblings, 4 replies; 14+ messages in thread
From: Vincent Liu @ 2025-10-01 15:15 UTC (permalink / raw)
  To: Greg Kroah-Hartman, Rafael J. Wysocki, Danilo Krummrich,
	linux-kernel
  Cc: Vincent Liu

When a PCIe device is hot-plugged, or when a VF is created, the
drivers_autoprobe sysfs attribute is not checked. This means that
drivers_autoprobe is not working as intended, e.g. hot-plugged devices
will still be autoprobed and bound to drivers even with
drivers_autoprobe disabled.

Make sure all devices check drivers_autoprobe by pushing the
drivers_autoprobe check into device_initial_probe. This should only
affect devices on the PCI bus as device_initial_probe is only called by
pci_bus_add_device (bus_probe_device already checks for autoprobe).
In particular, only hot-plugged PCIe devices/VFs should be affected as
the default value of pci/drivers_autoprobe remains 1 and can only be
cleared from userland.

Signed-off-by: Vincent Liu <vincent.liu@nutanix.com>
---
 drivers/base/bus.c |  3 +--
 drivers/base/dd.c  | 10 +++++++++-
 2 files changed, 10 insertions(+), 3 deletions(-)

diff --git a/drivers/base/bus.c b/drivers/base/bus.c
index 5e75e1bce551..320e155c6be7 100644
--- a/drivers/base/bus.c
+++ b/drivers/base/bus.c
@@ -533,8 +533,7 @@ void bus_probe_device(struct device *dev)
 	if (!sp)
 		return;
 
-	if (sp->drivers_autoprobe)
-		device_initial_probe(dev);
+	device_initial_probe(dev);
 
 	mutex_lock(&sp->mutex);
 	list_for_each_entry(sif, &sp->interfaces, node)
diff --git a/drivers/base/dd.c b/drivers/base/dd.c
index 13ab98e033ea..37fc57e44e54 100644
--- a/drivers/base/dd.c
+++ b/drivers/base/dd.c
@@ -1077,7 +1077,15 @@ EXPORT_SYMBOL_GPL(device_attach);
 
 void device_initial_probe(struct device *dev)
 {
-	__device_attach(dev, true);
+	struct subsys_private *sp = bus_to_subsys(dev->bus);
+
+	if (!sp)
+		return;
+
+	if (sp->drivers_autoprobe)
+		__device_attach(dev, true);
+
+	subsys_put(sp);
 }
 
 /*
-- 
2.43.7


^ permalink raw reply related	[flat|nested] 14+ messages in thread

end of thread, other threads:[~2025-11-20 17:01 UTC | newest]

Thread overview: 14+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-10-01 15:15 [PATCH] PCI: Check drivers_autoprobe for all added devices Vincent Liu
2025-10-02  5:55 ` Greg Kroah-Hartman
2025-10-02 12:04   ` [PATCH] driver core: " Vincent Liu
2025-10-13 18:14 ` [PATCH v2] driver core: " Vincent Liu
2025-10-14  5:14   ` Greg KH
2025-10-14 12:10     ` Vincent Liu
2025-10-21 12:49       ` Vincent Liu
2025-10-22 10:32         ` Greg KH
2025-10-14 20:07   ` Bjorn Helgaas
2025-10-15 10:23     ` Vincent Liu
2025-10-15 16:53       ` Bjorn Helgaas
2025-10-22 12:07 ` [PATCH v3] " Vincent Liu
2025-11-04 13:16   ` Vincent Liu
2025-11-20 17:00 ` [PATCH v3 RESEND] " Vincent Liu

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox