All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] kyber: fix integer overflow of latency targets on 32-bit
@ 2018-09-28 16:22 Omar Sandoval
  2018-09-28 16:50 ` Jens Axboe
  0 siblings, 1 reply; 2+ messages in thread
From: Omar Sandoval @ 2018-09-28 16:22 UTC (permalink / raw)
  To: linux-block; +Cc: Jens Axboe, kernel-team, Stephen Rothwell

From: Omar Sandoval <osandov@fb.com>

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>
---
 block/kyber-iosched.c | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)

diff --git a/block/kyber-iosched.c b/block/kyber-iosched.c
index 2b62e362fb36..eccac01a10b6 100644
--- a/block/kyber-iosched.c
+++ b/block/kyber-iosched.c
@@ -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,
 };
 
 /*
-- 
2.19.0

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

* Re: [PATCH] kyber: fix integer overflow of latency targets on 32-bit
  2018-09-28 16:22 [PATCH] kyber: fix integer overflow of latency targets on 32-bit Omar Sandoval
@ 2018-09-28 16:50 ` Jens Axboe
  0 siblings, 0 replies; 2+ messages in thread
From: Jens Axboe @ 2018-09-28 16:50 UTC (permalink / raw)
  To: Omar Sandoval, linux-block; +Cc: kernel-team, Stephen Rothwell

On 9/28/18 10:22 AM, Omar Sandoval wrote:
> From: Omar Sandoval <osandov@fb.com>
> 
> 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.

Applied, thanks Omar.

-- 
Jens Axboe

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

end of thread, other threads:[~2018-09-28 22:47 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2018-09-28 16:22 [PATCH] kyber: fix integer overflow of latency targets on 32-bit Omar Sandoval
2018-09-28 16:50 ` Jens Axboe

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.