Received: by 2002:a05:6a10:5bc5:0:0:0:0 with SMTP id os5csp1292305pxb; Sat, 30 Oct 2021 10:03:38 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzy7rILXICL6OZ5e2ckCjUjpru/4rIVtPkj2n1Tz3LdMilmwGj1xhPOXQdaHr0mJpAHDAv8 X-Received: by 2002:a6b:7e44:: with SMTP id k4mr11128093ioq.113.1635613417991; Sat, 30 Oct 2021 10:03:37 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1635613417; cv=none; d=google.com; s=arc-20160816; b=ZwDvh07PdDaknny2UQlRW8OMhK46eBObfrPyeTW1Km3HOdmN8053QVWfm7kG5bPkZI UCQR4Eaie7WA5ideFNNTM03Rq7Ze1/tgQpe5rzBLItVGTY6lDBIkRs4K4RJ0M6e7ntMS UByRCYh/U7Dd7sJuyvK0ijnjsXRXKRvcZs/vt51iyNRcVfzodZ2UEIhuIxpuNBlCNB9d IHG8DGKX2i3g2ZqRAE8BqLAiSVLA6msMM3UuKrZXaAqLOjDNcd9J5Pvjn+Cemrar+JtC yepKvpK37SRfWa1FsXLmY0V/ZYQzTeEtnNCtttcwczzHrbQ2Vjcv/8IfrH8ct6/QltB8 hQ9g== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:cc:to:subject:message-id:date:from:in-reply-to :references:mime-version:dkim-signature; bh=l/0UUkqf6KFkNkf6dBZ0pEkCS7X6LutBL6LgNXt9kNw=; b=k9wvvCrw4pOtXfzo4AJ54PJSK7iYFoFs8vkiiZttXelqtNY0VI0siPALgAUiB5jpiX QX5/8lZbPqbTn/rW0hIYxU0Id+/hKdNh/dwy6xYhaH82K2x5IbFBBxbEEuXEdWmM38Xx rzdvp70B/jpsHVf5RZ1NO8gLrnfC/YgaELpfIYc7jHEhW5wXnwNfXnIaeU8iS8BPZmF+ L7EcR0DaWg2EDK19umGVFX5QCpIhiLa1O+JGZQ4Os8JDypTD3wCLb+mCQnBvEezimDyc +g3jicnc4qKkv2fWdSdqzx5HTDC++8634P/mzoCrXqA7nEfAF00mVy3uDd4Ijs1ILLMK GydA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=COYcjMZH; 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 u9si6180574ill.20.2021.10.30.10.03.23; Sat, 30 Oct 2021 10:03:37 -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=COYcjMZH; 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 S229694AbhJ3RC0 (ORCPT + 99 others); Sat, 30 Oct 2021 13:02:26 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:55466 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229474AbhJ3RCZ (ORCPT ); Sat, 30 Oct 2021 13:02:25 -0400 Received: from mail-ua1-x936.google.com (mail-ua1-x936.google.com [IPv6:2607:f8b0:4864:20::936]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 84DD8C061570 for ; Sat, 30 Oct 2021 09:59:55 -0700 (PDT) Received: by mail-ua1-x936.google.com with SMTP id x3so24040076uar.13 for ; Sat, 30 Oct 2021 09:59:55 -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=l/0UUkqf6KFkNkf6dBZ0pEkCS7X6LutBL6LgNXt9kNw=; b=COYcjMZHo2AhOT7Qmebs1O2714sucGcw4oOFWAZd04mujHCpsr49AG3HZtjw7Im4lg ePKoBnjK9WgnzD/v5lNJMx61C/iclRy9VF3dc8XjgNfIEOeaMPRkrQ3RdG7oTsbcL0q9 qBJlNogLLIxUKBwUJZw5zUIGd9KoXRjJlKKLKHRVjGetr89QqXKZ6Mz75aHEqIWtSKVP mqvnOV4YEnoasMfw2yTM4pF3va7X9XaC1HbVOM/jn4DaZk7Iqcooo7Io0KcxKU8RbrsD sNLPWVQMO0Yx7KIVpU40dbfdaxXTs0re1gHao8v4RsL/SFjGvnuIw9G/XT4iJngYCfxs h/jg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=l/0UUkqf6KFkNkf6dBZ0pEkCS7X6LutBL6LgNXt9kNw=; b=4faGQYlxBZjA+kzsR8+ekTf8Zr3+XkDi8qW8PkU4egOKmo/7JwPkBhajJLrxLNT0xh K6IsxNeYLFSTG0PpxCr7EHURh4QM85j4hcxYNduWuEh/58CkCm24eN+fipYysE3/l8Fw Rh08oIldg+vLXb5Ghq+87Zq2hZXVWw3J11UwT/fXXhq9Qkp29YWhsu8PpysN9q0hLOLb TOPp9fztugAA2dI5JSu2DdiWE3ZMYsxfECf8RNnI168V5Giq2+Gc52hKSiAffGZ/95Vw usAV0NcfRD9vyESbaIixm6RstLCO3bPuBpg7d6ZSZMvtflyYtuQH+X9pmgiSw5eplTn1 5w2w== X-Gm-Message-State: AOAM533GcZiqTIofDosXgUK1j9rNmlq2oUiSGUt7naiNrXiQ95eXhuJ5 UwgT8vjdLP7QJU5v1Jglvt91kaSXBnV2Zp6sRNlZNQ== X-Received: by 2002:a05:6102:3ece:: with SMTP id n14mr1827009vsv.55.1635613194472; Sat, 30 Oct 2021 09:59:54 -0700 (PDT) MIME-Version: 1.0 References: <20211028183527.3050-1-semen.protsenko@linaro.org> <20211028183527.3050-8-semen.protsenko@linaro.org> <1ad6b625-4388-bc78-e258-eae0b9357b96@roeck-us.net> <7c9a8dd4-7607-55a2-3d65-a445fa246667@roeck-us.net> In-Reply-To: <7c9a8dd4-7607-55a2-3d65-a445fa246667@roeck-us.net> From: Sam Protsenko Date: Sat, 30 Oct 2021 19:59:42 +0300 Message-ID: Subject: Re: [PATCH 7/7] watchdog: s3c2410: Let kernel kick watchdog To: Guenter Roeck Cc: Wim Van Sebroeck , Rob Herring , Krzysztof Kozlowski , linux-watchdog@vger.kernel.org, devicetree , Linux Kernel Mailing List , linux-arm Mailing List , Linux Samsung SOC Content-Type: text/plain; charset="UTF-8" Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Sat, 30 Oct 2021 at 18:14, Guenter Roeck wrote: > > On 10/30/21 7:29 AM, Sam Protsenko wrote: > > On Fri, 29 Oct 2021 at 03:30, Guenter Roeck wrote: > >> > >> On 10/28/21 11:35 AM, Sam Protsenko wrote: > >>> When "tmr_atboot" module param is set, the watchdog is started in > >>> driver's probe. In that case, also set WDOG_HW_RUNNING bit to let > >>> watchdog core driver know it's running. This way wathcdog core can kick > >>> the watchdog for us (if CONFIG_WATCHDOG_HANDLE_BOOT_ENABLED option is > >>> enabled), until user space takes control. > >>> > >>> Signed-off-by: Sam Protsenko > >>> --- > >>> drivers/watchdog/s3c2410_wdt.c | 26 +++++++++++++++----------- > >>> 1 file changed, 15 insertions(+), 11 deletions(-) > >>> > >>> diff --git a/drivers/watchdog/s3c2410_wdt.c b/drivers/watchdog/s3c2410_wdt.c > >>> index ca082b1226e3..9af014ff1468 100644 > >>> --- a/drivers/watchdog/s3c2410_wdt.c > >>> +++ b/drivers/watchdog/s3c2410_wdt.c > >>> @@ -732,6 +732,21 @@ static int s3c2410wdt_probe(struct platform_device *pdev) > >>> wdt->wdt_device.bootstatus = s3c2410wdt_get_bootstatus(wdt); > >>> wdt->wdt_device.parent = dev; > >>> > >>> + /* > >>> + * If "tmr_atboot" param is non-zero, start the watchdog right now. Also > >>> + * set WDOG_HW_RUNNING bit, so that watchdog core can kick the watchdog. > >>> + * > >>> + * If we're not enabling the watchdog, then ensure it is disabled if it > >>> + * has been left running from the bootloader or other source. > >>> + */ > >>> + if (tmr_atboot && started == 0) { > >>> + dev_info(dev, "starting watchdog timer\n"); > >>> + s3c2410wdt_start(&wdt->wdt_device); > >>> + set_bit(WDOG_HW_RUNNING, &wdt->wdt_device.status); > >>> + } else if (!tmr_atboot) { > >>> + s3c2410wdt_stop(&wdt->wdt_device); > >>> + } > >>> + > >> > >> This doesn't cover the case where the watchdog is already enabled by the BIOS. > >> In that case, WDOG_HW_RUNNING won't be set, and the watchdog will time out > >> if the userspace handler is not loaded fast enough. The code should consistently > >> set WDOG_HW_RUNNING if the watchdog is running. > >> > > > > As I understand, in the case when bootloader started the watchdog, the > > driver just stops it. You can see it in the code you replied to. > > > > } else if (!tmr_atboot) { > > s3c2410wdt_stop(&wdt->wdt_device); > > > > In other words, having "tmr_atboot" module param makes it irrelevant > > whether bootloader enabled WDT or no. > > > > Sure, but I am concerned about "if (tmr_atboot && started)", which doesn't > set WDOG_HW_RUNNING with your current code, and I was looking for something > like > > if (tmr_atboot) { > if (!started) { > dev_info(dev, "starting watchdog timer\n"); > s3c2410wdt_start(&wdt->wdt_device); > } > set_bit(WDOG_HW_RUNNING, &wdt->wdt_device.status); > } else { > s3c2410wdt_stop(&wdt->wdt_device); > } > Wow, I really overlooked that case. Nice catch! Not having '} else {' section is vicious... Though if started != 0, it means s3c2410wdt_set_heartbeat() failed to set wdd->timeout, and without that the watchdog core won't be able to calculate correctly ping interval in watchdog_next_keepalive(), and WDOG_HW_RUNNING bit won't do much good, right? So I'll probably just call s3c2410wdt_stop() in that case, to be on the safe side. Also this 'started' variable name is misleading, I'll convert it to "bool timeout_ok" while at it. > Guenter