Received: by 2002:ab2:6d45:0:b0:1fb:d597:ff75 with SMTP id d5csp260691lqr; Wed, 5 Jun 2024 05:31:39 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCWD9K3Kuf5E93tL5YpNVbtNwayjQhX7ZYLYm8u6+qELjgGCHxYpkrqr4SNMRSP3P7rvdTHKchlZVeB2Ho3sWx061Qf6eE1UXr0eOwSbNw== X-Google-Smtp-Source: AGHT+IG4X+RREOJPfNGBkwOHPeEJaR3SS5yfX72mbd6zNLKkfX8+ANBBTnjfjDdkW/DJp2ZtaC1p X-Received: by 2002:ac8:578d:0:b0:43f:f231:6ad4 with SMTP id d75a77b69052e-4402b653319mr24624051cf.51.1717590699631; Wed, 05 Jun 2024 05:31:39 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1717590699; cv=pass; d=google.com; s=arc-20160816; b=T9mSmAi1cYidAfbD30t37hJVHMJtJgLRsU/U10YefKsdvZ01Xk36UQ8tntJ1/OZzNt FKOxFLzpFNZ1oLe7voF3EJnpiC+Ftf5Tuh42N9NzfTJX5+gV4w15h4QL11f2z5j76Lu+ HE70ywiz15cfpzJyiebNfcBuMKnhZJ8UIgUE/MCyy08UVL08pAMZFr9VlHask4zqSvBD TGCPVSR4jW7w48FMQ2fHDJJ1V9Yf3upSHsHpGjZpWHgb44DTtIuXJacoFSIsOma7KL18 zBHNWx6cbHw5uCeK98j6V38ZFlvy8AAJTTk27cXv6husFQUhfRfHb3W7UxaKTV1+CXzF j1Fw== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:references:in-reply-to:message-id :date:subject:cc:to:from:dkim-signature; bh=LHF9f1PLCLJr+Heje3q5uCXt0HbCDzyEFDsXU7Bhh/k=; fh=/bri4U0/umOekjWsVOwKJbXq0tgzc0O3fCUkqNe1v3E=; b=MGC5gHx6Qc6v3eLysUKNXbTLbJz/SQNA8/QqzT6DtkoAIXbEeE8m5htCN8BG128kWc raPJEk9D12yCUB2KsAAf1UU92egRxajPfvHcV6GrCAzcuWIsZNVaRI2zzaCV43NJth8A 8vvNYJoxXWMfp9pyHEy51zFw1v9UILJsf8FOWhm1BxEpHrt+eXwj81zH5D2mN43oZ5VW w+cFgpT0dzxucAPkGkBdx4NscYYI1unkoTvC2WJxFpbvK5WbWIrvGQDuoPwgT9X+w83q 891rcg9yg0cNmdZShtKYNf461xx7c3AzG+QhZJ7Kpp8/o96/r9Zu9hA4gRihYQ7vqQeJ K0+w==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=rfUB443L; arc=pass (i=1 dkim=pass dkdomain=kernel.org); spf=pass (google.com: domain of linux-kernel+bounces-202464-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) smtp.mailfrom="linux-kernel+bounces-202464-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from ny.mirrors.kernel.org (ny.mirrors.kernel.org. [147.75.199.223]) by mx.google.com with ESMTPS id d75a77b69052e-43ff23ac10csi32974931cf.34.2024.06.05.05.31.39 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 05 Jun 2024 05:31:39 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-202464-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) client-ip=147.75.199.223; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=rfUB443L; arc=pass (i=1 dkim=pass dkdomain=kernel.org); spf=pass (google.com: domain of linux-kernel+bounces-202464-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) smtp.mailfrom="linux-kernel+bounces-202464-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ny.mirrors.kernel.org (Postfix) with ESMTPS id 5CC031C23CA7 for ; Wed, 5 Jun 2024 12:31:39 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 25B0519FA9D; Wed, 5 Jun 2024 12:02:46 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="rfUB443L" Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 435F819FA83; Wed, 5 Jun 2024 12:02:45 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1717588965; cv=none; b=lCXOUdASKHQ1e+CZu64MiBOQ9eSBPO7o5AIWjb1OzHhWE5wr64f2FrW3/VShSjHrs+Cs/Z2PdtMyh9XdkN6HIALYYiJ1uwjFswwdsathA4vkN9cZ8T/3lnnTcZI/1Kb7kPMSpubJA2bAOei4MrTDniiO/JRkdi2nyUgu1ekZQRY= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1717588965; c=relaxed/simple; bh=BQlbPAvxsdi3X1d2VhHNpiIeTwGwQryj+ROh8dfsSWI=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=AQdbBk03BoeyRpEQxW9c1gblESCLj1VR6edZ/0rLJgaz+MSFVOT4HNtEdnl8W8e0WupUX1VbvxmzmTNFdO9S/wp76o0OblzNh7Lxa8H6nC99H6CjdMRtnFeSJy1gL2eoxZTVBXKG6wngIqunXbICZ8Wicv1eKWQIZH92bPbXKH4= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=rfUB443L; arc=none smtp.client-ip=10.30.226.201 Received: by smtp.kernel.org (Postfix) with ESMTPSA id 408F5C4AF09; Wed, 5 Jun 2024 12:02:44 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1717588965; bh=BQlbPAvxsdi3X1d2VhHNpiIeTwGwQryj+ROh8dfsSWI=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=rfUB443LzP7TXG7N5SYUwYTseiYa7PFmIsm5QKtNDuZjxE5E3mCb3KvvVxFuhUarq H1J+y9hCDXSNzxnrSRGJK8fWKU9V0KJZTl5tMyVIgVrz366T9aSrg6S9kYUavZBuOH P2W8MuPMcKwyUW9/jstPUg8pa1+pbi+1+pBNhaVwszxJChR4zB9Xqbq/HAm/O5QnmY iqDT0mUTOAYXlv8jyb2Z5IBJaTmzZtWM5SZVF2qY/g4jxk6oFbPx26/cNx7AdvZ++z 7EGovBcdCcm2QRoO/3nj7eo+MHkQ3PDfanOhI1jSC89S7yqHmD0eDVwyslyNLrXk88 mICsIYWZ8Whdw== From: Sasha Levin To: linux-kernel@vger.kernel.org, stable@vger.kernel.org Cc: Hannes Reinecke , Christoph Hellwig , John Garry , Jens Axboe , Sasha Levin , linux-block@vger.kernel.org Subject: [PATCH AUTOSEL 6.9 13/23] block: check for max_hw_sectors underflow Date: Wed, 5 Jun 2024 08:01:56 -0400 Message-ID: <20240605120220.2966127-13-sashal@kernel.org> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20240605120220.2966127-1-sashal@kernel.org> References: <20240605120220.2966127-1-sashal@kernel.org> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-stable: review X-Patchwork-Hint: Ignore X-stable-base: Linux 6.9.3 Content-Transfer-Encoding: 8bit From: Hannes Reinecke [ Upstream commit e993db2d6e5207f1ae061c2ac554ab1f714c741d ] The logical block size need to be smaller than the max_hw_sector setting, otherwise we can't even transfer a single LBA. Signed-off-by: Hannes Reinecke Reviewed-by: Christoph Hellwig Reviewed-by: John Garry Signed-off-by: Jens Axboe Signed-off-by: Sasha Levin --- block/blk-settings.c | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/block/blk-settings.c b/block/blk-settings.c index 9d6033e01f2e1..b4272bd926370 100644 --- a/block/blk-settings.c +++ b/block/blk-settings.c @@ -104,6 +104,7 @@ static int blk_validate_zoned_limits(struct queue_limits *lim) static int blk_validate_limits(struct queue_limits *lim) { unsigned int max_hw_sectors; + unsigned int logical_block_sectors; /* * Unless otherwise specified, default to 512 byte logical blocks and a @@ -134,8 +135,11 @@ static int blk_validate_limits(struct queue_limits *lim) lim->max_hw_sectors = BLK_SAFE_MAX_SECTORS; if (WARN_ON_ONCE(lim->max_hw_sectors < PAGE_SECTORS)) return -EINVAL; + logical_block_sectors = lim->logical_block_size >> SECTOR_SHIFT; + if (WARN_ON_ONCE(logical_block_sectors > lim->max_hw_sectors)) + return -EINVAL; lim->max_hw_sectors = round_down(lim->max_hw_sectors, - lim->logical_block_size >> SECTOR_SHIFT); + logical_block_sectors); /* * The actual max_sectors value is a complex beast and also takes the @@ -153,7 +157,7 @@ static int blk_validate_limits(struct queue_limits *lim) lim->max_sectors = min(max_hw_sectors, BLK_DEF_MAX_SECTORS_CAP); } lim->max_sectors = round_down(lim->max_sectors, - lim->logical_block_size >> SECTOR_SHIFT); + logical_block_sectors); /* * Random default for the maximum number of segments. Driver should not -- 2.43.0