From patchwork Wed Mar 14 23:58:56 2012 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: John Stultz X-Patchwork-Id: 7298 Return-Path: X-Original-To: patchwork@peony.canonical.com Delivered-To: patchwork@peony.canonical.com Received: from fiordland.canonical.com (fiordland.canonical.com [91.189.94.145]) by peony.canonical.com (Postfix) with ESMTP id 3A53923E0C for ; Wed, 14 Mar 2012 23:59:07 +0000 (UTC) Received: from mail-iy0-f180.google.com (mail-iy0-f180.google.com [209.85.210.180]) by fiordland.canonical.com (Postfix) with ESMTP id EAC3AA187D0 for ; Wed, 14 Mar 2012 23:59:06 +0000 (UTC) Received: by iage36 with SMTP id e36so4144873iag.11 for ; Wed, 14 Mar 2012 16:59:06 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20120113; h=x-forwarded-to:x-forwarded-for:delivered-to:received-spf:from:to:cc :subject:date:message-id:x-mailer:in-reply-to:references :x-content-scanned:x-cbid:x-gm-message-state; bh=Riq7V0DJy2QwlZYFRVQSaqVmxX74Hps9jkq4jhlS2f8=; b=LibvOxd2q6rC95vMAMl9fW1myJqY8VM7j39ar6yNyHYdDwFatZ73e9YxHcfMlsJwLs 6nbnc5RJUwanPs8MxjccoDLyYqeJJXeL7wz9cSuouGq7OPG4oP/3gf2LmXLMCY/qPPfp Qwd7rQg03Myg3ApVCysau/FeM8B5haXtoOa8htrvc5QeM8duYCbnGLYVekNJtWT7OsGW ibHnk1Y95pIxa6tZMdzAv1F/T+gNWr397PNsIfHLs51vbt8Qk0lmE/txotv6e8W7PAwE BlUd9O7K7ulV2n410sFs7NBteSYwa7ujbTUKi/o/UJluy36WP9XUAmbcmf/PbN+sI7XU oNmA== Received: by 10.42.147.199 with SMTP id o7mr5817829icv.50.1331769546397; Wed, 14 Mar 2012 16:59:06 -0700 (PDT) X-Forwarded-To: linaro-patchwork@canonical.com X-Forwarded-For: patch@linaro.org linaro-patchwork@canonical.com Delivered-To: patches@linaro.org Received: by 10.231.53.18 with SMTP id k18csp23268ibg; Wed, 14 Mar 2012 16:59:05 -0700 (PDT) Received: by 10.50.163.65 with SMTP id yg1mr7482724igb.31.1331769545562; Wed, 14 Mar 2012 16:59:05 -0700 (PDT) Received: from e9.ny.us.ibm.com (e9.ny.us.ibm.com. [32.97.182.139]) by mx.google.com with ESMTPS id c2si193013igj.0.2012.03.14.16.59.04 (version=TLSv1/SSLv3 cipher=OTHER); Wed, 14 Mar 2012 16:59:05 -0700 (PDT) Received-SPF: pass (google.com: domain of jstultz@us.ibm.com designates 32.97.182.139 as permitted sender) client-ip=32.97.182.139; Authentication-Results: mx.google.com; spf=pass (google.com: domain of jstultz@us.ibm.com designates 32.97.182.139 as permitted sender) smtp.mail=jstultz@us.ibm.com Received: from /spool/local by e9.ny.us.ibm.com with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted for from ; Wed, 14 Mar 2012 19:59:04 -0400 Received: from d01dlp02.pok.ibm.com (9.56.224.85) by e9.ny.us.ibm.com (192.168.1.109) with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted; Wed, 14 Mar 2012 19:59:02 -0400 Received: from d01relay06.pok.ibm.com (d01relay06.pok.ibm.com [9.56.227.116]) by d01dlp02.pok.ibm.com (Postfix) with ESMTP id 9AD2C6E804C; Wed, 14 Mar 2012 19:59:01 -0400 (EDT) Received: from d01av02.pok.ibm.com (d01av02.pok.ibm.com [9.56.224.216]) by d01relay06.pok.ibm.com (8.13.8/8.13.8/NCO v10.0) with ESMTP id q2ENx1Nn3485930; Wed, 14 Mar 2012 19:59:01 -0400 Received: from d01av02.pok.ibm.com (loopback [127.0.0.1]) by d01av02.pok.ibm.com (8.14.4/8.13.1/NCO v10.0 AVout) with ESMTP id q2ENx0MW026437; Wed, 14 Mar 2012 20:59:01 -0300 Received: from kernel.beaverton.ibm.com (kernel.beaverton.ibm.com [9.47.67.96]) by d01av02.pok.ibm.com (8.14.4/8.13.1/NCO v10.0 AVin) with ESMTP id q2ENx0va026423; Wed, 14 Mar 2012 20:59:00 -0300 Received: by kernel.beaverton.ibm.com (Postfix, from userid 1056) id EE168C0468; Wed, 14 Mar 2012 16:58:59 -0700 (PDT) From: John Stultz To: linux-kernel@vger.kernel.org Cc: John Stultz , Andy Lutomirski , Thomas Gleixner Subject: [PATCH 2/2] time: Fix change_clocksource locking Date: Wed, 14 Mar 2012 16:58:56 -0700 Message-Id: <1331769536-4602-3-git-send-email-john.stultz@linaro.org> X-Mailer: git-send-email 1.7.3.2.146.gca209 In-Reply-To: <1331769536-4602-1-git-send-email-john.stultz@linaro.org> References: <1331769536-4602-1-git-send-email-john.stultz@linaro.org> X-Content-Scanned: Fidelis XPS MAILER x-cbid: 12031423-7182-0000-0000-0000010B235D X-Gm-Message-State: ALoCoQmlJAiO+WYNuIQM1EczyAMOw5OXwF0uKFRqt8zvMtogmtKlLoirrNM4TcCpglbT/ymRSB/J change_clocksource() fails to grab locks or call timekeeping_update(), which leaves a race window for time inconsistencies. This adds proper locking and a call to timekeeping_update() to fix this. CC: Andy Lutomirski CC: Thomas Gleixner Signed-off-by: John Stultz --- kernel/time/timekeeping.c | 7 +++++++ 1 files changed, 7 insertions(+), 0 deletions(-) diff --git a/kernel/time/timekeeping.c b/kernel/time/timekeeping.c index 403c2a0..b53da5e 100644 --- a/kernel/time/timekeeping.c +++ b/kernel/time/timekeeping.c @@ -448,9 +448,12 @@ EXPORT_SYMBOL(timekeeping_inject_offset); static int change_clocksource(void *data) { struct clocksource *new, *old; + unsigned long flags; new = (struct clocksource *) data; + write_seqlock_irqsave(&timekeeper.lock, flags); + timekeeping_forward_now(); if (!new->enable || new->enable(new) == 0) { old = timekeeper.clock; @@ -458,6 +461,10 @@ static int change_clocksource(void *data) if (old->disable) old->disable(old); } + timekeeping_update(true); + + write_sequnlock_irqrestore(&timekeeper.lock, flags); + return 0; }