aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/base
diff options
context:
space:
mode:
authorRob Herring <robh@kernel.org>2018-07-09 11:41:48 -0400
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>2018-07-10 11:22:35 -0400
commit25b4e70dcce92168eab4d8113817bb4dd130ebd2 (patch)
treeeb08ff1080319008d0e75df75f7fbc1c1b5848fc /drivers/base
parent28af109a57d14211e5e8ba1551f00428be2fd508 (diff)
driver core: allow stopping deferred probe after init
Deferred probe will currently wait forever on dependent devices to probe, but sometimes a driver will never exist. It's also not always critical for a driver to exist. Platforms can rely on default configuration from the bootloader or reset defaults for things such as pinctrl and power domains. This is often the case with initial platform support until various drivers get enabled. There's at least 2 scenarios where deferred probe can render a platform broken. Both involve using a DT which has more devices and dependencies than the kernel supports. The 1st case is a driver may be disabled in the kernel config. The 2nd case is the kernel version may simply not have the dependent driver. This can happen if using a newer DT (provided by firmware perhaps) with a stable kernel version. Deferred probe issues can be difficult to debug especially if the console has dependencies or userspace fails to boot to a shell. There are also cases like IOMMUs where only built-in drivers are supported, so deferring probe after initcalls is not needed. The IOMMU subsystem implemented its own mechanism to handle this using OF_DECLARE linker sections. This commit adds makes ending deferred probe conditional on initcalls being completed or a debug timeout. Subsystems or drivers may opt-in by calling driver_deferred_probe_check_init_done() instead of unconditionally returning -EPROBE_DEFER. They may use additional information from DT or kernel's config to decide whether to continue to defer probe or not. The timeout mechanism is intended for debug purposes and WARNs loudly. The remaining deferred probe pending list will also be dumped after the timeout. Not that this timeout won't work for the console which needs to be enabled before userspace starts. However, if the console's dependencies are resolved, then the kernel log will be printed (as opposed to no output). Cc: Alexander Graf <agraf@suse.de> Signed-off-by: Rob Herring <robh@kernel.org> Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
Diffstat (limited to 'drivers/base')
-rw-r--r--drivers/base/dd.c59
1 files changed, 59 insertions, 0 deletions
diff --git a/drivers/base/dd.c b/drivers/base/dd.c
index e85705e84407..fb62f1be40d3 100644
--- a/drivers/base/dd.c
+++ b/drivers/base/dd.c
@@ -55,6 +55,7 @@ static LIST_HEAD(deferred_probe_pending_list);
55static LIST_HEAD(deferred_probe_active_list); 55static LIST_HEAD(deferred_probe_active_list);
56static atomic_t deferred_trigger_count = ATOMIC_INIT(0); 56static atomic_t deferred_trigger_count = ATOMIC_INIT(0);
57static struct dentry *deferred_devices; 57static struct dentry *deferred_devices;
58static bool initcalls_done;
58 59
59/* 60/*
60 * In some cases, like suspend to RAM or hibernation, It might be reasonable 61 * In some cases, like suspend to RAM or hibernation, It might be reasonable
@@ -219,6 +220,51 @@ static int deferred_devs_show(struct seq_file *s, void *data)
219} 220}
220DEFINE_SHOW_ATTRIBUTE(deferred_devs); 221DEFINE_SHOW_ATTRIBUTE(deferred_devs);
221 222
223static int deferred_probe_timeout = -1;
224static int __init deferred_probe_timeout_setup(char *str)
225{
226 deferred_probe_timeout = simple_strtol(str, NULL, 10);
227 return 1;
228}
229__setup("deferred_probe_timeout=", deferred_probe_timeout_setup);
230
231/**
232 * driver_deferred_probe_check_state() - Check deferred probe state
233 * @dev: device to check
234 *
235 * Returns -ENODEV if init is done and all built-in drivers have had a chance
236 * to probe (i.e. initcalls are done), -ETIMEDOUT if deferred probe debug
237 * timeout has expired, or -EPROBE_DEFER if none of those conditions are met.
238 *
239 * Drivers or subsystems can opt-in to calling this function instead of directly
240 * returning -EPROBE_DEFER.
241 */
242int driver_deferred_probe_check_state(struct device *dev)
243{
244 if (initcalls_done) {
245 if (!deferred_probe_timeout) {
246 dev_WARN(dev, "deferred probe timeout, ignoring dependency");
247 return -ETIMEDOUT;
248 }
249 dev_warn(dev, "ignoring dependency for device, assuming no driver");
250 return -ENODEV;
251 }
252 return -EPROBE_DEFER;
253}
254
255static void deferred_probe_timeout_work_func(struct work_struct *work)
256{
257 struct device_private *private, *p;
258
259 deferred_probe_timeout = 0;
260 driver_deferred_probe_trigger();
261 flush_work(&deferred_probe_work);
262
263 list_for_each_entry_safe(private, p, &deferred_probe_pending_list, deferred_probe)
264 dev_info(private->device, "deferred probe pending");
265}
266static DECLARE_DELAYED_WORK(deferred_probe_timeout_work, deferred_probe_timeout_work_func);
267
222/** 268/**
223 * deferred_probe_initcall() - Enable probing of deferred devices 269 * deferred_probe_initcall() - Enable probing of deferred devices
224 * 270 *
@@ -235,6 +281,19 @@ static int deferred_probe_initcall(void)
235 driver_deferred_probe_trigger(); 281 driver_deferred_probe_trigger();
236 /* Sort as many dependencies as possible before exiting initcalls */ 282 /* Sort as many dependencies as possible before exiting initcalls */
237 flush_work(&deferred_probe_work); 283 flush_work(&deferred_probe_work);
284 initcalls_done = true;
285
286 /*
287 * Trigger deferred probe again, this time we won't defer anything
288 * that is optional
289 */
290 driver_deferred_probe_trigger();
291 flush_work(&deferred_probe_work);
292
293 if (deferred_probe_timeout > 0) {
294 schedule_delayed_work(&deferred_probe_timeout_work,
295 deferred_probe_timeout * HZ);
296 }
238 return 0; 297 return 0;
239} 298}
240late_initcall(deferred_probe_initcall); 299late_initcall(deferred_probe_initcall);