From mboxrd@z Thu Jan 1 00:00:00 1970 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=-13.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,URIBL_BLOCKED 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 38AF3C48BE5 for ; Wed, 16 Jun 2021 14:01:32 +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 EC572601FC for ; Wed, 16 Jun 2021 14:01:31 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org EC572601FC 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:Cc:To:Subject:Message-ID:Date:From: In-Reply-To:References:MIME-Version:Reply-To:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=I1MPVx7rGXmyTqpG6uwMipTc59hJXzSV4VpWtEMMJ/k=; b=ybRgcBsOo81Z4V 7Lh45puscOhjPfP43n2Px4LkGXrEODZ3wEo2T2G0lPNNbvY3Ws7yn1stTC5TTJfyQ1d+ZqV4a41G4 JI3mAG6o0gGMNnVU9Y4uxwIRs+SaURSaW9baxt0AIvkw80jI/S8LmPpVI8NZqQPrFWiJJ2NXy3oYM 1FSWZYe6wuF705NdO0iLpfQTvYk0ey5GI4B5PUiG5Z71jpgXILWI2ZQQHdIBLoV8Q46cpkAIfAVyn 2ZNp3tPaEau7VfaMSbi2H86SeFNjDESXP9UrkkYnUaDs0vcNecO5KBeACBZ3RzCmjd1eFeYxIAsiZ AkAkwnf6RMtST+dktQXw==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.94.2 #2 (Red Hat Linux)) id 1ltW50-006bgm-Bq; Wed, 16 Jun 2021 13:59:42 +0000 Received: from mail-qv1-xf2a.google.com ([2607:f8b0:4864:20::f2a]) by bombadil.infradead.org with esmtps (Exim 4.94.2 #2 (Red Hat Linux)) id 1ltW4u-006bd2-FO for linux-arm-kernel@lists.infradead.org; Wed, 16 Jun 2021 13:59:38 +0000 Received: by mail-qv1-xf2a.google.com with SMTP id r19so1577618qvw.5 for ; Wed, 16 Jun 2021 06:59:35 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=QvTscpdtSME1zV++0MyBEAQ2RjASk3pBKLKm6ayPws4=; b=qukkYzbGBwvPyl927hREHi0xY6LXwNYfufoai+v0kddN+dKsee5WLPtX3pP42FJiA3 KfCwb6PeCt/KchPWeRw3b9lTs3KT62HFaQ4TjGqHD+7hyRXXyMwwDAHiusXlp98fcrsQ RgtWA1oaQe41CuZZQSl0wil2t3WPcC5e05Xo/ck74I8SuxfwM2kZgbJE1VtSagn3HPDw Wlo3SpxKgIJIoJ8mDvooYsL1zkPV/IJwaUD+uuMaf1DEendUkjv8kKA59chDA1xWxAr7 jNqmC2Zfwf9OX0M49722N54VJZlpj7ZaHYjD/N4F6WCdiU+0cOs6V4km7BVPLx7dZaio 6N6A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=QvTscpdtSME1zV++0MyBEAQ2RjASk3pBKLKm6ayPws4=; b=YHkpXoCKqRyR+UbqsiGt40d46IQUei1GP4gxoE0/k7i5XYHvQch+Yw6lxmCqrkkXx8 LaoKRskbHTGSSHDWI3Imq25g7xNJi1aNm8Tr/z0r8CNn/zizSCTYwQohTBXgT3Ufppow LO4S9JZt+A/8Kve+LzY+BsBfDYq/E35S8ZcJCpdDTPQVe85C4gjZpdmFcJHaj3+TJq8q 7DyhT+4tnMXowck42sfO2UVmfWh8hTYvpoMy4hphOx5r0pq6ak4ht9P6a5YFtxF254zE Bamlp3I/nvGfMFQuK6KcvGaxkXVdAL7urR9oS4h3nHJmH/Pz7m0v5iKWNSZS2BUaXsop Lrng== X-Gm-Message-State: AOAM532Zg8JFOjDXlC5b9vNuQAfUBF104SMZinaaQIGkDNv57I/oeAth b5W2z8g76J2Irhd7sqUBscoeuS/K0th3hruB7j68RQ== X-Google-Smtp-Source: ABdhPJwoQynC4K5L9lstAHzUHxhDOkpNlpy3ScLRAXogEJRDeiwMs/ngDax65rzow6AoBBLs0xl0UZDndFVNMH1CqpE= X-Received: by 2002:a05:6214:20c4:: with SMTP id 4mr147960qve.1.1623851974357; Wed, 16 Jun 2021 06:59:34 -0700 (PDT) MIME-Version: 1.0 References: <20210615123904.2568052-1-grzegorz.jaszczyk@linaro.org> <20210615123904.2568052-2-grzegorz.jaszczyk@linaro.org> <20210615141803.GA957871@roeck-us.net> In-Reply-To: <20210615141803.GA957871@roeck-us.net> From: Grzegorz Jaszczyk Date: Wed, 16 Jun 2021 15:59:23 +0200 Message-ID: Subject: Re: [PATCH 1/2] watchdog: introduce watchdog_dev_suspend/resume To: Guenter Roeck Cc: wim@linux-watchdog.org, shawnguo@kernel.org, linux-watchdog@vger.kernel.org, linux-arm-kernel , linux-kernel@vger.kernel.org X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20210616_065936_595058_68F382E0 X-CRM114-Status: GOOD ( 33.16 ) 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: , Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org On Tue, 15 Jun 2021 at 16:18, Guenter Roeck wrote: > > On Tue, Jun 15, 2021 at 02:39:03PM +0200, Grzegorz Jaszczyk wrote: > > 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. > > > > I'll have to look into this further, but I don't think this is the correct > solution. Most likely the watchdog core needs to have its own independent > suspend/resule functions and suspend the high resolution timer on > suspend and restore it on resume. This may require an additional flag > to be set by drivers to indicate that the timer should be stopped on > suspend. That makes sense - thank you for your suggestion. I think I could register a pm notifier in the watchdog core when the new e.g. WDOG_STOP_PING_ON_SUSPEND status flag will be set by the driver and actually call watchdog_dev_suspend/resume from the notifier callback. Please let me know if you see any other issue with this solution, if not I will post v2. Thank you in advance, Grzegorz > > > 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 > > _______________________________________________ linux-arm-kernel mailing list linux-arm-kernel@lists.infradead.org http://lists.infradead.org/mailman/listinfo/linux-arm-kernel