Received: by 2002:a05:6a10:206:0:0:0:0 with SMTP id 6csp3164439pxj; Mon, 10 May 2021 21:00:50 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwdZQ8MGIuIc2GLuLCTR3ldfac2Zz1UasnZr43n3MyM0+4lD7usvn2hByc/Zux/TP/bNTl7 X-Received: by 2002:a5d:88cf:: with SMTP id i15mr20704049iol.45.1620705650425; Mon, 10 May 2021 21:00:50 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1620705650; cv=none; d=google.com; s=arc-20160816; b=LuWeZgzqk8Gh85Uxd9VadW1f57AASfuT5Hd5ixy1RGg4LkNZ039AtZiqFOeUmYlDUj Z9cdcZIIUGPv8XtnVGEi2OH+1M2gSyl8DACQyg0zOGfEIPj5w1uLVq+tSX7RjlSbJC5i NMgQraxJnt/wWTpH0OOsnd6Vx4Oin0/CLPCPhoI7ACkjev06w0LCjMu8PTaxXKFQUQlp 0DlcjA8g04b8EHb9+pac6PO6EtgPWhDVcFRh3gTfhEslXpNNh9g5nnvd1Qh2M8uYBkU5 rLCZRFhn6Pgl0/TY4F0Coy6249c4YSxw4B1i4MmRTSyu5eliaPaCL1aCluUYfS4kMYu5 zb5g== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:content-language :in-reply-to:mime-version:user-agent:date:message-id:from:references :cc:to:subject:sender:dkim-signature; bh=giW4O7uyh9noQ9+JYEWJMRTABRiwMHrOiFKibTN3kLA=; b=IXNNWzuzjniElKyPhVIreshfjEi/E/GTODbjj1VVGNdwR34BQgxJryh4tM5OpCyhOt Bu8VHSQSKqzU1IaxG8fgB1ey0xhnmvnelWUznRVcZrdRX0IVHOZsGjDxUJ6akZ/Rop7S Vrf9A+6LJz4pMvqA+9A54jjp8NUUzTdMdfQ14PIFuovSVkgAITwvNzIvnFCSgEqBQWgO L+IC80kYlIDxaJgGuXQD4ylH/6Z1ipNZngrG60H6QJ4Hetio4g8RsvMqM6/+FXmzTnmW WjCkUdHsietewkp1RIayImryrogPuQzn+Sm2LANAFCXLmjQkf70jHMav/Tf2QglI8MEm +nDA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=NX3ACGqa; 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 Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id v3si18310119ilq.36.2021.05.10.21.00.37; Mon, 10 May 2021 21:00:50 -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=@gmail.com header.s=20161025 header.b=NX3ACGqa; 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 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230009AbhEKEAe (ORCPT + 99 others); Tue, 11 May 2021 00:00:34 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:48016 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229456AbhEKEAd (ORCPT ); Tue, 11 May 2021 00:00:33 -0400 Received: from mail-oo1-xc35.google.com (mail-oo1-xc35.google.com [IPv6:2607:f8b0:4864:20::c35]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 5FBEBC061574; Mon, 10 May 2021 20:59:28 -0700 (PDT) Received: by mail-oo1-xc35.google.com with SMTP id v13-20020a4aa40d0000b02902052145a469so2312775ool.3; Mon, 10 May 2021 20:59:28 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=sender:subject:to:cc:references:from:message-id:date:user-agent :mime-version:in-reply-to:content-language:content-transfer-encoding; bh=giW4O7uyh9noQ9+JYEWJMRTABRiwMHrOiFKibTN3kLA=; b=NX3ACGqasz3BJiTxn7UpjFIeMeHy5mgdkpOUxR8SwUK1jDbDB0QQHySay46bGLU+4b tQiauKJe4Rki7coLFTYLM/l1SJo5/6QljT+JLJrdglpKZjOwFaIbV5/NCA/t3/GpKQg+ JULfWHE9SRm70zYIoNge9I0lEL+3YT/ISroqfWkfn0vcFbOhsb6yFWczZ7wZRyju8cXF mmK7i784/Aa+uwRo26qZtf3HzmWIABTDVTUy/tF80IHNkJxUHfJOWe+/I8uqRZAzQHQE HGUr/hrbPhQ37e7qypo25l73vcYc0/KNBnjLeDBwfpZdw4RQ6SEL02Stte8oLUISEncv P/kg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:sender:subject:to:cc:references:from:message-id :date:user-agent:mime-version:in-reply-to:content-language :content-transfer-encoding; bh=giW4O7uyh9noQ9+JYEWJMRTABRiwMHrOiFKibTN3kLA=; b=UZKkFCC6CAoLUIsTB3XDE57hMYRJXUDW/qb8F4dkFvZDVEhX0IcLan/tX1ZCHjTHUj r5SkT79pTvaCIVit4Tdr6WXCMl1P3f4Ypr1p0a8Ff1juNG2OdklZa+3LgqDt7WFq2TmO 7V3FutmCFKL4WzTL3F/lzQ1nwAo67HRZ4k8WEVQgDqXUlPwxYp/uQWFP20a8ZG6+R5xy xSRWqL4+2VeT+/ZK8jMEYGQYLVusrM7uETGv1ZU8q2g8ke03K+MywimvBZMJ9dmRVfJn MUyWwsnrHb5xeWPWz7LwA8mL9QrN7RFux6DZmRfG84nn483lDaBlqteCMEPgZIDrKAFe 5LsA== X-Gm-Message-State: AOAM532j836vgfHgiwqZXafLX7NIkCS9lFHi8VZ551zYN2aE3wO41JNM PXxfyQioaaBF0PksgkNB6OuxrON2k/o= X-Received: by 2002:a4a:d0a5:: with SMTP id t5mr8027010oor.62.1620705567565; Mon, 10 May 2021 20:59:27 -0700 (PDT) Received: from server.roeck-us.net ([2600:1700:e321:62f0:329c:23ff:fee3:9d7c]) by smtp.gmail.com with ESMTPSA id o4sm1486331oia.36.2021.05.10.20.59.26 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Mon, 10 May 2021 20:59:27 -0700 (PDT) Sender: Guenter Roeck Subject: Re: [PATCH v1] watchdog: imx2_wdt: clear WDOG_HW_RUNNING before suspend To: Robin Gong , wim@linux-watchdog.org, shawnguo@kernel.org, s.hauer@pengutronix.de, festevam@gmail.com Cc: linux-imx@nxp.com, kernel@pengutronix.de, linux-watchdog@vger.kernel.org, linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org References: <1620732032-7675-1-git-send-email-yibin.gong@nxp.com> From: Guenter Roeck Message-ID: Date: Mon, 10 May 2021 20:59:25 -0700 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:78.0) Gecko/20100101 Thunderbird/78.7.1 MIME-Version: 1.0 In-Reply-To: <1620732032-7675-1-git-send-email-yibin.gong@nxp.com> Content-Type: text/plain; charset=utf-8; format=flowed Content-Language: en-US Content-Transfer-Encoding: 7bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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). Guenter