Received: by 2002:ac0:a5a7:0:0:0:0:0 with SMTP id m36-v6csp2577468imm; Mon, 16 Jul 2018 10:15:51 -0700 (PDT) X-Google-Smtp-Source: AAOMgpeYyGryH2FvvSyvbObzCp0J9qSq1Sw0tTtiEzNzmAqGhIg3v4PAGv8X54zLuEj40KUd6sSS X-Received: by 2002:a63:ff21:: with SMTP id k33-v6mr15881769pgi.38.1531761351638; Mon, 16 Jul 2018 10:15:51 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1531761351; cv=none; d=google.com; s=arc-20160816; b=RWXuS8mLnRB4H+KK+bKEH9jJPc1L32n6fV8fk92TjE9kmH40buespjNSbUv+1rmXIR 3rXLgSWH4jgZ1ZbxJSfMTXah5jma4z+InItXa2Z+ZdF6TgnuUkb+Mqn1Hrg/u8tfVf1x hgiElKY4HV3jTQ5c6RT0c9VEHo58XF+hOARvKlqcItzqpZ4eT19rLx5ORwVzKszjn3lG y2lm+qYbY7Wfvl6HNr/ClrsIWAuu3pxE2EXy6fI+atRTjnqwcIwTqH3c/irRDwaDVZ4D V3vr7ePEFOV3RfRptaaoNATT3/OuBigOJqvOstbQngcCdvl8GNAEgcdBoWaKdAjtgXzJ 7SVg== 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=javFYPUAjnphavH/VkT6F7Uu0X/LS1B7O7mtzd6pjvg=; b=riBxFZIHqmBdz1uvSbM+r/z/RKqlHeFebJDvL70PMZTPT6/nMW4BP4u9yoH+2awO/t 9sHPfo6U+nDHDZLJF6HA3CrHXlKLBeDGhHjkKZfQVhRZGFwZ4H3l7bIVGg/7zoJSPhYD T5EseHOhqtKeTUft5qfetTY48gftaFM4dW2uB5ABkePABnpZCNLVJcZqdcMDPfmTu9+4 Ckdxy0/W2w5QkrIpjGAlL1hOE6e6ZLJXtGgV/VMwBvOf2spUPcbiGBSBiXt4PxYTrcJv QKN40y0zO+fsN7tJvbpD1rfCYNx4sptfIOs771xsfPZvqJHDLAmK6hotx9YUyg/cL8no IMCw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b="X8G/I6yn"; 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 y128-v6si30920695pfb.299.2018.07.16.10.15.36; Mon, 16 Jul 2018 10:15:51 -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="X8G/I6yn"; 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 S1729859AbeGPRmm (ORCPT + 99 others); Mon, 16 Jul 2018 13:42:42 -0400 Received: from mail-wr1-f66.google.com ([209.85.221.66]:44725 "EHLO mail-wr1-f66.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727652AbeGPRmm (ORCPT ); Mon, 16 Jul 2018 13:42:42 -0400 Received: by mail-wr1-f66.google.com with SMTP id r16-v6so32669013wrt.11 for ; Mon, 16 Jul 2018 10:14:21 -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=javFYPUAjnphavH/VkT6F7Uu0X/LS1B7O7mtzd6pjvg=; b=X8G/I6yngxbTzBsB4GOvxxKVpEHVKQLjUlvTK+akcJLd+HCL+wdPJQgHch5mTs43/0 GndaKBo/65hwFaBxQi4av+kj3wrhxHybh2Pc432mVuLCuXGN2tUUEG5NX1iZU95+Fz4J yxeIR9Cd80MG+ZuocXFIa3ZzXpuRc10JcxoIk= 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=javFYPUAjnphavH/VkT6F7Uu0X/LS1B7O7mtzd6pjvg=; b=umbbdK25lKM+GBVFMw6AISEKju5vJdQjsrqbAiaFcnaIO3CenvGNQIGS4ib4W0jjAB DWaKV6foZgHUSLYkV/7Wkm1nEVuWZsFTmI23h59d6dvZ2jRlvaxhAIDk3e3sWCalFRlG lforkalrmhsnnLmkOQiUt5bJCR5mqVI+jUlhauRKjp5mp7GjRUzcGlL1tn2+ltmRKEfv Vz/pdCzWYTnsVB+2Ea2l0OWTJZdYt3Uoj6x8tQvqc8HVRy6TbGpXgo+nG59dm7n0uuBM y3e5G8hPawbdi5RSi95VukB0Le7DkjZgKBU6LcN69AgycjXIWp/Ih//60dDSM6cQbkoe +ylw== X-Gm-Message-State: AOUpUlHN4G79nNKeeamvo1q6+iRBiSS4UHWTfNCs0JTrhOvNGh99V+U0 okpEzAYqYtVMe0mEGAR/Awx9Faax1qgLOXoFynGHAg== X-Received: by 2002:adf:f342:: with SMTP id e2-v6mr12437029wrp.161.1531761260571; Mon, 16 Jul 2018 10:14:20 -0700 (PDT) MIME-Version: 1.0 Received: by 2002:a1c:c243:0:0:0:0:0 with HTTP; Mon, 16 Jul 2018 10:14:19 -0700 (PDT) In-Reply-To: References: <1530883047-17452-1-git-send-email-mojha@codeaurora.org> <7e25b63e-cc9b-1f6d-e3d2-087dd484f631@codeaurora.org> <45be9c4f-34fd-200a-df95-9c30b332a96b@codeaurora.org> From: John Stultz Date: Mon, 16 Jul 2018 10:14:19 -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 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. Sorry, I meant "with the logic bug above fixed it will work out". thanks -john