public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
* [PATCH] BUG in pv_clock when overflow condition is detected
@ 2012-02-13 18:20 Igor Mammedov
  2012-02-15 10:49 ` Avi Kivity
  0 siblings, 1 reply; 9+ messages in thread
From: Igor Mammedov @ 2012-02-13 18:20 UTC (permalink / raw)
  To: linux-kernel; +Cc: kvm, tglx, mingo, hpa, riel, amit.shah, mtosatti

BUG when overflow occurs at pvclock.c:pvclock_get_nsec_offset

    u64 delta = native_read_tsc() - shadow->tsc_timestamp;

this might happen at an attempt to read an uninitialized yet clock.
It won't prevent stalls and hangs but at least it won't do it silently.

Signed-off-by: Igor Mammedov <imammedo@redhat.com>
---
 arch/x86/kernel/pvclock.c |    5 ++++-
 1 files changed, 4 insertions(+), 1 deletions(-)

diff --git a/arch/x86/kernel/pvclock.c b/arch/x86/kernel/pvclock.c
index 42eb330..35a6190 100644
--- a/arch/x86/kernel/pvclock.c
+++ b/arch/x86/kernel/pvclock.c
@@ -43,7 +43,10 @@ void pvclock_set_flags(u8 flags)
 
 static u64 pvclock_get_nsec_offset(struct pvclock_shadow_time *shadow)
 {
-	u64 delta = native_read_tsc() - shadow->tsc_timestamp;
+	u64 delta;
+	u64 tsc = native_read_tsc();
+	BUG_ON(tsc < shadow->tsc_timestamp);
+	delta = tsc - shadow->tsc_timestamp;
 	return pvclock_scale_delta(delta, shadow->tsc_to_nsec_mul,
 				   shadow->tsc_shift);
 }
-- 
1.7.7.6


^ permalink raw reply related	[flat|nested] 9+ messages in thread

end of thread, other threads:[~2012-02-21 11:36 UTC | newest]

Thread overview: 9+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2012-02-13 18:20 [PATCH] BUG in pv_clock when overflow condition is detected Igor Mammedov
2012-02-15 10:49 ` Avi Kivity
2012-02-15 11:23   ` Igor Mammedov
2012-02-15 14:02     ` Avi Kivity
2012-02-15 17:18       ` Igor Mammedov
2012-02-16 14:03         ` Avi Kivity
2012-02-17 15:25           ` Igor Mammedov
2012-02-20 15:28             ` Konrad Rzeszutek Wilk
2012-02-21 11:35               ` Igor Mammedov

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox