linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] psi:fix divide by zero in psi_update_stats
@ 2019-11-08  7:33 tim
  2019-11-08  9:31 ` Peter Zijlstra
  2019-11-12 15:41 ` Johannes Weiner
  0 siblings, 2 replies; 11+ messages in thread
From: tim @ 2019-11-08  7:33 UTC (permalink / raw)
  To: Johannes Weiner, Ingo Molnar, Peter Zijlstra; +Cc: linux-kernel

In psi_update_stats, it is possible that period has value like
0xXXXXXXXX00000000 where the lower 32 bit is 0, then it calls div_u64 which
truncates u64 period to u32, results in zero divisor.
Use div64_u64() instead of div_u64()  if the divisor is u64 to avoid
truncation to 32-bit on 64-bit platforms.

Signed-off-by: xiejingfeng <xiejingfeng@linux.alibaba.com>
---
 kernel/sched/psi.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/kernel/sched/psi.c b/kernel/sched/psi.c
index 517e3719027e..399d6f106de5 100644
--- a/kernel/sched/psi.c
+++ b/kernel/sched/psi.c
@@ -291,7 +291,7 @@ static void calc_avgs(unsigned long avg[3], int missed_periods,
 	}
 
 	/* Sample the most recent active period */
-	pct = div_u64(time * 100, period);
+	pct = div64_u64(time * 100, period);
 	pct *= FIXED_1;
 	avg[0] = calc_load(avg[0], EXP_10s, pct);
 	avg[1] = calc_load(avg[1], EXP_60s, pct);
-- 
2.14.4.44.g2045bb




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

end of thread, other threads:[~2019-11-30  1:42 UTC | newest]

Thread overview: 11+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-11-08  7:33 [PATCH] psi:fix divide by zero in psi_update_stats tim
2019-11-08  9:31 ` Peter Zijlstra
2019-11-08  9:49   ` Jingfeng Xie
2019-11-08 10:05     ` Peter Zijlstra
2019-11-12 15:41 ` Johannes Weiner
2019-11-12 15:48   ` Johannes Weiner
2019-11-12 16:08     ` Johannes Weiner
2019-11-12 17:27       ` Suren Baghdasaryan
2019-11-29  6:37       ` Jingfeng Xie
2019-11-30  1:41         ` Suren Baghdasaryan
2019-11-12 18:33   ` Suren Baghdasaryan

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).