From patchwork Sat Oct 22 07:29:04 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Greg KH X-Patchwork-Id: 7682 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:4242:0:0:0:0:0 with SMTP id s2csp1108891wrr; Sat, 22 Oct 2022 01:46:27 -0700 (PDT) X-Google-Smtp-Source: AMsMyM43MXSUnXPxzwsH0qZhfqltHbXEVROnVPflHPSUTubufNmvZD66szJ3hPjXm2M01jI6lPdb X-Received: by 2002:aa7:d614:0:b0:458:f796:f86a with SMTP id c20-20020aa7d614000000b00458f796f86amr21382204edr.294.1666428386653; Sat, 22 Oct 2022 01:46:26 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1666428386; cv=none; d=google.com; s=arc-20160816; b=ENQ1PAwfGAqF7+YeEWub+hr5G4b5kAU+Wu35ITuWoGe2/GFcYdqJ+dXHsnLZeURN6o LfGVYVfVxfFxgA3UewRLlW1uVcjBzRGc34+fDhsVubjM0i+axv3zT1NcHndUgkrDvu1X G+TKckzuodbl6TXCG7i7Cx/+BrICFphFVGgj0a9y9YpvGYig1rKe0HWlizk75nA5EG1P PO+YvSs1757AnyP4c0q2WuVkM89hNq8/2cGfrRTS5Uj4bIVpxWU4hqP883aHAQVNK/fJ rstvptUZINb2iD10Lx3qaJILvdUaUBBtAusCXpwTWQ7g9w2haXUk6W9SEXlbvmOd7WIP 0ZUw== 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=MLyGy1DGICMMC1rqPP1dPuXWXK8MtdqP/UrWLDfzXTU=; b=VmsDmoawS0nvLKweLRhHEcTQ3ryvsNPpCTUO1vJpW4UGstL7fPPveTPyCnjQ9C+I3Q PzCqJBxGw3xk53iSaft9z0FyeXgBmQMlRdDYL6LWPapyykMJxKIXTZHIvCBxCTf7GRQQ CrJgoSgL/xBZ2LVpfR1VScDLKKano9rUJ6VwG/reVGMoOOCRu2PDmXvigtha6c94T1JG nb8JIJIBQVW1RqYsi6xUcp9qvRZ31ap645KgPhpsl8z5cpbJ9TGvW9EtbJlZR1a9Qppr DeB+lirX+fmd4f/lglNu1Km6Fuwt/WRIx2Ohp6M78HNG0lXKeegdyl5Ohtp4+9SHr4Mx HlZg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b="Qv4/panU"; 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 p11-20020a50cd8b000000b00459a988ca2csi20287288edi.116.2022.10.22.01.46.01; Sat, 22 Oct 2022 01:46:26 -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="Qv4/panU"; 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 S234450AbiJVIpc (ORCPT + 99 others); Sat, 22 Oct 2022 04:45:32 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:52862 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234659AbiJVInW (ORCPT ); Sat, 22 Oct 2022 04:43:22 -0400 Received: from ams.source.kernel.org (ams.source.kernel.org [145.40.68.75]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id D27762E96A8; Sat, 22 Oct 2022 01:07:12 -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 B22E4B82E33; Sat, 22 Oct 2022 08:05:38 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id C43D2C433C1; Sat, 22 Oct 2022 08:05:36 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1666425937; bh=LNGbMV8ZTXHP0BvFmkjIFu88R3KVUozTm+4VCWX6gBw=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=Qv4/panUUqAihJU0ODJyGLa4XuUOrd1K1fW76bALmQ6kQDroCq2dhVoUn7j4hN/8d /fCeuH7n8itKR5jeerwU52XrxJrZgeWIBSOFyvLuSb2+OiRauBRXUvJTLzN2HleMJv 0NNfk+vu4xLMlsGVvT5ZtO0lDIZN73bQCevk6A1M= 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.19 665/717] blk-throttle: prevent overflow while calculating wait time Date: Sat, 22 Oct 2022 09:29:04 +0200 Message-Id: <20221022072527.815483038@linuxfoundation.org> X-Mailer: git-send-email 2.38.1 In-Reply-To: <20221022072415.034382448@linuxfoundation.org> References: <20221022072415.034382448@linuxfoundation.org> User-Agent: quilt/0.67 MIME-Version: 1.0 X-Spam-Status: No, score=-7.3 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?1747376812038584634?= X-GMAIL-MSGID: =?utf-8?q?1747376812038584634?= 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 387783980024..acdd85a07f92 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)