[Devel,RHEL7,COMMIT] ms/timekeeping: Copy the shadow-timekeeper over the real timekeeper last

Submitted by Konstantin Khorenko on Dec. 9, 2016, 1:50 p.m.

Details

Message ID 201612091350.uB9DoQFq024200@finist_cl7.x64_64.work.ct
State New
Series "ms/timekeeping: Copy the shadow-timekeeper over the real timekeeper last"
Headers show

Commit Message

Konstantin Khorenko Dec. 9, 2016, 1:50 p.m.
The commit is pushed to "branch-rh7-3.10.0-327.36.1.vz7.20.x-ovz" and will appear at https://src.openvz.org/scm/ovz/vzkernel.git
after rh7-3.10.0-327.36.1.vz7.20.14
------>
commit dc05ea50227f6674afe5c0becfeeb0c4cbd2ada1
Author: John Stultz <john.stultz@linaro.org>
Date:   Fri Dec 9 17:50:26 2016 +0400

    ms/timekeeping: Copy the shadow-timekeeper over the real timekeeper last
    
        timekeeping: Copy the shadow-timekeeper over the real timekeeper last
    
        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.
    
        Reported-by: Prarit Bhargava <prarit@redhat.com>
        Tested-by: Prarit Bhargava <prarit@redhat.com>
        Tested-by: Daniel Bristot de Oliveira <bristot@redhat.com>
        Signed-off-by: John Stultz <john.stultz@linaro.org>
        Cc: Richard Cochran <richardcochran@gmail.com>
        Cc: Jan Kara <jack@suse.cz>
        Cc: Jiri Bohac <jbohac@suse.cz>
        Cc: Ingo Molnar <mingo@kernel.org>
        Link: http://lkml.kernel.org/r/1434560753-7441-1-git-send-email-john.stultz@linaro.org
        Signed-off-by: Thomas Gleixner <tglx@linutronix.de>
    
    ms commit 906c55579a6360dd9ef5a3101bb2e3ae396dfb97
    
    Bugzilla: http://bugzilla.redhat.com/1344747
    
    Taken from RHEL7.2 3.10.0-327.41.4.el7 kernel.
    
    Conflicts: minor diff conflict due to drift between upstream and RHEL7.
---
 kernel/time/timekeeping.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

Patch hide | download patch | download mbox

diff --git a/kernel/time/timekeeping.c b/kernel/time/timekeeping.c
index c7aa9b5..1197b73 100644
--- a/kernel/time/timekeeping.c
+++ b/kernel/time/timekeeping.c
@@ -1446,8 +1446,9 @@  void update_wall_time(void)
 	 * memcpy under the timekeeper_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(&timekeeper_seq);
 out:
 	raw_spin_unlock_irqrestore(&timekeeper_lock, flags);