From patchwork Wed Oct 19 08:34:54 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Greg KH X-Patchwork-Id: 4956 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:4ac7:0:0:0:0:0 with SMTP id y7csp226527wrs; Wed, 19 Oct 2022 02:46:10 -0700 (PDT) X-Google-Smtp-Source: AMsMyM48mhSRbtBxnzp6vyx7ljQDWZcIqUV7lfyLWtxN73NBjlR2gPFV8vPEqlRroJNDI3F+a1hN X-Received: by 2002:a05:6402:f83:b0:458:8c97:29af with SMTP id eh3-20020a0564020f8300b004588c9729afmr6539892edb.210.1666172770304; Wed, 19 Oct 2022 02:46:10 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1666172770; cv=none; d=google.com; s=arc-20160816; b=cozP0d+JpMSyJlY8sYD5ksADH4sORl9QVqAsc52KKfCU2VdcAWPw45hQQ4dcd0GTQa rRBUzdBJzPaGd/R90b2BkXCDyzD4pwY3D7hABX6asIYie+pR6rxH4p/fu96c0GJuGbob ByVWIEZo7qm+d7l1wrQSCDaGWrHH9uKZjOiNf0fKqBR+Re+wOBECFSM/WCUxLqfyNmIS Ma8N7NUI6dYG+O3MmHMsr7FuE7GQwyBBSSQCjkEIgWDp2mitW8a61NlBmIlFdCO9Bvvv orQP4gXVPegR/Yv1WTBliPoKSEzH/waHhc+008bb6kC4QEzUMLnFuYXPXCImBWg22SFR T+KQ== 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=0lKUGf7Xmvsq4ZoptBmA6/tbTuqhrnxY+t4D8GLjY+Y=; b=AIe4Va0+mdZOvKrrs1RaymlA1THwgI5rl7ja3ReB595Padn3LY/11i6uM9LttOIHYU CHfUZwuXKC+5Xdfh7jRL9l/9Ij+UL11wtaE5Vgtj3SCKNy3nwUYtlV22n7da5MNDflm5 vc47q7pnxzC0GgZCdrfaDYkF7ZKlkxtQ8KsdlyxKv5Q+o5oVp5LP2K/ITRfVPBTtlAih W2Fxk7e6Xuyk5t9eQeOQY1pmj1e/Trha4ThoXk5AgvcEdM7nJuf7b28hRZV8Z6/h8Bzz jZkEgkZgCxwycCndBd9WgwVD1186LSdHhoPBS2yJjHf1crH8e41xkuIvaFnImTiF8P46 5zLQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=ftzSWO+e; 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 du17-20020a17090772d100b00783ca4d1c74si14076436ejc.520.2022.10.19.02.45.28; Wed, 19 Oct 2022 02:46:10 -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=ftzSWO+e; 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 S234031AbiJSJmm (ORCPT + 99 others); Wed, 19 Oct 2022 05:42:42 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:52462 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234193AbiJSJjL (ORCPT ); Wed, 19 Oct 2022 05:39:11 -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 DCC51DED22; Wed, 19 Oct 2022 02:16:05 -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 A8400617D4; Wed, 19 Oct 2022 09:14:03 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id B671FC433D7; Wed, 19 Oct 2022 09:14:02 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1666170843; bh=FExqy90cvvKeQwgBS3G6vEsaIKxkIk3GIJCelzs91+g=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=ftzSWO+eC6HulXbNI8UJ63pYwCK6i+VcXgU2h9VAyJgIlpg69EXnQps8JKP9WZkZv mk5SRnj9GBHz0wVcKWIUs5KysclTyApt21i7O68V0R3VLWyCG+XTuRr82q6RhLwR36 wcKVQZjZW3oQqYkH1F7bU4g85UG5agWgO5yVr3Ag= 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 6.0 807/862] blk-throttle: prevent overflow while calculating wait time Date: Wed, 19 Oct 2022 10:34:54 +0200 Message-Id: <20221019083325.560259314@linuxfoundation.org> X-Mailer: git-send-email 2.38.0 In-Reply-To: <20221019083249.951566199@linuxfoundation.org> References: <20221019083249.951566199@linuxfoundation.org> User-Agent: quilt/0.67 MIME-Version: 1.0 X-Spam-Status: No, score=-7.4 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?1747108778485482880?= X-GMAIL-MSGID: =?utf-8?q?1747108778485482880?= 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 3c02a9b3275a..35cf744ea9d1 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)