Received: by 2002:a05:6a10:206:0:0:0:0 with SMTP id 6csp3644341pxj; Tue, 15 Jun 2021 05:41:04 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwvcAHtC0Zaejg1/Qxf1qKDhIPnb50FRWAecm80RCt86Bs60Kr7G209NfD5qsSWZ82ieagG X-Received: by 2002:a05:6602:1810:: with SMTP id t16mr17896848ioh.48.1623760864712; Tue, 15 Jun 2021 05:41:04 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1623760864; cv=none; d=google.com; s=arc-20160816; b=X04AlhfkefWQp1Oy7YTSP+p5JSczgFGs01MYQWYxYR6o4hCIWFJF8cU+O/G69eyDPw Jp0z88Quo7mvJg/6Tj0SCtO8kRTuP7JHxYQRr/ex00ZG5O0J45ZT9pcwvgwAHi34N/nd 9xA9UPHe3sUjq5zKP22I/KbPik6cnF6dIvtW7QWgWsuKZCwLpiX+DaWW6mQXa2dtEGuE 1mYCU/CfXMJKT5WGZr37EfEL9Y9wOBW+F6jZ3Fkryf2NBcPfL637M//FVVWgjecKNN0E hXI4Bvk8lOlJD5Un04HGsTtbSBU+CBHVp6R0nIrapB7HF6vFRf9N59jGOG/qmzARx2bR tzkA== 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=mCQV6HFgNE0pUdy53J60tsPDdaRJ25dx+ot7H8wMb+jwHeMrCeDv3Cw82wIHhin2IV IKe7hK8WbM1HcOvsUwvzSLQrq5EtQw1XVPqSTrIltM2S4DNLUVoffHeYEkMM8L2ymJoh GB2pu/ZFBlLEoXpIxTmHSbCmYvIFhVUsYI6QSzv/fWRGJmL4G5dOgu3Umt1F45WuZw98 Am+6VE30vVzODPKNCh6kmV9lAaGugUB/cmN5ksD9cpX93YRxNWVqcrrlXeONooJ4rTod B9JD8iMYfqnN6ZiCLPWzKgDDH+WbkjHZzPC1HyqLqxZ+NkYbKrAXi3LUJRVGArqcx160 RGlg== 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-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-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 q9si21940852ilo.56.2021.06.15.05.40.51; Tue, 15 Jun 2021 05:41:04 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-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-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-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 S230120AbhFOMlX (ORCPT + 99 others); Tue, 15 Jun 2021 08:41:23 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:42350 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229983AbhFOMlT (ORCPT ); Tue, 15 Jun 2021 08:41:19 -0400 Received: from mail-lj1-x235.google.com (mail-lj1-x235.google.com [IPv6:2a00:1450:4864:20::235]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 45FD9C0617AF for ; Tue, 15 Jun 2021 05:39:14 -0700 (PDT) Received: by mail-lj1-x235.google.com with SMTP id s22so24807805ljg.5 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=F9kIIDD1OJhEMFMAoq6ZdSzcr4nzUGsxEad4tTYzd4U4WcjXicl1HFO0GxvTntNYul CF3RZeAVBu/eSDa52W8g+wihsW1TlG2CJBPtT+4YQ/VZZUFBwAup3/1wmXNrl9STIYsJ gIJ05WT09to/olQQVQld/pRuNnuJWDNWjpnAHymdIs1DtFQgDF0kDNCDhfJhdD2NPoqy zAFFRQdmQLkpSGTNdPSYGyRbE+Vfg4tqY3n+WQaFQjbbZHQ2U9Es+y+kijrrdFywcUX2 i7ZWhxHJTkk27OVlwkcXttXzzpIsPtdwynmkLJcMopq9aV2/qoBPOzS7LoC4kC6Qh6Fq VxFg== X-Gm-Message-State: AOAM5316lhcpQg7JLuV41dA4Pj9joC0IiBE/EBuO5CPIL2Wl2p1kdXkC /HFLKeMkUJNHyHYGGJgBsbitk+sUFB+k7A== 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 Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@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(+) 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); -- 2.29.0