Received: by 2002:a05:6358:d186:b0:cc:af7:9280 with SMTP id ka6csp18961rwb; Wed, 19 Oct 2022 16:26:09 -0700 (PDT) X-Google-Smtp-Source: AMsMyM6nhoMbIKVDT6eZjVE2B3CcISSlRUWlUD/p0MwbZG+mh+9g3MUTaV6qsLsrJAUQ5xAOh+VZ X-Received: by 2002:a17:903:11cf:b0:178:a8f4:d511 with SMTP id q15-20020a17090311cf00b00178a8f4d511mr11000014plh.72.1666221968889; Wed, 19 Oct 2022 16:26:08 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1666221968; cv=none; d=google.com; s=arc-20160816; b=DRRW59XMO0iY8S7KSM+7eQznWWZe6wgDxGdpKghzzLTtDkRoq3sh2ys+HZnOJ37LhM vlUMEEtqor8TtXMp4Hn2W4ITG66kfCZQkfFa3NRN+QE2I1WE/cEcM+yjSJPpUg4LV7CT T4AMiORuMlH/7ZvpFneIxOsLP1dNJzA2ex98h/Ogik/DB2+mu1YDX7uSttGQZRRkMjZW bXH7wYvlykBrNeBUK9SlJ7nbkgQn+DmMMaiXT0uJbOljKkIn7vPa70wcmRABGNlWsAXe 51wisvGqJXYqAcbFmKL+j2dy0Fl+OgqabZDC9ekLbys9jA9n950WOP71xOYucRT16oMX Fc+w== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-disposition:mime-version:reply-to :message-id:subject:cc:to:from:date:dkim-signature; bh=9pQOHr7Ir5PYsHv958DXMu3lzWrdsxUO/rVdlS8vaEQ=; b=Ts6sR9UrkXrpkgjPg+b56GbMiUWlgPnlhfuML2QRa00YpHLVIPZNlknHs6OgGjDfPI unQ0ERdeCUFC/JPOv6KhfqsJ1/waCTTD8I5I9BIUjhF/20UImYCZ6FpnVKDN3JTsxePk bl983VG/LO97bSrLDNQ8ENmd2Ft0TAge8K37NMikGioHjdfiwEkD4j/VlOZjVSeQS+UI i/RdPXM3/Q1V0Q783Kb8QGdMCwPnNwFBp2rAtFRcwA/ABLcoINlsoXAHLD9BI2hs1ryn Jnjc7cl14fkPLwChnAPD88zZSJN2MPxXvJj+gCd6Ukl5Ysw0bNIVa+Uti8+I6VdMEN9V QAQA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=FWTCdwBB; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id 26-20020a63185a000000b0043949ac7067si20161413pgy.200.2022.10.19.16.25.56; Wed, 19 Oct 2022 16:26:08 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=FWTCdwBB; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230315AbiJSXJK (ORCPT + 99 others); Wed, 19 Oct 2022 19:09:10 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:54558 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231551AbiJSXJJ (ORCPT ); Wed, 19 Oct 2022 19:09:09 -0400 Received: from ams.source.kernel.org (ams.source.kernel.org [IPv6:2604:1380:4601:e00::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 3AA0715D091 for ; Wed, 19 Oct 2022 16:09:08 -0700 (PDT) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ams.source.kernel.org (Postfix) with ESMTPS id 8A605B8261A for ; Wed, 19 Oct 2022 23:09:06 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 2C1ABC433C1; Wed, 19 Oct 2022 23:09:05 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1666220945; bh=BHGbq0AYz6Alv20BhnG96r7P6jl8a1dcx8eJdRaPpFs=; h=Date:From:To:Cc:Subject:Reply-To:From; b=FWTCdwBBZISvzlpQvULM3Q4iY7kUkhx6Gu97ErrtAwTj9q2+BUVdcoL+czET+2QqQ 0/cDPGEga5cyVoJwqG+3MTuf5smc1WFtLDEfmtZA3IWGoG0MnToe61Gzng4W88lRb7 BZyjIy1mQp9+wtsGollAO1TabRjxW7AR5yXBa1Gd+2/bW32sZyquo57VvmrAJ/weMU lFmVjdKZXLt58NM1crCmJiObTJsu7qISU8fQ7t7JmgirLhwCDz0PVTsAAN7m5tH3r5 MejsphWUEuaeqmBmI+K6nG0apFtS46BrQBAxf7mFGKcUzAxqz3hb3WfpwXDabWU4GJ VHqsYTifRq/QA== Received: by paulmck-ThinkPad-P17-Gen-1.home (Postfix, from userid 1000) id BC76E5C06B4; Wed, 19 Oct 2022 16:09:04 -0700 (PDT) Date: Wed, 19 Oct 2022 16:09:04 -0700 From: "Paul E. McKenney" To: linux-kernel@vger.kernel.org Cc: clm@meta.com, jstultz@google.com, tglx@linutronix.de, sboyd@kernel.org, feng.tang@intel.com, longman@redhat.com Subject: [PATCH clocksource] Reject bogus watchdog clocksource measurements Message-ID: <20221019230904.GA2502730@paulmck-ThinkPad-P17-Gen-1> Reply-To: paulmck@kernel.org MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline X-Spam-Status: No, score=-7.4 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_HI, SPF_HELO_NONE,SPF_PASS autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org One remaining clocksource-skew issue involves extreme CPU overcommit, which can cause the clocksource watchdog measurements to be delayed by tens of seconds. This in turn means that a clock-skew criterion that is appropriate for a 500-millisecond interval will instead give lots of false positives. Therefore, check for the watchdog clocksource reporting much larger or much less than the time specified by WATCHDOG_INTERVAL. In these cases, print a pr_warn() warning and refrain from marking the clocksource under test as being unstable. Reported-by: Chris Mason Signed-off-by: Paul E. McKenney Cc: John Stultz Cc: Thomas Gleixner Cc: Stephen Boyd Cc: Feng Tang Cc: Waiman Long diff --git a/kernel/time/clocksource.c b/kernel/time/clocksource.c index 8058bec87acee..dcaf38c062161 100644 --- a/kernel/time/clocksource.c +++ b/kernel/time/clocksource.c @@ -386,7 +386,7 @@ EXPORT_SYMBOL_GPL(clocksource_verify_percpu); static void clocksource_watchdog(struct timer_list *unused) { - u64 csnow, wdnow, cslast, wdlast, delta; + u64 csnow, wdnow, cslast, wdlast, delta, wdi; int next_cpu, reset_pending; int64_t wd_nsec, cs_nsec; struct clocksource *cs; @@ -440,6 +440,17 @@ static void clocksource_watchdog(struct timer_list *unused) if (atomic_read(&watchdog_reset_pending)) continue; + /* Check for bogus measurements. */ + wdi = jiffies_to_nsecs(WATCHDOG_INTERVAL); + if (wd_nsec < (wdi >> 2)) { + pr_warn("timekeeping watchdog on CPU%d: Watchdog clocksource '%s' advanced only %lld ns during %d-jiffy time interval, skipping watchdog check.\n", smp_processor_id(), watchdog->name, wd_nsec, WATCHDOG_INTERVAL); + continue; + } + if (wd_nsec > (wdi << 2)) { + pr_warn("timekeeping watchdog on CPU%d: Watchdog clocksource '%s' advanced an excessive %lld ns during %d-jiffy time interval, probable CPU overutilization, skipping watchdog check.\n", smp_processor_id(), watchdog->name, wd_nsec, WATCHDOG_INTERVAL); + continue; + } + /* Check the deviation from the watchdog clocksource. */ md = cs->uncertainty_margin + watchdog->uncertainty_margin; if (abs(cs_nsec - wd_nsec) > md) {