Received: by 2002:a05:6358:1087:b0:cb:c9d3:cd90 with SMTP id j7csp186337rwi; Wed, 12 Oct 2022 18:20:09 -0700 (PDT) X-Google-Smtp-Source: AMsMyM4k4HvUAo5LxUjArA0lDwTnq98iBaYf/jC05iX+OOqyWfPQIh18UQE6Anx7D42C8PgnNzSu X-Received: by 2002:a17:90b:3ece:b0:20a:ea98:b93e with SMTP id rm14-20020a17090b3ece00b0020aea98b93emr8255319pjb.123.1665624008759; Wed, 12 Oct 2022 18:20:08 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1665624008; cv=none; d=google.com; s=arc-20160816; b=gPTVUvXA9voQUU7s9N7wRIc1I26d5w4t7y9kVRouIr3Fyotc4oEmav40jIkbINm8df LbUqvqcYLdiosToGhGgRflQcmSwJZ6o14sz5dj+9cIvRTOTjQZ78z33uTf/xXhul2ggP wDE94JdeIadFwCrJjVa0vtubZMTSGVBPkiOuyD1SQcuoKYUmmftQ6g1biCNmk3kXj7CT q/peOS01MemX5ccpXB7nkq3jTQWh19Gp+H8lxlByGXe5E/c5t2k2OmmLODCUbS5lAjJa y/0ijFQVNa/39rst6oM6rPj9NUFYorktM0V6cI37l3Cqm4VMg9PfsvW6p2fqMXF/iOqF YCMg== 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=m4RKBvSyUjQxZ7NJWQQwGRqwNQPkRGryZGYsl7FTeng=; b=TyDO2C1B6dQm+APKZrA1OZnoq3XTUDjAu55f0i4JyoElVajmUMlYf2Pvfo6hSXtA/+ LKlQpkfYq5gJqhxXr151MBscn6gELEP42mXuxgAUxVa/iTmItDTE1Y7lyknhdHg+zHe4 SfQmzoBlZPJXKM1zA1B0C/KSd9feXhT+xyeAsDy3XvdQr6QDynrWobfp7UqLGvmK4GRZ pCbyw4/mSRo+w7lTWcy5Rof0C3qbjW2FEa5SOic1vW7x+8Bh82F4oNLT3Nat8aZev7AK rJ4Od92DJkz4s3FN5nx3udctxJZrpajlDZ0gOk0KrS60fBc9nDJH6OhxXdcyMr9XTSEN JhaQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=N0p6fCRM; 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 mw18-20020a17090b4d1200b001fe30008cd0si4265810pjb.166.2022.10.12.18.19.57; Wed, 12 Oct 2022 18:20: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=@kernel.org header.s=k20201202 header.b=N0p6fCRM; 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 S229619AbiJMBNK (ORCPT + 99 others); Wed, 12 Oct 2022 21:13:10 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:51678 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229847AbiJMBMg (ORCPT ); Wed, 12 Oct 2022 21:12:36 -0400 Received: from ams.source.kernel.org (ams.source.kernel.org [IPv6:2604:1380:4601:e00::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 108D85D0F4; Wed, 12 Oct 2022 18:11:38 -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 70830B81CBD; Thu, 13 Oct 2022 00:22:17 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 51411C43144; Thu, 13 Oct 2022 00:22:15 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1665620536; bh=tyY7mApUCKy3nxZR8IiT8fEapo3BTVDOMAVT+cOVgtA=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=N0p6fCRMVoR/DoMxIjt2gjpCaaUzBn74/wiLh+bslI1tP9jXnmnz0jKR8EvU88QwZ kFOlUZHyitRTMExYHHdW/iVLDzpUwbQMcp43hTidOmBAB6xBdMPEY+CkXbY8YEx2di FE4MnLKUYIfZzDHTWy940waVyZRsm2Qs8FRqWR5nRR6Pmurl/qcb586gVC0ksNY5HA gvA+97D7I5jTw6ePtxBuIX+FLrPQG4B/VnXZpqoBIliQWBWx9nq8IvGnQsmFV5H6EZ ExmbLzKBoO9FrK58+X4Q2S9YZKp3N3IqWBkUGQS2c6J0iy/FVJ8FXxBJ2PKtqOtM/L S7QpCkME2hJiQ== 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 5.15 15/47] blk-throttle: prevent overflow while calculating wait time Date: Wed, 12 Oct 2022 20:20:50 -0400 Message-Id: <20221013002124.1894077-15-sashal@kernel.org> X-Mailer: git-send-email 2.35.1 In-Reply-To: <20221013002124.1894077-1-sashal@kernel.org> References: <20221013002124.1894077-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 7c4e7993ba97..68cf8dbb4c67 100644 --- a/block/blk-throttle.c +++ b/block/blk-throttle.c @@ -950,7 +950,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); @@ -967,10 +967,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