Received: by 2002:ac0:a5a7:0:0:0:0:0 with SMTP id m36-v6csp2664915imm; Mon, 16 Jul 2018 11:55:37 -0700 (PDT) X-Google-Smtp-Source: AAOMgpeMAJO++BySGqKaFbZzByNsBZ7aCtj4qMlnG78sXYy/IkaYyYQak9c7sDBAnw314ixA0iyv X-Received: by 2002:a62:4308:: with SMTP id q8-v6mr19488204pfa.86.1531767337157; Mon, 16 Jul 2018 11:55:37 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1531767337; cv=none; d=google.com; s=arc-20160816; b=KgAcIalSbzp37oM+Rbm+YIsQNLblX9ns8xoJTTDwx+FEzPFYeIWKJEl3asFQPq4bx8 RzcFh6E1nqLmrMNeUc23wejikIzqApPsdKUirlnmRZyoV+cbHRnrwu7SMmItOykekYcp 3D6EDpsXCdBq7niH4axaoWjXQY5o4YnaArugeCJMNXDl3nx77f2lHt+EXnGzLdXol1Z1 q6brLt2rH74zHreBNDEjNTu22fcHnXb3kAe4Rm28/eVyfyIaJLyU9+VxRGaM3PJ4cLnt WIx+Ff1ONd5iQxkkBf5YBMEp+5lAEwMVFyp/tKBhBXh9bngdyM5O7VtgByggeksPVZY9 WbRA== 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=i/Z1G+hcYEVl7jHUIMj6U3Bscp/LD6iiEp2NvqajwmA=; b=lWayXb1C5G8KwSrxZt4KaSBhfggjFkUp3IChvDzl2kp3cIQcPZQRI7GvFyvtwwI/18 5iBOAocvwPdAM5g863XeSxDEdwJonOZnIbZMt2SKbLASZsyZKlcxhetrHKLD19VDK+2S NKc+tI+3SSY+aS6pPSSbmqc7aNi5IJKDQtl7C/WvcCsIGQpa86EEreQ8R6Wyeu5QfUgT UT3CTmnNuE7C1YM7IhgtTbVITL1LHgLDrsUwsZq8wK2QKMbs3qAFhen7d1kxgNuAu+kt XkXLYKLQpAvU4gBPnrdNGBoUTexQQdKuAXug23sj78ert0hW66xQaKwsQ7onjsI+fSzu h7FA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=Wo574RDR; 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 m7-v6si6578220pgm.184.2018.07.16.11.55.11; Mon, 16 Jul 2018 11:55:37 -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=Wo574RDR; 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 S1728945AbeGPTXA (ORCPT + 99 others); Mon, 16 Jul 2018 15:23:00 -0400 Received: from mail-wm0-f68.google.com ([74.125.82.68]:54551 "EHLO mail-wm0-f68.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728285AbeGPTXA (ORCPT ); Mon, 16 Jul 2018 15:23:00 -0400 Received: by mail-wm0-f68.google.com with SMTP id c14-v6so5834142wmb.4 for ; Mon, 16 Jul 2018 11:54:15 -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=i/Z1G+hcYEVl7jHUIMj6U3Bscp/LD6iiEp2NvqajwmA=; b=Wo574RDR5Mnfy/5hpyETkPbw9lpqcBueWgEl3PzGq+yMVbCLELVawMFJ7hZQsP/2Xd IcI0Qc3XxPq3Sa5uTAnWZZ2R0f5aDgNP/EYAyLbOJaGIjZgALa+dudIu+YDLGA6x2Kg5 1GoJjNkfyBsPRGQDa1KzwSovEjvLx0/guMqLc= 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=i/Z1G+hcYEVl7jHUIMj6U3Bscp/LD6iiEp2NvqajwmA=; b=s5QZ4IQQLYgnqB8OC6E7kDPvERumOAVwcXNZeqi0d1PvZYlXVCcEA6/Y9b7DROZIKd r7IG88J65OfZ961doIx12psEfIFDLvSkBlIZVQBAhncsItLQdmEKH18EvQ+3UvgZj9tq GgvO/FHL0+pK1v0HbLm3Aznrc5t8l/iwQMBDqkdrTvkJJ1dZQudFIT+vomO0E8kvdMVz O9CXTbb07j1tervFlUQ/eEaRqhrIKLmq9jJOvYes0tvFG61n2sRU4LVD5D2CQ3Ydq9bi V8uoKRCNhWdXEljKsLbBlpRr0YsBB4hsAeXf9ZahiGOtSbmvSOPuoUtaZgGzGnQAUwWm pKjQ== X-Gm-Message-State: AOUpUlFUlzk5LFf93HpXupxNQxclH5vS+UdZRbykevuZAIRONqrzh8AU 2+xfi8jPjoc1T7ozi/ASflYdtBU+aClcmB5UCLGSDA== X-Received: by 2002:a1c:3c4:: with SMTP id 187-v6mr9682915wmd.96.1531767253821; Mon, 16 Jul 2018 11:54:13 -0700 (PDT) MIME-Version: 1.0 Received: by 2002:a1c:c243:0:0:0:0:0 with HTTP; Mon, 16 Jul 2018 11:54:13 -0700 (PDT) In-Reply-To: <19b10a21-2636-49a9-2a1a-488f293aeb45@codeaurora.org> References: <1530883047-17452-1-git-send-email-mojha@codeaurora.org> <7e25b63e-cc9b-1f6d-e3d2-087dd484f631@codeaurora.org> <45be9c4f-34fd-200a-df95-9c30b332a96b@codeaurora.org> <19b10a21-2636-49a9-2a1a-488f293aeb45@codeaurora.org> From: John Stultz Date: Mon, 16 Jul 2018 11:54:13 -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 Mon, Jul 16, 2018 at 11:30 AM, Mukesh Ojha wrote: > > > On 7/16/2018 10:44 PM, John Stultz wrote: >> >> On Mon, Jul 16, 2018 at 9:30 AM, John Stultz >> wrote: >>> >>> On Mon, Jul 16, 2018 at 9:17 AM, Mukesh Ojha >>> wrote: >>>> >>>> On 7/13/2018 10:50 PM, John Stultz wrote: >>>>> >>>>> On Fri, Jul 13, 2018 at 12:13 AM, Mukesh Ojha >>>>>> >>>>>> On 7/11/2018 1:43 AM, John Stultz wrote: >>>>>>> >>>>>>> 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 did not get your point "only set it to true when we don't inject any >>>>>> sleep >>>>>> time on resume? " >>>>>> How do we know this ? >>>>>> This question itself depends on the "sleeptime_injected" if it is true >>>>>> means >>>>>> no need to inject else need to inject. >>>>>> >>>>>> Also, we need to make this variable back and forth true, false; >>>>>> suspends >>>>>> path ensures it to make it false. >>>>> >>>>> So yea, I'm not saying logically the code is really any different, >>>>> this is more of a naming nit. So instead of having a variable that is >>>>> always on that we occasionally turn off, lets invert the naming and >>>>> have it be a flag that we occasionally turn on. >>>> >>>> >>>> I understand your concern about the name of the variable will be >>>> misleading. >>>> But the changing Boolean state would not solve the actual issue. >>>> >>>> If i understand you correctly you meant below code >>>> >>>> diff --git a/kernel/time/timekeeping.c b/kernel/time/timekeeping.c >>>> index 32ae9ae..becc5bd 100644 >>>> --- a/kernel/time/timekeeping.c >>>> +++ b/kernel/time/timekeeping.c >>>> @@ -1523,7 +1523,7 @@ void __weak read_boot_clock64(struct timespec64 >>>> *ts) >>>> * If a suspend fails before reaching timekeeping_resume() then the >>>> flag >>>> * stays true and prevents erroneous sleeptime injection. >>>> */ >>>> -static bool sleeptime_injected = true; >>>> +static bool suspend_timing_needed; >>>> >>>> /* Flag for if there is a persistent clock on this platform */ >>>> static bool persistent_clock_exists; >>>> @@ -1658,7 +1658,7 @@ void timekeeping_inject_sleeptime64(struct >>>> timespec64 >>>> *delta) >>>> raw_spin_lock_irqsave(&timekeeper_lock, flags); >>>> write_seqcount_begin(&tk_core.seq); >>>> >>>> - sleeptime_injected = true; >>>> + suspend_timing_needed = false; >>>> >>>> timekeeping_forward_now(tk); >>>> >>>> @@ -1714,10 +1714,10 @@ void timekeeping_resume(void) >>>> tk->tkr_mono.mask); >>>> nsec = mul_u64_u32_shr(cyc_delta, clock->mult, >>>> clock->shift); >>>> ts_delta = ns_to_timespec64(nsec); >>>> - sleeptime_injected = true; >>>> + suspend_timing_needed = true; >>>> } else if (timespec64_compare(&ts_new, >>>> &timekeeping_suspend_time) > >>>> 0) { >>>> ts_delta = timespec64_sub(ts_new, >>>> timekeeping_suspend_time); >>>> - sleeptime_injected = true; >>>> + suspend_timing_needed = true; >>>> } >>> >>> No no... This part is wrong. We only set suspend_timing_needed if we >>> *didn't* calculate the suspend time in timekeeping_resume. >>> >>> You have to invert all the boolean logic for it to be equivalent. >>> >> ... >>>> >>>> >>> >>> >>> So, I think with the logic bug above it will work out properly, but >>> let me know if I'm still missing something. > > > Please give it thought to a case where very first suspend fails with your > logic. I believe I did. If the first suspend fails, we never reach timekeeping_resume, so we never set "suspend_time_needed = true", so then timekeeping_rtc_skipresume can then return true, and we don't inject the time in the RTC code. > If i am not able to get your thought, please write a patch. I probably will, but I'd like to encourage you to follow through on this one. You reported the issue, and submitted a few patches, so I think it would be good for you to also get the patch credit here. I don't believe its a complex request I've made, and I think you can figure it out. So, please, take one more real stab at this and I'll rework it if it seems necessary. thanks -john