Received: by 2002:a05:6358:1087:b0:cb:c9d3:cd90 with SMTP id j7csp181085rwi; Wed, 12 Oct 2022 18:13:49 -0700 (PDT) X-Google-Smtp-Source: AMsMyM5+XLcLfzfh27/ooXpSn7I/UF+8qhTK0VhIrHFQUWsPsieUYqoZFu7NkXg1V2GL01Gv7J4e X-Received: by 2002:a05:6402:500d:b0:459:3e56:e6f9 with SMTP id p13-20020a056402500d00b004593e56e6f9mr30173611eda.367.1665623629283; Wed, 12 Oct 2022 18:13:49 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1665623629; cv=none; d=google.com; s=arc-20160816; b=VEA/5eJWgCE2GcgJMDwdjGc+SRexRzueNrZY1SgZnFlfrX0lQyTa3LvLxaUEE4PCXp GOK6ogrEasWWu9MPhzu6N4u5vCeMBfpAyxVCrE9twFaidXah5Au0vr07VWXQWSWAwnHX HuUwdZCMoyiLFMW/2FpLMPkCjkMsoUp3uHtT23Bcxd+ZsN8SpHmyDI6GiqwDF0a2ZTIo OI6+Gekts4FZAVTyT4Yhnede3STrlN75qd8qEO5hAqUQiXzE93W+xM1ujT5skr4T7ZQU b0emFFOgmwBb0SaDM8u7amecGBmYATbaKcddBUoomlLk0anaLzMn9Ui91yeMt1pwAuBu zvKQ== 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 :dkim-signature; bh=DQNxz1TmE8pCFFOBf5Vn220sEl/D5RZGFhQup3dE99c=; b=P0ZYMpUG6/LugipOYhW+v3wigOMY8DyOr5NgTs+safnf88fDwVVqRFRcxfgVBTRAUk F7pmqGRNmn1d1q5Yc2IP61lLJ2QX6UXgxzRfdWNXOuuY5PnSsNKsTYlUT6b7RTB42Qjf Xluj6NA05boCdQUv4126jRv16PkiJnvjiDqJFvNOwQSb28hX5Tp5z/n1oSF7zxJ+2s7s P3XkskfMewjCxdA7M5rS6kFlYpHSICpOsI0CBzx95ii8BWyqFV/1QESFvrFAVwkOflaX oxZDrT0KuSeQ4nkKVAsXryLYeDVUHwcRPOBFqF9iD/JYXtTYcg17oK51xoru1obHrSIX CJsw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=a5CIkR2M; 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=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id eb6-20020a0564020d0600b0044d7a93e44dsi19954049edb.579.2022.10.12.18.13.23; Wed, 12 Oct 2022 18:13:49 -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; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=a5CIkR2M; 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=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229996AbiJMASg (ORCPT + 99 others); Wed, 12 Oct 2022 20:18:36 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:38460 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229966AbiJMARn (ORCPT ); Wed, 12 Oct 2022 20:17:43 -0400 Received: from ams.source.kernel.org (ams.source.kernel.org [145.40.68.75]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 45D0D18C94D; Wed, 12 Oct 2022 17:17:02 -0700 (PDT) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ams.source.kernel.org (Postfix) with ESMTPS id F017DB81CC1; Thu, 13 Oct 2022 00:16:46 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id D3C50C43470; Thu, 13 Oct 2022 00:16:44 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1665620205; bh=HiDHAOPSQv6P3nE8r2l5k+CLpdCGeWChgEX9BNsMegY=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=a5CIkR2Mitb82E4vl9gQn9/fzdho6eDrA8slnHZK4A1fy7fpjYxQypRqMIvt3z4Ek PcbptdG+PEXiiBOJ0BWjd+I4sjSXTdx5t6hD5gjQ/nNTtAU1zW6rjReIWeneiGeEMN JIpDs1Zf0KYerQZyrv5H9LcNWlLdeoYrg+/R0XvnHqgRCD6YsEQC4vEFGzEeqfWHbK JmeM9BbXWbJgvNm6Qwvtgg3qzlovjLnE3xhyBYjT0PaDcDfsbRXACMeeMlMK3OySdS Pk89ASq0Ns9YeADXVve37ZNMpTTTeVrEUWS9YwZe+yGVLUm2o5e7TNXUWQTChZNmvZ /Q8Syde+cmF9w== From: Sasha Levin To: linux-kernel@vger.kernel.org, stable@vger.kernel.org Cc: Yu Kuai , Tejun Heo , Jens Axboe , Sasha Levin , cgroups@vger.kernel.org, linux-block@vger.kernel.org Subject: [PATCH AUTOSEL 6.0 19/67] blk-throttle: prevent overflow while calculating wait time Date: Wed, 12 Oct 2022 20:15:00 -0400 Message-Id: <20221013001554.1892206-19-sashal@kernel.org> X-Mailer: git-send-email 2.35.1 In-Reply-To: <20221013001554.1892206-1-sashal@kernel.org> References: <20221013001554.1892206-1-sashal@kernel.org> MIME-Version: 1.0 X-stable: review X-Patchwork-Hint: Ignore Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-7.1 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_HI, SPF_HELO_NONE,SPF_PASS autolearn=ham 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 From: Yu Kuai [ Upstream commit 8d6bbaada2e0a65f9012ac4c2506460160e7237a ] There is a problem found by code review in tg_with_in_bps_limit() that 'bps_limit * jiffy_elapsed_rnd' might overflow. Fix the problem by calling mul_u64_u64_div_u64() instead. Signed-off-by: Yu Kuai Acked-by: Tejun Heo Link: https://lore.kernel.org/r/20220829022240.3348319-3-yukuai1@huaweicloud.com Signed-off-by: Jens Axboe Signed-off-by: Sasha Levin --- 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 9f5fe62afff9..55a764e5ba61 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.35.1