lists.openwall.net   lists  /  announce  owl-users  owl-dev  john-users  john-dev  passwdqc-users  yescrypt  popa3d-users  /  oss-security  kernel-hardening  musl  sabotage  tlsify  passwords  /  crypt-dev  xvendor  /  Bugtraq  Full-Disclosure  linux-kernel  linux-netdev  linux-ext4  linux-hardening  linux-cve-announce  PHC 
Open Source and information security mailing list archives
 
Hash Suite: Windows password security audit tool. GUI, reports in PDF.
[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-Id: <678981cc4761fb38a793c217c9cac42503cf3719.1434501121.git.luto@kernel.org>
Date:	Tue, 16 Jun 2015 17:36:05 -0700
From:	Andy Lutomirski <luto@...nel.org>
To:	x86@...nel.org
Cc:	Borislav Petkov <bp@...e.de>,
	Peter Zijlstra <peterz@...radead.org>,
	John Stultz <john.stultz@...aro.org>,
	linux-kernel@...r.kernel.org, Len Brown <lenb@...nel.org>,
	Huang Rui <ray.huang@....com>,
	Denys Vlasenko <dvlasenk@...hat.com>, kvm@...r.kernel.org,
	Ralf Baechle <ralf@...ux-mips.org>,
	Andy Lutomirski <luto@...nel.org>,
	Paolo Bonzini <pbonzini@...hat.com>,
	Radim Krcmar <rkrcmar@...hat.com>,
	Marcelo Tosatti <mtosatti@...hat.com>
Subject: [PATCH v3 17/18] x86/kvm/tsc: Drop extra barrier and use rdtsc_ordered in kvmclock

__pvclock_read_cycles had an unnecessary barrier.  Get rid of that
barrier and clean up the code by just using rdtsc_ordered().

Cc: Paolo Bonzini <pbonzini@...hat.com>
Cc: Radim Krcmar <rkrcmar@...hat.com>
Cc: Marcelo Tosatti <mtosatti@...hat.com>
Cc: kvm@...r.kernel.org
Signed-off-by: Andy Lutomirski <luto@...nel.org>
---

I'm hoping to get an ack for this to go in through -tip.  (Arguably
I'm the maintainer of this code given how it's used, but I should
still ask for an ack.)

arch/x86/include/asm/pvclock.h | 21 ++++++++++++---------
 1 file changed, 12 insertions(+), 9 deletions(-)

diff --git a/arch/x86/include/asm/pvclock.h b/arch/x86/include/asm/pvclock.h
index 6084bce345fc..cf2329ca4812 100644
--- a/arch/x86/include/asm/pvclock.h
+++ b/arch/x86/include/asm/pvclock.h
@@ -62,7 +62,18 @@ static inline u64 pvclock_scale_delta(u64 delta, u32 mul_frac, int shift)
 static __always_inline
 u64 pvclock_get_nsec_offset(const struct pvclock_vcpu_time_info *src)
 {
-	u64 delta = rdtsc() - src->tsc_timestamp;
+	/*
+	 * Note: emulated platforms which do not advertise SSE2 support
+	 * break rdtsc_ordered, resulting in kvmclock not using the
+	 * necessary RDTSC barriers.  Without barriers, it is possible
+	 * that RDTSC instruction is executed before prior loads,
+	 * resulting in violation of monotonicity.
+	 *
+	 * On an SMP guest without SSE2, it's unclear how anything is
+	 * supposed to work correctly, though -- memory fences
+	 * (e.g. smp_mb) are important for more than just timing.
+	 */
+	u64 delta = rdtsc_ordered() - src->tsc_timestamp;
 	return pvclock_scale_delta(delta, src->tsc_to_system_mul,
 				   src->tsc_shift);
 }
@@ -76,17 +87,9 @@ unsigned __pvclock_read_cycles(const struct pvclock_vcpu_time_info *src,
 	u8 ret_flags;
 
 	version = src->version;
-	/* Note: emulated platforms which do not advertise SSE2 support
-	 * result in kvmclock not using the necessary RDTSC barriers.
-	 * Without barriers, it is possible that RDTSC instruction reads from
-	 * the time stamp counter outside rdtsc_barrier protected section
-	 * below, resulting in violation of monotonicity.
-	 */
-	rdtsc_barrier();
 	offset = pvclock_get_nsec_offset(src);
 	ret = src->system_time + offset;
 	ret_flags = src->flags;
-	rdtsc_barrier();
 
 	*cycles = ret;
 	*flags = ret_flags;
-- 
2.4.2

--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@...r.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/

Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ