Skip to content

Commit c3e0ef9

Browse files
author
Martin Schwidefsky
committed
[S390] fix cputime overflow in uptime_proc_show
For 32-bit architectures using standard jiffies the idletime calculation in uptime_proc_show will quickly overflow. It takes (2^32 / HZ) seconds of idle-time, or e.g. 12.45 days with no load on a quad-core with HZ=1000. Switch to 64-bit calculations. Cc: stable@vger.kernel.org Cc: Michael Abbott <michael.abbott@diamond.ac.uk> Signed-off-by: Martin Schwidefsky <schwidefsky@de.ibm.com>
1 parent 6486163 commit c3e0ef9

1 file changed

Lines changed: 7 additions & 2 deletions

File tree

‎fs/proc/uptime.c‎

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,15 +11,20 @@ static int uptime_proc_show(struct seq_file *m, void *v)
1111
{
1212
struct timespec uptime;
1313
struct timespec idle;
14+
cputime64_t idletime;
15+
u64 nsec;
16+
u32 rem;
1417
int i;
15-
cputime_t idletime = 0;
1618

19+
idletime = 0;
1720
for_each_possible_cpu(i)
1821
idletime += kstat_cpu(i).cpustat.idle;
1922

2023
do_posix_clock_monotonic_gettime(&uptime);
2124
monotonic_to_bootbased(&uptime);
22-
cputime_to_timespec(idletime, &idle);
25+
nsec = cputime64_to_jiffies64(idletime) * TICK_NSEC;
26+
idle.tv_sec = div_u64_rem(nsec, NSEC_PER_SEC, &rem);
27+
idle.tv_nsec = rem;
2328
seq_printf(m, "%lu.%02lu %lu.%02lu\n",
2429
(unsigned long) uptime.tv_sec,
2530
(uptime.tv_nsec / (NSEC_PER_SEC / 100)),

0 commit comments

Comments
 (0)