Linux cgroups development
 help / color / mirror / Atom feed
* [PATCH] blk-throttle: check for overflow in calculate_bytes_allowed
@ 2023-10-20 22:36 Khazhismel Kumykov
  2023-10-21  0:22 ` Tejun Heo
  2023-10-21  0:38 ` Jens Axboe
  0 siblings, 2 replies; 3+ messages in thread
From: Khazhismel Kumykov @ 2023-10-20 22:36 UTC (permalink / raw)
  To: Tejun Heo, Josef Bacik
  Cc: Jens Axboe, Yu Kuai, cgroups, linux-block, linux-kernel, oleg,
	linan122, Khazhismel Kumykov

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>
---
 block/blk-throttle.c | 6 ++++++
 1 file changed, 6 insertions(+)

diff --git a/block/blk-throttle.c b/block/blk-throttle.c
index 38a881cf97d0..13e4377a8b28 100644
--- a/block/blk-throttle.c
+++ b/block/blk-throttle.c
@@ -723,6 +723,12 @@ static unsigned int calculate_io_allowed(u32 iops_limit,
 
 static u64 calculate_bytes_allowed(u64 bps_limit, unsigned long jiffy_elapsed)
 {
+	/*
+	 * Can result be wider than 64 bits?
+	 * We check against 62, not 64, due to ilog2 truncation.
+	 */
+	if (ilog2(bps_limit) + ilog2(jiffy_elapsed) - ilog2(HZ) > 62)
+		return U64_MAX;
 	return mul_u64_u64_div_u64(bps_limit, (u64)jiffy_elapsed, (u64)HZ);
 }
 
-- 
2.42.0.655.g421f12c284-goog


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

* Re: [PATCH] blk-throttle: check for overflow in calculate_bytes_allowed
  2023-10-20 22:36 [PATCH] blk-throttle: check for overflow in calculate_bytes_allowed Khazhismel Kumykov
@ 2023-10-21  0:22 ` Tejun Heo
  2023-10-21  0:38 ` Jens Axboe
  1 sibling, 0 replies; 3+ messages in thread
From: Tejun Heo @ 2023-10-21  0:22 UTC (permalink / raw)
  To: Khazhismel Kumykov
  Cc: Josef Bacik, Jens Axboe, Yu Kuai, cgroups, linux-block,
	linux-kernel, oleg, linan122, Khazhismel Kumykov

On Fri, Oct 20, 2023 at 03:36:17PM -0700, Khazhismel Kumykov wrote:
> 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>

Thanks.

-- 
tejun

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

* Re: [PATCH] blk-throttle: check for overflow in calculate_bytes_allowed
  2023-10-20 22:36 [PATCH] blk-throttle: check for overflow in calculate_bytes_allowed Khazhismel Kumykov
  2023-10-21  0:22 ` Tejun Heo
@ 2023-10-21  0:38 ` Jens Axboe
  1 sibling, 0 replies; 3+ messages in thread
From: Jens Axboe @ 2023-10-21  0:38 UTC (permalink / raw)
  To: Tejun Heo, Josef Bacik, Khazhismel Kumykov
  Cc: Yu Kuai, cgroups, linux-block, linux-kernel, oleg, linan122,
	Khazhismel Kumykov


On Fri, 20 Oct 2023 15:36:17 -0700, Khazhismel Kumykov wrote:
> 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.
> 
> 
> [...]

Applied, thanks!

[1/1] blk-throttle: check for overflow in calculate_bytes_allowed
      commit: 2dd710d476f2f1f6eaca884f625f69ef4389ed40

Best regards,
-- 
Jens Axboe




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

end of thread, other threads:[~2023-10-21  0:38 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2023-10-20 22:36 [PATCH] blk-throttle: check for overflow in calculate_bytes_allowed Khazhismel Kumykov
2023-10-21  0:22 ` Tejun Heo
2023-10-21  0:38 ` Jens Axboe

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox