Received: by 2002:ac0:c50a:0:0:0:0:0 with SMTP id y10csp1030159imi; Fri, 1 Jul 2022 01:15:27 -0700 (PDT) X-Google-Smtp-Source: AGRyM1sNLMx535xrhFnqu1I82ePCypTkTk8fquroq1iPed2FPzUKtC0yKlnkDnbzREA5mPldgtYn X-Received: by 2002:a17:906:794e:b0:726:3fbb:5761 with SMTP id l14-20020a170906794e00b007263fbb5761mr12931471ejo.346.1656663326850; Fri, 01 Jul 2022 01:15:26 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1656663326; cv=none; d=google.com; s=arc-20160816; b=C6UbzebfHrsLwVoHrL6bnnnhMMzNsc82fKj0mB3x1wP74DtxwNMzFwiG+7dPHkq6VV Oe7e3rcJAKQFgo8JxLN3K0yG8wNEp+68Ol2ihAiHmwQGNfOnRmOzW52qcOl7iZ6UIPEy oLCQHGuJyztq2EBjMzaSRVGYyLFRTHk5brpPMe1a+3Qdm8dUcQX8cnZn4H6kAEedEOZs 3zcWKvyc0/u7jpbq/TJTVtm3DJ1USstiLyumcHjW44aLwmnSu7f1tQTcYjod6QKTGrnd CsabgRTKTeWF9cWk+RPh6ihjzWonl1bY3HP9s9PxgZ9+gT756gQL7toaUrQ/E13dSZ6W audg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from; bh=4Z2Fuft78l+D1NrZqSbe/qSIf/g1eKzj/FfO0Pr+sxE=; b=Cn/iUsYYs3ELgNgwIUi/AhszDkrSrJiQSBHkBtDXEJM5NhQvWq5Wu00r99GTW5hD/G 6ltSodanpQG1S0ng9MbqYeg4RZIWy28scmOxVaqcT9ThY1Xp3Cip9wOHjcYe5lSGVEQD debGp8ecQZIALZwNMr2WGG9qXhksKs5j2k3FzQyWGZTmbv1ky0DyFoGM1kjQJnV6xSji DVCHog+ZhU/5ZPeaBgJCfM6gtd2QG02OZ47dfh2XUU5TrMj4cRmotIhDdgwvHKOW43Pj Vyes+I+nYmSDWNQqAc1GpN08yUfgadHoblpBXib+DYus+OJqqylERmV9KQGBeaMh/Zgm H5uQ== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=huawei.com Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id qw21-20020a1709066a1500b0071572d1bc73si4676156ejc.785.2022.07.01.01.15.01; Fri, 01 Jul 2022 01:15:26 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=huawei.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S234852AbiGAHzV (ORCPT + 99 others); Fri, 1 Jul 2022 03:55:21 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:50952 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S235517AbiGAHzN (ORCPT ); Fri, 1 Jul 2022 03:55:13 -0400 Received: from dggsgout11.his.huawei.com (dggsgout11.his.huawei.com [45.249.212.51]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 7F90A6D56D; Fri, 1 Jul 2022 00:55:12 -0700 (PDT) Received: from mail02.huawei.com (unknown [172.30.67.153]) by dggsgout11.his.huawei.com (SkyGuard) with ESMTP id 4LZ6SV4ZzyzKJlh; Fri, 1 Jul 2022 15:35:54 +0800 (CST) Received: from huaweicloud.com (unknown [10.175.127.227]) by APP3 (Coremail) with SMTP id _Ch0CgAXFWgIpL5igL73AA--.48972S7; Fri, 01 Jul 2022 15:36:43 +0800 (CST) From: Yu Kuai To: tj@kernel.org, mkoutny@suse.com, axboe@kernel.dk, ming.lei@redhat.com Cc: cgroups@vger.kernel.org, linux-block@vger.kernel.org, linux-kernel@vger.kernel.org, yukuai3@huawei.com, yukuai1@huaweicloud.com, yi.zhang@huawei.com Subject: [PATCH v6 2/8] blk-throttle: prevent overflow while calculating wait time Date: Fri, 1 Jul 2022 15:49:17 +0800 Message-Id: <20220701074923.657426-4-yukuai3@huawei.com> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20220701074923.657426-1-yukuai3@huawei.com> References: <20220701074923.657426-1-yukuai3@huawei.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-CM-TRANSID: _Ch0CgAXFWgIpL5igL73AA--.48972S7 X-Coremail-Antispam: 1UD129KBjvJXoW7Ary5Aw1UurWDtF47uF1rJFb_yoW8JFWrpr WfCr10gF45Xw1xKF13Gan0vay8ArsxJFy5G3y3WanayF90kF97XF95ZryFva18ZFZ7ua1f Aw1DtFy7Ar1DArJanT9S1TB71UUUUUUqnTZGkaVYY2UrUUUUjbIjqfuFe4nvWSU5nxnvy2 9KBjDU0xBIdaVrnRJUUUQjb4IE77IF4wAFF20E14v26rWj6s0DM7CY07I20VC2zVCF04k2 6cxKx2IYs7xG6r1j6r18M7CIcVAFz4kK6r1j6r18M28IrcIa0xkI8VA2jI8067AKxVWUWw A2048vs2IY020Ec7CjxVAFwI0_Xr0E3s1l8cAvFVAK0II2c7xJM28CjxkF64kEwVA0rcxS w2x7M28EF7xvwVC0I7IYx2IY67AKxVWDJVCq3wA2z4x0Y4vE2Ix0cI8IcVCY1x0267AKxV W8Jr0_Cr1UM28EF7xvwVC2z280aVAFwI0_GcCE3s1l84ACjcxK6I8E87Iv6xkF7I0E14v2 6rxl6s0DM2AIxVAIcxkEcVAq07x20xvEncxIr21l5I8CrVACY4xI64kE6c02F40Ex7xfMc Ij6xIIjxv20xvE14v26r106r15McIj6I8E87Iv67AKxVW8JVWxJwAm72CE4IkC6x0Yz7v_ Jr0_Gr1lF7xvr2IYc2Ij64vIr41lF7Iv64x0x7Aq67IIx4CEVc8vx2IErcIFxwACI402YV CY1x02628vn2kIc2xKxwCF04k20xvY0x0EwIxGrwCF04k20xvEw4C26cxK6c8Ij28IcwCF x2IqxVCFs4IE7xkEbVWUJVW8JwC20s026c02F40E14v26r1j6r18MI8I3I0E7480Y4vE14 v26r106r1rMI8E67AF67kF1VAFwI0_Jw0_GFylIxkGc2Ij64vIr41lIxAIcVC0I7IYx2IY 67AKxVWUJVWUCwCI42IY6xIIjxv20xvEc7CjxVAFwI0_Gr0_Cr1lIxAIcVCF04k26cxKx2 IYs7xG6r1j6r1xMIIF0xvEx4A2jsIE14v26r4j6F4UMIIF0xvEx4A2jsIEc7CjxVAFwI0_ Gr0_Gr1UYxBIdaVFxhVjvjDU0xZFpf9x07UZ2-nUUUUU= Sender: yukuai1@huaweicloud.com X-CM-SenderInfo: 51xn3trlr6x35dzhxuhorxvhhfrp/ X-CFilter-Loop: Reflected X-Spam-Status: No, score=-1.7 required=5.0 tests=BAYES_00, HEADER_FROM_DIFFERENT_DOMAINS,SPF_HELO_NONE,SPF_PASS, T_SCC_BODY_TEXT_LINE autolearn=no autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org In tg_with_in_bps_limit(), 'bps_limit * jiffy_elapsed_rnd' might overflow. FIx the problem by calling mul_u64_u64_div_u64() instead. Signed-off-by: Yu Kuai --- block/blk-throttle.c | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/block/blk-throttle.c b/block/blk-throttle.c index 5c1d1c4d8188..a89c62bef2fb 100644 --- a/block/blk-throttle.c +++ b/block/blk-throttle.c @@ -806,7 +806,7 @@ static bool tg_with_in_bps_limit(struct throtl_grp *tg, struct bio *bio, u64 bps_limit, unsigned long *wait) { bool rw = bio_data_dir(bio); - u64 bytes_allowed, extra_bytes, tmp; + u64 bytes_allowed, extra_bytes; unsigned long jiffy_elapsed, jiffy_wait, jiffy_elapsed_rnd; unsigned int bio_size = throtl_bio_data_size(bio); @@ -824,10 +824,8 @@ static bool tg_with_in_bps_limit(struct throtl_grp *tg, struct bio *bio, jiffy_elapsed_rnd = tg->td->throtl_slice; jiffy_elapsed_rnd = roundup(jiffy_elapsed_rnd, tg->td->throtl_slice); - - tmp = bps_limit * jiffy_elapsed_rnd; - do_div(tmp, HZ); - bytes_allowed = tmp; + bytes_allowed = mul_u64_u64_div_u64(bps_limit, (u64)jiffy_elapsed_rnd, + (u64)HZ); if (tg->bytes_disp[rw] + bio_size <= bytes_allowed) { if (wait) -- 2.31.1