From patchwork Mon Oct 24 11:32:38 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Greg KH X-Patchwork-Id: 9215 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:6687:0:0:0:0:0 with SMTP id l7csp459237wru; Mon, 24 Oct 2022 06:39:09 -0700 (PDT) X-Google-Smtp-Source: AMsMyM4+gni3Quwi+fmDFFqAUlinuK1FyREySBs6VNifHkF3xifjvHVjqoHPAq1C0lswykQz53cm X-Received: by 2002:a05:6402:1d86:b0:457:e84:f0e with SMTP id dk6-20020a0564021d8600b004570e840f0emr30599330edb.241.1666618748945; Mon, 24 Oct 2022 06:39:08 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1666618748; cv=none; d=google.com; s=arc-20160816; b=ugJSR7Gr4XnK29ci4x8KNM5YDhssJVFR9pmhL0Qr7amRrFCbC4uym56bEF6ftDwN4j 73UogoBsl+v+mcarl4wY6abVvVv+X73T3gE0V+V1rCoRHLUQ/jJVte9FK7XukqoNpuDH 0LWao6jgqpjhKOCwmnmPWHYgcuy38RSp0BgOEd9g+8Rzr2g1QmyD/sOXMX2R/utTtRU8 XyhhvNJzfOWAWkgJmZiHqkKjhbW30fnbBdhMOqc8jrd+MEtY5NpH4da5+aCQbTADdqD0 RHeDmg0i3XhnDn8vremJ2rRyZ234YxJslejHumRBGuBi2TJ/TLlifPqGfaGflnepuKtv srqA== 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 :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=FXvPYFDkJe26cKCP95AmcLeHvoYKFfADUu03GmNp2Vk=; b=zt+997hpD5CeFCpmKJ28ED49U7uftdv0YqglABC61j/LfdqUZ+RwtqTH6WRWkKm1iU A/euR7LtaV6X2hmEGgsjm/aIJ+5KDloG7/zDkRmwA5uFCfzoplWd36kfIVNmEh6hSc1C x6RDc9carSlGkccugEHS1nvBA2mZCEltqmwzklM0PD3l9BGm2k7kdJZI31iZ/9H2/nPo cA28lX30NzvkWjDbYQ+6FWqbGffybG8DMUHby0DuwUXoBWjCR1X+QNHXJmKIXdKR+vKK EKRaI9yw6J6ErB938mFquSCGEqg8gzTwNCvegPav9FvLOB7egYB36kSeV06c92uyCQZ0 BFpA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=ADWkvwv5; 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=linuxfoundation.org Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id ne22-20020a1709077b9600b007701a050273si32473997ejc.942.2022.10.24.06.38.42; Mon, 24 Oct 2022 06:39:08 -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=@linuxfoundation.org header.s=korg header.b=ADWkvwv5; 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=linuxfoundation.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232499AbiJXNfq (ORCPT + 99 others); Mon, 24 Oct 2022 09:35:46 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:49862 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231640AbiJXN2r (ORCPT ); Mon, 24 Oct 2022 09:28:47 -0400 Received: from dfw.source.kernel.org (dfw.source.kernel.org [IPv6:2604:1380:4641:c500::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 1E682AA36F; Mon, 24 Oct 2022 05:31:59 -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 dfw.source.kernel.org (Postfix) with ESMTPS id 98F3C61280; Mon, 24 Oct 2022 12:31:39 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id AED34C433D6; Mon, 24 Oct 2022 12:31:38 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1666614699; bh=p6GiSY8fKFEwVLEYaOs1ega9J3UWlailRKtYivPY8dg=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=ADWkvwv5LE+JOxdbESB5viC1rvWlvR1Pi9O1ZbeX2t8IQggPbygxtoWt/NPAew0/Q tVLx6SpjJI6eUgN38pM5gJ287JvmTu+tr3VzEF/JR8R67QsKhAuIVpZeahZUCsNjCj ACCutL6DbKFDDNn/RNMuLiDLuZAUBhvcTaY9d7hk= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Yu Kuai , Tejun Heo , Jens Axboe , Sasha Levin Subject: [PATCH 5.10 361/390] blk-throttle: prevent overflow while calculating wait time Date: Mon, 24 Oct 2022 13:32:38 +0200 Message-Id: <20221024113038.365489430@linuxfoundation.org> X-Mailer: git-send-email 2.38.1 In-Reply-To: <20221024113022.510008560@linuxfoundation.org> References: <20221024113022.510008560@linuxfoundation.org> User-Agent: quilt/0.67 MIME-Version: 1.0 X-Spam-Status: No, score=-7.6 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 X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1747576421792111437?= X-GMAIL-MSGID: =?utf-8?q?1747576421792111437?= 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 c53a254171a2..c526fdd0a7b9 100644 --- a/block/blk-throttle.c +++ b/block/blk-throttle.c @@ -944,7 +944,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); @@ -961,10 +961,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)