From patchwork Mon Jul 9 15:41:48 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Rob Herring X-Patchwork-Id: 141439 Delivered-To: patch@linaro.org Received: by 2002:a2e:9754:0:0:0:0:0 with SMTP id f20-v6csp2813418ljj; Mon, 9 Jul 2018 08:42:07 -0700 (PDT) X-Google-Smtp-Source: AAOMgpf9m65BqeDhl1S9tKUBdYbB9F5vpio3+z6W+U7LjkaJO/SQySiTt0RHjF+DdjdD4j4Jjymb X-Received: by 2002:a17:902:8206:: with SMTP id x6-v6mr20728661pln.220.1531150927428; Mon, 09 Jul 2018 08:42:07 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1531150927; cv=none; d=google.com; s=arc-20160816; b=egjlaO7o19MW+cs7YWGRms42YvdlkQFdV0KwkzTjj8iOKS+YQHC3oIrsm18vhpso28 RearF8WhL6Is152slHseVPK5xlcbuAt2E9FPJnZRNbMMAD1L4Z9mnUY/7sdWU5oJ6cM6 o/GaRFbaEdzB/LjcOAWrR15cPPEgXdGj4c0Do49lIAIiMXJrfGiOYRmpBYXUN+jYcaWY JEBpHr7ZXco22FRCoiwYY6cn8tD65ngULYVrw1FV8YuuEpNeBVAvoJLjqIJltw06yA3e 3cH4rMMjlnHGlz4gYl94kM0pF/fNYJ6ogZjBngmruJ1v+dYpvtNDXS4BMviUsaBrhf6Y 5Oeg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:references:in-reply-to:message-id:date :subject:cc:to:from:arc-authentication-results; bh=saQ436eaurAbu2okU+dKORu9bdhDpvxbPgF9Cd5+TaA=; b=rd/cl10S5q1LUXLMRMtRzAyLaGIuOEi5mGy8Nl473c8YjSuAOkSUjhtxpju3QF9ELr tqMg9hupdPa2kgn69SNBN3mQ9cC9GyPwyirFIPQFoYm+nBiwXx7NDIUW0F7aoPUlR+XQ Bv7/VSQXGBtIjF1WHbE/2oKNORYw+RDQpqSawCpcC5GByY059afQCnMpR3lVSr+V6i9l jXUQdU8ezQPO8rvqeTWXbtLWwIzOPm/2o2Ti3pTIEme0KHbqQf6DV4s075VBBKoc6Ide boYiG0mH9LUKi7VmnGPpmDW8OXqfW79NYiH0EYVxm/ljwnSL6KbE4QH+fXJhFOrsR9Tn 7WAw== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id t6-v6si14403828plo.508.2018.07.09.08.42.07; Mon, 09 Jul 2018 08:42:07 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S933651AbeGIPmE (ORCPT + 30 others); Mon, 9 Jul 2018 11:42:04 -0400 Received: from mail-oi0-f67.google.com ([209.85.218.67]:42828 "EHLO mail-oi0-f67.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S933520AbeGIPmB (ORCPT ); Mon, 9 Jul 2018 11:42:01 -0400 Received: by mail-oi0-f67.google.com with SMTP id n84-v6so36700480oib.9; Mon, 09 Jul 2018 08:42:00 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=saQ436eaurAbu2okU+dKORu9bdhDpvxbPgF9Cd5+TaA=; b=FhmHGVd0OiHKIGTjzIksXK47oESMtmVBWHT64XvGt2g2Vphf6bgW9psX6WdF4Pli2B /icJgpAV50uhk3mGky6Kb5qf+bsTgTtL8TH9r3SRD/tCzkwMI8Rmpsh+bbD78sZqhoEi F1+f4oFZUZTKoWjy4WCAyPyuHfF7v8hcAaArpxHq9jkYxf+w+kzxKx5gnr7md8x075uX Muv4HlFvD3/Qm5Q9RQazpir4vJCahYxis1lbBSzRmRdtJtNC2LV/ynPsu4xgG4aGqbYq o9JAptVZQhIevSHW0ipc8bbh24t5pfOvd3VAaaOYlJLIswgrv57uMO2DLfF3CvdMdd6T k18g== X-Gm-Message-State: APt69E0NbLG85nmakCcPlVY2C5TZ+5WKuT5r+/rE1ZFfUQgXDzWEQA09 R1XagCYSR0iE5+ZBijIXqw== X-Received: by 2002:aca:3954:: with SMTP id g81-v6mr25211279oia.215.1531150920437; Mon, 09 Jul 2018 08:42:00 -0700 (PDT) Received: from localhost.localdomain (24-223-123-72.static.usa-companies.net. [24.223.123.72]) by smtp.googlemail.com with ESMTPSA id z196-v6sm30759391oig.12.2018.07.09.08.41.58 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 09 Jul 2018 08:41:59 -0700 (PDT) From: Rob Herring To: Greg Kroah-Hartman Cc: Linus Walleij , Alexander Graf , Bjorn Andersson , "Rafael J. Wysocki" , Kevin Hilman , Ulf Hansson , Joerg Roedel , Robin Murphy , Mark Brown , Frank Rowand , linux-kernel@vger.kernel.org, devicetree@vger.kernel.org, boot-architecture@lists.linaro.org, linux-arm-kernel@lists.infradead.org Subject: [PATCH v4 1/6] driver core: allow stopping deferred probe after init Date: Mon, 9 Jul 2018 09:41:48 -0600 Message-Id: <20180709154153.15742-2-robh@kernel.org> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20180709154153.15742-1-robh@kernel.org> References: <20180709154153.15742-1-robh@kernel.org> Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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 Signed-off-by: Rob Herring --- v4: - Rebase on driver-core-next - Only allow base 10 for timeout v3: - Merged with timeout patch. - Clarify that deferred_probe_timeout is a debug option. - Drop the 'optional' param. The only user was pinctrl, so it has to handle that functionality. - Rename function to driver_deferred_probe_check_state - Added kerneldoc for driver_deferred_probe_check_state - Print a 1 line warning if stopping deferred probe after initcalls and a WARN on timeout. .../admin-guide/kernel-parameters.txt | 9 +++ drivers/base/dd.c | 59 +++++++++++++++++++ include/linux/device.h | 2 + 3 files changed, 70 insertions(+) -- 2.17.1 diff --git a/Documentation/admin-guide/kernel-parameters.txt b/Documentation/admin-guide/kernel-parameters.txt index efc7aa7a0670..e83ef4648ea4 100644 --- a/Documentation/admin-guide/kernel-parameters.txt +++ b/Documentation/admin-guide/kernel-parameters.txt @@ -804,6 +804,15 @@ Defaults to the default architecture's huge page size if not specified. + deferred_probe_timeout= + [KNL] Debugging option to set a timeout in seconds for + deferred probe to give up waiting on dependencies to + probe. Only specific dependencies (subsystems or + drivers) that have opted in will be ignored. A timeout of 0 + will timeout at the end of initcalls. This option will also + dump out devices still on the deferred probe list after + retrying. + dhash_entries= [KNL] Set number of hash buckets for dentry cache. 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); static LIST_HEAD(deferred_probe_active_list); static atomic_t deferred_trigger_count = ATOMIC_INIT(0); static struct dentry *deferred_devices; +static bool initcalls_done; /* * 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) } DEFINE_SHOW_ATTRIBUTE(deferred_devs); +static int deferred_probe_timeout = -1; +static int __init deferred_probe_timeout_setup(char *str) +{ + deferred_probe_timeout = simple_strtol(str, NULL, 10); + return 1; +} +__setup("deferred_probe_timeout=", deferred_probe_timeout_setup); + +/** + * driver_deferred_probe_check_state() - Check deferred probe state + * @dev: device to check + * + * Returns -ENODEV if init is done and all built-in drivers have had a chance + * to probe (i.e. initcalls are done), -ETIMEDOUT if deferred probe debug + * timeout has expired, or -EPROBE_DEFER if none of those conditions are met. + * + * Drivers or subsystems can opt-in to calling this function instead of directly + * returning -EPROBE_DEFER. + */ +int driver_deferred_probe_check_state(struct device *dev) +{ + if (initcalls_done) { + if (!deferred_probe_timeout) { + dev_WARN(dev, "deferred probe timeout, ignoring dependency"); + return -ETIMEDOUT; + } + dev_warn(dev, "ignoring dependency for device, assuming no driver"); + return -ENODEV; + } + return -EPROBE_DEFER; +} + +static void deferred_probe_timeout_work_func(struct work_struct *work) +{ + struct device_private *private, *p; + + deferred_probe_timeout = 0; + driver_deferred_probe_trigger(); + flush_work(&deferred_probe_work); + + list_for_each_entry_safe(private, p, &deferred_probe_pending_list, deferred_probe) + dev_info(private->device, "deferred probe pending"); +} +static DECLARE_DELAYED_WORK(deferred_probe_timeout_work, deferred_probe_timeout_work_func); + /** * deferred_probe_initcall() - Enable probing of deferred devices * @@ -235,6 +281,19 @@ static int deferred_probe_initcall(void) driver_deferred_probe_trigger(); /* Sort as many dependencies as possible before exiting initcalls */ flush_work(&deferred_probe_work); + initcalls_done = true; + + /* + * Trigger deferred probe again, this time we won't defer anything + * that is optional + */ + driver_deferred_probe_trigger(); + flush_work(&deferred_probe_work); + + if (deferred_probe_timeout > 0) { + schedule_delayed_work(&deferred_probe_timeout_work, + deferred_probe_timeout * HZ); + } return 0; } late_initcall(deferred_probe_initcall); diff --git a/include/linux/device.h b/include/linux/device.h index 575c5a35ece5..d2acc78d279b 100644 --- a/include/linux/device.h +++ b/include/linux/device.h @@ -339,6 +339,8 @@ struct device *driver_find_device(struct device_driver *drv, struct device *start, void *data, int (*match)(struct device *dev, void *data)); +int driver_deferred_probe_check_state(struct device *dev); + /** * struct subsys_interface - interfaces to device functions * @name: name of the device function