mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Borislav Petkov <bp@alien8.de>
To: Ingo Molnar <mingo@kernel.org>
Cc: LKML <linux-kernel@vger.kernel.org>
Subject: [PATCH 15/19] x86/tsc_sync: Use rdtsc_ordered() in check_tsc_warp() and drop extra barriers
Date: Thu, 25 Jun 2015 18:44:09 +0200	[thread overview]
Message-ID: <1435250653-30182-16-git-send-email-bp@alien8.de> (raw)
In-Reply-To: <1435250653-30182-1-git-send-email-bp@alien8.de>

From: Andy Lutomirski <luto@kernel.org>

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: Andy Lutomirski <luto@kernel.org>
Cc: Denys Vlasenko <dvlasenk@redhat.com>
Cc: Huang Rui <ray.huang@amd.com>
Cc: John Stultz <john.stultz@linaro.org>
Cc: Len Brown <lenb@kernel.org>
Cc: Peter Zijlstra <peterz@infradead.org>
Cc: Ralf Baechle <ralf@linux-mips.org>
Cc: kvm ML <kvm@vger.kernel.org>
Cc: x86-ml <x86@kernel.org>
Link: http://lkml.kernel.org/r/387c4c3a75f875bcde6cd68cee013273a744f364.1434501121.git.luto@kernel.org
Signed-off-by: Borislav Petkov <bp@suse.de>
---
 arch/x86/kernel/tsc_sync.c | 14 ++++++--------
 1 file changed, 6 insertions(+), 8 deletions(-)

diff --git a/arch/x86/kernel/tsc_sync.c b/arch/x86/kernel/tsc_sync.c
index dd8d0791dfb5..78083bf23ed1 100644
--- a/arch/x86/kernel/tsc_sync.c
+++ b/arch/x86/kernel/tsc_sync.c
@@ -39,16 +39,15 @@ static cycles_t max_warp;
 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)
 {
 	cycles_t start, now, prev, end;
 	int i;
 
-	rdtsc_barrier();
-	start = get_cycles();
-	rdtsc_barrier();
+	start = rdtsc_ordered();
 	/*
 	 * The measurement runs for 'timeout' msecs:
 	 */
@@ -63,9 +62,7 @@ static void check_tsc_warp(unsigned int timeout)
 		 */
 		arch_spin_lock(&sync_lock);
 		prev = last_tsc;
-		rdtsc_barrier();
-		now = get_cycles();
-		rdtsc_barrier();
+		now = rdtsc_ordered();
 		last_tsc = now;
 		arch_spin_unlock(&sync_lock);
 
@@ -126,7 +123,7 @@ void check_tsc_sync_source(int cpu)
 
 	/*
 	 * No need to check if we already know that the TSC is not
-	 * synchronized:
+	 * synchronized or if we have no TSC.
 	 */
 	if (unsynchronized_tsc())
 		return;
@@ -190,6 +187,7 @@ void check_tsc_sync_target(void)
 {
 	int cpus = 2;
 
+	/* Also aborts if there is no TSC. */
 	if (unsynchronized_tsc() || tsc_clocksource_reliable)
 		return;
 
-- 
2.3.5


  parent reply	other threads:[~2015-06-25 16:48 UTC|newest]

Thread overview: 20+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2015-06-25 16:43 [PATCH 00/19] tip queue 2015-06-25 (rdtsc cleanup) Borislav Petkov
2015-06-25 16:43 ` [PATCH 01/19] x86/tsc: Inline native_read_tsc() and remove __native_read_tsc() Borislav Petkov
2015-06-25 16:43 ` [PATCH 02/19] x86/msr, kvm: Remove vget_cycles() Borislav Petkov
2015-06-25 16:43 ` [PATCH 03/19] x86/kernel/paravirt: Remove read_tsc() and read_tscp() paravirt hooks Borislav Petkov
2015-06-25 16:43 ` [PATCH 04/19] x86/tsc: Replace rdtscll() with native_read_tsc() Borislav Petkov
2015-06-25 16:43 ` [PATCH 05/19] x86/tsc: Remove the rdtscp() and rdtscpll() macros Borislav Petkov
2015-06-25 16:44 ` [PATCH 06/19] x86/tsc: Use the full 64-bit TSC in delay_tsc() Borislav Petkov
2015-06-25 16:44 ` [PATCH 07/19] x86/cpu/amd: Use the full 64-bit TSC to detect the 2.6.2 bug Borislav Petkov
2015-06-25 16:44 ` [PATCH 08/19] drivers/net/hamradio/baycom_epp: Replace rdtscl() with native_read_tsc() Borislav Petkov
2015-06-25 16:44 ` [PATCH 09/19] staging/lirc_serial: Remove TSC-based timing Borislav Petkov
2015-06-25 16:44 ` [PATCH 10/19] input/joystick/analog: Switch from rdtscl() to native_read_tsc() Borislav Petkov
2015-06-25 16:44 ` [PATCH 11/19] drivers/input/gameport: Replace rdtscl() with native_read_tsc() Borislav Petkov
2015-06-25 16:44 ` [PATCH 12/19] x86/asm: Remove rdtscl() Borislav Petkov
2015-06-25 16:44 ` [PATCH 13/19] x86: Rename native_read_tsc() to rdtsc() Borislav Petkov
2015-06-25 16:44 ` [PATCH 14/19] x86: Add rdtsc_ordered() and use it in trivial call sites Borislav Petkov
2015-06-25 16:44 ` Borislav Petkov [this message]
2015-06-25 16:44 ` [PATCH 16/19] x86/tsc: Use rdtsc_ordered() in read_tsc() instead of get_cycles() Borislav Petkov
2015-06-25 16:44 ` [PATCH 17/19] x86/kvm/tsc: Drop extra barrier and use rdtsc_ordered() in kvmclock Borislav Petkov
2015-06-25 16:44 ` [PATCH 18/19] x86/asm: Remove rdtsc_barrier() Borislav Petkov
2015-06-25 16:44 ` [PATCH 19/19] x86/asm: Save an instruction in DECLARE_ARGS users Borislav Petkov

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=1435250653-30182-16-git-send-email-bp@alien8.de \
    --to=bp@alien8.de \
    --cc=linux-kernel@vger.kernel.org \
    --cc=mingo@kernel.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

Powered by JetHome