Received: by 2002:a05:7412:f690:b0:e2:908c:2ebd with SMTP id ej16csp1322040rdb; Fri, 20 Oct 2023 15:38:28 -0700 (PDT) X-Google-Smtp-Source: AGHT+IGclb1kPIIZ0zZqS92OpgykJXsUd31DPPycGrFoezvV1VXwnk9cYQCSUqVPw9hjzk8b+KnM X-Received: by 2002:a05:6358:4320:b0:164:9d1e:c3cd with SMTP id r32-20020a056358432000b001649d1ec3cdmr2477818rwc.28.1697841508422; Fri, 20 Oct 2023 15:38:28 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1697841508; cv=none; d=google.com; s=arc-20160816; b=s5aU4qi7nEQuIGtpLXuIs5pTh+YiyqKBW4piJhAcbJ6cTSB4QUk3ZLoRvZmkDZbKY6 2mOruxlVsCxZLX1CfWztcLj98MNjrvNfiK2bgnjvyImHBx5SrPO3juehhJd8+t8W7wJC U3dJPF1xDLQGhzcCht88hmzbp9/Bj1YL5Dnfrj+M+xgOufbYpeyy0ix9S3WHwPrVa2jK nzUc+65iGoDHPtEh657acx3UkX0ZY69qib08AYJf0W9g8gaxAH4Z30LqDcRedUe50DIk jXtCyc3F/yPlPBXAm1/v18hzRP5Ra2WatV2CHjRMSzEfKiFoQXYTLN70v70UOnx/Ym39 WcHQ== 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 :message-id:date:subject:cc:to:from:dkim-signature; bh=Pp7b71HPUhZRYWiCA2ecvkahN2T6L1Zohh0DcisfMqo=; fh=KzwSBeAHmUK1JKGafH5fdQYsk0kK+aRZs1StH931QAk=; b=X6zVDrYib4rYdmZPZdZEYLVlQrMa3C5RCq50CvhHgD0inyngv9omsFX2gLuJPw19Lk NBI8JirU6QeBJWVfQ/KDu5ynqhJlWYNQOZSxUlpzQc8HzYGO7Uj4n6mdboYTppiVFRX/ rOISAZSI151dZIFqQwDPO/1O7acMblQW+b37II8rW34jkWm2Fx4q5VEL0u1v+NiLgEa5 NnQ/eI0ahvHtHuM0Kc40kx4ewtWMB5yE6Zx59faif3DWszY4MHAi6rFU9ZIeOBzkla1N djR1s86o5+MoO1GMKP7SKIOF4SdQ8MqsN+qLJUylE/4CnFiOhlvcX8pOzIA7Gdy8+eeQ 1m+A== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@chromium.org header.s=google header.b=mpghkfyz; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.37 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=chromium.org Return-Path: Received: from snail.vger.email (snail.vger.email. [23.128.96.37]) by mx.google.com with ESMTPS id t16-20020a639550000000b005af44ed3148si2674615pgn.367.2023.10.20.15.38.03 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 20 Oct 2023 15:38:28 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.37 as permitted sender) client-ip=23.128.96.37; Authentication-Results: mx.google.com; dkim=pass header.i=@chromium.org header.s=google header.b=mpghkfyz; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.37 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=chromium.org Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by snail.vger.email (Postfix) with ESMTP id 0B74B8328FDA; Fri, 20 Oct 2023 15:38:03 -0700 (PDT) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.10 at snail.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230188AbjJTWh7 (ORCPT + 99 others); Fri, 20 Oct 2023 18:37:59 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:52840 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229983AbjJTWh5 (ORCPT ); Fri, 20 Oct 2023 18:37:57 -0400 Received: from mail-pl1-x636.google.com (mail-pl1-x636.google.com [IPv6:2607:f8b0:4864:20::636]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id CA856D76 for ; Fri, 20 Oct 2023 15:37:50 -0700 (PDT) Received: by mail-pl1-x636.google.com with SMTP id d9443c01a7336-1ca052ec63bso10958335ad.1 for ; Fri, 20 Oct 2023 15:37:50 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; t=1697841470; x=1698446270; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:from:to:cc:subject:date:message-id:reply-to; bh=Pp7b71HPUhZRYWiCA2ecvkahN2T6L1Zohh0DcisfMqo=; b=mpghkfyzOutQ8CeN0RTsOB/0AWJ4MqMMREcBV150vT/rU4NoA0CTQBI09Id5QZgKu6 zsDGGBYpFyLGzg/FOj8u29B6DTgrQLkbAV7OQJmfl29HFC57Ux4CvgUWCFQvQMNMXN04 gBLuVmp0DsoLj8I6TEB4/RGOu0MfMJ9eNFUnc= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1697841470; x=1698446270; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=Pp7b71HPUhZRYWiCA2ecvkahN2T6L1Zohh0DcisfMqo=; b=R+nYnuohgJVGp3WsEO/8H1EyitfjMVKZkVP18Q7Rd0wEDfFUNqBMn5ZiDGDsbDK+o/ 6gxBVhU9PvoCpGMf9/+tOH2yf9O3VrjARYdr9x3vpVsOsW99fXI/+34MmZpbyDYTQVwM Pu+h0pcvfddPIiQK0d4rl8ExA/bkKjt985ANbdIkFXW3EZcYRiYAYwCHfhkoy+Ziapez I8ir4cwAfqYtpF3bcFV4SGoQ0OofYnJkSB7DZ4GjLgsGZLlu+gXhsUoKD8meFo05yrKg zhCfuhYSl4q+z2TDKz+JS3UFy1ilXjp0nVwcGiyWR3FKS5pxxS/nJ3mCcAg1XfrCbRru ZW6g== X-Gm-Message-State: AOJu0Yx+16rs34OOvBLDHK5zsBLl8s2I30OvBz4pSrFfs1nF45xB8csn SnJWOp628fWdc9y6llTire8xOw== X-Received: by 2002:a17:903:610:b0:1c4:387a:3259 with SMTP id kg16-20020a170903061000b001c4387a3259mr3542740plb.46.1697841470337; Fri, 20 Oct 2023 15:37:50 -0700 (PDT) Received: from khazhy-linux.svl.corp.google.com ([2620:15c:2a3:200:8e83:71b3:7861:9c5]) by smtp.gmail.com with ESMTPSA id g12-20020a170902c38c00b001bbd1562e75sm2013392plg.55.2023.10.20.15.37.49 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 20 Oct 2023 15:37:50 -0700 (PDT) From: Khazhismel Kumykov X-Google-Original-From: Khazhismel Kumykov To: Tejun Heo , Josef Bacik Cc: Jens Axboe , Yu Kuai , cgroups@vger.kernel.org, linux-block@vger.kernel.org, linux-kernel@vger.kernel.org, oleg@redhat.com, linan122@huawei.com, Khazhismel Kumykov Subject: [PATCH] blk-throttle: check for overflow in calculate_bytes_allowed Date: Fri, 20 Oct 2023 15:36:17 -0700 Message-ID: <20231020223617.2739774-1-khazhy@google.com> X-Mailer: git-send-email 2.42.0.655.g421f12c284-goog MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_NONE, 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-Greylist: Sender passed SPF test, not delayed by milter-greylist-4.6.4 (snail.vger.email [0.0.0.0]); Fri, 20 Oct 2023 15:38:03 -0700 (PDT) Inexact, we may reject some not-overflowing values incorrectly, but they'll be on the order of exabytes allowed anyways. This fixes divide error crash on x86 if bps_limit is not configured or is set too high in the rare case that jiffy_elapsed is greater than HZ. Fixes: e8368b57c006 ("blk-throttle: use calculate_io/bytes_allowed() for throtl_trim_slice()") Fixes: 8d6bbaada2e0 ("blk-throttle: prevent overflow while calculating wait time") Signed-off-by: Khazhismel Kumykov --- block/blk-throttle.c | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/block/blk-throttle.c b/block/blk-throttle.c index 38a881cf97d0..13e4377a8b28 100644 --- a/block/blk-throttle.c +++ b/block/blk-throttle.c @@ -723,6 +723,12 @@ static unsigned int calculate_io_allowed(u32 iops_limit, static u64 calculate_bytes_allowed(u64 bps_limit, unsigned long jiffy_elapsed) { + /* + * Can result be wider than 64 bits? + * We check against 62, not 64, due to ilog2 truncation. + */ + if (ilog2(bps_limit) + ilog2(jiffy_elapsed) - ilog2(HZ) > 62) + return U64_MAX; return mul_u64_u64_div_u64(bps_limit, (u64)jiffy_elapsed, (u64)HZ); } -- 2.42.0.655.g421f12c284-goog