Received: by 2002:a05:6a10:5bc5:0:0:0:0 with SMTP id os5csp2622819pxb; Sun, 17 Oct 2021 20:47:38 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzRlp0FZmYnUpC00iKfmxxXe9Ga2I72X4bFiS8emIdzOCIdOzwy6jPmtXZSLiLwU/fDzrBs X-Received: by 2002:a17:90b:33cb:: with SMTP id lk11mr44636736pjb.0.1634528858790; Sun, 17 Oct 2021 20:47:38 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1634528858; cv=none; d=google.com; s=arc-20160816; b=oWAF4eTWD9HHKbAdfIoka2ccfwDffszf3GeD0hvZ6ehISW+EVqQvHYyZENPYYzFDkE vIpKcy/sF2h5KHp6XV/RaHOAClSD1syfbtWYoqJQG79nxMlWTzsWrTLNV+d2CNLzzIWx Q//Mj0sgtYbXpBye6A5W9iyN3/M8dAzYM4uvC6byFTub6te2gtPUt5B35SOUAOTudmgn PMoad+J9AMw2ynZxGd9ucUrCvikZd/7nOnSPejdvQEuTvm0gY8GWqL62m91igFsXcubv UBYd/usrZfOyf+LbzjYEg5EAjVrlyDXbppxn4cizaSaIsJDi5Fk0fjSX/WJZFXKs7iFF h5FA== 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=8r8xgy65ZR76BqRT88sVTuFNy8P/G7PRukyy/pHFjGc=; b=MLE58ZpfASeAYfynEVuFH6T2FLgHTwx6ZvNGsYUzFpTq3HXhfGa86bm/PPpAEon1Z2 UgXE0dhWNiyLSjEBDEtw6jUIev2LlPLw2XAEa/4kveijT0165eDtCLq3woVGtUda08dZ f5Kl4fa7Su4vQtmweoPi1YawF/aDpt5wvVreWCRaa4zjavH8AZZ0JqWXdrwOw4hfERWT 0bW47Bdao61y5kr7OFfiAAfSA1lYR3W7c4Kbb+DDlkbh+nsPOZNmsLrlQyngg7lYd/tf ftPQAwOw6DVSqbykOlR9KEcMjGuvO/YgH2d9nqSTOM90RBCvdYUdMN/G9Q1DvgijlCi9 oAOQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass (test mode) header.i=@o2.pl header.s=1024a header.b=KBRLFG6p; 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 lk11si1190848pjb.187.2021.10.17.20.47.26; Sun, 17 Oct 2021 20:47:38 -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=KBRLFG6p; 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 S238426AbhJQToQ (ORCPT + 98 others); Sun, 17 Oct 2021 15:44:16 -0400 Received: from mx-out.tlen.pl ([193.222.135.142]:12748 "EHLO mx-out.tlen.pl" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230434AbhJQToP (ORCPT ); Sun, 17 Oct 2021 15:44:15 -0400 Received: (wp-smtpd smtp.tlen.pl 25145 invoked from network); 17 Oct 2021 21:42:03 +0200 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=o2.pl; s=1024a; t=1634499723; bh=8r8xgy65ZR76BqRT88sVTuFNy8P/G7PRukyy/pHFjGc=; h=From:To:Cc:Subject; b=KBRLFG6p8hawldF7GfzfxR6+bsUrmYq304P6mEIjlLxqL0fwLJ3iE+6uGpUw+SBTS yptxy71/Ghyw6tGQ+tKbxOWrzgj9IgvHriyVncODX16DJCjj4FNSwDWIuoybYi0ayg W2tYTXoTLCp9ekZTWLltkQBb/uVUx76uUpa7x3MU= Received: from aaet142.neoplus.adsl.tpnet.pl (HELO localhost.localdomain) (mat.jonczyk@o2.pl@[83.4.123.142]) (envelope-sender ) by smtp.tlen.pl (WP-SMTPD) with SMTP for ; 17 Oct 2021 21:42:03 +0200 From: =?UTF-8?q?Mateusz=20Jo=C5=84czyk?= To: linux-kernel@vger.kernel.org, linux-rtc@vger.kernel.org Cc: =?UTF-8?q?Mateusz=20Jo=C5=84czyk?= , Alessandro Zummo , Alexandre Belloni Subject: [TEST PATCH] rtc-cmos: cmos_read_alarm bug demonstration Date: Sun, 17 Oct 2021 21:41:53 +0200 Message-Id: <20211017194153.277610-1-mat.jonczyk@o2.pl> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20211017193927.277409-3-mat.jonczyk@o2.pl> References: <20211017193927.277409-3-mat.jonczyk@o2.pl> MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-WP-MailID: d81c2cf7da2bd723763b864266a77aa4 X-WP-AV: skaner antywirusowy Poczty o2 X-WP-SPAM: NO 0000000 [kaMU] Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Before my commit "rtc-cmos: dont touch alarm registers during update", 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. 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 f353a41dfe8c..c24465f7bed4 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) { /* @@ -234,6 +239,8 @@ static int cmos_read_time(struct device *dev, struct rtc_time *t) * That'll make Y3K compatility (year > 2070) easy! */ mc146818_get_time(t); + + cmos_read_alarm_uip_debugging(dev); return 0; } @@ -348,6 +355,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