Received: by 2002:a05:6a10:8c0a:0:0:0:0 with SMTP id go10csp4114403pxb; Tue, 26 Jan 2021 12:48:16 -0800 (PST) X-Google-Smtp-Source: ABdhPJw5DQRclXZQQIx9JDL0CJwei9wrqYwMXlLFQ5/HAeVtH3h5dICVTG7UNfsVoAGuzMssLbyR X-Received: by 2002:a50:cf02:: with SMTP id c2mr5905014edk.333.1611694096354; Tue, 26 Jan 2021 12:48:16 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1611694096; cv=none; d=google.com; s=arc-20160816; b=y8eCOdGVaDMGQTZSAaNp46D4kboxVjS85drxDqu7KrGunzjw/TkPSBqHAk/FayzN8e 0Hmb+q+PcuDPUNwzetUtZ6yrD94yopn8Z8qh253PH8wumS10OJ7v6+OEjz9mPNoO7eNe i6Pr15VeAndNh02fkdy+DzzEOqrh9UPqHiQeEoW5ka3Iv9ngXJRhatl2VanSzYbuY9aC 2PoFlUMIGSh6MFTXaNYPGO+2yF4bPuvwMeJCwkoIJNP98pnROJ4P28KKvS3rBzYldTr5 izGxIgpnsj5I+d9ki9k6EW1SkDxSibdOyCpf627NojpeUJ7iI5IeC6/yqncNj8I+n5+Q 3YPw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:in-reply-to:content-transfer-encoding :content-disposition:mime-version:references:message-id:subject:cc :to:from:date; bh=wFgI7xTWTeQJEPBJJILFMx8H45I/IGcYHZhfdfqtyWU=; b=q50lRl2eP4SmE3r8bwWIyBhS7S4j6aVuEQXF/2pH8l0O+UsDaLNucXw8vMhPt3FWJd qeEJ8yHqy+Mzlk2qDaRkXKGFe3Hi5W2440Ie6oHmfXoQMKmNFtlbBp7tOjvbJwnX2mcn TTOSwbUm+jM1yXdqf4yO+yzBbK8b+wfca0samMkfgameBq4KdZxOhJni3Qc1oe7FgOfV 8R/XsPtICC/9jL771ZguHEbDkSNx7SfrnEFTIKGEwgB8j3b8phoj2qWJwaNZDs7kj5so ywz107Av7nhwXmFGKyn0uyLuj73ZDsbAR66MlYBus/JMbPFbZmf1OBFSnryZ+D1U9TMm nYDA== ARC-Authentication-Results: i=1; mx.google.com; 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 Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id f18si7512367ejb.475.2021.01.26.12.47.51; Tue, 26 Jan 2021 12:48:16 -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; 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 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2394539AbhAZSRs (ORCPT + 99 others); Tue, 26 Jan 2021 13:17:48 -0500 Received: from relay4-d.mail.gandi.net ([217.70.183.196]:57345 "EHLO relay4-d.mail.gandi.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2393913AbhAZSBw (ORCPT ); Tue, 26 Jan 2021 13:01:52 -0500 X-Originating-IP: 86.202.109.140 Received: from localhost (lfbn-lyo-1-13-140.w86-202.abo.wanadoo.fr [86.202.109.140]) (Authenticated sender: alexandre.belloni@bootlin.com) by relay4-d.mail.gandi.net (Postfix) with ESMTPSA id 22EDEE001A; Tue, 26 Jan 2021 18:00:42 +0000 (UTC) Date: Tue, 26 Jan 2021 19:00:42 +0100 From: Alexandre Belloni To: Thomas Gleixner Cc: =?iso-8859-1?Q?Micka=EBl_Sala=FCn?= , LKML , Jason Gunthorpe , Miroslav Lichvar , John Stultz , Prarit Bhargava , Alessandro Zummo , linux-rtc@vger.kernel.org, Peter Zijlstra Subject: Re: [PATCH V2] rtc: mc146818: Detect and handle broken RTCs Message-ID: <20210126180042.GC1196852@piout.net> 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> <87tur3fx7w.fsf@nanos.tec.linutronix.de> MIME-Version: 1.0 Content-Type: text/plain; charset=iso-8859-1 Content-Disposition: inline Content-Transfer-Encoding: 8bit In-Reply-To: <87tur3fx7w.fsf@nanos.tec.linutronix.de> Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On 26/01/2021 18:02:11+0100, Thomas Gleixner wrote: > 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?l Sala?n > Signed-off-by: Thomas Gleixner > Tested-by: Micka?l Sala?n Acked-by: Alexandre Belloni > --- > V2: Fixed the sizeof() as spotted by Micka?l > --- > 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 > > spin_lock_irq(&rtc_lock); > > + /* Ensure that the RTC is accessible. Bit 0-6 must be 0! */ > + if ((CMOS_READ(RTC_VALID) & 0x7f) != 0) { > + spin_unlock_irq(&rtc_lock); > + dev_warn(dev, "not accessible\n"); > + retval = -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 > > 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) != 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 -- Alexandre Belloni, Bootlin Embedded Linux and Kernel engineering https://bootlin.com