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=-14.4 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 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 734CEC43461 for ; Wed, 12 May 2021 14:17:40 +0000 (UTC) Received: from desiato.infradead.org (desiato.infradead.org [90.155.92.199]) (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 CC5A6613E6 for ; Wed, 12 May 2021 14:17:39 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org CC5A6613E6 Authentication-Results: mail.kernel.org; dmarc=none (p=none dis=none) header.from=roeck-us.net 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=desiato.20200630; h=Sender:Content-Transfer-Encoding :Content-Type:List-Subscribe:List-Help:List-Post:List-Archive: List-Unsubscribe:List-Id:In-Reply-To:MIME-Version:References:Message-ID: Subject:Cc:To:From:Date:Reply-To:Content-ID:Content-Description:Resent-Date: Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Owner; bh=bPJFaIkUsO77WBpJgpm95K+kklvMlBkX7tPmw6U4kUg=; b=I0odNgtpFeJCvTdRUUrcUruh/ CkYQ+1Iik3i5M48pYLqc9HdZDfaKHj5mNmCraMr+Do4kuudERJUjGMq3k9E4b2CHj+IYTI+TpPnTk licJhBhMc7yvfxGEIxLcBU1jGqnJYrjAaCpDLtNWMTv2vA4ZcK7Kwf4ne3iefWNq4FQdq6fqdp7my YsL7xeuDoj9uposayo8kDen94APHY76+2IhNZIJ1pTIPkF3b7IE9goK04Cx1bAFdSt+CHLSeTpeLK /MPfcU7/Ze0FrBrzLoQxFTupxeVjJbqgYYz1TLvlFkbKHdZK9epItzNzh24CQx0zgpWS+z9zCrFTi b4SIutnHw==; Received: from localhost ([::1] helo=desiato.infradead.org) by desiato.infradead.org with esmtp (Exim 4.94 #2 (Red Hat Linux)) id 1lgpdL-002zwr-Ua; Wed, 12 May 2021 14:14:44 +0000 Received: from bombadil.infradead.org ([2607:7c80:54:e::133]) by desiato.infradead.org with esmtps (Exim 4.94 #2 (Red Hat Linux)) id 1lgpdJ-002zwd-K9 for linux-arm-kernel@desiato.infradead.org; Wed, 12 May 2021 14:14:41 +0000 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=bombadil.20210309; h=In-Reply-To:Content-Type:MIME-Version :References:Message-ID:Subject:Cc:To:From:Date:Sender:Reply-To: Content-Transfer-Encoding:Content-ID:Content-Description; bh=h/2v8S6FtY6HcuVUHrB5RBON1H72Nf5qzZh/OC/rNz0=; b=W7jAxqv5Slgrz6cuzJOpruSQsJ ygOM9juGdN7Gmd2mnIcf8o/Xau1yqao5ADKpkJTCZYknTKeB3eU758mUvswyZW62e460YQMJInsRc CFta2UbwoE3sxyCFrTVTefDFz+f0pj001eMqfRg2lnnIal1AdrWlVblaKqHr3pZbUFVuLO8ysStMW olOLbabPBWhdHMPNL8C5aNlqDjQSGrLx2izwn/JxICtvWHya/m5JOG28NEmVtnX0K636C6xtSCFiT e9skCqfeeTSXn4JwjyAXp23JXOgg0hYsrozJyGGS8BuCum4yjndC4a2FJwQLozE67UbCRGaYqZMJ6 xAnBVrMw==; Received: from mail-ot1-x330.google.com ([2607:f8b0:4864:20::330]) by bombadil.infradead.org with esmtps (Exim 4.94 #2 (Red Hat Linux)) id 1lgpdG-00ARBT-Kb for linux-arm-kernel@lists.infradead.org; Wed, 12 May 2021 14:14:40 +0000 Received: by mail-ot1-x330.google.com with SMTP id q7-20020a9d57870000b02902a5c2bd8c17so20678784oth.5 for ; Wed, 12 May 2021 07:14:38 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=sender:date:from:to:cc:subject:message-id:references:mime-version :content-disposition:in-reply-to; bh=h/2v8S6FtY6HcuVUHrB5RBON1H72Nf5qzZh/OC/rNz0=; b=notmZQ44aCKDeGmL+DT6ijYkyZArYwy/nen6vTCnOMft2JsPO40HrthjgJ7I3gyUIi AyepODpe/c9EAWPTw14AQFpzpVOpKoi/m8tyTezJLRcWdOxCWip58J9yCDbM7DkxXRlv 1Ez9PWcv6o8zwEhhA1RAaB6DSzqIo2Zml5kEPQOpJPUpOmvHq3tP3XKIupcPS7gA0dVu 2NrQf2Zgz8+QymIYvvqZywJQOqmWFqFBw5VVfmRsiW88vcWiw3UdHwo9PQcBoc+JvcvW cvMJkrNDUqRon83mJ+BtyCg0X4fMxsTOZTGhMfKcGH0cVx+Acxa90MgyjU+dmradJhPj HV8Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:sender:date:from:to:cc:subject:message-id :references:mime-version:content-disposition:in-reply-to; bh=h/2v8S6FtY6HcuVUHrB5RBON1H72Nf5qzZh/OC/rNz0=; b=p3F/MQmvKU4PMgYBzdqhZgrj434vQOOwXyHX2854kMWtN/jN7UHFzUIDr7tkTI951O vkdnNgPsZFe7Lmx9UZb9rEyaw2dJzjJbBxmeSgNuRA67qQ6E+HTFRUpI3QFW3bZRtg0/ HHEcdVZ7+M3xfR0qWqhqNp1SJXYWdeMU5KeOQ1L54tURwbM12Qc2JW1kUYyCBlMomLLu 8xFJeqRguSZHkjD55+S75lswCdX59+9Jd83sM2iap/qF2GtDPxcPBPTSt5KjsFxxzBUD TUfMxm77xlk+C/Uhph6Zg/Eq4PB/4cOcUNIgZCLrKagR1EuHikNu+yffwQfpWEDLIYhU vFoA== X-Gm-Message-State: AOAM533VejbPIlYydTpcYnjNtUYupDkLENKpSWqcAFuwzATd8e9VmmKD pg8ADR+DwkhrbJqsOqiNfSI= X-Google-Smtp-Source: ABdhPJwFZion7oe6mvm7vc9ex2JG29Ufe3gjJOw30Wt+ev77WHmd8lSKoEDPcx9RA5OJsGQ3Ee95hw== X-Received: by 2002:a9d:2f66:: with SMTP id h93mr26009143otb.188.1620828877708; Wed, 12 May 2021 07:14:37 -0700 (PDT) Received: from localhost ([2600:1700:e321:62f0:329c:23ff:fee3:9d7c]) by smtp.gmail.com with ESMTPSA id z9sm25659oog.25.2021.05.12.07.14.36 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 12 May 2021 07:14:36 -0700 (PDT) Date: Wed, 12 May 2021 07:14:35 -0700 From: Guenter Roeck To: Robin Gong Cc: "wim@linux-watchdog.org" , "shawnguo@kernel.org" , "s.hauer@pengutronix.de" , "festevam@gmail.com" , dl-linux-imx , "kernel@pengutronix.de" , "linux-watchdog@vger.kernel.org" , "linux-arm-kernel@lists.infradead.org" , "linux-kernel@vger.kernel.org" Subject: Re: [PATCH v1] watchdog: imx2_wdt: clear WDOG_HW_RUNNING before suspend Message-ID: <20210512141435.GL1333995@roeck-us.net> References: <1620732032-7675-1-git-send-email-yibin.gong@nxp.com> MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20210512_071438_705404_4CB51D1B X-CRM114-Status: GOOD ( 34.83 ) 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 Wed, May 12, 2021 at 11:34:37AM +0000, Robin Gong wrote: > On 2021/05/11 11:59 Guenter Roeck wrote: > > On 5/11/21 4:20 AM, Robin Gong wrote: > > > Since watchdog_ping_work is not freezable so that it maybe scheduled > > > before imx2_wdt_resume where watchdog clock enabled, hence, kernel > > > will hang in imx2_wdt_ping without clock, and then watchdog reset > > > happen. Prevent the above case by clearing WDOG_HW_RUNNING before > > > suspend, and restore it with ping in imx2_wdt_resume. > > > > > > Signed-off-by: Robin Gong > > > --- > > > drivers/watchdog/imx2_wdt.c | 8 ++++++++ > > > 1 file changed, 8 insertions(+) > > > > > > diff --git a/drivers/watchdog/imx2_wdt.c b/drivers/watchdog/imx2_wdt.c > > > index b84f80f..d3751e9 100644 > > > --- a/drivers/watchdog/imx2_wdt.c > > > +++ b/drivers/watchdog/imx2_wdt.c > > > @@ -357,6 +357,13 @@ static int __maybe_unused > > imx2_wdt_suspend(struct device *dev) > > > */ > > > __imx2_wdt_set_timeout(wdog, IMX2_WDT_MAX_TIME); > > > imx2_wdt_ping(wdog); > > > + > > > + /* > > > + * clear WDOG_HW_RUNNING to prevent watchdog_ping_work > > running > > > + * before imx2_wdt_resume where clock enabled, otherwise kernel > > > + * will hang and watchdog reset happen then. > > > + */ > > > + clear_bit(WDOG_HW_RUNNING, &wdog->status); > > > } > > > > > > clk_disable_unprepare(wdev->clk); > > > @@ -386,6 +393,7 @@ static int __maybe_unused imx2_wdt_resume(struct > > device *dev) > > > if (imx2_wdt_is_running(wdev)) { > > > imx2_wdt_set_timeout(wdog, wdog->timeout); > > > imx2_wdt_ping(wdog); > > > + set_bit(WDOG_HW_RUNNING, &wdog->status); > > > } > > > > > > return 0; > > > > > I really don't like this; it depends on assumptions how the watchdog core > > works, and it misuses WDOG_HW_RUNNING to indicate that the clock is > > stopped (or that the driver is in suspend mode). > > > > If ping doesn't work with the clock stopped, I think it would be much better to > > have a flag indicating that the clock is stopped, and have the ping function do > > nothing if it is called with stopped clock (ie if suspended). > > > Understood, but I think that corner case should be a common potential issue > in all watchdog drivers which disable clock in suspend with WDOG_HW_RUNNING. > So common way looks better than many different specific flags in such different > watchdog driver with the similar intention? > We can not assume that the situation is exactly the same for all drivers and use a core flag to indicate some driver specific state just to avoid a driver-internal flag. Either case, it looks like you are saying that the watchdog can be stopped after all, by disabling its clock. > BTW, for i.mx2_wdt which watchdog can't be stop unless kernel enter into suspend, > that seems like watchdog stop after suspend and clear WDOG_HW_RUNNING makes > sense? > Yes, if you make it official and add a stop function which disables the watchdog by stopping its clock. Then the driver should not set WDOG_HW_RUNNING in the first place, and use the normal mechanisms to start and stop the watchdog. That would include starting the clock in the start function, and stopping it in the stop function. Thanks, Guenter _______________________________________________ linux-arm-kernel mailing list linux-arm-kernel@lists.infradead.org http://lists.infradead.org/mailman/listinfo/linux-arm-kernel