Skip to content

Commit bac3b10

Browse files
Saravana Kannangregkh
authored andcommitted
driver core: fw_devlink: Stop trying to optimize cycle detection logic
In attempting to optimize fw_devlink runtime, I introduced numerous cycle detection bugs by foregoing cycle detection logic under specific conditions. Each fix has further narrowed the conditions for optimization. It's time to give up on these optimization attempts and just run the cycle detection logic every time fw_devlink tries to create a device link. The specific bug report that triggered this fix involved a supplier fwnode that never gets a device created for it. Instead, the supplier fwnode is represented by the device that corresponds to an ancestor fwnode. In this case, fw_devlink didn't do any cycle detection because the cycle detection logic is only run when a device link is created between the devices that correspond to the actual consumer and supplier fwnodes. With this change, fw_devlink will run cycle detection logic even when creating SYNC_STATE_ONLY proxy device links from a device that is an ancestor of a consumer fwnode. Reported-by: Tomi Valkeinen <[email protected]> Closes: https://lore.kernel.org/all/[email protected]/ Fixes: 6442d79 ("driver core: fw_devlink: Improve detection of overlapping cycles") Cc: stable <[email protected]> Tested-by: Tomi Valkeinen <[email protected]> Signed-off-by: Saravana Kannan <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Greg Kroah-Hartman <[email protected]>
1 parent 562e932 commit bac3b10

File tree

1 file changed

+24
-31
lines changed

1 file changed

+24
-31
lines changed

drivers/base/core.c

Lines changed: 24 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -1989,10 +1989,10 @@ static struct device *fwnode_get_next_parent_dev(const struct fwnode_handle *fwn
19891989
*
19901990
* Return true if one or more cycles were found. Otherwise, return false.
19911991
*/
1992-
static bool __fw_devlink_relax_cycles(struct device *con,
1992+
static bool __fw_devlink_relax_cycles(struct fwnode_handle *con_handle,
19931993
struct fwnode_handle *sup_handle)
19941994
{
1995-
struct device *sup_dev = NULL, *par_dev = NULL;
1995+
struct device *sup_dev = NULL, *par_dev = NULL, *con_dev = NULL;
19961996
struct fwnode_link *link;
19971997
struct device_link *dev_link;
19981998
bool ret = false;
@@ -2009,22 +2009,22 @@ static bool __fw_devlink_relax_cycles(struct device *con,
20092009

20102010
sup_handle->flags |= FWNODE_FLAG_VISITED;
20112011

2012-
sup_dev = get_dev_from_fwnode(sup_handle);
2013-
20142012
/* Termination condition. */
2015-
if (sup_dev == con) {
2013+
if (sup_handle == con_handle) {
20162014
pr_debug("----- cycle: start -----\n");
20172015
ret = true;
20182016
goto out;
20192017
}
20202018

2019+
sup_dev = get_dev_from_fwnode(sup_handle);
2020+
con_dev = get_dev_from_fwnode(con_handle);
20212021
/*
20222022
* If sup_dev is bound to a driver and @con hasn't started binding to a
20232023
* driver, sup_dev can't be a consumer of @con. So, no need to check
20242024
* further.
20252025
*/
20262026
if (sup_dev && sup_dev->links.status == DL_DEV_DRIVER_BOUND &&
2027-
con->links.status == DL_DEV_NO_DRIVER) {
2027+
con_dev && con_dev->links.status == DL_DEV_NO_DRIVER) {
20282028
ret = false;
20292029
goto out;
20302030
}
@@ -2033,7 +2033,7 @@ static bool __fw_devlink_relax_cycles(struct device *con,
20332033
if (link->flags & FWLINK_FLAG_IGNORE)
20342034
continue;
20352035

2036-
if (__fw_devlink_relax_cycles(con, link->supplier)) {
2036+
if (__fw_devlink_relax_cycles(con_handle, link->supplier)) {
20372037
__fwnode_link_cycle(link);
20382038
ret = true;
20392039
}
@@ -2048,7 +2048,7 @@ static bool __fw_devlink_relax_cycles(struct device *con,
20482048
else
20492049
par_dev = fwnode_get_next_parent_dev(sup_handle);
20502050

2051-
if (par_dev && __fw_devlink_relax_cycles(con, par_dev->fwnode)) {
2051+
if (par_dev && __fw_devlink_relax_cycles(con_handle, par_dev->fwnode)) {
20522052
pr_debug("%pfwf: cycle: child of %pfwf\n", sup_handle,
20532053
par_dev->fwnode);
20542054
ret = true;
@@ -2066,7 +2066,7 @@ static bool __fw_devlink_relax_cycles(struct device *con,
20662066
!(dev_link->flags & DL_FLAG_CYCLE))
20672067
continue;
20682068

2069-
if (__fw_devlink_relax_cycles(con,
2069+
if (__fw_devlink_relax_cycles(con_handle,
20702070
dev_link->supplier->fwnode)) {
20712071
pr_debug("%pfwf: cycle: depends on %pfwf\n", sup_handle,
20722072
dev_link->supplier->fwnode);
@@ -2114,11 +2114,6 @@ static int fw_devlink_create_devlink(struct device *con,
21142114
if (link->flags & FWLINK_FLAG_IGNORE)
21152115
return 0;
21162116

2117-
if (con->fwnode == link->consumer)
2118-
flags = fw_devlink_get_flags(link->flags);
2119-
else
2120-
flags = FW_DEVLINK_FLAGS_PERMISSIVE;
2121-
21222117
/*
21232118
* In some cases, a device P might also be a supplier to its child node
21242119
* C. However, this would defer the probe of C until the probe of P
@@ -2139,25 +2134,23 @@ static int fw_devlink_create_devlink(struct device *con,
21392134
return -EINVAL;
21402135

21412136
/*
2142-
* SYNC_STATE_ONLY device links don't block probing and supports cycles.
2143-
* So, one might expect that cycle detection isn't necessary for them.
2144-
* However, if the device link was marked as SYNC_STATE_ONLY because
2145-
* it's part of a cycle, then we still need to do cycle detection. This
2146-
* is because the consumer and supplier might be part of multiple cycles
2147-
* and we need to detect all those cycles.
2137+
* Don't try to optimize by not calling the cycle detection logic under
2138+
* certain conditions. There's always some corner case that won't get
2139+
* detected.
21482140
*/
2149-
if (!device_link_flag_is_sync_state_only(flags) ||
2150-
flags & DL_FLAG_CYCLE) {
2151-
device_links_write_lock();
2152-
if (__fw_devlink_relax_cycles(con, sup_handle)) {
2153-
__fwnode_link_cycle(link);
2154-
flags = fw_devlink_get_flags(link->flags);
2155-
pr_debug("----- cycle: end -----\n");
2156-
dev_info(con, "Fixed dependency cycle(s) with %pfwf\n",
2157-
sup_handle);
2158-
}
2159-
device_links_write_unlock();
2141+
device_links_write_lock();
2142+
if (__fw_devlink_relax_cycles(link->consumer, sup_handle)) {
2143+
__fwnode_link_cycle(link);
2144+
pr_debug("----- cycle: end -----\n");
2145+
pr_info("%pfwf: Fixed dependency cycle(s) with %pfwf\n",
2146+
link->consumer, sup_handle);
21602147
}
2148+
device_links_write_unlock();
2149+
2150+
if (con->fwnode == link->consumer)
2151+
flags = fw_devlink_get_flags(link->flags);
2152+
else
2153+
flags = FW_DEVLINK_FLAGS_PERMISSIVE;
21612154

21622155
if (sup_handle->flags & FWNODE_FLAG_NOT_DEVICE)
21632156
sup_dev = fwnode_get_next_parent_dev(sup_handle);

0 commit comments

Comments
 (0)