Received: by 2002:a05:6a10:5bc5:0:0:0:0 with SMTP id os5csp1482770pxb; Sat, 30 Oct 2021 14:51:08 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzEd3iCOPPbrIih+GAYGJs74kql8FB7Naz9lZ5trcfmkESxlf1wpDz4mcYkC2vFTeOisiSQ X-Received: by 2002:a17:906:f742:: with SMTP id jp2mr3069705ejb.214.1635630668445; Sat, 30 Oct 2021 14:51:08 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1635630668; cv=none; d=google.com; s=arc-20160816; b=Aka6Ue6RLN7dNbQApqklgterNTjYTSkAF4jW7WslDU2x5yGxfXNJHt8emjbKeZVN/U 6EnXdMjWshDHD3L3lu84Y222TOihiy9ULKk73CtiXeXZSLvYknQLHld8dlzGqDl94SZY m2XP0OUhQ0oRqNTj/b6OPCPaQlnGIIfXAEJHQavcNEAsZCOxwKz8KNzRqyxlIBC2FUkC W4uNFqd346MkxiaQJulzhOkY6WB5Lvzlb55BoIt3m+XZE0thoEV2PDI/mTLICU6h2qda ZqHMVBHIooqQDClRfbqSo3kjSdzckgBygoFi71uJ7J5sMK7a+BMaJkYjGi9nbLHqNMHw towg== 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 :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=6EV3+Db16M1TTmcxm0Ltf+cHXWaK6K5VL+dcc/n0F48=; b=Km7eCyLcmpt3M1wb2jBNIAuUyawyMgclhlv7/QGZ2+V6bRdBNcBG4DDjEfp3x77hPZ e82XWjllUvdRYxFY3rOefqYTk2PzOGB2riT5Yj3zsFaGPuPz7uzcjeuZ8QvMQshht10P 37IqBwQbVJNwAIurhnlLtc+hDJMJtx7MKg/SSv1hjiYiEMZwEvo81ZbGvXdp9BjFXSHW PDMW5Tx6yS21zzxuXPhhJRF/cjAyruTrzNvnLas/W5BxbPQu3RXWY2CzJStm/81gDd33 1DIeF/ZYzbZPrcR2JMY7Rnb7ZKDS2JNT7/fT2khe3wtkTqUGbnWfK1JJzCEQpfOKBb+0 0HDg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass (test mode) header.i=@o2.pl header.s=1024a header.b=nKPWUIuP; 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=NONE dis=NONE) header.from=o2.pl Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id hv12si17017546ejc.244.2021.10.30.14.50.45; Sat, 30 Oct 2021 14:51:08 -0700 (PDT) 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 (test mode) header.i=@o2.pl header.s=1024a header.b=nKPWUIuP; 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=NONE dis=NONE) header.from=o2.pl Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232112AbhJ3Vu3 (ORCPT + 99 others); Sat, 30 Oct 2021 17:50:29 -0400 Received: from mx-out.tlen.pl ([193.222.135.142]:45528 "EHLO mx-out.tlen.pl" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232042AbhJ3VuT (ORCPT ); Sat, 30 Oct 2021 17:50:19 -0400 Received: (wp-smtpd smtp.tlen.pl 27089 invoked from network); 30 Oct 2021 23:47:44 +0200 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=o2.pl; s=1024a; t=1635630464; bh=6EV3+Db16M1TTmcxm0Ltf+cHXWaK6K5VL+dcc/n0F48=; h=From:To:Cc:Subject; b=nKPWUIuPkOCUlSBwb2L5EbGfTLpPQ6MOYEP0HvfakKWE1yEINnzqE6mNlYqn/qYJ1 zrh2TpT6oZfYrcnYoejH9FxRRLwLmwsZ41uB5zpryaR3npQBPJi0cdh0xXRPeS7b9h Qla3oeTO6r3Hxo9OuYCcO585bjjVBcEsi8Tb3q00= Received: from ablz112.neoplus.adsl.tpnet.pl (HELO localhost.localdomain) (mat.jonczyk@o2.pl@[83.7.219.112]) (envelope-sender ) by smtp.tlen.pl (WP-SMTPD) with SMTP for ; 30 Oct 2021 23:47:44 +0200 From: =?UTF-8?q?Mateusz=20Jo=C5=84czyk?= To: linux-rtc@vger.kernel.org, linux-kernel@vger.kernel.org Cc: =?UTF-8?q?Mateusz=20Jo=C5=84czyk?= , Alessandro Zummo , Alexandre Belloni Subject: [DEBUG PATCH v3] rtc-cmos: cmos_read_alarm bug demonstration Date: Sat, 30 Oct 2021 23:46:36 +0200 Message-Id: <20211030214636.49602-9-mat.jonczyk@o2.pl> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20211030214636.49602-1-mat.jonczyk@o2.pl> References: <20211030214636.49602-1-mat.jonczyk@o2.pl> MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-WP-MailID: 750861c663260497be442ce509100eed X-WP-AV: skaner antywirusowy Poczty o2 X-WP-SPAM: NO 0000000 [QYOk] Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Before my commit "rtc-cmos: avoid UIP when reading alarm time", applying this patch and reading the CMOS time like so: while true; do cat /sys/class/rtc/rtc0/time ; sleep 0.5; done produces errors in dmesg on my Intel Kaby Lake laptop. Signed-off-by: Mateusz Jończyk Cc: Alessandro Zummo Cc: Alexandre Belloni --- drivers/rtc/rtc-cmos.c | 61 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 61 insertions(+) diff --git a/drivers/rtc/rtc-cmos.c b/drivers/rtc/rtc-cmos.c index b6d7dd3cf066..3de049930745 100644 --- a/drivers/rtc/rtc-cmos.c +++ b/drivers/rtc/rtc-cmos.c @@ -43,6 +43,9 @@ #include #endif +#include +#include + /* this is for "generic access to PC-style RTC" using CMOS_READ/CMOS_WRITE */ #include @@ -220,6 +223,8 @@ static inline void cmos_write_bank2(unsigned char val, unsigned char addr) /*----------------------------------------------------------------*/ +static void cmos_read_alarm_uip_debugging(struct device *dev); + static int cmos_read_time(struct device *dev, struct rtc_time *t) { /* @@ -230,6 +235,8 @@ static int cmos_read_time(struct device *dev, struct rtc_time *t) return -EIO; mc146818_get_time(t); + + cmos_read_alarm_uip_debugging(dev); return 0; } @@ -338,6 +345,60 @@ static int cmos_read_alarm(struct device *dev, struct rtc_wkalrm *t) return 0; } +static void cmos_read_alarm_uip_debugging(struct device *dev) +{ + unsigned long flags; + unsigned char rtc_uip_baseline, rtc_uip; + struct rtc_wkalrm t_baseline, t; + ktime_t time_start, time_end; + int i; + + spin_lock_irqsave(&rtc_lock, flags); + rtc_uip_baseline = CMOS_READ(RTC_FREQ_SELECT) & RTC_UIP; + spin_unlock_irqrestore(&rtc_lock, flags); + + cmos_read_alarm(dev, &t_baseline); + + time_start = ktime_get(); + + for (i = 0; i < 2000; i++) { + spin_lock_irqsave(&rtc_lock, flags); + rtc_uip = CMOS_READ(RTC_FREQ_SELECT) & RTC_UIP; + spin_unlock_irqrestore(&rtc_lock, flags); + + cmos_read_alarm(dev, &t); + + if (t_baseline.time.tm_sec != t.time.tm_sec) { + dev_err(dev, + "Inconsistent alarm tm_sec value: %d != %d (RTC_UIP = %d; %d)\n", + t_baseline.time.tm_sec, + t.time.tm_sec, + rtc_uip_baseline, rtc_uip); + } + if (t_baseline.time.tm_min != t.time.tm_min) { + dev_err(dev, + "Inconsistent alarm tm_min value: %d != %d (RTC_UIP = %d; %d)\n", + t_baseline.time.tm_min, + t.time.tm_min, + rtc_uip_baseline, rtc_uip); + } + if (t_baseline.time.tm_hour != t.time.tm_hour) { + dev_err(dev, + "Inconsistent alarm tm_hour value: %d != %d (RTC_UIP = %d; %d)\n", + t_baseline.time.tm_hour, + t.time.tm_hour, + rtc_uip_baseline, rtc_uip); + } + + } + + time_end = ktime_get(); + + pr_info_ratelimited("%s: loop executed in %lld ns\n", + __func__, ktime_to_ns(ktime_sub(time_end, time_start))); +} + + static void cmos_checkintr(struct cmos_rtc *cmos, unsigned char rtc_control) { unsigned char rtc_intr; -- 2.25.1