Received: by 2002:a05:6a10:8c0a:0:0:0:0 with SMTP id go10csp4231511pxb; Tue, 26 Jan 2021 16:28:08 -0800 (PST) X-Google-Smtp-Source: ABdhPJw5QWA5T/faZf5KUw62dJxggNkuxSUckLRpH1mNxlyA0dWRuSXKt77UqVjMDEYfXVqyEFco X-Received: by 2002:aa7:dcc9:: with SMTP id w9mr6421538edu.22.1611707288239; Tue, 26 Jan 2021 16:28:08 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1611707288; cv=none; d=google.com; s=arc-20160816; b=VdipmO101JkyySzrx10BDseSw0/rp8iprAjJvefYFgD1x3rX3S4wtTGGelgWl6aTG9 1BYJODSHJE2c4fkME1gmwE8DQoyIRDCz9LdTWgzrYN2k7ZFh+1cvTu63MtjeCx28wTlL 8m9wyMD/fFWp+I+wHFnBGhtTKF/dkUVIABqhN+A8d0HitOL6ANzg2I15q4jSh2A2Idcw AU0XdjC97tfApr/OextXpAUglEaEMjTkV8emA6kJCKQ5VCy48OPIH4FUItcv/Vxlp1XR 0mUXtLTRloQBFMGwCfsaNeLoJI3d95Scga7oDyBuL829clBYcCgjVvbcjYVvUNLtxi1O ooWQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :message-id:date:references:in-reply-to:subject:cc:to:dkim-signature :dkim-signature:from; bh=HrMDZ4yyjVd0WEX5TShN5hNg9g3vf27cMToBCTxUBfA=; b=KuABZ+z//ZAkGl1C0g/kACBO9IGD0gB4cr+KqRP0MFPNiw1hJpZKd+f/WCM9mnU5Sy zn0GJIKiohKDxc2ohypr7GlJIX2vIzQfdt7CD9nWRgFlX0oDvxUiA3xC2PzsEZliv/gu mz4kk/T1XMxdbHdOgNRSuP/qNhaSTOaRjrQBiVnab558mGk7QtMsT7IXjchzE5xCvGs0 oHccg/AXrWWLmS40JzjS0FcnG+DSpq1a/pRqPh7OkAh98Oon4SORLX+g1zAJx+7tQXVb 5OBV6ENR8rb2j2dG2p78cxG95oUOXhAnoX+hYdOXr5fcJV3jq+hBFbf7+kFXJbZysmU0 x0yA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linutronix.de header.s=2020 header.b=Xvv8yMUp; dkim=neutral (no key) header.i=@linutronix.de; 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=QUARANTINE dis=NONE) header.from=linutronix.de Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id m24si108786ejg.728.2021.01.26.16.27.43; Tue, 26 Jan 2021 16:28:08 -0800 (PST) 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=@linutronix.de header.s=2020 header.b=Xvv8yMUp; dkim=neutral (no key) header.i=@linutronix.de; 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=QUARANTINE dis=NONE) header.from=linutronix.de Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2389800AbhA0AJX (ORCPT + 99 others); Tue, 26 Jan 2021 19:09:23 -0500 Received: from Galois.linutronix.de ([193.142.43.55]:50596 "EHLO galois.linutronix.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1729311AbhAZRC6 (ORCPT ); Tue, 26 Jan 2021 12:02:58 -0500 From: Thomas Gleixner DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020; t=1611680531; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=HrMDZ4yyjVd0WEX5TShN5hNg9g3vf27cMToBCTxUBfA=; b=Xvv8yMUp0L+Ni2uJDRs1EOwTOFmGwFvW1GAYHuGK9l0NAUM7BS+PWnQDllxhB7A37j8sOf cVYrXy2JZwp6mMtIqOMA9p8Y1rZ/7MpmylCPL6jXYNJwF8qEukbx5rG0YmMKZFYw/esBGs 6Ait0iIUv8oGt2Y8YIv6j14lv6/XgyDB8pM7injs/YWZONNKUNkCxv46y4EHvnmmGvEYbC Ktn+td6fJUiB2a8oWoRt7fjIobYPvgFZHzKH/v277HbCek9FMIpJYfPA8YoPy/G34m9Cuz yiNRzYQs+mJMYalybSzgeBoR3fnA7ThcHoAHLCO74u+sp8PqESzirJBbkce+eA== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020e; t=1611680531; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=HrMDZ4yyjVd0WEX5TShN5hNg9g3vf27cMToBCTxUBfA=; b=ZBFLUZmQbDVKmkgAybOjKtWIDN4MtZBPVL3cJfnwEt7UP5gRQfuKs0S0nsmRojG9fHzN67 M8BryvH1KzMG2/Cw== To: =?utf-8?Q?Micka=C3=ABl_Sala=C3=BCn?= , LKML Cc: Alexandre Belloni , Jason Gunthorpe , Miroslav Lichvar , John Stultz , Prarit Bhargava , Alessandro Zummo , linux-rtc@vger.kernel.org, Peter Zijlstra Subject: [PATCH V2] rtc: mc146818: Detect and handle broken RTCs In-Reply-To: <87y2gfg18p.fsf@nanos.tec.linutronix.de> References: <20201206214613.444124194@linutronix.de> <20201206220541.594826678@linutronix.de> <19a7753c-c492-42e4-241a-8a052b32bb63@digikod.net> <871re7hlsg.fsf@nanos.tec.linutronix.de> <98cb59e8-ecb4-e29d-0b8f-73683ef2bee7@digikod.net> <87y2gfg18p.fsf@nanos.tec.linutronix.de> Date: Tue, 26 Jan 2021 18:02:11 +0100 Message-ID: <87tur3fx7w.fsf@nanos.tec.linutronix.de> MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org The recent fix for handling the UIP bit unearthed another issue in the RTC code. If the RTC is advertised but the readout is straight 0xFF because it's not available, the old code just proceeded with crappy values, but the new code hangs because it waits for the UIP bit to become low. Add a sanity check in the RTC CMOS probe function which reads the RTC_VALID register (Register D) which should have bit 0-6 cleared. If that's not the case then fail to register the CMOS. Add the same check to mc146818_get_time(), warn once when the condition is true and invalidate the rtc_time data. Reported-by: Micka=C3=ABl Sala=C3=BCn Signed-off-by: Thomas Gleixner Tested-by: Micka=C3=ABl Sala=C3=BCn --- V2: Fixed the sizeof() as spotted by Micka=C3=ABl --- drivers/rtc/rtc-cmos.c | 8 ++++++++ drivers/rtc/rtc-mc146818-lib.c | 7 +++++++ 2 files changed, 15 insertions(+) --- a/drivers/rtc/rtc-cmos.c +++ b/drivers/rtc/rtc-cmos.c @@ -805,6 +805,14 @@ cmos_do_probe(struct device *dev, struct =20 spin_lock_irq(&rtc_lock); =20 + /* Ensure that the RTC is accessible. Bit 0-6 must be 0! */ + if ((CMOS_READ(RTC_VALID) & 0x7f) !=3D 0) { + spin_unlock_irq(&rtc_lock); + dev_warn(dev, "not accessible\n"); + retval =3D -ENXIO; + goto cleanup1; + } + if (!(flags & CMOS_RTC_FLAGS_NOFREQ)) { /* force periodic irq to CMOS reset default of 1024Hz; * --- a/drivers/rtc/rtc-mc146818-lib.c +++ b/drivers/rtc/rtc-mc146818-lib.c @@ -21,6 +21,13 @@ unsigned int mc146818_get_time(struct rt =20 again: spin_lock_irqsave(&rtc_lock, flags); + /* Ensure that the RTC is accessible. Bit 0-6 must be 0! */ + if (WARN_ON_ONCE((CMOS_READ(RTC_VALID) & 0x7f) !=3D 0)) { + spin_unlock_irqrestore(&rtc_lock, flags); + memset(time, 0xff, sizeof(*time)); + return 0; + } + /* * Check whether there is an update in progress during which the * readout is unspecified. The maximum update time is ~2ms. Poll