Skip to content

Commit 4560e7c

Browse files
author
Martin Schwidefsky
committed
s390/vtime: correct idle time calculation
Use the ACCESS_ONCE macro for both accesses to idle->sequence in the loops to calculate the idle time. If only one access uses the macro, the compiler is free to cache the value for the second access which can cause endless loops. Cc: stable@vger.kernel.org # 3.6+ Signed-off-by: Martin Schwidefsky <schwidefsky@de.ibm.com>
1 parent 7ab64a8 commit 4560e7c

File tree

2 files changed

+3
-3
lines changed

2 files changed

+3
-3
lines changed

arch/s390/kernel/smp.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -920,7 +920,7 @@ static ssize_t show_idle_count(struct device *dev,
920920
idle_count = ACCESS_ONCE(idle->idle_count);
921921
if (ACCESS_ONCE(idle->clock_idle_enter))
922922
idle_count++;
923-
} while ((sequence & 1) || (idle->sequence != sequence));
923+
} while ((sequence & 1) || (ACCESS_ONCE(idle->sequence) != sequence));
924924
return sprintf(buf, "%llu\n", idle_count);
925925
}
926926
static DEVICE_ATTR(idle_count, 0444, show_idle_count, NULL);
@@ -938,7 +938,7 @@ static ssize_t show_idle_time(struct device *dev,
938938
idle_time = ACCESS_ONCE(idle->idle_time);
939939
idle_enter = ACCESS_ONCE(idle->clock_idle_enter);
940940
idle_exit = ACCESS_ONCE(idle->clock_idle_exit);
941-
} while ((sequence & 1) || (idle->sequence != sequence));
941+
} while ((sequence & 1) || (ACCESS_ONCE(idle->sequence) != sequence));
942942
idle_time += idle_enter ? ((idle_exit ? : now) - idle_enter) : 0;
943943
return sprintf(buf, "%llu\n", idle_time >> 12);
944944
}

arch/s390/kernel/vtime.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -191,7 +191,7 @@ cputime64_t s390_get_idle_time(int cpu)
191191
sequence = ACCESS_ONCE(idle->sequence);
192192
idle_enter = ACCESS_ONCE(idle->clock_idle_enter);
193193
idle_exit = ACCESS_ONCE(idle->clock_idle_exit);
194-
} while ((sequence & 1) || (idle->sequence != sequence));
194+
} while ((sequence & 1) || (ACCESS_ONCE(idle->sequence) != sequence));
195195
return idle_enter ? ((idle_exit ?: now) - idle_enter) : 0;
196196
}
197197

0 commit comments

Comments
 (0)