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: 12322531 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-16.9 required=3.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER, INCLUDES_PATCH,MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,USER_AGENT_GIT autolearn=unavailable autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 97377C48BE5 for ; Tue, 15 Jun 2021 17:36:14 +0000 (UTC) Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 5ED04613E4 for ; Tue, 15 Jun 2021 17:36:14 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 5ED04613E4 Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=linaro.org Authentication-Results: mail.kernel.org; spf=none smtp.mailfrom=linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender: Content-Transfer-Encoding:Content-Type:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:MIME-Version:References:In-Reply-To: Message-Id:Date:Subject:Cc:To:From:Reply-To:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=iyQZfUkY6khRCIVQdW4CIvJ13+em8oczSjROhTcOI0k=; b=kqfI8r/nTVugyD K4WcEa3lk+yo+0KRGWKctXGGhgxtxC/ADipmu+yvQ+bQtgD7XWiJSq3F0gkKFu0OYESaU42/q23vd gy4rV50Tj0PcBT9CEBNg9ZzuohsKwXkcYcgCmopl+UNw7xkWNPOy8RGJ/thBDFg2cayQNwPkjEtXx 1XXIv/i+Mi2LJduTi3HgjnqnQEh2atHWL6Z26QzUROw+lBK7oLV/hLGjlxUmkhfw+D1RV3Hf9ytcq ARU3/UleIzpYL0cYXxsRTA3jLNnr4/P2sVTMD6KXTwAiZA36OeqUlJMWoclJtJih26jotOh5mcym6 DQT6U+JPguc3ytbr9s8g==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.94.2 #2 (Red Hat Linux)) id 1ltCwN-001lcG-Qs; Tue, 15 Jun 2021 17:33:32 +0000 Received: from desiato.infradead.org ([2001:8b0:10b:1:d65d:64ff:fe57:4e05]) by bombadil.infradead.org with esmtps (Exim 4.94.2 #2 (Red Hat Linux)) id 1lt9DM-000ByJ-D6 for linux-arm-kernel@bombadil.infradead.org; Tue, 15 Jun 2021 13:34:48 +0000 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=desiato.20200630; h=Content-Transfer-Encoding:MIME-Version :References:In-Reply-To:Message-Id:Date:Subject:Cc:To:From:Sender:Reply-To: Content-Type:Content-ID:Content-Description; bh=3pEsLcQ/8PBueEyiqA/kBMEdoALnX+fHc+Skgy5Wse4=; b=dg53XdoO1HeDdPWc+Vaxg0sIyN 5Vi4YRyfW4KZR9exfyGBSnJ6sbtL/U5C3P5WBqtiFtd09RuSk7HqCTpA9OY7FA9a2VFG+GBlI8Q0+ cPeLUox1LzRH52BEF4YOxB6nftSHEu9NT4Sjv5/7Mw3ahtnT1lOPsJFWjxp4aoSEDpF1kldR5QRHa CMm9c5LjhsZQs2Ydsyp5+ALRJYC4NMuA6poRbWwY9c7eg0LctJlPxOR4+NRxTPVMr0Ek0uMrayeKE mzqX4KMZaDksbQXGdLpnYHcTau7QwBIGaXEhG6EZTLz/5sNXYO839VztCMuUumygD1i8mY1gxTzJJ IqCywPXA==; Received: from mail-lj1-x233.google.com ([2a00:1450:4864:20::233]) by desiato.infradead.org with esmtps (Exim 4.94.2 #2 (Red Hat Linux)) id 1lt8LV-007t3A-Re for linux-arm-kernel@lists.infradead.org; Tue, 15 Jun 2021 12:39:20 +0000 Received: by mail-lj1-x233.google.com with SMTP id d13so12662420ljg.12 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=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=sL7dyrUYr0JvS1rFv3oiPfT6bBI7CSmFYbdHXRYovAx42jby27qgnwyN7qUSHSrrZc PI+bJttpndSm8DBFThFcPSe96ZU3dTrKajZ+toV931nS6WhDtm0McnV+Razz801yUSRi kfKGDDexzHRarBLSprVbvwalT1aZTMm/K5S0bwWYDboV6oQrK7rVysXp3VMXUINZHOEM 11ctN3GfCZ2Bh8RX8Bj9DDg9ep8pObBT+mPM+cDeloDZ3QDt7uTeVxoyRZ9LepowZCe7 LWyvMEdE5IkjFGggV6E4Tftzp6dil0iHkpD7wM7g3TtfJ6iP+04cinwJkMecYaog7CEF o6ww== X-Gm-Message-State: AOAM532z0MfgDb6/TPKoMbU3SuqffqblxGaZdnLoCthsfPYdrxkAUDmC LNfDS0pQxR3DjCvfWaRZ9KiOFw== X-Google-Smtp-Source: ABdhPJwRsf+yNOWqXkRPrg7C6+J4ziUSxP9L+WvAbfpgF/03zjoPDhYxMZParIYV9z2a3UBO/FrilQ== 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 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20210615_133916_695672_3D733328 X-CRM114-Status: GOOD ( 15.23 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.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 Reported-by: kernel test robot --- 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);