From: Alex Kazinsky <a.kazinsky@ideco.ru>
To: Tejun Heo <tj@kernel.org>
Cc: Alex Kazinsky <a.kazinsky@ideco.ru>,
Josef Bacik <josef@toxicpanda.com>, Jens Axboe <axboe@kernel.dk>,
cgroups@vger.kernel.org, linux-block@vger.kernel.org,
linux-kernel@vger.kernel.org, lvc-project@linuxtesting.org,
stable@vger.kernel.org
Subject: [PATCH] blk-iocost: Fix overflow in donation weight calculation
Date: Fri, 13 Nov 2026 15:08:40 +0400 [thread overview]
Message-ID: <20261113110842.4189035-1-a.kazinsky@ideco.ru> (raw)
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
reply other threads:[~2026-11-13 11:08 UTC|newest]
Thread overview: [no followups] expand[flat|nested] mbox.gz Atom feed
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20261113110842.4189035-1-a.kazinsky@ideco.ru \
--to=a.kazinsky@ideco.ru \
--cc=axboe@kernel.dk \
--cc=cgroups@vger.kernel.org \
--cc=josef@toxicpanda.com \
--cc=linux-block@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=lvc-project@linuxtesting.org \
--cc=stable@vger.kernel.org \
--cc=tj@kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®