From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1762356AbaGRWJ5 (ORCPT ); Fri, 18 Jul 2014 18:09:57 -0400 Received: from smtp.codeaurora.org ([198.145.11.231]:43256 "EHLO smtp.codeaurora.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1755665AbaGRWJ4 (ORCPT ); Fri, 18 Jul 2014 18:09:56 -0400 From: Stephen Boyd To: John Stultz , Thomas Gleixner Cc: linux-kernel@vger.kernel.org, linux-arm-kernel@lists.infradead.org Subject: [PATCH] sched_clock: Avoid corrupting hrtimer tree during suspend Date: Fri, 18 Jul 2014 15:09:52 -0700 Message-Id: <1405721392-30795-1-git-send-email-sboyd@codeaurora.org> X-Mailer: git-send-email 1.9.0.1.gd5ccf8c Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org During suspend we call sched_clock_poll() to update the epoch and accumulated time and reprogram the sched_clock_timer to fire before the next wrap-around time. Unfortunately, sched_clock_poll() doesn't restart the timer, instead it relies on the hrtimer layer to do that and during suspend we aren't calling that function from the hrtimer layer. Instead, we're reprogramming the expires time while the hrtimer is enqueued, which can cause the hrtimer tree to be corrupted. Fix this problem by updating the state via update_sched_clock() and properly restarting the timer via hrtimer_start(). Fixes: a08ca5d1089d "sched_clock: Use an hrtimer instead of timer" Signed-off-by: Stephen Boyd --- I also wonder if we should be restarting the timer during resume instead of suspend given that the resume path modifies the epoch. At that point timers can't run because interrupts are disabled and we don't really care if the timer fires earlier than it's supposed to anyway because it's just there to avoid rollover events, but does it seem better to do it that way? I didn't send that version because this patch is to fix the code intention, but I'm curious if anyone else feels like it should be changed. kernel/time/sched_clock.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/kernel/time/sched_clock.c b/kernel/time/sched_clock.c index 445106d2c729..9e32ce88e9ee 100644 --- a/kernel/time/sched_clock.c +++ b/kernel/time/sched_clock.c @@ -191,7 +191,9 @@ void __init sched_clock_postinit(void) static int sched_clock_suspend(void) { - sched_clock_poll(&sched_clock_timer); + update_sched_clock(); + /* Restart the timer because we forced an update */ + hrtimer_start(&sched_clock_timer, cd.wrap_kt, HRTIMER_MODE_REL); cd.suspended = true; return 0; } -- The Qualcomm Innovation Center, Inc. is a member of the Code Aurora Forum, hosted by The Linux Foundation