From: Saravana Kannan <saravanak@google.com>
To: Greg Kroah-Hartman <gregkh@linuxfoundation.org>,
"Rafael J. Wysocki" <rafael@kernel.org>,
Marek Szyprowski <m.szyprowski@samsung.com>,
Geert Uytterhoeven <geert@linux-m68k.org>,
Marc Zyngier <maz@kernel.org>,
Tudor Ambarus <Tudor.Ambarus@microchip.com>,
Linus Walleij <linus.walleij@linaro.org>,
Bartosz Golaszewski <bgolaszewski@baylibre.com>,
Martin Kaiser <martin@kaiser.cx>,
Rob Herring <robh+dt@kernel.org>,
Frank Rowand <frowand.list@gmail.com>,
Len Brown <lenb@kernel.org>,
Saravana Kannan <saravanak@google.com>
Cc: linux-kernel@vger.kernel.org, devicetree@vger.kernel.org,
linux-acpi@vger.kernel.org, kernel-team@android.com
Subject: [PATCH v2 2/3] driver core: fw_devlink: Handle missing drivers for optional suppliers
Date: Mon, 1 Feb 2021 20:33:43 -0800 [thread overview]
Message-ID: <20210202043345.3778765-3-saravanak@google.com> (raw)
In-Reply-To: <20210202043345.3778765-1-saravanak@google.com>
After a deferred probe attempt has exhaused all the devices that can be
bound, any device that remains unbound has one/both of these conditions
true:
(1) It is waiting on its supplier to bind
(2) It does not have a matching driver
So, to make fw_devlink=on more forgiving of missing drivers for optional
suppliers, after we've done a full deferred probe attempt, this patch
deletes all device links created by fw_devlink where the supplier hasn't
probed yet and the supplier itself is not waiting on any of its
suppliers. This allows consumers to probe during another deferred probe
attempt if they were waiting on optional suppliers.
When modules are enabled, we can't differentiate between a driver
that'll never be registered vs a driver that'll be registered soon by
loading a module. So, this patch doesn't do anything for the case where
modules are enabled.
Fixes: e590474768f1 ("driver core: Set fw_devlink=on by default")
Signed-off-by: Saravana Kannan <saravanak@google.com>
---
drivers/base/base.h | 2 +
drivers/base/core.c | 104 ++++++++++++++++++++++++++++++++++++--------
drivers/base/dd.c | 5 +++
3 files changed, 94 insertions(+), 17 deletions(-)
diff --git a/drivers/base/base.h b/drivers/base/base.h
index f5600a83124f..34befe9475cb 100644
--- a/drivers/base/base.h
+++ b/drivers/base/base.h
@@ -186,6 +186,8 @@ extern void device_links_no_driver(struct device *dev);
extern bool device_links_busy(struct device *dev);
extern void device_links_unbind_consumers(struct device *dev);
+bool fw_devlink_deferred_probe_retry(void);
+
/* device pm support */
void device_pm_move_to_tail(struct device *dev);
diff --git a/drivers/base/core.c b/drivers/base/core.c
index c95b1daabac7..5e53fc6a21ea 100644
--- a/drivers/base/core.c
+++ b/drivers/base/core.c
@@ -50,6 +50,7 @@ static LIST_HEAD(deferred_sync);
static unsigned int defer_sync_state_count = 1;
static DEFINE_MUTEX(fwnode_link_lock);
static bool fw_devlink_is_permissive(void);
+static bool fw_devlink_def_probe_retry;
/**
* fwnode_link_add - Create a link between two fwnode_handles.
@@ -881,6 +882,13 @@ static void device_link_put_kref(struct device_link *link)
WARN(1, "Unable to drop a managed device link reference\n");
}
+static void device_link_drop_managed(struct device_link *link)
+{
+ link->flags &= ~DL_FLAG_MANAGED;
+ WRITE_ONCE(link->status, DL_STATE_NONE);
+ kref_put(&link->kref, __device_link_del);
+}
+
/**
* device_link_del - Delete a stateless link between two devices.
* @link: Device link to delete.
@@ -943,6 +951,29 @@ static void device_links_missing_supplier(struct device *dev)
}
}
+/**
+ * device_links_probe_blocked_by - Return first supplier blocking probe
+ * @dev: Consumer device.
+ *
+ * Checks if the probe of @dev is blocked by a supplier without a driver. If
+ * yes, return that supplier dev. Otherwise, return NULL.
+ */
+static struct device *device_links_probe_blocked_by(struct device *dev)
+{
+ struct device_link *link;
+
+ list_for_each_entry(link, &dev->links.suppliers, c_node) {
+ if (!(link->flags & DL_FLAG_MANAGED) ||
+ link->flags & DL_FLAG_SYNC_STATE_ONLY)
+ continue;
+
+ if (link->status != DL_STATE_AVAILABLE)
+ return link->supplier;
+ }
+
+ return NULL;
+}
+
/**
* device_links_check_suppliers - Check presence of supplier drivers.
* @dev: Consumer device.
@@ -961,7 +992,7 @@ static void device_links_missing_supplier(struct device *dev)
*/
int device_links_check_suppliers(struct device *dev)
{
- struct device_link *link;
+ struct device_link *link, *tmp;
int ret = 0;
/*
@@ -982,19 +1013,47 @@ int device_links_check_suppliers(struct device *dev)
device_links_write_lock();
- list_for_each_entry(link, &dev->links.suppliers, c_node) {
+ list_for_each_entry_safe(link, tmp, &dev->links.suppliers, c_node) {
if (!(link->flags & DL_FLAG_MANAGED))
continue;
- if (link->status != DL_STATE_AVAILABLE &&
- !(link->flags & DL_FLAG_SYNC_STATE_ONLY)) {
- device_links_missing_supplier(dev);
- dev_dbg(dev, "probe deferral - supplier %s not ready\n",
- dev_name(link->supplier));
- ret = -EPROBE_DEFER;
- break;
+
+ if (link->status == DL_STATE_AVAILABLE ||
+ link->flags & DL_FLAG_SYNC_STATE_ONLY) {
+ WRITE_ONCE(link->status, DL_STATE_CONSUMER_PROBE);
+ continue;
+ }
+
+ /*
+ * After a deferred probe attempt has exhaused all the devices
+ * that can be bound, any device that remains unbound has
+ * one/both of these conditions true:
+ *
+ * (1) It is waiting on its supplier to bind
+ * (2) It does not have a matching driver
+ *
+ * If this device is waiting on a supplier to bind to a driver,
+ * we make sure condition (1) above is not true for the
+ * supplier. In which case, condition (2) has to be true for
+ * the supplier. That is, the supplier doesn't have a matching
+ * driver.
+ *
+ * When we find such a supplier, we delete the device link if
+ * it was created by fw_devlink. This it to allow the consumer
+ * to probe in case the supplier is an optional.
+ */
+ if (fw_devlink_def_probe_retry &&
+ link->flags & DL_FLAG_INFERRED &&
+ !device_links_probe_blocked_by(link->supplier)) {
+ device_link_drop_managed(link);
+ continue;
}
- WRITE_ONCE(link->status, DL_STATE_CONSUMER_PROBE);
+
+ device_links_missing_supplier(dev);
+ dev_dbg(dev, "probe deferral - supplier %s not ready\n",
+ dev_name(link->supplier));
+ ret = -EPROBE_DEFER;
+ break;
}
dev->links.status = DL_DEV_PROBING;
@@ -1132,13 +1191,6 @@ static void __device_links_supplier_defer_sync(struct device *sup)
list_add_tail(&sup->links.defer_sync, &deferred_sync);
}
-static void device_link_drop_managed(struct device_link *link)
-{
- link->flags &= ~DL_FLAG_MANAGED;
- WRITE_ONCE(link->status, DL_STATE_NONE);
- kref_put(&link->kref, __device_link_del);
-}
-
static ssize_t waiting_for_supplier_show(struct device *dev,
struct device_attribute *attr,
char *buf)
@@ -1597,6 +1649,24 @@ static int fw_devlink_relax_cycle(struct device *con, void *sup)
return ret;
}
+/** fw_devlink_deferred_probe_retry - Set up fw_devlink for probe retries
+ *
+ * This function requests fw_devlink to set itself up for a deferred probe
+ * retry. This allows fw_devlink to ignore device links it created to
+ * suppliers that'll never probe. This is necessary in case some of the
+ * suppliers are optional and their consumers can probe without them.
+ *
+ * Returns true if deferred probe retry is likely to make any difference.
+ */
+bool fw_devlink_deferred_probe_retry(void)
+{
+ if (IS_ENABLED(CONFIG_MODULES))
+ return false;
+
+ fw_devlink_def_probe_retry = true;
+ return fw_devlink_get_flags() && !fw_devlink_is_permissive();
+}
+
/**
* fw_devlink_create_devlink - Create a device link from a consumer to fwnode
* @con - Consumer device for the device link
diff --git a/drivers/base/dd.c b/drivers/base/dd.c
index 9179825ff646..11325df2327f 100644
--- a/drivers/base/dd.c
+++ b/drivers/base/dd.c
@@ -317,6 +317,11 @@ static int deferred_probe_initcall(void)
driver_deferred_probe_trigger();
/* Sort as many dependencies as possible before exiting initcalls */
flush_work(&deferred_probe_work);
+
+ if (fw_devlink_deferred_probe_retry()) {
+ driver_deferred_probe_trigger();
+ flush_work(&deferred_probe_work);
+ }
initcalls_done = true;
/*
--
2.30.0.365.g02bc693789-goog
next prev parent reply other threads:[~2021-02-02 4:35 UTC|newest]
Thread overview: 22+ messages / expand[flat|nested] mbox.gz Atom feed top
2021-02-02 4:33 [PATCH v2 0/3] Make fw_devlink=on more forgiving Saravana Kannan
2021-02-02 4:33 ` [PATCH v2 1/3] driver core: fw_devlink: Detect supplier devices that will never be added Saravana Kannan
2021-02-02 14:12 ` Rafael J. Wysocki
2021-02-02 19:35 ` Saravana Kannan
2021-02-02 4:33 ` Saravana Kannan [this message]
2021-02-02 14:34 ` [PATCH v2 2/3] driver core: fw_devlink: Handle missing drivers for optional suppliers Rafael J. Wysocki
2021-02-02 19:46 ` Saravana Kannan
2021-02-04 18:41 ` Rafael J. Wysocki
2021-02-04 19:03 ` Saravana Kannan
2021-02-02 4:33 ` [PATCH v2 3/3] of: property: Don't add links to absent suppliers Saravana Kannan
2021-02-04 19:17 ` Saravana Kannan
2021-02-02 16:52 ` [PATCH v2 0/3] Make fw_devlink=on more forgiving Tudor.Ambarus
2021-02-02 17:41 ` Rob Herring
2021-02-02 18:28 ` Saravana Kannan
2021-02-02 21:22 ` Martin Kaiser
2021-02-02 22:43 ` Saravana Kannan
2021-02-03 7:54 ` Geert Uytterhoeven
2021-02-03 8:11 ` Saravana Kannan
2021-02-03 8:15 ` Geert Uytterhoeven
2021-02-03 22:02 ` Martin Kaiser
2021-02-03 21:57 ` Martin Kaiser
2021-02-03 22:03 ` Saravana Kannan
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20210202043345.3778765-3-saravanak@google.com \
--to=saravanak@google.com \
--cc=Tudor.Ambarus@microchip.com \
--cc=bgolaszewski@baylibre.com \
--cc=devicetree@vger.kernel.org \
--cc=frowand.list@gmail.com \
--cc=geert@linux-m68k.org \
--cc=gregkh@linuxfoundation.org \
--cc=kernel-team@android.com \
--cc=lenb@kernel.org \
--cc=linus.walleij@linaro.org \
--cc=linux-acpi@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=m.szyprowski@samsung.com \
--cc=martin@kaiser.cx \
--cc=maz@kernel.org \
--cc=rafael@kernel.org \
--cc=robh+dt@kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).