From: John Stultz <jstultz@google.com>
To: LKML <linux-kernel@vger.kernel.org>
Cc: John Stultz <jstultz@google.com>,
Thomas Gleixner <tglx@linutronix.de>,
Stephen Boyd <sboyd@kernel.org>, Arnd Bergmann <arnd@arndb.de>,
Michael <michael@mipisi.de>,
Michael Trimarchi <michael@amarulasolutions.com>,
kernel-team@android.com
Subject: [RFC][PATCH 1/2] time: alarmtimer: Fix erroneous case of using 0 as an "invalid" initialization value
Date: Sat, 11 Feb 2023 06:45:26 +0000 [thread overview]
Message-ID: <20230211064527.3481754-1-jstultz@google.com> (raw)
Michael reported seeing an error where alarmtimers would
occasionally not wake the system up.
It was found that in alarmtimer_suspend() it was exiting via
the:
if (min == 0)
return 0;
check. This logic was from one of the early versions of the
original alarmtimer patch, where we initialized min to 0, and
then this check would exit early if we found no timers to expire
(leaving min still at 0).
However, its possible for an alarmtimer to expire as we are
checking it, leaving the calculated delta to be zero, and thus
setting min to zero.
This is the result of my using 0 as an invalid time value which
is clearly erroneous. Instead KTIME_MAX should have been used.
This patch, split out from a change originally suggested by
Thomas Gleixner, changes the logic to instead use KTIME_MAX.
Cc: Thomas Gleixner <tglx@linutronix.de>
Cc: Stephen Boyd <sboyd@kernel.org>
Cc: Arnd Bergmann <arnd@arndb.de>
Cc: Michael <michael@mipisi.de>
Cc: Michael Trimarchi <michael@amarulasolutions.com>
Cc: kernel-team@android.com
Reported-by: Michael <michael@mipisi.de>
Reported-by: Michael Trimarchi <michael@amarulasolutions.com>
Fixes: ff3ead96d17f ("timers: Introduce in-kernel alarm-timer interface")
Originally-by: Thomas Gleixner <tglx@linutronix.de>
Link: https://lore.kernel.org/lkml/alpine.DEB.2.21.1909021247250.3955@nanos.tec.linutronix.de/
[jstultz: Forward ported to 6.2-rc, and split out just the
KTIME_MAX change]
Signed-off-by: John Stultz <jstultz@google.com>
---
kernel/time/alarmtimer.c | 9 +++++----
1 file changed, 5 insertions(+), 4 deletions(-)
diff --git a/kernel/time/alarmtimer.c b/kernel/time/alarmtimer.c
index 5897828b9d7e..f7b2128f64e2 100644
--- a/kernel/time/alarmtimer.c
+++ b/kernel/time/alarmtimer.c
@@ -251,7 +251,7 @@ static int alarmtimer_suspend(struct device *dev)
min = freezer_delta;
expires = freezer_expires;
type = freezer_alarmtype;
- freezer_delta = 0;
+ freezer_delta = KTIME_MAX;
spin_unlock_irqrestore(&freezer_delta_lock, flags);
rtc = alarmtimer_get_rtcdev();
@@ -271,13 +271,14 @@ static int alarmtimer_suspend(struct device *dev)
if (!next)
continue;
delta = ktime_sub(next->expires, base->get_ktime());
- if (!min || (delta < min)) {
+ if (delta < min) {
expires = next->expires;
min = delta;
type = i;
}
}
- if (min == 0)
+ /* No timers to expire */
+ if (min == KTIME_MAX)
return 0;
if (ktime_to_ns(min) < 2 * NSEC_PER_SEC) {
@@ -503,7 +504,7 @@ static void alarmtimer_freezerset(ktime_t absexp, enum alarmtimer_type type)
delta = ktime_sub(absexp, base->get_ktime());
spin_lock_irqsave(&freezer_delta_lock, flags);
- if (!freezer_delta || (delta < freezer_delta)) {
+ if (delta < freezer_delta) {
freezer_delta = delta;
freezer_expires = absexp;
freezer_alarmtype = type;
--
2.39.1.581.gbfd45094c4-goog
next reply other threads:[~2023-02-11 6:45 UTC|newest]
Thread overview: 35+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-02-11 6:45 John Stultz [this message]
2023-02-11 6:45 ` [RFC][PATCH 2/2] time: alarmtimer: Use TASK_FREEZABLE to cleanup freezer handling John Stultz
2023-02-15 8:22 ` Michael Nazzareno Trimarchi
2023-02-15 13:52 ` Thomas Gleixner
2023-02-18 14:56 ` Michael Nazzareno Trimarchi
2023-02-20 7:23 ` Thomas Gleixner
2023-02-20 8:23 ` Michael Nazzareno Trimarchi
2023-02-20 11:47 ` Michael Nazzareno Trimarchi
2023-02-20 17:48 ` Thomas Gleixner
2023-02-20 18:11 ` Michael Nazzareno Trimarchi
2023-02-20 21:18 ` Thomas Gleixner
2023-02-20 21:32 ` Michael Nazzareno Trimarchi
2023-02-21 0:12 ` Thomas Gleixner
2023-02-21 7:10 ` Michael Nazzareno Trimarchi
2023-02-24 10:02 ` Michael Nazzareno Trimarchi
2023-02-24 10:32 ` Michael Nazzareno Trimarchi
2023-02-24 11:57 ` Michael Nazzareno Trimarchi
2023-02-28 0:03 ` John Stultz
2023-02-28 4:06 ` John Stultz
2023-03-01 22:11 ` Thomas Gleixner
2023-03-02 0:47 ` John Stultz
2023-03-02 9:34 ` Michael Nazzareno Trimarchi
2023-03-02 15:00 ` Rafael J. Wysocki
2023-03-15 20:12 ` Michael Nazzareno Trimarchi
2023-03-02 14:54 ` Rafael J. Wysocki
2023-03-02 14:56 ` Rafael J. Wysocki
2023-03-02 14:32 ` Rafael J. Wysocki
2023-03-02 22:21 ` Thomas Gleixner
2023-03-02 22:58 ` Thomas Gleixner
2024-06-27 7:46 ` Michael Nazzareno Trimarchi
2024-07-13 10:47 ` Thomas Gleixner
2024-07-15 8:20 ` Michael Nazzareno Trimarchi
2023-02-21 11:50 ` Michael Nazzareno Trimarchi
2024-01-11 8:28 ` Michael Nazzareno Trimarchi
2023-02-18 14:51 ` [RFC][PATCH 1/2] time: alarmtimer: Fix erroneous case of using 0 as an "invalid" initialization value Michael Nazzareno Trimarchi
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20230211064527.3481754-1-jstultz@google.com \
--to=jstultz@google.com \
--cc=arnd@arndb.de \
--cc=kernel-team@android.com \
--cc=linux-kernel@vger.kernel.org \
--cc=michael@amarulasolutions.com \
--cc=michael@mipisi.de \
--cc=sboyd@kernel.org \
--cc=tglx@linutronix.de \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox