From patchwork Wed Jun 17 17:05:53 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: John Stultz X-Patchwork-Id: 49983 Return-Path: X-Original-To: linaro@patches.linaro.org Delivered-To: linaro@patches.linaro.org Received: from mail-wi0-f199.google.com (mail-wi0-f199.google.com [209.85.212.199]) by ip-10-151-82-157.ec2.internal (Postfix) with ESMTPS id 4E1AB228CC for ; Wed, 17 Jun 2015 17:06:02 +0000 (UTC) Received: by wifx6 with SMTP id x6sf15150590wif.1 for ; Wed, 17 Jun 2015 10:06:01 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:mime-version:delivered-to:from:to:cc:subject :date:message-id:x-original-sender:x-original-authentication-results :precedence:mailing-list:list-id:list-post:list-help:list-archive :list-unsubscribe; bh=tDXBUvWk99QqyrVVrx+b0kq74WGYwZeG2bjEPbgmHiI=; b=ESyte5mpaOBw0n+ellMgUhsot0n8e0KEfaP+jfdh4P8zUNz0rCKgs8CnB8PJTJnDfe 4lx4pNcf0SCAXYH1mC6fEAFeyZhIZTPvPeAk7yHtpz2k3544CL7dwVFlQ3AkBPZKtWv/ kiVeWpbODjtBVJLm5y+PUsMtZZop9FtjcK+uoX4QpuLJN9nXdDDYcQ4Z6jzWzIQdQkjj Gk3AGU7tkgDzl8riKB18YpfTykBtJvTJHBlk43paccKgk7oy+4/j5lLaxYqxecx81up5 xmO8bDefBiIQBcKVB8/1IoAmXkNNKTUU4M/wfAGyFuLCQnqCx0ZWXkvMO3Fh/5agwM47 Ngcg== X-Gm-Message-State: ALoCoQnU0nTg5N7MS82Comn5N/vrU4GUGyXZbCYTAM+wj+eeNSKrSWX20L7ptCTjO0hhLboPfL4P X-Received: by 10.112.159.41 with SMTP id wz9mr6255066lbb.17.1434560761512; Wed, 17 Jun 2015 10:06:01 -0700 (PDT) MIME-Version: 1.0 X-BeenThere: patchwork-forward@linaro.org Received: by 10.152.87.81 with SMTP id v17ls376585laz.2.gmail; Wed, 17 Jun 2015 10:06:01 -0700 (PDT) X-Received: by 10.112.154.71 with SMTP id vm7mr8785891lbb.96.1434560761374; Wed, 17 Jun 2015 10:06:01 -0700 (PDT) Received: from mail-lb0-f181.google.com (mail-lb0-f181.google.com. [209.85.217.181]) by mx.google.com with ESMTPS id h3si4085877lbj.145.2015.06.17.10.06.01 for (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 17 Jun 2015 10:06:01 -0700 (PDT) Received-SPF: pass (google.com: domain of patch+caf_=patchwork-forward=linaro.org@linaro.org designates 209.85.217.181 as permitted sender) client-ip=209.85.217.181; Received: by lbbqq2 with SMTP id qq2so35969245lbb.3 for ; Wed, 17 Jun 2015 10:06:01 -0700 (PDT) X-Received: by 10.152.179.234 with SMTP id dj10mr2325021lac.73.1434560761239; Wed, 17 Jun 2015 10:06:01 -0700 (PDT) X-Forwarded-To: patchwork-forward@linaro.org X-Forwarded-For: patch@linaro.org patchwork-forward@linaro.org Delivered-To: patches@linaro.org Received: by 10.112.108.230 with SMTP id hn6csp600866lbb; Wed, 17 Jun 2015 10:06:00 -0700 (PDT) X-Received: by 10.70.38.33 with SMTP id d1mr12575557pdk.99.1434560759409; Wed, 17 Jun 2015 10:05:59 -0700 (PDT) Received: from mail-pa0-f48.google.com (mail-pa0-f48.google.com. [209.85.220.48]) by mx.google.com with ESMTPS id f6si7191941pds.59.2015.06.17.10.05.58 for (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 17 Jun 2015 10:05:59 -0700 (PDT) Received-SPF: pass (google.com: domain of john.stultz@linaro.org designates 209.85.220.48 as permitted sender) client-ip=209.85.220.48; Received: by pacgb13 with SMTP id gb13so40320913pac.1 for ; Wed, 17 Jun 2015 10:05:58 -0700 (PDT) X-Received: by 10.68.228.168 with SMTP id sj8mr12729598pbc.102.1434560758487; Wed, 17 Jun 2015 10:05:58 -0700 (PDT) Received: from localhost.localdomain (c-71-63-136-39.hsd1.or.comcast.net. [71.63.136.39]) by mx.google.com with ESMTPSA id jd4sm5253432pbd.46.2015.06.17.10.05.56 (version=TLSv1.2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Wed, 17 Jun 2015 10:05:57 -0700 (PDT) From: John Stultz To: lkml Cc: John Stultz , Prarit Bhargava , Daniel Bristot de Oliveira , Richard Cochran , Jan Kara , Jiri Bohac , Ingo Molnar , Thomas Gleixner Subject: [PATCH] timekeeping: Copy the shadow-timekeeper over the real timekeeper last Date: Wed, 17 Jun 2015 10:05:53 -0700 Message-Id: <1434560753-7441-1-git-send-email-john.stultz@linaro.org> X-Mailer: git-send-email 1.9.1 X-Removed-Original-Auth: Dkim didn't pass. X-Original-Sender: john.stultz@linaro.org X-Original-Authentication-Results: mx.google.com; spf=pass (google.com: domain of patch+caf_=patchwork-forward=linaro.org@linaro.org designates 209.85.217.181 as permitted sender) smtp.mail=patch+caf_=patchwork-forward=linaro.org@linaro.org Precedence: list Mailing-list: list patchwork-forward@linaro.org; contact patchwork-forward+owners@linaro.org List-ID: X-Google-Group-Id: 836684582541 List-Post: , List-Help: , List-Archive: List-Unsubscribe: , The fix in d151832650ed9 (time: Move clock_was_set_seq update before updating shadow-timekeeper) was unfortunately incomplete. The main gist of that change was to do the shadow-copy update last, so that any state changes were properly duplicated, and we wouldn't accidentally have stale data in the shadow. Unfortunately in the main update_wall_time() logic, we update use the shadow-timekeeper to calculate the next update values, then while holding the lock, copy the shadow-timekeeper over, then call timekeeping_update() to do some additional bookkeeping, (skipping the shadow mirror). The bug with this is the additional bookkeeping isn't all read-only, and some changes timkeeper state. Thus we might then overwrite this state change on the next update. To avoid this problem, do the timekeeping_update() on the shadow-timekeeper prior to copying the full state over to the real-timekeeper. This avoids problems with both the clock_was_set_seq and next_leap_ktime being overwritten and possibly the fast-timekeepers as well. Many thanks to Prarit for his rigorous testing, which discovered this problem, along with Prarit and Daniel's work validating this fix. Cc: Prarit Bhargava Cc: Daniel Bristot de Oliveira Cc: Richard Cochran Cc: Jan Kara Cc: Jiri Bohac Cc: Ingo Molnar Cc: Thomas Gleixner Reported-by: Prarit Bhargava Tested-by: Prarit Bhargava Tested-by: Daniel Bristot de Oliveira Signed-off-by: John Stultz --- (This patch applies to tip/timers/core) kernel/time/timekeeping.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/kernel/time/timekeeping.c b/kernel/time/timekeeping.c index 5d67ffb..30b7a40 100644 --- a/kernel/time/timekeeping.c +++ b/kernel/time/timekeeping.c @@ -1853,8 +1853,9 @@ void update_wall_time(void) * memcpy under the tk_core.seq against one before we start * updating. */ + timekeeping_update(tk, clock_set); memcpy(real_tk, tk, sizeof(*tk)); - timekeeping_update(real_tk, clock_set); + /* The memcpy must come last. Do not put anything here! */ write_seqcount_end(&tk_core.seq); out: raw_spin_unlock_irqrestore(&timekeeper_lock, flags);