Received: by 10.192.165.148 with SMTP id m20csp5404449imm; Tue, 1 May 2018 14:32:03 -0700 (PDT) X-Google-Smtp-Source: AB8JxZrWUEG25P5HfYPDZZjoxWsjErVieRZMWEF4uwgRNLZ9t7Zi2TIAzKt/TF27hSOWP5s8chfY X-Received: by 2002:a17:902:70c4:: with SMTP id l4-v6mr15025582plt.174.1525210323732; Tue, 01 May 2018 14:32:03 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1525210323; cv=none; d=google.com; s=arc-20160816; b=n2ASWcDMQ6BQQXXi2mvwKvha1diibEuSD72mfuggBObrfViNngMkQ2AtQXEF+pcYHt sTXaFknSL1WIDgjOw9NPisNJ+VYQ3Wh/jHtSZ0AQ1gljl5hHRHm3hpXxDu0UMLjktkJp kJIN3+34iFD0aNGJkKSh5i1c5OA7dp8rkPNGoQfsqhZUyyEa/EdajsjyUBLlwmbsRYKd 6jKhcsZ8iS1KQuABhV1xDkKgLm35ArZV/iT8vDR+lkFz+kZyFrYe9lY36iDPMZmBngir ctYUBJAnV4ukbss8ufsgFLY5f2NtkooFouE2JIjTE2p89u+qkVLq7s4b7Bf3fViZG49a iQZQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:message-id:date:subject:cc:to:from :arc-authentication-results; bh=3cYFgsswRS+nQtL2/pArPQ1MvoY0ti57mnwCmOACsCY=; b=K+HhRKCBS+K3aPUtBRCsn8lh26EjAnAgmfQXglnsO4ypxP2YQuQZkTGU2B4QyIARpA QySNcheIn/3eS1QuUryyuD2lijfczHpKeC+BhX2yPS6MZ8uierUaYEwwdZyIMPCRgOWx h3WXkqC2ciDpwJSVw2iXcdrq8OjvKlFENc2PEiGAL3L9dYUFQyrBLmKozCsxAYXc5bhq gmautaALd/a2HC0EJXhqFZedOrZ1mQ5rMvgDyxlTWXXvg1VNRAAVvH8T0ABhn0UXhUYv eNCkhgup4L+6eMBzKl9t33kHtl49WBY9Wrzv3IKG/5XG8XARIHeO6S1tuKvQHMKryG/7 6g2Q== 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 Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id g2-v6si8480330pgu.212.2018.05.01.14.31.49; Tue, 01 May 2018 14:32:03 -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 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751360AbeEAVbV (ORCPT + 99 others); Tue, 1 May 2018 17:31:21 -0400 Received: from mail-oi0-f67.google.com ([209.85.218.67]:46460 "EHLO mail-oi0-f67.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751094AbeEAVbR (ORCPT ); Tue, 1 May 2018 17:31:17 -0400 Received: by mail-oi0-f67.google.com with SMTP id y15-v6so11170495oia.13; Tue, 01 May 2018 14:31:17 -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; bh=3cYFgsswRS+nQtL2/pArPQ1MvoY0ti57mnwCmOACsCY=; b=h70X7Ouhn7KpIUezfFR46xosvouFyElQj2yvcLe/3+TKfDs8JI6s8up91bxQGv/1dz LFB/z1ZUARVjGMEf3K7TEsBelYlLPozRL4WbemDIGNyka7uVwcLkSkjQ5xMa2WtvtFKH iET5/+PjeZBz+5ID23U9aM/WBmQop7H9D5bmAsKrJOgjkKTmEmVNiTSMyisjhMe9sCC+ q9N1YBWiZyjHIME9AFYhVPUXD2/8Kx6CWi5vHoOF9z6Apg1P/lsn3Hni7hAlPSyF63Wb Q1aRuswm5OfQlM6YZxeXa/efYSke1y4P7NF4MSsn2L5J+7hKe2YBDxa+yReD5l60uzPh DhhQ== X-Gm-Message-State: ALQs6tAqQNB5gbPpRlie5TVNhjWXk2cCLrwWsRgWJlpo8pG3nPAVRMS4 VG17GIWtSBvXGlumDQv+dcfFcy/GdA== X-Received: by 2002:aca:c609:: with SMTP id w9-v6mr10908504oif.308.1525210276429; Tue, 01 May 2018 14:31:16 -0700 (PDT) Received: from xps15.herring.priv (216-188-254-6.dyn.grandenetworks.net. [216.188.254.6]) by smtp.googlemail.com with ESMTPSA id r200-v6sm5974715oie.4.2018.05.01.14.31.15 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 01 May 2018 14:31:15 -0700 (PDT) From: Rob Herring To: linux-kernel@vger.kernel.org, devicetree@vger.kernel.org Cc: Greg Kroah-Hartman , Grant Likely , Linus Walleij , Mark Brown , Stephen Boyd , boot-architecture@lists.linaro.org, linux-arm-kernel@lists.infradead.org, Alexander Graf Subject: [RFC PATCH] driver core: make deferring probe forever optional Date: Tue, 1 May 2018 16:31:14 -0500 Message-Id: <20180501213114.20183-1-robh@kernel.org> X-Mailer: git-send-email 2.17.0 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. Unfortunately, this change breaks with modules as we have no way of knowing when modules are done loading. One possibility is to make this opt in or out based on compatible strings rather than at a subsystem level. Ideally this information could be extracted automatically somehow. OTOH, maybe the lists are pretty small. There's only a handful of subsystems that can be optional, and then only so many drivers in those that can be modules (at least for pinctrl, many drivers are built-in only). Cc: Alexander Graf Signed-off-by: Rob Herring --- This patch came out of a discussion on the ARM boot-architecture list[1] about DT forwards and backwards compatibility issues. There are issues with newer DTs breaking on older, stable kernels. Some of these are difficult to solve, but cases of optional devices not having kernel support should be solvable. I tested this on a RPi3 B with the pinctrl driver forced off. With this change, the MMC/SD and UART drivers can function without the pinctrl driver. Rob [1] https://lists.linaro.org/pipermail/boot-architecture/2018-April/000466.html drivers/base/dd.c | 16 ++++++++++++++++ drivers/pinctrl/devicetree.c | 2 +- include/linux/device.h | 2 ++ 3 files changed, 19 insertions(+), 1 deletion(-) diff --git a/drivers/base/dd.c b/drivers/base/dd.c index c9f54089429b..5848808b9d7a 100644 --- a/drivers/base/dd.c +++ b/drivers/base/dd.c @@ -226,6 +226,15 @@ void device_unblock_probing(void) driver_deferred_probe_trigger(); } + +int driver_deferred_probe_optional(void) +{ + if (initcalls_done) + return -ENODEV; + + return -EPROBE_DEFER; +} + /** * deferred_probe_initcall() - Enable probing of deferred devices * @@ -240,6 +249,13 @@ static int deferred_probe_initcall(void) /* 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); return 0; } late_initcall(deferred_probe_initcall); diff --git a/drivers/pinctrl/devicetree.c b/drivers/pinctrl/devicetree.c index b601039d6c69..096e52a5c506 100644 --- a/drivers/pinctrl/devicetree.c +++ b/drivers/pinctrl/devicetree.c @@ -120,7 +120,7 @@ static int dt_to_map_one_config(struct pinctrl *p, np_config); of_node_put(np_pctldev); /* OK let's just assume this will appear later then */ - return -EPROBE_DEFER; + return driver_deferred_probe_optional(); } /* If we're creating a hog we can use the passed pctldev */ if (pctldev && (np_pctldev == p->dev->of_node)) diff --git a/include/linux/device.h b/include/linux/device.h index 0059b99e1f25..8de920442bc1 100644 --- a/include/linux/device.h +++ b/include/linux/device.h @@ -332,6 +332,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_optional(void); + /** * struct subsys_interface - interfaces to device functions * @name: name of the device function -- 2.17.0