Linux block layer
 help / color / mirror / Atom feed
* [PATCH] blk-iocost: Fix overflow in donation weight calculation
@ 2026-11-13 11:08 Alex Kazinsky
  2026-11-13 19:08 ` Tejun Heo
  2026-11-13 22:02 ` Jens Axboe
  0 siblings, 2 replies; 3+ messages in thread
From: Alex Kazinsky @ 2026-11-13 11:08 UTC (permalink / raw)
  To: Tejun Heo
  Cc: Alex Kazinsky, Josef Bacik, Jens Axboe, cgroups, linux-block,
	linux-kernel, lvc-project, stable

hweight_after_donation() receives usage as u32, clamped to the range
[1, WEIGHT_ONE]. Since WEIGHT_ONE is 1 << 16, multiplying it by usage
equal to WEIGHT_ONE wraps the 32-bit unsigned result to zero before
it is passed to div64_s64().

This makes new_hwi zero, which is then clamped to 1, incorrectly
reducing the cgroup's in-use weight to the minimum.

Cast WEIGHT_ONE to s64 before multiplication to preserve the full
product.

Found by Linux Verification Center (linuxtesting.org) with SVACE static
analysis tool.

Fixes: f1de2439ec43 ("blk-iocost: revamp donation amount determination")
Cc: stable@vger.kernel.org
Signed-off-by: Alex Kazinsky <a.kazinsky@ideco.ru>
---
 block/blk-iocost.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/block/blk-iocost.c b/block/blk-iocost.c
index 1c1025157d8e..0ffe34bd95b7 100644
--- a/block/blk-iocost.c
+++ b/block/blk-iocost.c
@@ -1853,7 +1853,8 @@ static u32 hweight_after_donation(struct ioc_gq *iocg, u32 old_hwi, u32 hwm,
 	delta = div64_s64(WEIGHT_ONE * (now->vnow - vtime),
 			  now->vnow - ioc->period_at_vtime);
 	target = WEIGHT_ONE * MARGIN_TARGET_PCT / 100;
-	new_hwi = div64_s64(WEIGHT_ONE * usage, WEIGHT_ONE - target + delta);
+	new_hwi = div64_s64((s64)WEIGHT_ONE * usage,
+			    WEIGHT_ONE - target + delta);
 
 	return clamp_t(s64, new_hwi, 1, hwm);
 }
-- 
2.56.0



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

end of thread, other threads:[~2026-11-13 22:02 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-11-13 11:08 [PATCH] blk-iocost: Fix overflow in donation weight calculation Alex Kazinsky
2026-11-13 19:08 ` Tejun Heo
2026-11-13 22:02 ` Jens Axboe

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