From: Thomas Gleixner <tglx@linutronix.de>
To: John Stultz <john.stultz@linaro.org>
Cc: LKML <linux-kernel@vger.kernel.org>,
Andy Lutomirski <luto@amacapital.net>,
John Stultz <john.stultz@lianro.org>
Subject: Re: [PATCH] time: x86: Fix race switching from vsyscall to non-vsyscall clock
Date: Mon, 12 Mar 2012 17:08:26 +0100 (CET) [thread overview]
Message-ID: <alpine.LFD.2.02.1203121703390.2466@ionos> (raw)
In-Reply-To: <1331330647-31480-1-git-send-email-john.stultz@linaro.org>
On Fri, 9 Mar 2012, John Stultz wrote:
> When switching from a vsyscall capable to a non-vsyscall capable
> clocksource, there was a small race, where the last vsyscall
> gettimeofday before the switch might return a invalid time value
> using the new non-vsyscall enabled clocksource values after the
> switch is complete.
>
> This is due to the vsyscall code checking the vclock_mode once
> outside of the seqcount protected section. After it reads the
> vclock mode, it doesn't re-check that the sampled clock data
> that is obtained in the seqcount critical section still matches.
>
> The fix is to sample vclock_mode inside the protected section,
> and as long as it isn't VCLOCK_NONE, return the calculated
> value. If it has changed and is now VCLOCK_NONE, fall back
> to the syscall gettime calculation.
>
> CC: Andy Lutomirski <luto@amacapital.net>
> CC: Thomas Gleixner <tglx@linutronix.de>
> Signed-off-by: John Stultz <john.stultz@lianro.org>
> ---
> arch/x86/vdso/vclock_gettime.c | 25 ++++++++++++++++++++-----
> 1 files changed, 20 insertions(+), 5 deletions(-)
>
> diff --git a/arch/x86/vdso/vclock_gettime.c b/arch/x86/vdso/vclock_gettime.c
> index 6bc0e72..e7cf1dd 100644
> --- a/arch/x86/vdso/vclock_gettime.c
> +++ b/arch/x86/vdso/vclock_gettime.c
> @@ -85,21 +85,28 @@ notrace static inline long vgetns(void)
> notrace static noinline int do_realtime(struct timespec *ts)
> {
> unsigned long seq, ns;
> + int mode;
> do {
> seq = read_seqbegin(>od->lock);
> + mode = gtod->clock.vclock_mode;
> ts->tv_sec = gtod->wall_time_sec;
> ts->tv_nsec = gtod->wall_time_nsec;
> ns = vgetns();
> } while (unlikely(read_seqretry(>od->lock, seq)));
> +
> timespec_add_ns(ts, ns);
> + if (mode == VCLOCK_NONE)
> + return -1;
Can't we just return mode and avoid repeated conditionals all over the
place ?
> {
res = VCLOCK_NONE;
> switch (clock) {
> case CLOCK_REALTIME:
> - if (likely(gtod->clock.vclock_mode != VCLOCK_NONE))
> - return do_realtime(ts);
res = do_realtime(ts);
break;
> case CLOCK_MONOTONIC_COARSE:
> return do_monotonic_coarse(ts);
> }
return res != VCLOCK_NONE ? 0 : vdso_fallback_gettime(clock, ts);
Thanks,
tglx
prev parent reply other threads:[~2012-03-12 16:08 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2012-03-09 22:04 [PATCH] time: x86: Fix race switching from vsyscall to non-vsyscall clock John Stultz
2012-03-12 16:08 ` Thomas Gleixner [this message]
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=alpine.LFD.2.02.1203121703390.2466@ionos \
--to=tglx@linutronix.de \
--cc=john.stultz@lianro.org \
--cc=john.stultz@linaro.org \
--cc=linux-kernel@vger.kernel.org \
--cc=luto@amacapital.net \
/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