Skip to contentSkip to conversation

driver core: Avoid pointless deferred probe attempts

PATCH In review Saravana Kannan 3 participants 7 messages Feb 17, 2021 – Feb 25, 2021 Driver core

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 driver core: Avoid pointless deferred probe attempts

There's no point in adding a device to the deferred probe list if we know for sure that it doesn't have a matching driver. So, check if a device can match with a driver before adding it to the deferred probe list.

---
Geert,

Can you give this a shot for your I2C DMA issue with fw_devlink=on?

-Saravana

 drivers/base/dd.c      | 6 ++++++
 include/linux/device.h | 4 ++++
 2 files changed, 10 insertions(+)
drivers/base/dd.c +6 -0
index 9179825ff646..f18963f42e21 100644
@@ -123,6 +123,9 @@ static DECLARE_WORK(deferred_probe_work, deferred_probe_work_func);
 
 void driver_deferred_probe_add(struct device *dev)
 {
+	if (!dev->can_match)
+		return;
+
 	mutex_lock(&deferred_probe_mutex);
 	if (list_empty(&dev->p->deferred_probe)) {
 		dev_dbg(dev, "Added to deferred list\n");
@@ -726,6 +729,7 @@ static int driver_probe_device(struct device_driver *drv, struct device *dev)
 	if (!device_is_registered(dev))
 		return -ENODEV;
 
+	dev->can_match = true;
 	pr_debug("bus: '%s': %s: matched device %s with driver %s\n",
 		 drv->bus->name, __func__, dev_name(dev), drv->name);
 
@@ -829,6 +833,7 @@ static int __device_attach_driver(struct device_driver *drv, void *_data)
 		return 0;
 	} else if (ret == -EPROBE_DEFER) {
 		dev_dbg(dev, "Device match requests probe deferral\n");
+		dev->can_match = true;
 		driver_deferred_probe_add(dev);
 	} else if (ret < 0) {
 		dev_dbg(dev, "Bus failed to match device: %d\n", ret);
@@ -1064,6 +1069,7 @@ static int __driver_attach(struct device *dev, void *data)
 		return 0;
 	} else if (ret == -EPROBE_DEFER) {
 		dev_dbg(dev, "Device match requests probe deferral\n");
+		dev->can_match = true;
 		driver_deferred_probe_add(dev);
 	} else if (ret < 0) {
 		dev_dbg(dev, "Bus failed to match device: %d\n", ret);
include/linux/device.h +4 -0
index 7619a84f8ce4..1f9cc1ba78bc 100644
@@ -438,6 +438,9 @@ struct dev_links_info {
  * @state_synced: The hardware state of this device has been synced to match
  *		  the software state of this device by calling the driver/bus
  *		  sync_state() callback.
+ * @can_match:	The device has matched with a driver at least once or it is in
+ *		a bus (like AMBA) which can't check for matching drivers until
+ *		other devices probe successfully.
  * @dma_coherent: this particular device is dma coherent, even if the
  *		architecture supports non-coherent devices.
  * @dma_ops_bypass: If set to %true then the dma_ops are bypassed for the
@@ -544,6 +547,7 @@ struct device {
 	bool			offline:1;
 	bool			of_node_reused:1;
 	bool			state_synced:1;
+	bool			can_match:1;
 #if defined(CONFIG_ARCH_HAS_SYNC_DMA_FOR_DEVICE) || \
     defined(CONFIG_ARCH_HAS_SYNC_DMA_FOR_CPU) || \
     defined(CONFIG_ARCH_HAS_SYNC_DMA_FOR_CPU_ALL)
Signature · 1 line
2.30.0.478.g8a0d178c01-goog
#1 lore raw
Quoted 5 lines · Saravana Kannan

There's no point in adding a device to the deferred probe list if we know for sure that it doesn't have a matching driver. So, check if a device can match with a driver before adding it to the deferred probe list.

What if a matching driver module loads in the meantime?

Quoted 74 lines

---
Geert,

Can you give this a shot for your I2C DMA issue with fw_devlink=on?

(quoted diff) +0 -1
-Saravana
 
 drivers/base/dd.c      | 6 ++++++
 include/linux/device.h | 4 ++++
 2 files changed, 10 insertions(+)
drivers/base/dd.c +6 -0
index 9179825ff646..f18963f42e21 100644
@@ -123,6 +123,9 @@ static DECLARE_WORK(deferred_probe_work, deferred_probe_work_func);
 
 void driver_deferred_probe_add(struct device *dev)
 {
+       if (!dev->can_match)
+               return;
+
        mutex_lock(&deferred_probe_mutex);
        if (list_empty(&dev->p->deferred_probe)) {
                dev_dbg(dev, "Added to deferred list\n");
@@ -726,6 +729,7 @@ static int driver_probe_device(struct device_driver *drv, struct device *dev)
        if (!device_is_registered(dev))
                return -ENODEV;
 
+       dev->can_match = true;
        pr_debug("bus: '%s': %s: matched device %s with driver %s\n",
                 drv->bus->name, __func__, dev_name(dev), drv->name);
 
@@ -829,6 +833,7 @@ static int __device_attach_driver(struct device_driver *drv, void *_data)
                return 0;
        } else if (ret == -EPROBE_DEFER) {
                dev_dbg(dev, "Device match requests probe deferral\n");
+               dev->can_match = true;
                driver_deferred_probe_add(dev);
        } else if (ret < 0) {
                dev_dbg(dev, "Bus failed to match device: %d\n", ret);
@@ -1064,6 +1069,7 @@ static int __driver_attach(struct device *dev, void *data)
                return 0;
        } else if (ret == -EPROBE_DEFER) {
                dev_dbg(dev, "Device match requests probe deferral\n");
+               dev->can_match = true;
                driver_deferred_probe_add(dev);
        } else if (ret < 0) {
                dev_dbg(dev, "Bus failed to match device: %d\n", ret);
include/linux/device.h +4 -1
index 7619a84f8ce4..1f9cc1ba78bc 100644
@@ -438,6 +438,9 @@ struct dev_links_info {
  * @state_synced: The hardware state of this device has been synced to match
  *               the software state of this device by calling the driver/bus
  *               sync_state() callback.
+ * @can_match: The device has matched with a driver at least once or it is in
+ *             a bus (like AMBA) which can't check for matching drivers until
+ *             other devices probe successfully.
  * @dma_coherent: this particular device is dma coherent, even if the
  *             architecture supports non-coherent devices.
  * @dma_ops_bypass: If set to %true then the dma_ops are bypassed for the
@@ -544,6 +547,7 @@ struct device {
        bool                    offline:1;
        bool                    of_node_reused:1;
        bool                    state_synced:1;
+       bool                    can_match:1;
 #if defined(CONFIG_ARCH_HAS_SYNC_DMA_FOR_DEVICE) || \
     defined(CONFIG_ARCH_HAS_SYNC_DMA_FOR_CPU) || \
     defined(CONFIG_ARCH_HAS_SYNC_DMA_FOR_CPU_ALL)
--
#2 lore raw
Quoted 9 lines · Rafael J. Wysocki
Quoted 5 lines · Saravana Kannan

There's no point in adding a device to the deferred probe list if we know for sure that it doesn't have a matching driver. So, check if a device can match with a driver before adding it to the deferred probe list.

What if a matching driver module loads in the meantime?

Driver registration always triggers a match attempt and this flag will get set at that point. Yes, the user can disable autoprobe, but that'll block deferred probes too.

-Saravana

Quoted 75 lines
Quoted 75 lines

---
Geert,

Can you give this a shot for your I2C DMA issue with fw_devlink=on?

(quoted diff) +0 -1
-Saravana
 
 drivers/base/dd.c      | 6 ++++++
 include/linux/device.h | 4 ++++
 2 files changed, 10 insertions(+)
drivers/base/dd.c +6 -0
index 9179825ff646..f18963f42e21 100644
@@ -123,6 +123,9 @@ static DECLARE_WORK(deferred_probe_work, deferred_probe_work_func);
 
 void driver_deferred_probe_add(struct device *dev)
 {
+       if (!dev->can_match)
+               return;
+
        mutex_lock(&deferred_probe_mutex);
        if (list_empty(&dev->p->deferred_probe)) {
                dev_dbg(dev, "Added to deferred list\n");
@@ -726,6 +729,7 @@ static int driver_probe_device(struct device_driver *drv, struct device *dev)
        if (!device_is_registered(dev))
                return -ENODEV;
 
+       dev->can_match = true;
        pr_debug("bus: '%s': %s: matched device %s with driver %s\n",
                 drv->bus->name, __func__, dev_name(dev), drv->name);
 
@@ -829,6 +833,7 @@ static int __device_attach_driver(struct device_driver *drv, void *_data)
                return 0;
        } else if (ret == -EPROBE_DEFER) {
                dev_dbg(dev, "Device match requests probe deferral\n");
+               dev->can_match = true;
                driver_deferred_probe_add(dev);
        } else if (ret < 0) {
                dev_dbg(dev, "Bus failed to match device: %d\n", ret);
@@ -1064,6 +1069,7 @@ static int __driver_attach(struct device *dev, void *data)
                return 0;
        } else if (ret == -EPROBE_DEFER) {
                dev_dbg(dev, "Device match requests probe deferral\n");
+               dev->can_match = true;
                driver_deferred_probe_add(dev);
        } else if (ret < 0) {
                dev_dbg(dev, "Bus failed to match device: %d\n", ret);
include/linux/device.h +4 -1
index 7619a84f8ce4..1f9cc1ba78bc 100644
@@ -438,6 +438,9 @@ struct dev_links_info {
  * @state_synced: The hardware state of this device has been synced to match
  *               the software state of this device by calling the driver/bus
  *               sync_state() callback.
+ * @can_match: The device has matched with a driver at least once or it is in
+ *             a bus (like AMBA) which can't check for matching drivers until
+ *             other devices probe successfully.
  * @dma_coherent: this particular device is dma coherent, even if the
  *             architecture supports non-coherent devices.
  * @dma_ops_bypass: If set to %true then the dma_ops are bypassed for the
@@ -544,6 +547,7 @@ struct device {
        bool                    offline:1;
        bool                    of_node_reused:1;
        bool                    state_synced:1;
+       bool                    can_match:1;
 #if defined(CONFIG_ARCH_HAS_SYNC_DMA_FOR_DEVICE) || \
     defined(CONFIG_ARCH_HAS_SYNC_DMA_FOR_CPU) || \
     defined(CONFIG_ARCH_HAS_SYNC_DMA_FOR_CPU_ALL)
--
#3 lore raw
Quoted 10 lines · Saravana Kannan
Quoted 8 lines · Rafael J. Wysocki
Quoted 5 lines · Saravana Kannan

There's no point in adding a device to the deferred probe list if we know for sure that it doesn't have a matching driver. So, check if a device can match with a driver before adding it to the deferred probe list.

Quoted 6 lines
Quoted 1 line

What if a matching driver module loads in the meantime?

Driver registration always triggers a match attempt and this flag will get set at that point. Yes, the user can disable autoprobe, but that'll block deferred probes too.

Btw, this can wait for 5.13. Doesn't need to go into 5.12-rcX.

Quoted 11 lines
Quoted 11 lines

drivers/base/dd.c static DECLARE_WORK(deferred_probe_work, deferred_probe_work_func); · line 128

Quoted 11 lines
drivers/base/dd.c +3 -0
index 9179825ff646..f18963f42e21 100644
@@ -123,6 +123,9 @@ static DECLARE_WORK(deferred_probe_work, deferred_probe_work_func);
 
 void driver_deferred_probe_add(struct device *dev)
 {
+       if (!dev->can_match)
+               return;
+

Also, if you are worried about this check, for now, I can move it inside device_links_driver_bound() which is the only place that currently adds a device to the deferred probe list before the driver is present. But it seemed like a good check in general to have in driver_deferred_probe_add(), so I put it there.

-Saravana

#4 lore raw
In reply to Saravana Kannan
Quoted 10 lines · Saravana Kannan
Quoted 8 lines · Rafael J. Wysocki
Quoted 5 lines · Saravana Kannan

There's no point in adding a device to the deferred probe list if we know for sure that it doesn't have a matching driver. So, check if a device can match with a driver before adding it to the deferred probe list.

Quoted 6 lines
Quoted 1 line

What if a matching driver module loads in the meantime?

Driver registration always triggers a match attempt and this flag will get set at that point. Yes, the user can disable autoprobe, but that'll block deferred probes too.

Let me know what you think Rafael.

-Saravana

Quoted 76 lines
Quoted 76 lines
Quoted 76 lines

---
Geert,

Can you give this a shot for your I2C DMA issue with fw_devlink=on?

(quoted diff) +0 -1
-Saravana
 
 drivers/base/dd.c      | 6 ++++++
 include/linux/device.h | 4 ++++
 2 files changed, 10 insertions(+)
drivers/base/dd.c +6 -0
index 9179825ff646..f18963f42e21 100644
@@ -123,6 +123,9 @@ static DECLARE_WORK(deferred_probe_work, deferred_probe_work_func);
 
 void driver_deferred_probe_add(struct device *dev)
 {
+       if (!dev->can_match)
+               return;
+
        mutex_lock(&deferred_probe_mutex);
        if (list_empty(&dev->p->deferred_probe)) {
                dev_dbg(dev, "Added to deferred list\n");
@@ -726,6 +729,7 @@ static int driver_probe_device(struct device_driver *drv, struct device *dev)
        if (!device_is_registered(dev))
                return -ENODEV;
 
+       dev->can_match = true;
        pr_debug("bus: '%s': %s: matched device %s with driver %s\n",
                 drv->bus->name, __func__, dev_name(dev), drv->name);
 
@@ -829,6 +833,7 @@ static int __device_attach_driver(struct device_driver *drv, void *_data)
                return 0;
        } else if (ret == -EPROBE_DEFER) {
                dev_dbg(dev, "Device match requests probe deferral\n");
+               dev->can_match = true;
                driver_deferred_probe_add(dev);
        } else if (ret < 0) {
                dev_dbg(dev, "Bus failed to match device: %d\n", ret);
@@ -1064,6 +1069,7 @@ static int __driver_attach(struct device *dev, void *data)
                return 0;
        } else if (ret == -EPROBE_DEFER) {
                dev_dbg(dev, "Device match requests probe deferral\n");
+               dev->can_match = true;
                driver_deferred_probe_add(dev);
        } else if (ret < 0) {
                dev_dbg(dev, "Bus failed to match device: %d\n", ret);
include/linux/device.h +4 -1
index 7619a84f8ce4..1f9cc1ba78bc 100644
@@ -438,6 +438,9 @@ struct dev_links_info {
  * @state_synced: The hardware state of this device has been synced to match
  *               the software state of this device by calling the driver/bus
  *               sync_state() callback.
+ * @can_match: The device has matched with a driver at least once or it is in
+ *             a bus (like AMBA) which can't check for matching drivers until
+ *             other devices probe successfully.
  * @dma_coherent: this particular device is dma coherent, even if the
  *             architecture supports non-coherent devices.
  * @dma_ops_bypass: If set to %true then the dma_ops are bypassed for the
@@ -544,6 +547,7 @@ struct device {
        bool                    offline:1;
        bool                    of_node_reused:1;
        bool                    state_synced:1;
+       bool                    can_match:1;
 #if defined(CONFIG_ARCH_HAS_SYNC_DMA_FOR_DEVICE) || \
     defined(CONFIG_ARCH_HAS_SYNC_DMA_FOR_CPU) || \
     defined(CONFIG_ARCH_HAS_SYNC_DMA_FOR_CPU_ALL)
--
#5 lore raw
In reply to Saravana Kannan

Hi Saravana,

Quoted 6 lines · Saravana Kannan

There's no point in adding a device to the deferred probe list if we know for sure that it doesn't have a matching driver. So, check if a device can match with a driver before adding it to the deferred probe list.

Thanks for your patch!

Quoted 4 lines

---
Geert,

Can you give this a shot for your I2C DMA issue with fw_devlink=on?

Yes, this makes I2C use DMA again on Salvator-XS during kernel boot-up.

I haven't run any more elaborate tests on other platforms.

Gr{oetje,eeting}s,

Geert

Signature · 5 lines
Geert Uytterhoeven -- There's lots of Linux beyond ia32 -- [email protected]

In personal conversations with technical people, I call myself a hacker. But
when I'm talking to journalists I just say "programmer" or something like that.
                                -- Linus Torvalds
#6 lore raw
Quoted 11 lines · Geert Uytterhoeven

Hi Saravana,

Quoted 6 lines · Saravana Kannan

There's no point in adding a device to the deferred probe list if we know for sure that it doesn't have a matching driver. So, check if a device can match with a driver before adding it to the deferred probe list.

Quoted 8 lines

Thanks for your patch!

Quoted 4 lines

---
Geert,

Can you give this a shot for your I2C DMA issue with fw_devlink=on?

Yes, this makes I2C use DMA again on Salvator-XS during kernel boot-up.

Thanks for testing Geert!

Quoted 1 line

I haven't run any more elaborate tests on other platforms.

Yeah, this change should only go into 5.13 after it gets tested as part of driver-core-next.

-Saravana