From patchwork Thu Oct 8 16:57:07 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Grygorii Strashko X-Patchwork-Id: 7354271 Return-Path: X-Original-To: patchwork-linux-pm@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork1.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.136]) by patchwork1.web.kernel.org (Postfix) with ESMTP id A81209F1B9 for ; Thu, 8 Oct 2015 16:57:24 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 9793C207E8 for ; Thu, 8 Oct 2015 16:57:23 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 57D9120437 for ; Thu, 8 Oct 2015 16:57:22 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S964931AbbJHQ5U (ORCPT ); Thu, 8 Oct 2015 12:57:20 -0400 Received: from bear.ext.ti.com ([192.94.94.41]:57641 "EHLO bear.ext.ti.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S964922AbbJHQ5T (ORCPT ); Thu, 8 Oct 2015 12:57:19 -0400 Received: from dlelxv90.itg.ti.com ([172.17.2.17]) by bear.ext.ti.com (8.13.7/8.13.7) with ESMTP id t98GvCii003633; Thu, 8 Oct 2015 11:57:12 -0500 Received: from DLEE71.ent.ti.com (dlee71.ent.ti.com [157.170.170.114]) by dlelxv90.itg.ti.com (8.14.3/8.13.8) with ESMTP id t98GvBFb010872; Thu, 8 Oct 2015 11:57:11 -0500 Received: from dflp32.itg.ti.com (10.64.6.15) by DLEE71.ent.ti.com (157.170.170.114) with Microsoft SMTP Server id 14.3.224.2; Thu, 8 Oct 2015 11:57:11 -0500 Received: from localhost (ileax41-snat.itg.ti.com [10.172.224.153]) by dflp32.itg.ti.com (8.14.3/8.13.8) with ESMTP id t98GvBDB028917; Thu, 8 Oct 2015 11:57:11 -0500 From: Grygorii Strashko To: Greg Kroah-Hartman , "Rafael J. Wysocki" , Alan Stern CC: Pavel Machek , Len Brown , , , Grygorii Strashko , Thierry Reding Subject: [PATCH 2/2] PM / sleep: prohibit devices probing during suspend/hibernation Date: Thu, 8 Oct 2015 11:57:07 -0500 Message-ID: <1444323427-6822-3-git-send-email-grygorii.strashko@ti.com> X-Mailer: git-send-email 2.5.1 In-Reply-To: <1444323427-6822-1-git-send-email-grygorii.strashko@ti.com> References: <1444323427-6822-1-git-send-email-grygorii.strashko@ti.com> MIME-Version: 1.0 Sender: linux-pm-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-pm@vger.kernel.org X-Spam-Status: No, score=-6.9 required=5.0 tests=BAYES_00, RCVD_IN_DNSWL_HI, T_RP_MATCHES_RCVD, UNPARSEABLE_RELAY autolearn=unavailable version=3.3.1 X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on mail.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP It is unsafe [1] if probing of devices will happen during suspend or hibernation and system behavior will be unpredictable in this case. So, lets prohibit device's probing in dpm_prepare() and defer their probing instead. The normal behavior will be restored in dpm_complete(). This patch introduces new DD core API device_defer_all_probes(bool enable) to enable/disable probing of devices: if @enable = true It will disable probing of devices and defer their probes. otherwise It will restore normal behavior and trigger re-probing of deferred devices. [1] https://lkml.org/lkml/2015/9/11/554 Cc: Alan Stern Cc: Rafael J. Wysocki Cc: Thierry Reding Signed-off-by: Grygorii Strashko --- drivers/base/base.h | 1 + drivers/base/dd.c | 35 ++++++++++++++++++++++++++++++++++- drivers/base/power/main.c | 13 +++++++++++++ 3 files changed, 48 insertions(+), 1 deletion(-) diff --git a/drivers/base/base.h b/drivers/base/base.h index 1782f3a..6c9684b 100644 --- a/drivers/base/base.h +++ b/drivers/base/base.h @@ -131,6 +131,7 @@ extern void device_remove_groups(struct device *dev, extern char *make_class_name(const char *name, struct kobject *kobj); extern int devres_release_all(struct device *dev); +extern void device_defer_all_probes(bool enable); /* /sys/devices directory */ extern struct kset *devices_kset; diff --git a/drivers/base/dd.c b/drivers/base/dd.c index 98de1a5..d600c14 100644 --- a/drivers/base/dd.c +++ b/drivers/base/dd.c @@ -55,6 +55,13 @@ static struct workqueue_struct *deferred_wq; static atomic_t deferred_trigger_count = ATOMIC_INIT(0); /* + * In some cases, like suspend to RAM or hibernation, It might be reasonable + * to prohibit probing of devices as it could be unsafe. + * Once defer_all_probes is true all drivers probes will be forcibly deferred. + */ +static bool defer_all_probes; + +/* * deferred_probe_work_func() - Retry probing devices in the active list. */ static void deferred_probe_work_func(struct work_struct *work) @@ -172,6 +179,26 @@ static void driver_deferred_probe_trigger(void) } /** + * device_defer_all_probes() - Enable/disable probing of devices + * @enable: Enable/disable probing of devices + * + * if @enable = true + * It will disable probing of devices and defer their probes. + * otherwise + * It will restore normal behavior and trigger re-probing of deferred + * devices. + */ +void device_defer_all_probes(bool enable) +{ + defer_all_probes = enable; + if (enable) + /* sync with probes to avoid any races. */ + wait_for_device_probe(); + else + driver_deferred_probe_trigger(); +} + +/** * deferred_probe_initcall() - Enable probing of deferred devices * * We don't want to get in the way when the bulk of drivers are getting probed. @@ -277,9 +304,15 @@ static DECLARE_WAIT_QUEUE_HEAD(probe_waitqueue); static int really_probe(struct device *dev, struct device_driver *drv) { - int ret = 0; + int ret = -EPROBE_DEFER; int local_trigger_count = atomic_read(&deferred_trigger_count); + if (defer_all_probes) { + dev_dbg(dev, "Driver %s force probe deferral\n", drv->name); + driver_deferred_probe_add(dev); + return ret; + } + atomic_inc(&probe_count); pr_debug("bus: '%s': %s: probing driver %s with device %s\n", drv->bus->name, __func__, drv->name, dev_name(dev)); diff --git a/drivers/base/power/main.c b/drivers/base/power/main.c index 1710c26..98c1da36 100644 --- a/drivers/base/power/main.c +++ b/drivers/base/power/main.c @@ -963,6 +963,9 @@ void dpm_complete(pm_message_t state) } list_splice(&list, &dpm_list); mutex_unlock(&dpm_list_mtx); + + /* Allow device probing and trigger re-probing of deferred devices */ + device_defer_all_probes(false); trace_suspend_resume(TPS("dpm_complete"), state.event, false); } @@ -1624,6 +1627,16 @@ int dpm_prepare(pm_message_t state) trace_suspend_resume(TPS("dpm_prepare"), state.event, true); might_sleep(); + /* Give a chance for the known devices to complete their probing. */ + wait_for_device_probe(); + /* + * It is unsafe if probing of devices will happen during suspend or + * hibernation and system behavior will be unpredictable in this case. + * So, lets prohibit device's probing here and defer their probes + * instead. The normal behavior will be restored in dpm_complete(). + */ + device_defer_all_probes(true); + mutex_lock(&dpm_list_mtx); while (!list_empty(&dpm_list)) { struct device *dev = to_device(dpm_list.next);