From: Tejun Heo <tj@kernel.org>
To: Jens Axboe <axboe@kernel.dk>
Cc: linux-block@vger.kernel.org, linux-kernel@vger.kernel.org,
kernel-team@fb.com, cgroups@vger.kernel.org
Subject: [PATCH block/for-next] blk-iocost: fix divide-by-zero in transfer_surpluses()
Date: Fri, 11 Sep 2020 13:07:46 -0400 [thread overview]
Message-ID: <20200911170746.GG4295@mtj.thefacebook.com> (raw)
Conceptually, root_iocg->hweight_donating must be less than WEIGHT_ONE but
all hweight calculations round up and thus it may end up >= WEIGHT_ONE
triggering divide-by-zero and other issues. Bound the value to avoid
surprises.
Signed-off-by: Tejun Heo <tj@kernel.org>
Fixes: e08d02aa5fc9 ("blk-iocost: implement Andy's method for donation weight updates")
---
block/blk-iocost.c | 14 ++++++++++----
1 file changed, 10 insertions(+), 4 deletions(-)
diff --git a/block/blk-iocost.c b/block/blk-iocost.c
index fc897bb142bcd..978753335370a 100644
--- a/block/blk-iocost.c
+++ b/block/blk-iocost.c
@@ -1881,15 +1881,21 @@ static void transfer_surpluses(struct list_head *surpluses, struct ioc_now *now)
/*
* Calculate the global donation rate (gamma) - the rate to adjust
- * non-donating budgets by. No need to use 64bit multiplication here as
- * the first operand is guaranteed to be smaller than WEIGHT_ONE
- * (1<<16).
+ * non-donating budgets by.
+ *
+ * No need to use 64bit multiplication here as the first operand is
+ * guaranteed to be smaller than WEIGHT_ONE (1<<16).
+ *
+ * We know that there are beneficiary nodes and the sum of the donating
+ * hweights can't be whole; however, due to the round-ups during hweight
+ * calculations, root_iocg->hweight_donating might still end up equal to
+ * or greater than whole. Limit the range when calculating the divider.
*
* gamma = (1 - t_r') / (1 - t_r)
*/
gamma = DIV_ROUND_UP(
(WEIGHT_ONE - root_iocg->hweight_after_donation) * WEIGHT_ONE,
- WEIGHT_ONE - root_iocg->hweight_donating);
+ WEIGHT_ONE - min_t(root_iocg->hweight_donating, WEIGHT_ONE - 1));
/*
* Calculate adjusted hwi, child_adjusted_sum and inuse for the inner
next reply other threads:[~2020-09-11 17:08 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
2020-09-11 17:07 Tejun Heo [this message]
2020-09-11 17:10 ` [PATCH block/for-next] blk-iocost: fix divide-by-zero in transfer_surpluses() Jens Axboe
2020-09-11 22:40 ` [PATCH v2 " Tejun Heo
2020-09-11 22:43 ` Jens Axboe
2020-09-11 22:44 ` Tejun Heo
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=20200911170746.GG4295@mtj.thefacebook.com \
--to=tj@kernel.org \
--cc=axboe@kernel.dk \
--cc=cgroups@vger.kernel.org \
--cc=kernel-team@fb.com \
--cc=linux-block@vger.kernel.org \
--cc=linux-kernel@vger.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;
as well as URLs for NNTP newsgroup(s).