blk-throttle: check for overflow in calculate_bytes_allowed
authorKhazhismel Kumykov <khazhy@chromium.org>
Fri, 20 Oct 2023 22:36:17 +0000 (15:36 -0700)
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Thu, 2 Nov 2023 08:35:29 +0000 (09:35 +0100)
commit6a5b845b57b122534d051129bc4fc85eac7f4a68
tree00714207b65c4a181245efaa61960881c2d02c0c
parentbb20a245df9c42fc93fc9d16ad7e9855a428cb57
blk-throttle: check for overflow in calculate_bytes_allowed

commit 2dd710d476f2f1f6eaca884f625f69ef4389ed40 upstream.

Inexact, we may reject some not-overflowing values incorrectly, but
they'll be on the order of exabytes allowed anyways.

This fixes divide error crash on x86 if bps_limit is not configured or
is set too high in the rare case that jiffy_elapsed is greater than HZ.

Fixes: e8368b57c006 ("blk-throttle: use calculate_io/bytes_allowed() for throtl_trim_slice()")
Fixes: 8d6bbaada2e0 ("blk-throttle: prevent overflow while calculating wait time")
Signed-off-by: Khazhismel Kumykov <khazhy@google.com>
Acked-by: Tejun Heo <tj@kernel.org>
Link: https://lore.kernel.org/r/20231020223617.2739774-1-khazhy@google.com
Signed-off-by: Jens Axboe <axboe@kernel.dk>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
block/blk-throttle.c