History

driver core: Add edit_links() callback for drivers

The driver core/bus adding supplier-consumer dependencies by default enables functional dependencies to be tracked correctly even when the consumer devices haven't had their drivers registered or loaded (if they are modules). However, when the bus incorrectly adds dependencies that it shouldn't have added, the devices might never probe. For example, if device-C is a consumer of device-S and they have phandles to each other in DT, the following could happen: 1. Device-S get added first. 2. The bus add_links() callback will (incorrectly) try to link it as a consumer of device-C. 3. Since device-C isn't present, device-S will be put in "waiting-for-supplier" list. 4. Device-C gets added next. 5. All devices in "waiting-for-supplier" list are retried for linking. 6. Device-S gets linked as consumer to Device-C. 7. The bus add_links() callback will (correctly) try to link it as a consumer of device-S. 8. This isn't allowed because it would create a cyclic device links. Neither devices will get probed since the supplier is marked as dependent on the consumer. And the consumer will never probe because the consumer can't get resources from the supplier. Without this patch, things stay in this broken state. However, with this patch, the execution will continue like this: 9. Device-C's driver is loaded. 10. Device-C's driver removes Device-S as a consumer of Device-C. 11. Device-C's driver adds Device-C as a consumer of Device-S. 12. Device-S probes. 14. Device-C probes. kbuild test robot reported missing documentation for device.has_edit_links Reported-by: kbuild test robot <lkp@intel.com> Signed-off-by: Saravana Kannan <saravanak@google.com> Link: https://lore.kernel.org/r/20190731221721.187713-3-saravanak@google.com Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>

Saravana Kannan committed 7 years ago

Commit 134b23e1 parent 5302dd73 files · +71 −2Browse files

Showing the changes to include/linux (1 of 3 files). Show all

Unified · Split

include/linux/device.h+20−0
@@ -349,6 +349,20 @@ enum probe_type { · 348 unmodified lines
349349 * @probe_type: Type of the probe (synchronous or asynchronous) to use.
350350 * @of_match_table: The open firmware table.
351351 * @acpi_match_table: The ACPI match table.
352+ * @edit_links: Called to allow a matched driver to edit the device links the
353+ * bus might have added incorrectly. This will be useful to handle
354+ * cases where the bus incorrectly adds functional dependencies
355+ * that aren't true or tries to create cyclic dependencies. But
356+ * doesn't correctly handle functional dependencies that are
357+ * missed by the bus as the supplier's sync_state might get to
358+ * execute before the driver for a missing consumer is loaded and
359+ * gets to edit the device links for the consumer.
360+ *
361+ * This function might be called multiple times after a new device
362+ * is added. The function is expected to create all the device
363+ * links for the new device and return 0 if it was completed
364+ * successfully or return an error if it needs to be reattempted
365+ * in the future.
352366 * @probe: Called to query the existence of a specific device,
353367 * whether this driver can work with it, and bind the driver
354368 * to a specific device.
@@ -388,6 +402,7 @@ struct device_driver { · 33 unmodified lines
388402 const struct of_device_id *of_match_table;
389403 const struct acpi_device_id *acpi_match_table;
390404
405+ int (*edit_links)(struct device *dev);
391406 int (*probe) (struct device *dev);
392407 int (*remove) (struct device *dev);
393408 void (*shutdown) (struct device *dev);
@@ -1220,6 +1235,8 @@ struct dev_links_info { · 826 unmodified lines
12201235 * @offline: Set after successful invocation of bus type's .offline().
12211236 * @of_node_reused: Set if the device-tree node is shared with an ancestor
12221237 * device.
1238+ * @has_edit_links: This device has a driver than is capable of
1239+ * editing the device links created by driver core.
12231240 * @dma_coherent: this particular device is dma coherent, even if the
12241241 * architecture supports non-coherent devices.
12251242 *
@@ -1313,6 +1330,7 @@ struct device { · 87 unmodified lines
13131330 bool offline_disabled:1;
13141331 bool offline:1;
13151332 bool of_node_reused:1;
1333+ bool has_edit_links:1;
13161334 #if defined(CONFIG_ARCH_HAS_SYNC_DMA_FOR_DEVICE) || \
13171335 defined(CONFIG_ARCH_HAS_SYNC_DMA_FOR_CPU) || \
13181336 defined(CONFIG_ARCH_HAS_SYNC_DMA_FOR_CPU_ALL)
@@ -1564,6 +1582,7 @@ extern int __must_check device_attach(struct device *dev); · 245 unmodified lines
15641582 extern int __must_check driver_attach(struct device_driver *drv);
15651583 extern void device_initial_probe(struct device *dev);
15661584 extern int __must_check device_reprobe(struct device *dev);
1585+extern int driver_edit_links(struct device *dev);
15671586
15681587 extern bool device_is_bound(struct device *dev);
15691588
@@ -1654,6 +1673,7 @@ struct device_link *device_link_add(struct device *consumer, · 84 unmodified lines
16541673 struct device *supplier, u32 flags);
16551674 void device_link_del(struct device_link *link);
16561675 void device_link_remove(void *consumer, struct device *supplier);
1676+void device_link_remove_from_wfs(struct device *consumer);
16571677
16581678 #ifndef dev_fmt
16591679 #define dev_fmt(fmt) fmt

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