Received: by 2002:ac0:a5a7:0:0:0:0:0 with SMTP id m36-v6csp2099560imm; Tue, 10 Jul 2018 13:16:05 -0700 (PDT) X-Google-Smtp-Source: AAOMgpd8RTDk/QQ3SUSTTMTAePsUlvmRJmfTP65ANaAqiGnSUBT1P96o5gfw6OsjZuZiXkbMPfrf X-Received: by 2002:a63:4306:: with SMTP id q6-v6mr23155049pga.181.1531253765235; Tue, 10 Jul 2018 13:16:05 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1531253765; cv=none; d=google.com; s=arc-20160816; b=nXgylyiBI19d8N+DQGYSYhXeJsC+VNZ/1pM+qgbTYLmwczuh184mf91htCWOrTEwpO D3qgoqIT2MWE3Rwo7kYwaG3LJR1RFvoEdrel5ib3wY3isNXaa6NBFpecfLd/ktH9aIoP 41Up8+hcgs9tKKfQU+kuUETj7tNnrTHJ68h30QWZHC/xWlMYsNHOnGhaKKXcTnk3YzLq LWuc2kpwuRxfHLgif9L/GjBETf6Dh9U7dKg3FuoWv5VBZ+gVCIaMOYBQF3XwmmepQc/c cKoVOiiX3GGz/FV/at+vZiD59Cq+7vVXPPtz8h4P/ULcOX/SB58r3ii3+2/MuvVPwVvZ DoaQ== 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=/B7E6VG0yqE+/NWzoM2gNQyl88scAfku1P4y5N7GhMM=; b=w0wRucDVcNAXBE21WyZhjRmWVpwj6+CHgt7TXTyBM7yJC86iuWnFjsYLJFN/8XhWoG 2XQZQ1lMrxlqIz9HkseO9k13ubrDp69ZgqzWPWC+9oLbBBPGb5QvF41/KUTqh1ECJHOb n0LgYqbS+MeIApwWvOYfBmAYzXqg8kZEN5rcJvcS4Z9IG9oyOnQthZp6gkp9Wz1WXFD8 uDE2tWzAEjzsLGqmOry5XEc18A5pooWrhWW0+z4RAIpdIhnM9z4wsCWJMGHSQZTDOmAB LY9ok4brhxMoaFFeWEknZHep4HstBfa+uJoOX9BbhonsXXFKcZIuI/G/264X1+PwUPyh cboQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=KeiezXPu; 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=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id g6-v6si15855678pgq.240.2018.07.10.13.15.50; Tue, 10 Jul 2018 13:16:05 -0700 (PDT) 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=@linaro.org header.s=google header.b=KeiezXPu; 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=NONE sp=NONE dis=NONE) header.from=linaro.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1732661AbeGJUOP (ORCPT + 99 others); Tue, 10 Jul 2018 16:14:15 -0400 Received: from mail-wr1-f67.google.com ([209.85.221.67]:44891 "EHLO mail-wr1-f67.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1732354AbeGJUOP (ORCPT ); Tue, 10 Jul 2018 16:14:15 -0400 Received: by mail-wr1-f67.google.com with SMTP id r16-v6so15885571wrt.11 for ; Tue, 10 Jul 2018 13:13:37 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=mime-version:in-reply-to:references:from:date:message-id:subject:to :cc; bh=/B7E6VG0yqE+/NWzoM2gNQyl88scAfku1P4y5N7GhMM=; b=KeiezXPuF0adi5ZwOribeWdYSoFRWJ/Uf+2+brXxssQfmuP+o5YJwlEZ4e/0xc4Q7I nI9v6cgkq4eL+TqPzaAw63teCKWu3qaBEdafExG3PhY/QDDNOG34e0rXTiEtftJWbLX5 uy1qWq6Xd9EW5Poc3qvhVM68ajXwOSg+wJ/L8= 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=/B7E6VG0yqE+/NWzoM2gNQyl88scAfku1P4y5N7GhMM=; b=pg96DwwkwIdWNYfwXjZsB3+0f4sNSpzgDFjsx6SefNkpmS5l5jrnVmbSab9s7PTMrd OgnTHQBWF/jNQ0lGsPB8vVeGZcFM87AQPvPZlUq/2nH2kI/s0a09YkwEkGfS9vwDjlp3 gtlaaJ7nvHIz4rJTHa2vM+xmJXEYd2Em1oRBbSCREMW+6SVp+ul2WFw34zTKzLfvIpF+ npznbwFcO4WgLr3WsOozEIwmmJ+Whi5us6QjtligLE42I+3dWxrpWXjsK8nXArHWgoTV efNgiOgTtEpAlJmNcQpiBNzbe7mMYzizdkFkf7G4w/Bp8LGiou/2kk/tyH8OzFGdRuHZ 07ww== X-Gm-Message-State: APt69E1enrdFgHOqxYhDDZ8pv48ClcAq67fqglaE90WA1KouJj7hlvcN BhwN1WZ8r1MgsGpdhimkk8569Dc6IvwGfpdqvhEjDWoSFco= X-Received: by 2002:a5d:4985:: with SMTP id r5-v6mr19195456wrq.116.1531253616484; Tue, 10 Jul 2018 13:13:36 -0700 (PDT) MIME-Version: 1.0 Received: by 2002:a1c:c202:0:0:0:0:0 with HTTP; Tue, 10 Jul 2018 13:13:35 -0700 (PDT) In-Reply-To: <1530883047-17452-1-git-send-email-mojha@codeaurora.org> References: <1530883047-17452-1-git-send-email-mojha@codeaurora.org> From: John Stultz Date: Tue, 10 Jul 2018 13:13:35 -0700 Message-ID: Subject: Re: [PATCH v3] time: Fix incorrect sleeptime injection when suspend fails To: Mukesh Ojha Cc: Thomas Gleixner , lkml , gkohli@codeaurora.org, cpandya@codeaurora.org, neeraju@codeaurora.org, Baolin Wang 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 On Fri, Jul 6, 2018 at 6:17 AM, Mukesh Ojha wrote: > Currently, there exists a corner case assuming when there is > only one clocksource e.g RTC, and system failed to go to > suspend mode. While resume rtc_resume() injects the sleeptime > as timekeeping_rtc_skipresume() returned 'false' (default value > of sleeptime_injected) due to which we can see mismatch in > timestamps. > > This issue can also come in a system where more than one > clocksource are present and very first suspend fails. > > Fix this by handling `sleeptime_injected` flag properly. > > Success case: > ------------ > {sleeptime_injected=false} > rtc_suspend() => timekeeping_suspend() => timekeeping_resume() => > > (sleeptime injected) > rtc_resume() > > Failure case: > ------------ > {failure in sleep path} {sleeptime_injected=false} > rtc_suspend() => rtc_resume() > > sleeptime injected again which was not required as the suspend failed) > > Originally-by: Thomas Gleixner > Signed-off-by: Mukesh Ojha > --- > Changes in v3: > * Updated commit subject and description. > * Updated the patch as per the fix given by Thomas Gleixner. > > Changes in v2: > * Updated the commit text. > * Removed extra variable and used the earlier static > variable 'sleeptime_injected'. > > kernel/time/timekeeping.c | 21 ++++++++++++++++++--- > 1 file changed, 18 insertions(+), 3 deletions(-) > > diff --git a/kernel/time/timekeeping.c b/kernel/time/timekeeping.c > index 4786df9..32ae9ae 100644 > --- a/kernel/time/timekeeping.c > +++ b/kernel/time/timekeeping.c > @@ -1510,8 +1510,20 @@ void __weak read_boot_clock64(struct timespec64 *ts) > ts->tv_nsec = 0; > } > > -/* Flag for if timekeeping_resume() has injected sleeptime */ > -static bool sleeptime_injected; > +/* > + * Flag reflecting whether timekeeping_resume() has injected sleeptime. > + * > + * The flag starts of true and is only cleared when a suspend reaches > + * timekeeping_suspend(), timekeeping_resume() sets it when the timekeeper > + * clocksource is not stopping across suspend and has been used to update > + * sleep time. If the timekeeper clocksource has stopped then the flag > + * stays false and is used by the RTC resume code to decide whether sleep > + * time must be injected and if so the flag gets set then. > + * > + * If a suspend fails before reaching timekeeping_resume() then the flag > + * stays true and prevents erroneous sleeptime injection. > + */ > +static bool sleeptime_injected = true; I worry this upside-down logic is too subtle to be easily reasoned about, and will just lead to future mistakes. Can we instead call this "suspend_timing_needed" and only set it to true when we don't inject any sleep time on resume? I think that will help make things a bit more clear, no? thanks -john