kyber: fix integer overflow of latency targets on 32-bit
authorOmar Sandoval <osandov@fb.com>
Fri, 28 Sep 2018 16:22:50 +0000 (09:22 -0700)
committerJens Axboe <axboe@kernel.dk>
Fri, 28 Sep 2018 16:49:39 +0000 (10:49 -0600)
NSEC_PER_SEC has type long, so 5 * NSEC_PER_SEC is calculated as a long.
However, 5 seconds is 5,000,000,000 nanoseconds, which overflows a
32-bit long. Make sure all of the targets are calculated as 64-bit
values.

Fixes: 6e25cb01ea20 ("kyber: implement improved heuristics")
Reported-by: Stephen Rothwell <sfr@canb.auug.org.au>
Signed-off-by: Omar Sandoval <osandov@fb.com>
Signed-off-by: Jens Axboe <axboe@kernel.dk>
block/kyber-iosched.c

index 2b62e36..eccac01 100644 (file)
@@ -79,9 +79,9 @@ static const unsigned int kyber_depth[] = {
  * Default latency targets for each scheduling domain.
  */
 static const u64 kyber_latency_targets[] = {
-       [KYBER_READ] = 2 * NSEC_PER_MSEC,
-       [KYBER_WRITE] = 10 * NSEC_PER_MSEC,
-       [KYBER_DISCARD] = 5 * NSEC_PER_SEC,
+       [KYBER_READ] = 2ULL * NSEC_PER_MSEC,
+       [KYBER_WRITE] = 10ULL * NSEC_PER_MSEC,
+       [KYBER_DISCARD] = 5ULL * NSEC_PER_SEC,
 };
 
 /*