From: Ingo Molnar <mingo@elte.hu>
To: Linus Torvalds <torvalds@linux-foundation.org>
Cc: linux-kernel@vger.kernel.org,
Andrew Morton <akpm@linux-foundation.org>,
Peter Zijlstra <a.p.zijlstra@chello.nl>,
Mike Galbraith <efault@gmx.de>,
Thomas Gleixner <tglx@linutronix.de>,
"H. Peter Anvin" <hpa@zytor.com>
Subject: Re: [git pull] scheduler updates
Date: Sat, 8 Nov 2008 19:57:58 +0100 [thread overview]
Message-ID: <20081108185758.GA3986@elte.hu> (raw)
In-Reply-To: <20081108185219.GA23413@elte.hu>
* Ingo Molnar <mingo@elte.hu> wrote:
> For that one, i chickened out, because we have this use in
> arch/x86/kernel/vsyscall_64.c:
>
> now = vread();
> base = __vsyscall_gtod_data.clock.cycle_last;
> mask = __vsyscall_gtod_data.clock.mask;
> mult = __vsyscall_gtod_data.clock.mult;
> shift = __vsyscall_gtod_data.clock.shift;
>
> which can be triggered by gettimeofday() on certain systems.
>
> And i couldnt convince myself that this sequence couldnt result in
> userspace-observable GTOD time warps there, so i went for the
> obvious fix first.
>
> If the "now = vread()"'s RDTSC instruction is speculated to after it
> reads cycle_last, and another vdso call shortly after this does
> another RDTSC in this same sequence, the two RDTSC's could be mixed
> up in theory, resulting in negative time?
the fuller sequence is:
now = vread();
base = __vsyscall_gtod_data.clock.cycle_last;
mask = __vsyscall_gtod_data.clock.mask;
mult = __vsyscall_gtod_data.clock.mult;
shift = __vsyscall_gtod_data.clock.shift;
tv->tv_sec = __vsyscall_gtod_data.wall_time_sec;
nsec = __vsyscall_gtod_data.wall_time_nsec;
} while (read_seqretry(&__vsyscall_gtod_data.lock, seq));
now here we could have another race as well: on another CPU we have a
timer IRQ running, which updates
__vsyscall_gtod_data.wall_time_[n]sec.
now __vsyscall_gtod_data updates are protected via the
__vsyscall_gtod_data.lock seqlock, but that assumes that all
instructions within that sequence listen to the barriers.
Except for RDTSC, which can be speculated to outside that region of
code.
RDTSC has no 'explicit' data dependency - there's no MESI-alike
coherency guarantee for stuffing a cycle counter into a register and
then putting that into __vsyscall_gtod_data.clock.cycle_last. So we
create one, by using the combination of LFENCE and SFENCE. (because
RDTSC implementations on Intel and AMD CPUs listen to different
sequences.)
all in one, i think it's still needed to avoid negative GTOD jumps.
Ingo
next prev parent reply other threads:[~2008-11-08 18:58 UTC|newest]
Thread overview: 24+ messages / expand[flat|nested] mbox.gz Atom feed top
2008-11-08 17:02 [git pull] scheduler updates Ingo Molnar
2008-11-08 18:28 ` Linus Torvalds
2008-11-08 18:38 ` Linus Torvalds
2008-11-08 18:41 ` Arjan van de Ven
2008-11-08 19:00 ` Linus Torvalds
2008-11-08 19:05 ` Ingo Molnar
2008-11-08 19:20 ` Linus Torvalds
2008-11-08 19:29 ` Ingo Molnar
2008-11-17 22:43 ` Venki Pallipadi
2008-11-17 22:50 ` Ingo Molnar
2008-11-17 23:04 ` Venki Pallipadi
2008-11-17 23:13 ` Ingo Molnar
2008-11-08 19:40 ` Ingo Molnar
2008-11-08 19:10 ` Ingo Molnar
2008-11-08 18:52 ` Ingo Molnar
2008-11-08 18:57 ` Ingo Molnar [this message]
2008-11-08 19:32 ` Ingo Molnar
-- strict thread matches above, loose matches on Subject: below --
2018-02-06 21:38 [GIT PULL] " Ingo Molnar
2008-03-21 16:23 [git pull] " Ingo Molnar
2008-02-29 18:04 Ingo Molnar
2008-02-13 15:58 Ingo Molnar
2008-01-31 21:54 Ingo Molnar
2007-12-30 16:45 Ingo Molnar
2007-10-24 16:39 Ingo Molnar
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=20081108185758.GA3986@elte.hu \
--to=mingo@elte.hu \
--cc=a.p.zijlstra@chello.nl \
--cc=akpm@linux-foundation.org \
--cc=efault@gmx.de \
--cc=hpa@zytor.com \
--cc=linux-kernel@vger.kernel.org \
--cc=tglx@linutronix.de \
--cc=torvalds@linux-foundation.org \
/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