From patchwork Mon Oct 24 11:33:52 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Greg KH X-Patchwork-Id: 9808 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:6687:0:0:0:0:0 with SMTP id l7csp554915wru; Mon, 24 Oct 2022 09:58:26 -0700 (PDT) X-Google-Smtp-Source: AMsMyM6OD6WPBPWswBxKuOhX8FyRazESqgZFxzjZpbQdzfaPtec9wrNINqEzy5zCuUa/Q2Am5+8+ X-Received: by 2002:a63:485f:0:b0:458:764a:2224 with SMTP id x31-20020a63485f000000b00458764a2224mr28640409pgk.620.1666630706284; Mon, 24 Oct 2022 09:58:26 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1666630706; cv=none; d=google.com; s=arc-20160816; b=FBH2p28/dzoU0C10lAWMvPY2eMkbematOLhsThi+s3grvC5E1bUQ/j/zW19tafzvka kP5fnzewpg4ldFPH9TiRzointcYU6iLqZAc7rzMoytDeb7LlR06eV6hCu/2l/7xvs2jI c0usGXJhopFSh0vnZOddYBVtgAa/zBoraVM5TW9sJ38qLnlLjRQlwAaH+VcjztrwjHz1 xFkII0nxDPDt/sF8mzyV5hHU+v1ZjE7S5HKBbJ4TfExiuk6bvZaSbqW3T9n+vv4axDR+ 3SV/VsuQmIAQDSuxvZamFR65C8FxDQjHTo3NVOBc0xMzdUKRBhDXYvX4LceizJHG7uBn zEWw== 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=m4RKBvSyUjQxZ7NJWQQwGRqwNQPkRGryZGYsl7FTeng=; b=UVhpDPtKCQ2qlG5jkE9DgrEYCNQ+DSWSX0NWKVZZRgcOIJnpJpq9Z/OkL2CHr+k+CH 0FAu7REldLQSrEOpKbsjyRfITC3kGc8JDMp+FG12VwGpXENJZZoC7XuinoVfWL8P9yNf BoxcnhPvXn8XFL/U8lfluG/TYcnMGqKGrQsGPp0d0HjAZ9zRcSXj+43ecwyEvFVgS/l2 n+q95c95ozvseki3ckAQnyfDuFj8ylt541clYiMwWgtP9x2MDzpDo+LiqYrkXrPOmDwQ lp4qVy0VEf9Pq40zr1vcNQh0PfAdLrsyQuY7Dmrd7B6sN+RtygDRNKipsZ9gy2h04YEK nVPg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=Z1ASDSmY; 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 n9-20020a654889000000b0043c7b0510c1si37101729pgs.841.2022.10.24.09.58.04; Mon, 24 Oct 2022 09:58: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=Z1ASDSmY; 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 S233376AbiJXQxB (ORCPT + 99 others); Mon, 24 Oct 2022 12:53:01 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:35108 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S235300AbiJXQtW (ORCPT ); Mon, 24 Oct 2022 12:49:22 -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 4D2E28BB84; Mon, 24 Oct 2022 08:32:34 -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 C91F4B81995; Mon, 24 Oct 2022 12:54:28 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 21E11C433C1; Mon, 24 Oct 2022 12:54:26 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1666616067; bh=tyY7mApUCKy3nxZR8IiT8fEapo3BTVDOMAVT+cOVgtA=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=Z1ASDSmYEWfn1K2geTOOIfdAC3VWtboNufZNGEAzxAvkNeqxJjHRUHmNZMfNvk1zh bGNHhSuY+3euyI4yFJErEa3ZpbCQ5F55eoUjxXi+PI9UTZkhHLd/yHJ/t+KBYtlaf9 XiK2jt5NiIWSjzLpZwk8J1YbPp1841uP1nrvdpjQ= 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.15 488/530] blk-throttle: prevent overflow while calculating wait time Date: Mon, 24 Oct 2022 13:33:52 +0200 Message-Id: <20221024113107.138651678@linuxfoundation.org> X-Mailer: git-send-email 2.38.1 In-Reply-To: <20221024113044.976326639@linuxfoundation.org> References: <20221024113044.976326639@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?1747588959767562915?= X-GMAIL-MSGID: =?utf-8?q?1747588959767562915?= 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)