Received: by 10.223.185.116 with SMTP id b49csp4497274wrg; Mon, 26 Feb 2018 19:56:55 -0800 (PST) X-Google-Smtp-Source: AH8x226glpDWy2eMtmoI/VQnR5pU2b2k8PGzK14wgt/qxkcCwG/aJLRLE9H8+MAjOWD1UFScv2M+ X-Received: by 10.101.93.15 with SMTP id e15mr10065678pgr.175.1519703815107; Mon, 26 Feb 2018 19:56:55 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1519703815; cv=none; d=google.com; s=arc-20160816; b=xRaI1IEHsQKjPy0wm25CvjmvLXz/54Ve4maFIoSp8ahhwfBUGPd8G0tBc23o4q2TvI KclKQNfgKLWpD8UVBLg+2mdVn6S772IoPxv8jgRhqTa1n1Vb7pTIORX5dtkZOYKdpJhW trTB3rGr7QGPZF2DEUDy4tCv0n3OzVZS77VVFaoiWA+yuaemYKjzwCCDFBdWWDDJjCIX Cc26li7NbtBglX2gJLXeV3j0KyeLcQfkOoBu8z5WFa2xsGIkMAZGHQ241HoBVAniDr84 okFQMJf4gVPnnKgJI/Us4v7BqxZ587nTFKEIPGIBvoXldN+kL0MdhTj6cg8vPL1Jop1H Mfow== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:cc:to:subject:message-id:date:from :references:in-reply-to:mime-version:dkim-signature :arc-authentication-results; bh=OKD6SWI4uhwXTtV2llzUbF7Slsrrn/o8QMDfnYkuHRA=; b=CzMvUPYahxJ4Mehxv+Vt0+aH0o23EKeFY5BxU+U1D2AuINkQG5tkfBkt+NvFdszFQe kQobEKOmBuj/bFEn9bBIfM+2uHdD8DCsLlVblHdlmyCSv8wZRXt6/0sQXsMwXwfHZxdd PaoWiOnuPKBpifupegH50jOi7VSOmIC6xvaeN2qvJIO7k8i98dN5PZjHiOe1e2eRBSya 2f9mwEJsFhwQRr1GPAJPN9afY2E+mzRKs9Kax9FJ1H7/3mZUxquaM9MtF7sXZOOQiKZp tD3lIUOW5GVSnvpWPmvQQF7al3cLxVsjLHeuxOHBnS8wYBRzM8dtH3M5zNFFzjbEO7bB DacQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20161025 header.b=MiiR75mH; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id t12si6426654pgb.190.2018.02.26.19.56.39; Mon, 26 Feb 2018 19:56:55 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@google.com header.s=20161025 header.b=MiiR75mH; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751812AbeB0D4A (ORCPT + 99 others); Mon, 26 Feb 2018 22:56:00 -0500 Received: from mail-wm0-f66.google.com ([74.125.82.66]:50241 "EHLO mail-wm0-f66.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751631AbeB0Dz7 (ORCPT ); Mon, 26 Feb 2018 22:55:59 -0500 Received: by mail-wm0-f66.google.com with SMTP id w128so15373252wmw.0 for ; Mon, 26 Feb 2018 19:55:58 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20161025; h=mime-version:in-reply-to:references:from:date:message-id:subject:to :cc; bh=OKD6SWI4uhwXTtV2llzUbF7Slsrrn/o8QMDfnYkuHRA=; b=MiiR75mHU+KcTWMz7NlfTCgHrMKZti2wM02Jb56WfEP/8ovzT0N6yd7fYHEbx82nzT JchAjd7o4NJjbPz/LN4MF2BIwB67M2c9tLNcBYhiLOIYs2Lw3jn+qMxF3S6o2RUpN1uT dvqUY1Y+yeNTOo4ie44neCz6boiXpqYaoBpcgfa8ssd/B4SJnlVGNAvCs6rbnuFSza7U oDIPnWynTZez99QFF7rUpucK0DkbwaTApg+UaI4AKobXBUbxYkHJmsUg9QEC6ph4Kj0p KzeepV6OuycPZWLnKjOjICGfU1aAGy+UArr7sNUjcHTwfXk5wO4puUv0/qAllb1WKG+o M1dQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:in-reply-to:references:from:date :message-id:subject:to:cc; bh=OKD6SWI4uhwXTtV2llzUbF7Slsrrn/o8QMDfnYkuHRA=; b=ZwcQW2ZtqC/+nZi0KZ97151NhO4uvfZcfx3A8GotYf0pJtT7Op0VOEKpxHFgxMn4RO WqzUg1gccDnZiAZgLWOxekvficnWlInUdvzB4WEonP7lq4uWTZ/yTnKLHLgZVJ7ZsYaa tVgjFpjFwp3URCVGuIbqXLlQLQBisxKkWP63ccn5W4pcQ42qMRGGUFuOWkWQVR05KXeO vz0Co9ZjAXC47r8bZ5pE3wc6jY2nx/fyjAm0AKubImsRjxQxOoJgMOk2dcbooo01ti99 dbZz2SZwKbvTABZZ77aq2qzOxXdf9pa3A5U+nt2agkf20nkQeVwgMb7iAy02dvvddwCM C0oQ== X-Gm-Message-State: APf1xPCZ9RCuUImv6n5DLAIdjhNjj7whVYtr67YooNqU2XWR1Oz8Ik+5 nUHEfzJJCrpuf7+wk13YHk3dSeMVVCHDPCxPNd27+Q== X-Received: by 10.80.128.230 with SMTP id 93mr17281760edb.34.1519703757714; Mon, 26 Feb 2018 19:55:57 -0800 (PST) MIME-Version: 1.0 Received: by 10.80.133.201 with HTTP; Mon, 26 Feb 2018 19:55:56 -0800 (PST) In-Reply-To: <20180227025003.8823-1-jeffy.chen@rock-chips.com> References: <20180227025003.8823-1-jeffy.chen@rock-chips.com> From: Brian Norris Date: Mon, 26 Feb 2018 19:55:56 -0800 Message-ID: Subject: Re: [RESEND PATCH v3] rtc: cros-ec: return -ETIME when refused to set alarms in the past To: Jeffy Chen Cc: Linux Kernel , Chris Zhong , Doug Anderson , Julius Werner , linux-rtc@vger.kernel.org, Alexandre Belloni , Alessandro Zummo Content-Type: text/plain; charset="UTF-8" Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Hi Jeffy, On Mon, Feb 26, 2018 at 6:50 PM, Jeffy Chen wrote: > Since accessing a Chrome OS EC based rtc is a slow operation, there is a > race window where if the alarm is set for the next second and the second > ticks over right before calculating the alarm offset. > > In this case the current driver is setting a 0-second alarm, which would > be considered as disabling alarms by the EC(EC_RTC_ALARM_CLEAR). > > This breaks, e.g., hwclock which relies on RTC_UIE_ON -> > rtc_update_irq_enable(), which sets a 1-second alarm and expects it to > fire an interrupt. > > So return -ETIME when the alarm is in the past, follow __rtc_set_alarm(). > > Signed-off-by: Jeffy Chen Commit message is better. Thanks! And this is exactly what I was already testing. I still need to get through a bit more testing to ensure it has resolved all the races I saw, but it's good on several of them: Reviewed-by: Brian Norris Tested-by: Brian Norris > --- > > Changes in v3: > Fix alarm time comparing. > > Changes in v2: > Rewrite commit message as Brian suggested. > Check alarm time only when that alarm is enabled. > > drivers/rtc/rtc-cros-ec.c | 8 ++++---- > 1 file changed, 4 insertions(+), 4 deletions(-) > > diff --git a/drivers/rtc/rtc-cros-ec.c b/drivers/rtc/rtc-cros-ec.c > index f0ea6899c731..bf7ced095c94 100644 > --- a/drivers/rtc/rtc-cros-ec.c > +++ b/drivers/rtc/rtc-cros-ec.c > @@ -197,10 +197,10 @@ static int cros_ec_rtc_set_alarm(struct device *dev, struct rtc_wkalrm *alrm) > cros_ec_rtc->saved_alarm = (u32)alarm_time; > } else { > /* Don't set an alarm in the past. */ > - if ((u32)alarm_time < current_time) > - alarm_offset = EC_RTC_ALARM_CLEAR; > - else > - alarm_offset = (u32)alarm_time - current_time; > + if ((u32)alarm_time <= current_time) > + return -ETIME; > + > + alarm_offset = (u32)alarm_time - current_time; > } > > ret = cros_ec_rtc_set(cros_ec, EC_CMD_RTC_SET_ALARM, alarm_offset); > -- > 2.11.0 > >