From patchwork Tue Jun 15 12:39:03 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Grzegorz Jaszczyk X-Patchwork-Id: 460514 Delivered-To: patch@linaro.org Received: by 2002:a02:735a:0:0:0:0:0 with SMTP id a26csp4251204jae; Tue, 15 Jun 2021 05:39:23 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwnT/3WK9i/wFCPVOEZzGev7iDJf2EYGVK9JWDe+5VzT9eE0yeqvsRGmGODrkPEaOGKMZp/ X-Received: by 2002:a17:906:606:: with SMTP id s6mr20382034ejb.206.1623760763118; Tue, 15 Jun 2021 05:39:23 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1623760763; cv=none; d=google.com; s=arc-20160816; b=IapZ70IljVnTx1CMOk+rKbnYIn21hfqCA7zSPIeZ0l2cSvSLOgtS4V3pLu6q3z1Sm1 WLzPfJ6vE/4oSKW21KtgDr8T3CGvairtBd4VbmIo0NnfARKsgBWHqLbYEpWysGi0heov dUCIvWOViyheJ1oD1KQYkmJcpd10+7JSEjPWqDH38xRj1cWDJ8Iwqc3oWxTZ9XPYwhEN CLgKy3rwVUC23BIVGWaiUAxI1OlmW6guR4b475uANDxLebqu55/WTXKDHa1ISUYvYbSe FXgWIInTKyJrfYsAczyNQJC+va/e9+hit2g1qBYnxeL/BCv47xNGjqpUE9gnF7wWLoOp IReA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=3pEsLcQ/8PBueEyiqA/kBMEdoALnX+fHc+Skgy5Wse4=; b=ap9IrYYk0iMw3InLfOqI9vGxeo4zfkLoPakbhVgNaJsVXVrW0uv5oObzsOoviHi/lP 8418jJwOcMLV0ozJTiemx9sIm6IF4fvgc8FyDwxDYZYe4Jn9FGGFLYlR25TFXFe6uO2c xG7sGgiaefxFwRxZtbPS3yCR6Ujj33Cq/T6DM7cqJN+MSUjdBiKoH9hFpZyqnsMOpKx9 Dk/ahkQwSYZ0D5RawlL2zxKyusuCxMzqSqZtdVupbNR87gPvMwx+K7z0+jnp25YcIwJX kW1QG7jcy0KAGUjLNDkoe2TCV83UtkOapw0iDUosP/2iQdtceIb89d6TpNJNoQjYrSS9 tn5A== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=Lo9Mxugj; spf=pass (google.com: domain of linux-watchdog-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-watchdog-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id d7si15016618ejo.445.2021.06.15.05.39.22 for ; Tue, 15 Jun 2021 05:39:23 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-watchdog-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=Lo9Mxugj; spf=pass (google.com: domain of linux-watchdog-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-watchdog-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230113AbhFOMlW (ORCPT ); Tue, 15 Jun 2021 08:41:22 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:42348 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229979AbhFOMlT (ORCPT ); Tue, 15 Jun 2021 08:41:19 -0400 Received: from mail-lj1-x231.google.com (mail-lj1-x231.google.com [IPv6:2a00:1450:4864:20::231]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 43426C061767 for ; Tue, 15 Jun 2021 05:39:14 -0700 (PDT) Received: by mail-lj1-x231.google.com with SMTP id 131so24863079ljj.3 for ; Tue, 15 Jun 2021 05:39:14 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=3pEsLcQ/8PBueEyiqA/kBMEdoALnX+fHc+Skgy5Wse4=; b=Lo9MxugjizgQOg5AcVDyMzvLOktI70lW6BqlHYqn00ELIrDqv7V6Ov0lEQBnp5sUVD MEPCbDZuIh8/nel5c0auOPPLNOU1H5uIjDc5vhxFBss4iCdhMUGN4yXFTkQTjBA5tCqL QSweT1vPd5k3r6/wIVz2sAPIKrLLhjUZoy0MdVzBIqa6GfCi7DXrgMbCvsglVKzATE/v U2ntj3TKpDWL/fdjmifyV7fEFa9yXls5YSBx9Z7CfljNUaX8KAokcCIBmkJWHmifwOxZ Zo5LCFEfPs+mr2AHHq8fv1wP4akbn6uuxYtycGEU+5Q2vfV0FpH0JafAhiXQ/edCTEyb YM3g== 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:mime-version:content-transfer-encoding; bh=3pEsLcQ/8PBueEyiqA/kBMEdoALnX+fHc+Skgy5Wse4=; b=AsZbzK3Kq9rguOazWooR8s1QTQpzOt8aMXgXT/MyklcA0tN7+doqsbO/2WnuBQyjbj qpONHO5vJ1uHwEvXJKDztjfSSSiiEwagK+i2+okAjk08VgcQqwqWddcpOgkr4hYrRTUk CVh4ZKDC5avufvQGN1CTHQHJ9KTI86pYX5aZetbXiHUSzRGywxDoKSWCfq+PIHcT4tdR KSnDbRCsnpSPBLBSEBvOb6C2+5Z3sEilyrLmbLbyX8y7/mIBhvF1zF+XDVZS7KpJj3DU oaQpotmMKR0uTivBEuo2uXLxZZxDaVS/fqP6K4DuSEnRi9NK/+hfIkUC0ZuZhluPDo9d Hb/A== X-Gm-Message-State: AOAM530Z/OuID5JS/kax0v176JRidaEGXp2DiT30i94Oh+srMxZGVuht wmTtsANY2orFO/GqFa2ZiDFWXQ== X-Received: by 2002:a2e:6c0e:: with SMTP id h14mr17848984ljc.267.1623760752547; Tue, 15 Jun 2021 05:39:12 -0700 (PDT) Received: from gilgamesh.lab.semihalf.net ([83.142.187.85]) by smtp.gmail.com with ESMTPSA id m12sm811418lfb.231.2021.06.15.05.39.11 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 15 Jun 2021 05:39:12 -0700 (PDT) From: Grzegorz Jaszczyk To: wim@linux-watchdog.org, linux@roeck-us.net, shawnguo@kernel.org Cc: linux-watchdog@vger.kernel.org, linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org, grzegorz.jaszczyk@linaro.org Subject: [PATCH 1/2] watchdog: introduce watchdog_dev_suspend/resume Date: Tue, 15 Jun 2021 14:39:03 +0200 Message-Id: <20210615123904.2568052-2-grzegorz.jaszczyk@linaro.org> X-Mailer: git-send-email 2.29.0 In-Reply-To: <20210615123904.2568052-1-grzegorz.jaszczyk@linaro.org> References: <20210615123904.2568052-1-grzegorz.jaszczyk@linaro.org> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-watchdog@vger.kernel.org The watchdog drivers often disable wdog clock during suspend and then enable it again during resume. Nevertheless the ping worker is still running and can issue low-level ping while the wdog clock is disabled causing the system hang. To prevent such condition introduce watchdog_dev_suspend/resume which can be used by any wdog driver and actually cancel ping worker during suspend and restore it back, if needed, during resume. Signed-off-by: Grzegorz Jaszczyk --- drivers/watchdog/watchdog_dev.c | 49 +++++++++++++++++++++++++++++++++ include/linux/watchdog.h | 2 ++ 2 files changed, 51 insertions(+) -- 2.29.0 Reported-by: kernel test robot diff --git a/drivers/watchdog/watchdog_dev.c b/drivers/watchdog/watchdog_dev.c index 2946f3a63110..3feca1567281 100644 --- a/drivers/watchdog/watchdog_dev.c +++ b/drivers/watchdog/watchdog_dev.c @@ -1219,6 +1219,55 @@ void __exit watchdog_dev_exit(void) kthread_destroy_worker(watchdog_kworker); } +int watchdog_dev_suspend(struct watchdog_device *wdd) +{ + struct watchdog_core_data *wd_data = wdd->wd_data; + int ret; + + if (!wdd->wd_data) + return -ENODEV; + + /* ping for the last time before suspend */ + mutex_lock(&wd_data->lock); + if (watchdog_worker_should_ping(wd_data)) + ret = __watchdog_ping(wd_data->wdd); + mutex_unlock(&wd_data->lock); + + if (ret) + return ret; + + /* + * make sure that watchdog worker will not kick in when the wdog is + * suspended + */ + hrtimer_cancel(&wd_data->timer); + kthread_cancel_work_sync(&wd_data->work); + + return 0; +} +EXPORT_SYMBOL_GPL(watchdog_dev_suspend); + +int watchdog_dev_resume(struct watchdog_device *wdd) +{ + struct watchdog_core_data *wd_data = wdd->wd_data; + int ret; + + if (!wdd->wd_data) + return -ENODEV; + + /* + * __watchdog_ping will also retrigger hrtimer and therefore restore the + * ping worker if needed. + */ + mutex_lock(&wd_data->lock); + if (watchdog_worker_should_ping(wd_data)) + ret = __watchdog_ping(wd_data->wdd); + mutex_unlock(&wd_data->lock); + + return ret; +} +EXPORT_SYMBOL_GPL(watchdog_dev_resume); + module_param(handle_boot_enabled, bool, 0444); MODULE_PARM_DESC(handle_boot_enabled, "Watchdog core auto-updates boot enabled watchdogs before userspace takes over (default=" diff --git a/include/linux/watchdog.h b/include/linux/watchdog.h index 9b19e6bb68b5..febfde3b1ff6 100644 --- a/include/linux/watchdog.h +++ b/include/linux/watchdog.h @@ -209,6 +209,8 @@ extern int watchdog_init_timeout(struct watchdog_device *wdd, unsigned int timeout_parm, struct device *dev); extern int watchdog_register_device(struct watchdog_device *); extern void watchdog_unregister_device(struct watchdog_device *); +int watchdog_dev_suspend(struct watchdog_device *wdd); +int watchdog_dev_resume(struct watchdog_device *wdd); int watchdog_set_last_hw_keepalive(struct watchdog_device *, unsigned int); From patchwork Tue Jun 15 12:39:04 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Grzegorz Jaszczyk X-Patchwork-Id: 460513 Delivered-To: patch@linaro.org Received: by 2002:a02:735a:0:0:0:0:0 with SMTP id a26csp4251119jae; Tue, 15 Jun 2021 05:39:18 -0700 (PDT) X-Google-Smtp-Source: ABdhPJyCQRLX+SPEDmKlrSJBwsLMhx4hkKMP+TkpESlhoZAPSGEVtdFyyHrb7Gv90du/a37Rkg0+ X-Received: by 2002:aa7:dd8d:: with SMTP id g13mr23742514edv.30.1623760758587; Tue, 15 Jun 2021 05:39:18 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1623760758; cv=none; d=google.com; s=arc-20160816; b=UyLe3H5qCO4G8rG02kcCDmqM/TvBzoKTyUmXkTNBbMUkGnE11mKk5sBsFpRLOxXUjW 7PKFYXV8DKS8VjwS6T2+6aAKaEvYP4cNxnEOEalRKGB1JS536+9mozPU8drtmK1qqbLw 1xoznmczDOpGA41vdgl3yl+ESfVvEkm6OTAYBeEJ/win/GMy+9iCOKnKOA99v5hr0eef sN981RZ1Q1L+6eYCnWmw7VjUbtFjjgIh157bbZ8FFEA5gMYiADV2HCuczPYRE/kPYe4V TPbZXiZyTzBe9UenGPzChU/k0WenEKStyUYYDfXmjVWxsGx53VvJbZmP8eGMtwq73gI0 kifA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=pyZKI2E4xTT0UFZR/tw10S5XdRfz+byZmgoSg9CzmTo=; b=UoNGx/xEvAz59HvDVhZdnR/NiXZsbBNUkaq21Fe8hMO333mZCR/leJSP0pOyE1BD3t WubAlV+2fkItjf7LxVJjoTAwZ5WaA1mD6vWxDV2qH219XZ9+JdcoksKeusVvHehsUaom i0IS/9SLIukSYesjjhORxBulnKUxTM0KGpvDcmk2yB3HKi6K8n6dG/vr/2RxR6l22Y6Y hsPN5RovmZ2yCRjgEA9T9Oe6tlOH4B4kjbAPklSpnyxRKv8OQTRKKftmd3WiNj9Sn1Ij iTi/FlwpyqvEQshbcNHxwjD38xce7/3ZIi5lJdSj5ffjHsXc1sMi07Ym5W8GrFj7Pb9j jXwg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=rIYK1gIK; spf=pass (google.com: domain of linux-watchdog-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-watchdog-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id f27si14762738ejl.134.2021.06.15.05.39.18 for ; Tue, 15 Jun 2021 05:39:18 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-watchdog-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=rIYK1gIK; spf=pass (google.com: domain of linux-watchdog-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-watchdog-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230089AbhFOMlV (ORCPT ); Tue, 15 Jun 2021 08:41:21 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:42356 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230052AbhFOMlU (ORCPT ); Tue, 15 Jun 2021 08:41:20 -0400 Received: from mail-lf1-x135.google.com (mail-lf1-x135.google.com [IPv6:2a00:1450:4864:20::135]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 301F4C061574 for ; Tue, 15 Jun 2021 05:39:15 -0700 (PDT) Received: by mail-lf1-x135.google.com with SMTP id f30so26828863lfj.1 for ; Tue, 15 Jun 2021 05:39:15 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=pyZKI2E4xTT0UFZR/tw10S5XdRfz+byZmgoSg9CzmTo=; b=rIYK1gIKo3lAxjw+6EGBH8HFSTz0+g9e1u0LDG0pFGprGw/dR5tKmTnXiZVF/mu0vd FaIvQbVu7aPUysVyTt/PDXrWBB5al/txEClciVkBCvn1wy5JzYeA2qvIIKRKZl5FMk++ uwtt0d0sT3JKxIp63hf9AeAH5JhiXZUdB/UA3c3p1xlKKH4bW2e6BdPav0veoBYdrFUr rIzOqkvh8F1rYn6JB1DHFpZmoiHBOLPycUCqg6IM8leMWedzLCYb63Fz/ZxG97ged74T 30AEpzHKU2nuZ2bcGGEJ5zK1yAY5EmVPZsA7Nj2cjQ0jPlBC/KPAx7/+XGIohZY+bzVt 5NrA== 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:mime-version:content-transfer-encoding; bh=pyZKI2E4xTT0UFZR/tw10S5XdRfz+byZmgoSg9CzmTo=; b=aWVuyTBBQ6jQ4qMLSWacDB5YV4rDl/wwgv2CQXKS88ceoreXV8hAAGX7FujBLBpxFM GkLi4GPIIBTxD/1X5lt8smRBEF/bnNJOY22qoYlz3JZiup4nqcrpu0966495agPOnuVd /xfhk6Ux/4wzkT7NX1v68WPyxXqA0Ctn2Asm731MZD4f+f6+ihpdIBLoZoAzL7HTy3HY lhfQhwzRHa/nAjCb28Gx/h3tNHxqjnFS7p1X1IEO7KHsx59Ow88E5OjGQrU8hQxSk0nT OtxDWfVAHHeEIQjrcwbjmpBM9gB4mS0Cor+f4fXvicjl6FCy6Z8WCvUYdp9v8sCB7r0c bf8w== X-Gm-Message-State: AOAM532WnHHBKUeJ4okfHNnJYWEvJCEj7CJRcjDQAIhEGKPhPWp+44N8 74tdylpNKJR1zrlDd2tO/HX+yw== X-Received: by 2002:a19:6a0b:: with SMTP id u11mr5558470lfu.269.1623760753465; Tue, 15 Jun 2021 05:39:13 -0700 (PDT) Received: from gilgamesh.lab.semihalf.net ([83.142.187.85]) by smtp.gmail.com with ESMTPSA id m12sm811418lfb.231.2021.06.15.05.39.12 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 15 Jun 2021 05:39:13 -0700 (PDT) From: Grzegorz Jaszczyk To: wim@linux-watchdog.org, linux@roeck-us.net, shawnguo@kernel.org Cc: linux-watchdog@vger.kernel.org, linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org, grzegorz.jaszczyk@linaro.org, Michal Koziel Subject: [PATCH 2/2] watchdog: imx2_wdg: notify wdog subsystem about wdog suspend/resume Date: Tue, 15 Jun 2021 14:39:04 +0200 Message-Id: <20210615123904.2568052-3-grzegorz.jaszczyk@linaro.org> X-Mailer: git-send-email 2.29.0 In-Reply-To: <20210615123904.2568052-1-grzegorz.jaszczyk@linaro.org> References: <20210615123904.2568052-1-grzegorz.jaszczyk@linaro.org> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-watchdog@vger.kernel.org Suspend routine disables wdog clk. Nevertheless, the watchdog subsystem is not aware of that and can still try to ping wdog through watchdog_ping_work. In order to prevent such condition and therefore prevent from system hang (caused by the wdog register access issued while the wdog clock is disabled) take advantage of watchdog_dev_suspend/resume routines which will take care of watchdog ping worker cancel and restore. Additionally remove hw ping from suspend/resume since it will be issued by watchdog_dev_suspend/resume routines. Signed-off-by: Michal Koziel Signed-off-by: Grzegorz Jaszczyk --- drivers/watchdog/imx2_wdt.c | 20 +++++++++++++++----- 1 file changed, 15 insertions(+), 5 deletions(-) -- 2.29.0 diff --git a/drivers/watchdog/imx2_wdt.c b/drivers/watchdog/imx2_wdt.c index b84f80f7d342..24e3a4d2b529 100644 --- a/drivers/watchdog/imx2_wdt.c +++ b/drivers/watchdog/imx2_wdt.c @@ -348,6 +348,17 @@ static int __maybe_unused imx2_wdt_suspend(struct device *dev) { struct watchdog_device *wdog = dev_get_drvdata(dev); struct imx2_wdt_device *wdev = watchdog_get_drvdata(wdog); + int ret; + + /* + * Before disabling clk we need to notify wdog subsystem that HW wdog + * is being suspended. This e.g. prevents watchdog_ping_work to fire + * when the clk is disabled, which would result with system hang caused + * by wdog register access while wdog clock is disabled. + */ + ret = watchdog_dev_suspend(wdog); + if (ret) + return ret; /* The watchdog IP block is running */ if (imx2_wdt_is_running(wdev)) { @@ -356,7 +367,6 @@ static int __maybe_unused imx2_wdt_suspend(struct device *dev) * during resume. */ __imx2_wdt_set_timeout(wdog, IMX2_WDT_MAX_TIME); - imx2_wdt_ping(wdog); } clk_disable_unprepare(wdev->clk); @@ -383,12 +393,12 @@ static int __maybe_unused imx2_wdt_resume(struct device *dev) */ imx2_wdt_setup(wdog); } - if (imx2_wdt_is_running(wdev)) { + if (imx2_wdt_is_running(wdev)) imx2_wdt_set_timeout(wdog, wdog->timeout); - imx2_wdt_ping(wdog); - } - return 0; + ret = watchdog_dev_resume(wdog); + + return ret; } static SIMPLE_DEV_PM_OPS(imx2_wdt_pm_ops, imx2_wdt_suspend,