aboutsummaryrefslogtreecommitdiffstats
path: root/arch/mn10300/kernel
diff options
context:
space:
mode:
authorDavid Howells <dhowells@redhat.com>2010-10-27 12:28:35 -0400
committerDavid Howells <dhowells@redhat.com>2010-10-27 12:28:35 -0400
commit3b950de9c94b4b9fde4f1340358ab52ce0f34be0 (patch)
tree724923f90b0d12bd6e0374b73e8fd06d8d8787e1 /arch/mn10300/kernel
parentdcd42ed3ea829aa99cf00d34c61e082ce575b193 (diff)
MN10300: Prevent cnt32_to_63() from being preempted in sched_clock()
Prevent cnt32_to_63() from being preempted in sched_clock() because it may read its internal counter, get preempted, get delayed for more than the half period of the 'TSC' and then write the internal counter, thus corrupting it. Whilst some callers of sched_clock() have interrupts disabled or hold spinlocks, not all do, and so preemption must be held here. Note that sched_clock() is called from lockdep, but that shouldn't be a problem because although preempt_disable() calls into lockdep, lockdep has a recursion counter to deal with this. Signed-off-by: David Howells <dhowells@redhat.com>
Diffstat (limited to 'arch/mn10300/kernel')
-rw-r--r--arch/mn10300/kernel/time.c5
1 files changed, 5 insertions, 0 deletions
diff --git a/arch/mn10300/kernel/time.c b/arch/mn10300/kernel/time.c
index 8f7f6d22783d..0b5c856b4266 100644
--- a/arch/mn10300/kernel/time.c
+++ b/arch/mn10300/kernel/time.c
@@ -54,6 +54,9 @@ unsigned long long sched_clock(void)
54 unsigned long tsc, tmp; 54 unsigned long tsc, tmp;
55 unsigned product[3]; /* 96-bit intermediate value */ 55 unsigned product[3]; /* 96-bit intermediate value */
56 56
57 /* cnt32_to_63() is not safe with preemption */
58 preempt_disable();
59
57 /* read the TSC value 60 /* read the TSC value
58 */ 61 */
59 tsc = 0 - get_cycles(); /* get_cycles() counts down */ 62 tsc = 0 - get_cycles(); /* get_cycles() counts down */
@@ -64,6 +67,8 @@ unsigned long long sched_clock(void)
64 */ 67 */
65 tsc64.ll = cnt32_to_63(tsc) & 0x7fffffffffffffffULL; 68 tsc64.ll = cnt32_to_63(tsc) & 0x7fffffffffffffffULL;
66 69
70 preempt_enable();
71
67 /* scale the 64-bit TSC value to a nanosecond value via a 96-bit 72 /* scale the 64-bit TSC value to a nanosecond value via a 96-bit
68 * intermediate 73 * intermediate
69 */ 74 */