Commit eee6946e authored by Andy Lutomirski's avatar Andy Lutomirski Committed by Ingo Molnar

x86/asm/tsc/sync: Use rdtsc_ordered() in check_tsc_warp() and drop extra barriers

Using get_cycles was unnecessary: check_tsc_warp() is not called
on TSC-less systems. Replace rdtsc_barrier(); get_cycles() with
rdtsc_ordered().

While we're at it, make the somewhat more dangerous change of
removing barrier_before_rdtsc after RDTSC in the TSC warp check
code. This should be okay, though -- the vDSO TSC code doesn't
have that barrier, so, if removing the barrier from the warp
check would cause us to detect a warp that we otherwise wouldn't
detect, then we have a genuine bug.
Signed-off-by: default avatarAndy Lutomirski <luto@kernel.org>
Signed-off-by: default avatarBorislav Petkov <bp@suse.de>
Cc: Andy Lutomirski <luto@amacapital.net>
Cc: Borislav Petkov <bp@alien8.de>
Cc: Brian Gerst <brgerst@gmail.com>
Cc: Denys Vlasenko <dvlasenk@redhat.com>
Cc: H. Peter Anvin <hpa@zytor.com>
Cc: Huang Rui <ray.huang@amd.com>
Cc: John Stultz <john.stultz@linaro.org>
Cc: Len Brown <lenb@kernel.org>
Cc: Linus Torvalds <torvalds@linux-foundation.org>
Cc: Peter Zijlstra <peterz@infradead.org>
Cc: Ralf Baechle <ralf@linux-mips.org>
Cc: Thomas Gleixner <tglx@linutronix.de>
Cc: kvm ML <kvm@vger.kernel.org>
Link: http://lkml.kernel.org/r/387c4c3a75f875bcde6cd68cee013273a744f364.1434501121.git.luto@kernel.orgSigned-off-by: default avatarIngo Molnar <mingo@kernel.org>
parent 03b9730b
...@@ -39,16 +39,15 @@ static cycles_t max_warp; ...@@ -39,16 +39,15 @@ static cycles_t max_warp;
static int nr_warps; static int nr_warps;
/* /*
* TSC-warp measurement loop running on both CPUs: * TSC-warp measurement loop running on both CPUs. This is not called
* if there is no TSC.
*/ */
static void check_tsc_warp(unsigned int timeout) static void check_tsc_warp(unsigned int timeout)
{ {
cycles_t start, now, prev, end; cycles_t start, now, prev, end;
int i; int i;
rdtsc_barrier(); start = rdtsc_ordered();
start = get_cycles();
rdtsc_barrier();
/* /*
* The measurement runs for 'timeout' msecs: * The measurement runs for 'timeout' msecs:
*/ */
...@@ -63,9 +62,7 @@ static void check_tsc_warp(unsigned int timeout) ...@@ -63,9 +62,7 @@ static void check_tsc_warp(unsigned int timeout)
*/ */
arch_spin_lock(&sync_lock); arch_spin_lock(&sync_lock);
prev = last_tsc; prev = last_tsc;
rdtsc_barrier(); now = rdtsc_ordered();
now = get_cycles();
rdtsc_barrier();
last_tsc = now; last_tsc = now;
arch_spin_unlock(&sync_lock); arch_spin_unlock(&sync_lock);
...@@ -126,7 +123,7 @@ void check_tsc_sync_source(int cpu) ...@@ -126,7 +123,7 @@ void check_tsc_sync_source(int cpu)
/* /*
* No need to check if we already know that the TSC is not * No need to check if we already know that the TSC is not
* synchronized: * synchronized or if we have no TSC.
*/ */
if (unsynchronized_tsc()) if (unsynchronized_tsc())
return; return;
...@@ -190,6 +187,7 @@ void check_tsc_sync_target(void) ...@@ -190,6 +187,7 @@ void check_tsc_sync_target(void)
{ {
int cpus = 2; int cpus = 2;
/* Also aborts if there is no TSC. */
if (unsynchronized_tsc() || tsc_clocksource_reliable) if (unsynchronized_tsc() || tsc_clocksource_reliable)
return; return;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment