Received: by 2002:ac2:464d:0:0:0:0:0 with SMTP id s13csp1991504lfo; Sat, 28 May 2022 12:57:47 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzKtsRRNpt3yPDTXD1xj1UrMkA5IuJHsMkpjWV0q60H6ggKf9XUa8w5K8rjB90/0hrGY3gJ X-Received: by 2002:a17:902:cf05:b0:156:9d:ca01 with SMTP id i5-20020a170902cf0500b00156009dca01mr48459239plg.111.1653767866788; Sat, 28 May 2022 12:57:46 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1653767866; cv=none; d=google.com; s=arc-20160816; b=wgBqtdVp3J0kvZwZDkLSX7QGKusH0uAMGejt07kbPnHOG/hzOe5GwXVDFirSc1K2+I Qgv7aZs8tpiMeovSkCs0pRcgyjudfF+Td1umdoy5cUuAUH4Td38iZF/6J9BSrCU998qm poA7HE4ZxNNgH2Hd34dpAEwuGIVISulWPGPmHi9LbPeCKscF+xIolA5tbhppsyRMUfWY tCKZylVGtrVLER9COJlMrwgnemGVyWhQhi+kZopf3pfeAkUq4WQ7VyCZuJlnG0Nurk/W k6dUpSLdWaaZERCX+a51oQfX+/AQIjVGEEmi79UECDBnfodQu2vcicHisRG0kic57mcu 5UGQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from; bh=4Z2Fuft78l+D1NrZqSbe/qSIf/g1eKzj/FfO0Pr+sxE=; b=rMN5jGHLcyNGRTbB1tMcFv5Xi6Unq2voKoUPulFSWYpBSfLOmLtCdq5+VrJT8YAKPn //6+jDRkjuOgIJHivROW8S5NJX+6MTgvOUce1JExlW1qRkorH2loLZLzXOnIoMA5+jWr LUNVHF2SMQ9sIrTvVJsoJrwbrF6ezQ6XsrBYXAbQi7UPLe2jNZVCpELH8HJY8NppQwTm /TiI4v2ZOoMaRouhPKQTYSvEkaIzoPTMmVhLQ+ljG1AakH7dY9Kt2Xwz+GetYT/u+pVf 9P4qVITj5c+e2j30U2x5UJpOTEIjhlgn/XWbxv4GFz8YpYz6wLBhJDU30GVcE5MrAn9+ zpwQ== 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:18 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 lindbergh.monkeyblade.net (lindbergh.monkeyblade.net. [2620:137:e000::1:18]) by mx.google.com with ESMTPS id j190-20020a6380c7000000b003fbea5453c4si1423976pgd.607.2022.05.28.12.57.46 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 28 May 2022 12:57:46 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:18 as permitted sender) client-ip=2620:137:e000::1:18; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=huawei.com Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id B4FAE34BA4; Sat, 28 May 2022 12:16:46 -0700 (PDT) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1355877AbiE1Gal (ORCPT + 99 others); Sat, 28 May 2022 02:30:41 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:44008 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1355822AbiE1GaX (ORCPT ); Sat, 28 May 2022 02:30:23 -0400 Received: from szxga03-in.huawei.com (szxga03-in.huawei.com [45.249.212.189]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id E21BD3D49F; Fri, 27 May 2022 23:30:03 -0700 (PDT) Received: from kwepemi100015.china.huawei.com (unknown [172.30.72.56]) by szxga03-in.huawei.com (SkyGuard) with ESMTP id 4L9Bc26WQqzDqWP; Sat, 28 May 2022 14:29:54 +0800 (CST) Received: from kwepemm600009.china.huawei.com (7.193.23.164) by kwepemi100015.china.huawei.com (7.221.188.125) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2375.24; Sat, 28 May 2022 14:30:01 +0800 Received: from huawei.com (10.175.127.227) by kwepemm600009.china.huawei.com (7.193.23.164) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2375.24; Sat, 28 May 2022 14:30:00 +0800 From: Yu Kuai To: , , , CC: , , , , Subject: [PATCH -next v5 2/8] blk-throttle: prevent overflow while calculating wait time Date: Sat, 28 May 2022 14:43:24 +0800 Message-ID: <20220528064330.3471000-3-yukuai3@huawei.com> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20220528064330.3471000-1-yukuai3@huawei.com> References: <20220528064330.3471000-1-yukuai3@huawei.com> MIME-Version: 1.0 Content-Transfer-Encoding: 7BIT Content-Type: text/plain; charset=US-ASCII X-Originating-IP: [10.175.127.227] X-ClientProxiedBy: dggems706-chm.china.huawei.com (10.3.19.183) To kwepemm600009.china.huawei.com (7.193.23.164) X-CFilter-Loop: Reflected X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00, HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI,RDNS_NONE, SPF_HELO_NONE,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