From patchwork Mon Feb 26 09:49:35 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Pankaj Raghav (Samsung)" X-Patchwork-Id: 13571770 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by smtp.lore.kernel.org (Postfix) with ESMTP id A99AAC48BF6 for ; Mon, 26 Feb 2024 09:50:39 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 36D39940026; Mon, 26 Feb 2024 04:50:39 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 31BF7940014; Mon, 26 Feb 2024 04:50:39 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 1BE65940026; Mon, 26 Feb 2024 04:50:39 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0013.hostedemail.com [216.40.44.13]) by kanga.kvack.org (Postfix) with ESMTP id 0812B940014 for ; Mon, 26 Feb 2024 04:50:39 -0500 (EST) Received: from smtpin15.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay08.hostedemail.com (Postfix) with ESMTP id 892FA140715 for ; Mon, 26 Feb 2024 09:50:38 +0000 (UTC) X-FDA: 81833485356.15.346838F Received: from mout-p-201.mailbox.org (mout-p-201.mailbox.org [80.241.56.171]) by imf27.hostedemail.com (Postfix) with ESMTP id BFF6640017 for ; Mon, 26 Feb 2024 09:50:36 +0000 (UTC) Authentication-Results: imf27.hostedemail.com; dkim=pass header.d=pankajraghav.com header.s=MBO0001 header.b=hAVlxzD2; spf=pass (imf27.hostedemail.com: domain of me@pankajraghav.com designates 80.241.56.171 as permitted sender) smtp.mailfrom=me@pankajraghav.com; dmarc=none ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1708941037; h=from:from:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:dkim-signature; bh=HlYEwWAE6vZZcw5JeU6SUv0SKwh4LwGux0locayr8EQ=; b=pPxrdyY1sUUYtukUrKwmByjZC0jMLSXL1aDWuyMHyuXYxVPtVKlIdYKuxHVKU9ngax8XYn MjAxSZ/D6rwLGLv3XWEX0bCeeccfib+I9ZjmOLv968gOgWIdt242lTYeX31R+3gDeoJvuO Jo96h18bj9m//3BgW5t1Jrzho3knkVA= ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1708941037; a=rsa-sha256; cv=none; b=sga0OIN+Qi8Pfu+xCgFrPWRVsvWswR4Z2s0ACBdiIfWQjfFphzmD4q0T24cpAAenEa/AQe 7iJCjPBI5z7lh3MiTo6kZWidQ0TZWMtTAaOvs5JancN03Hufds/f57TXhIyNKpox05Kcsl Y1iIL0TqPAgpg5HdOJN7f9u796mV1LU= ARC-Authentication-Results: i=1; imf27.hostedemail.com; dkim=pass header.d=pankajraghav.com header.s=MBO0001 header.b=hAVlxzD2; spf=pass (imf27.hostedemail.com: domain of me@pankajraghav.com designates 80.241.56.171 as permitted sender) smtp.mailfrom=me@pankajraghav.com; dmarc=none Received: from smtp202.mailbox.org (smtp202.mailbox.org [10.196.197.202]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by mout-p-201.mailbox.org (Postfix) with ESMTPS id 4Tjwpd5S1bz9sqr; Mon, 26 Feb 2024 10:50:33 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=pankajraghav.com; s=MBO0001; t=1708941033; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=HlYEwWAE6vZZcw5JeU6SUv0SKwh4LwGux0locayr8EQ=; b=hAVlxzD2LUL1rbpSWjPjfIWWZ+5drZJNxCuKnYF1eJy8lXLqGyC3JvVjJva165jpZA8JrK /NizHCJ/YjEL816L5LIhVDRvYkcIOLksj7bpIUgXlYkP3mVY1kr/aMoGEUbK03wka8yZ9S Sr6WVXmeCkUN9ZfZ97Ut4XQrp4ARMV4/DD2WK22lwFyIP5AfsEkvUGV3hnyVAFzwTdDNL0 Q5nftWFtgrFUeqMaxatl83Cq1koGPzuefYzt7zvoWkCPf69Ydn5PYfAqOWucArjj7RmCxM LPwD8UfbzpoS3DW1EujY+tdRK5i5lGBa24C8u4KLR8TX8md71im/pzk2XnBEsQ== From: "Pankaj Raghav (Samsung)" To: linux-xfs@vger.kernel.org, linux-fsdevel@vger.kernel.org Cc: linux-kernel@vger.kernel.org, david@fromorbit.com, chandan.babu@oracle.com, akpm@linux-foundation.org, mcgrof@kernel.org, ziy@nvidia.com, hare@suse.de, djwong@kernel.org, gost.dev@samsung.com, linux-mm@kvack.org, willy@infradead.org, Pankaj Raghav Subject: [PATCH 12/13] xfs: make the calculation generic in xfs_sb_validate_fsb_count() Date: Mon, 26 Feb 2024 10:49:35 +0100 Message-ID: <20240226094936.2677493-13-kernel@pankajraghav.com> In-Reply-To: <20240226094936.2677493-1-kernel@pankajraghav.com> References: <20240226094936.2677493-1-kernel@pankajraghav.com> MIME-Version: 1.0 X-Rspamd-Queue-Id: BFF6640017 X-Rspam-User: X-Rspamd-Server: rspam11 X-Stat-Signature: n4ekc4q5bcz9ry4y4ihq8x1b9ou4ai5n X-HE-Tag: 1708941036-287264 X-HE-Meta: U2FsdGVkX186lVrwAyZzgiXY1vCEDtQ8plBbH9rF24LTY6qlwD4NRLmIvC/ufVhXhBboHO5L81DtVTCr7HLejjzWqyWlSfWvJK7M3Tne2A2VsDA0tQkb+VQ+EmsL7iSAlbwjHN6pZhX3DrL1ITAIQ6c0X3aWCG2DA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y6QMZ5rr/RL6Y5F90jS9nq8wgYv5fWqDA8Q+vUVXNN5+vmtr2+WWRbhKoiNFSHlEJXRgMOXMxIrxX2SLSzdz+wrtoFK7/tLqKWzgVj44AeF9JPLnzYjrM= X-Bogosity: Ham, tests=bogofilter, spamicity=0.000006, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: List-Subscribe: List-Unsubscribe: From: Pankaj Raghav Instead of assuming that PAGE_SHIFT is always higher than the blocklog, make the calculation generic so that page cache count can be calculated correctly for LBS. Signed-off-by: Pankaj Raghav --- fs/xfs/xfs_mount.c | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/fs/xfs/xfs_mount.c b/fs/xfs/xfs_mount.c index aabb25dc3efa..69af3b06be99 100644 --- a/fs/xfs/xfs_mount.c +++ b/fs/xfs/xfs_mount.c @@ -133,9 +133,15 @@ xfs_sb_validate_fsb_count( { ASSERT(PAGE_SHIFT >= sbp->sb_blocklog); ASSERT(sbp->sb_blocklog >= BBSHIFT); + uint64_t mapping_count; + uint64_t bytes; + if (check_mul_overflow(nblocks, (1 << sbp->sb_blocklog), &bytes)) + return -EFBIG; + + mapping_count = bytes >> PAGE_SHIFT; /* Limited by ULONG_MAX of page cache index */ - if (nblocks >> (PAGE_SHIFT - sbp->sb_blocklog) > ULONG_MAX) + if (mapping_count > ULONG_MAX) return -EFBIG; return 0; }