Received: by 2002:a25:8b91:0:0:0:0:0 with SMTP id j17csp8083068ybl; Thu, 16 Jan 2020 10:18:59 -0800 (PST) X-Google-Smtp-Source: APXvYqykCPdESovPMQgRlPPQlQuj3z9oNRQc2WUsXdKoKr+DCJfYrpZuOgIXJ552K09b3NKht4zP X-Received: by 2002:a05:6808:aa8:: with SMTP id r8mr281662oij.7.1579198739812; Thu, 16 Jan 2020 10:18:59 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1579198739; cv=none; d=google.com; s=arc-20160816; b=oooha6Ksa+G0pZb5HfmOjfpyhKLKL46i10v7LPgn/J0lJBcjwu1sSMID+EgVtExMuI f5QYR0plwVw0FcFklVKXWvf1qRexiSmCezrnddQxEu76fJzPkIqtCbqCbTaNVHipU0BM PW9ts9Qx/sdcSQ5vBXmH7WpwWyqoh6GE5ivXAlp+wgLkDTcbxRShZmu8IzhiKCgAiXqS mszL30YL2mlpmd1Tg0JizfLvF8rNlA0rKRADVfRoHTaoB6HtnlvKuDwJpMadNPfG52tW 7NpWf1pnb8rySoyOrrR+R3zUWUf5OzwS7lkMC2yGXkudOYMpjtgvI5QyQytX5H+p4BOW MqGw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:mime-version:message-id:date:references :in-reply-to:subject:cc:to:from; bh=Sp7lSyx0iG7x7gY+GuwzoLnFgm+2focOMF1IOqn19rc=; b=tx4fdcx4WbTZ+Iok1KBa1U7QMkLtr6utpVuEgB5SWPfjZ7G8xBubBiMlTMzfSaw3HX uFP8WrnPkfHra9BH2Tpn7PQ1wKg/3RXQAyyl5CSN/SoiV2qzP8VuSNbbJXwu3SOs8FPu TDYnQryV+lkwy7J24MXttOd1Rtj+/i6KZ7ykc0pascNu5wjMumVbCerxnaZd9Ku1RAle qI97GRVhHy5uuQpfu2fFxWoUu49ym0+CKFenkeq5gbBLCiAYT0RBACiu2FKW6BikDOPS n9IqpRs877twzl7a1hxG6IZLqGkg4FZoJa4BqRJNSFakn+pHCnPFwfWUIVgXH4uh54MF X2ig== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id c17si13361534otp.131.2020.01.16.10.18.47; Thu, 16 Jan 2020 10:18:59 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2436486AbgAPSRT (ORCPT + 99 others); Thu, 16 Jan 2020 13:17:19 -0500 Received: from Galois.linutronix.de ([193.142.43.55]:52900 "EHLO Galois.linutronix.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2436474AbgAPSRR (ORCPT ); Thu, 16 Jan 2020 13:17:17 -0500 Received: from p5b06da22.dip0.t-ipconnect.de ([91.6.218.34] helo=nanos.tec.linutronix.de) by Galois.linutronix.de with esmtpsa (TLS1.2:DHE_RSA_AES_256_CBC_SHA256:256) (Exim 4.80) (envelope-from ) id 1is9hX-0003ni-5o; Thu, 16 Jan 2020 19:17:03 +0100 Received: by nanos.tec.linutronix.de (Postfix, from userid 1000) id 92A16101226; Thu, 16 Jan 2020 19:17:02 +0100 (CET) From: Thomas Gleixner To: Robert Richter Cc: Waiman Long , Andrew Morton , Ingo Molnar , "linux-kernel\@vger.kernel.org" , Mike Rapoport , Kees Cook , Catalin Marinas , Will Deacon , Peter Zijlstra , Petr Mladek Subject: [PATCH] watchdog/softlockup: Enforce that timestamp is valid on boot In-Reply-To: <20200116151146.wn6ec7igl2bfk4c2@rric.localdomain> References: <20200103151032.19590-1-longman@redhat.com> <87sgkgw3xq.fsf@nanos.tec.linutronix.de> <87blr3wrqw.fsf@nanos.tec.linutronix.de> <20200116151146.wn6ec7igl2bfk4c2@rric.localdomain> Date: Thu, 16 Jan 2020 19:17:02 +0100 Message-ID: <87o8v3uuzl.fsf@nanos.tec.linutronix.de> MIME-Version: 1.0 Content-Type: text/plain X-Linutronix-Spam-Score: -1.0 X-Linutronix-Spam-Level: - X-Linutronix-Spam-Status: No , -1.0 points, 5.0 required, ALL_TRUSTED=-1,SHORTCIRCUIT=-0.0001 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Robert reported that during boot the watchdog timestamp is set to 0 for one second which is the indicator for a watchdog reset. The reason for this is that the timestamp is in seconds and the time is taken from sched clock and divided by ~1e9. sched clock starts at 0 which means that for the first second during boot the watchdog timestamp is 0, i.e. reset. Use ULONG_MAX as the reset indicator value so the watchdog works correctly right from the start. ULONG_MAX would only conflict with a real timestamp if the system reaches an uptime of 136 years on 32bit and almost eternity on 64bit. Reported-by: Robert Richter Signed-off-by: Thomas Gleixner --- kernel/watchdog.c | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) --- a/kernel/watchdog.c +++ b/kernel/watchdog.c @@ -161,6 +161,8 @@ static void lockup_detector_update_enabl #ifdef CONFIG_SOFTLOCKUP_DETECTOR +#define SOFTLOCKUP_RESET ULONG_MAX + /* Global variables, exported for sysctl */ unsigned int __read_mostly softlockup_panic = CONFIG_BOOTPARAM_SOFTLOCKUP_PANIC_VALUE; @@ -272,7 +274,7 @@ notrace void touch_softlockup_watchdog_s * Preemption can be enabled. It doesn't matter which CPU's timestamp * gets zeroed here, so use the raw_ operation. */ - raw_cpu_write(watchdog_touch_ts, 0); + raw_cpu_write(watchdog_touch_ts, SOFTLOCKUP_RESET); } notrace void touch_softlockup_watchdog(void) @@ -296,14 +298,14 @@ void touch_all_softlockup_watchdogs(void * the softlockup check. */ for_each_cpu(cpu, &watchdog_allowed_mask) - per_cpu(watchdog_touch_ts, cpu) = 0; + per_cpu(watchdog_touch_ts, cpu) = SOFTLOCKUP_RESET; wq_watchdog_touch(-1); } void touch_softlockup_watchdog_sync(void) { __this_cpu_write(softlockup_touch_sync, true); - __this_cpu_write(watchdog_touch_ts, 0); + __this_cpu_write(watchdog_touch_ts, SOFTLOCKUP_RESET); } static int is_softlockup(unsigned long touch_ts) @@ -379,7 +381,7 @@ static enum hrtimer_restart watchdog_tim /* .. and repeat */ hrtimer_forward_now(hrtimer, ns_to_ktime(sample_period)); - if (touch_ts == 0) { + if (touch_ts == SOFTLOCKUP_RESET) { if (unlikely(__this_cpu_read(softlockup_touch_sync))) { /* * If the time stamp was touched atomically