Received: by 2002:a05:6a10:8c0a:0:0:0:0 with SMTP id go10csp518563pxb; Wed, 27 Jan 2021 13:41:09 -0800 (PST) X-Google-Smtp-Source: ABdhPJxYP5SJqchfVS18BcjJ0+ElNEL2kQNh0wlpUkDuHc6DCkfuT6gSa2EjCD8KZthHWaX9ko9F X-Received: by 2002:a05:6402:22ba:: with SMTP id cx26mr10888969edb.350.1611783669035; Wed, 27 Jan 2021 13:41:09 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1611783669; cv=none; d=google.com; s=arc-20160816; b=UfRDPdixP0F8b/xP1ZU326MAOsr4KVDqDLHPYRDoyq04zlA5pSqKoKlXahJzWs/RY+ 64FcLosOMYgIly1bPOGhp5XSwN+2a/FakpFCD/uUCs1xFSHyfvpOVgcqFhiTS/S6pv0m oHN67LyTBJtFjEopGGFp1DurcBA84OvK1gSjK47HZy7gvzn+4rv86jlZSmNhPTb1f9SD 17ysfABJodMsq29cxLD35GmScvEJSF89SeFIofeC8mvyXjBp5oI8gP3kCbT+shZVNXbM OjcrP73AivzWBi6lmn0Jb0Wq8Xtppiq/kBhtaUe7ceQzh0yFQk3OGNs2U3oYb/aiHpSy q1sg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:robot-unsubscribe :robot-id:message-id:mime-version:references:in-reply-to:cc:subject :to:reply-to:sender:from:dkim-signature:dkim-signature:date; bh=cemEJYV9vVSDX4IDyOlVNtus9i2DLQyCgcp84j2W8sA=; b=CSyJ1pR2+KDNHqFDs+vf9cSreGLuqSS/p3KC/i+BZEUz/azKkwq8hq+J5C5B3Edu04 7rrNYMgOADIh6kcowg1JEhG7mgGfAjeZMUKCr2cNe09qj9d/aLY6iOGsleikktPXpUvJ Ue5UvojDXyYssSwdzPB2y5yEILf9AStQtLLm4mp7EwDpmNhKPpbft+sfS5kKW5aMyzv9 8PqyznwSnO1SuOqSIv+XTTX9AoYSq4nG75EJoflO7XN+8MSj4Lu/7DSftGcvh06mrV7S y56m5O9y0GeA8ab6lsUikTG937AJ28+vr3W9KxuQYwtpv0q/Nk37VRiM4yoSnB2oqcmf acAQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linutronix.de header.s=2020 header.b=pZnKsp5n; dkim=neutral (no key) header.i=@linutronix.de header.b=wL2XPOQe; 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 os5si1307306ejb.629.2021.01.27.13.40.43; Wed, 27 Jan 2021 13:41:09 -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=pZnKsp5n; dkim=neutral (no key) header.i=@linutronix.de header.b=wL2XPOQe; 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 S231317AbhA0Iod (ORCPT + 99 others); Wed, 27 Jan 2021 03:44:33 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:54534 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231922AbhA0ImU (ORCPT ); Wed, 27 Jan 2021 03:42:20 -0500 Received: from galois.linutronix.de (Galois.linutronix.de [IPv6:2a0a:51c0:0:12e:550::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 69CCDC061573; Wed, 27 Jan 2021 00:41:40 -0800 (PST) Date: Wed, 27 Jan 2021 08:41:37 -0000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020; t=1611736898; h=from:from:sender:sender:reply-to: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=cemEJYV9vVSDX4IDyOlVNtus9i2DLQyCgcp84j2W8sA=; b=pZnKsp5nEb1N9gxjFAiF+1ivkZn7XflFPP30t1KjfjgfCa0uEFV2i0CP7o3aq4AZOluHSj NsS8pXyTrFngd5vRGEwUDMliC7SvjVH89IzXNQbzuWUe3YNEaYddbtkcRuKJCrkqCS1Q81 td0LCEhDtxcOH+pEhjdGtpvZELBmxqhU//R7g0eAUon1YiqhOuVHIeYZBLopsbdMpZmjS6 bR5NqDlVGrIbtzjEfx8WvK25heOfXMREhCjxrZDRnpuem37lhP4fuCwifbfa3qEyP2A3FC iV+J4hHJ5zE36z/MrCMhY5iKAE/5p6dEw4IfRtyi3KIVLrDfelJ5g4OJtztKhQ== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020e; t=1611736898; h=from:from:sender:sender:reply-to: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=cemEJYV9vVSDX4IDyOlVNtus9i2DLQyCgcp84j2W8sA=; b=wL2XPOQeogxM4FbAQ/xHycx2xlhsTfZaynDIXUdvI7HCQ0SJbM5VDonRTE/KNpO1sAGi0i KqRirepB7ZN64UAQ== From: "tip-bot2 for Thomas Gleixner" Sender: tip-bot2@linutronix.de Reply-to: linux-kernel@vger.kernel.org To: linux-tip-commits@vger.kernel.org Subject: [tip: timers/urgent] rtc: mc146818: Detect and handle broken RTCs Cc: mic@digikod.net, Thomas Gleixner , mic@linux.microsoft.com, Alexandre Belloni , x86@kernel.org, linux-kernel@vger.kernel.org In-Reply-To: <87tur3fx7w.fsf@nanos.tec.linutronix.de> References: <87tur3fx7w.fsf@nanos.tec.linutronix.de> MIME-Version: 1.0 Message-ID: <161173689701.414.6157646664420167420.tip-bot2@tip-bot2> Robot-ID: Robot-Unsubscribe: Contact to get blacklisted from these emails 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 following commit has been merged into the timers/urgent branch of tip: Commit-ID: 211e5db19d15a721b2953ea54b8f26c2963720eb Gitweb: https://git.kernel.org/tip/211e5db19d15a721b2953ea54b8f26c2963= 720eb Author: Thomas Gleixner AuthorDate: Tue, 26 Jan 2021 18:02:11 +01:00 Committer: Thomas Gleixner CommitterDate: Wed, 27 Jan 2021 09:36:22 +01:00 rtc: mc146818: Detect and handle broken RTCs 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 Acked-by: Alexandre Belloni Link: https://lore.kernel.org/r/87tur3fx7w.fsf@nanos.tec.linutronix.de --- drivers/rtc/rtc-cmos.c | 8 ++++++++ drivers/rtc/rtc-mc146818-lib.c | 7 +++++++ 2 files changed, 15 insertions(+) diff --git a/drivers/rtc/rtc-cmos.c b/drivers/rtc/rtc-cmos.c index 51e80bc..68a9ac6 100644 --- a/drivers/rtc/rtc-cmos.c +++ b/drivers/rtc/rtc-cmos.c @@ -805,6 +805,14 @@ cmos_do_probe(struct device *dev, struct resource *ports= , int rtc_irq) =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; * diff --git a/drivers/rtc/rtc-mc146818-lib.c b/drivers/rtc/rtc-mc146818-lib.c index 972a5b9..f83c138 100644 --- a/drivers/rtc/rtc-mc146818-lib.c +++ b/drivers/rtc/rtc-mc146818-lib.c @@ -21,6 +21,13 @@ unsigned int mc146818_get_time(struct rtc_time *time) =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