From patchwork Thu Apr 25 11:37:45 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: 13643186 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 EA8FEC4345F for ; Thu, 25 Apr 2024 11:38:35 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 76FF86B009F; Thu, 25 Apr 2024 07:38:35 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 720A46B00A0; Thu, 25 Apr 2024 07:38:35 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 5E9576B00A1; Thu, 25 Apr 2024 07:38:35 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0017.hostedemail.com [216.40.44.17]) by kanga.kvack.org (Postfix) with ESMTP id 3EFE06B009F for ; Thu, 25 Apr 2024 07:38:35 -0400 (EDT) Received: from smtpin22.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay05.hostedemail.com (Postfix) with ESMTP id 00C83409D4 for ; Thu, 25 Apr 2024 11:38:34 +0000 (UTC) X-FDA: 82047856590.22.D8FB662 Received: from mout-p-103.mailbox.org (mout-p-103.mailbox.org [80.241.56.161]) by imf30.hostedemail.com (Postfix) with ESMTP id 5FF7A80012 for ; Thu, 25 Apr 2024 11:38:33 +0000 (UTC) Authentication-Results: imf30.hostedemail.com; dkim=pass header.d=pankajraghav.com header.s=MBO0001 header.b=iUOZlanZ; dmarc=pass (policy=quarantine) header.from=pankajraghav.com; spf=pass (imf30.hostedemail.com: domain of kernel@pankajraghav.com designates 80.241.56.161 as permitted sender) smtp.mailfrom=kernel@pankajraghav.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1714045113; 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=7L6awWLepRreCjOlDARDMkw2Tlyq8BMiql1zMtjdTDw=; b=MFcySsDOtnS13jAvk28+JdHViR6mlQ8AhNuy7Kk/C9On2SMiTlYt2dAfOvyI/Sf+xUVQeQ EEl9vtBo9NMwWPNCeik4F0fOKwHBmBYun0G9DMZ+U7LyKDG3x+u9lLXkKBhyqcN0tksjxm EljgHA/6qZGxPTXR/JelfLpLwqvpAYs= ARC-Authentication-Results: i=1; imf30.hostedemail.com; dkim=pass header.d=pankajraghav.com header.s=MBO0001 header.b=iUOZlanZ; dmarc=pass (policy=quarantine) header.from=pankajraghav.com; spf=pass (imf30.hostedemail.com: domain of kernel@pankajraghav.com designates 80.241.56.161 as permitted sender) smtp.mailfrom=kernel@pankajraghav.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1714045113; a=rsa-sha256; cv=none; b=t1QmUp+hAbjl7nN2Qi2zVjEQW/DbHvQVK/99Xyreqmq716U+iOEQ9Ebm1SvUUqZFBz5zaM ZzG/bfgTpCt+0kVfDGGnK2wYwhl9I5DtbsKPhsxCYlkqF8TP3goCjWn5ozUnyhSgLW+Ibi Y3gn+n/qnQCeu0S505cjd1vZcflysrg= Received: from smtp102.mailbox.org (smtp102.mailbox.org [10.196.197.102]) (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-103.mailbox.org (Postfix) with ESMTPS id 4VQDPy34JRz9s7Q; Thu, 25 Apr 2024 13:38:30 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=pankajraghav.com; s=MBO0001; t=1714045110; 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=7L6awWLepRreCjOlDARDMkw2Tlyq8BMiql1zMtjdTDw=; b=iUOZlanZ2C3/jZz2S8ABbp1qPpO2hBWafHSyLzmGwpJXYKBBM8sP2yDLliwXN8E31p5Sm8 pXxktiBVBG9c/vnRc3jIanZQ7+QirXLJ4CE+3CC+ctJRrk5MY5schTRVXhHiQTLxJkV4RO c/tOp1e03rMQKQ/PQfLmkA1ODo58Njdtw8zsPmf0KQum0MFlRpkd6Qyf+RN49/2sImpc/b 4mMPhHbF5Z9qmwgtpMU2ltkFqJdHcPvxkiocluP7yumz76XrCgrCJcQXZtH24p6XHSkbhI hGXfFkOa6pEt/ZQyEsK/MDTurV+oXp9dwW14zJA9Q5DjnJhld/76witYmemPeg== From: "Pankaj Raghav (Samsung)" To: willy@infradead.org, djwong@kernel.org, brauner@kernel.org, david@fromorbit.com, chandan.babu@oracle.com, akpm@linux-foundation.org Cc: linux-fsdevel@vger.kernel.org, hare@suse.de, linux-kernel@vger.kernel.org, linux-mm@kvack.org, linux-xfs@vger.kernel.org, mcgrof@kernel.org, gost.dev@samsung.com, p.raghav@samsung.com Subject: [PATCH v4 10/11] xfs: make the calculation generic in xfs_sb_validate_fsb_count() Date: Thu, 25 Apr 2024 13:37:45 +0200 Message-Id: <20240425113746.335530-11-kernel@pankajraghav.com> In-Reply-To: <20240425113746.335530-1-kernel@pankajraghav.com> References: <20240425113746.335530-1-kernel@pankajraghav.com> MIME-Version: 1.0 X-Rspamd-Server: rspam04 X-Rspamd-Queue-Id: 5FF7A80012 X-Rspam-User: X-Stat-Signature: w6k3awye4x7z9q7xbo3sfw4mt6b4phry X-HE-Tag: 1714045113-944935 X-HE-Meta: U2FsdGVkX19at8WjQLfr/gVfjbNKt5h1JjPKDYpm1b9AYxLBlwvaMGtOqtBQ8qLwT7FPE86HbNGTVZVrzd2xU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MlaJcHF9Upc8i92xx0M4YveuEVD8ca6bG3PaV/GKsPPGEZT7CmRfq9sE1lPw== X-Bogosity: Ham, tests=bogofilter, spamicity=0.000013, 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 Reviewed-by: Darrick J. Wong --- fs/xfs/xfs_mount.c | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/fs/xfs/xfs_mount.c b/fs/xfs/xfs_mount.c index df370eb5dc15..56d71282972a 100644 --- a/fs/xfs/xfs_mount.c +++ b/fs/xfs/xfs_mount.c @@ -133,9 +133,16 @@ xfs_sb_validate_fsb_count( { ASSERT(PAGE_SHIFT >= sbp->sb_blocklog); ASSERT(sbp->sb_blocklog >= BBSHIFT); + uint64_t max_index; + uint64_t max_bytes; + + if (check_shl_overflow(nblocks, sbp->sb_blocklog, &max_bytes)) + return -EFBIG; /* Limited by ULONG_MAX of page cache index */ - if (nblocks >> (PAGE_SHIFT - sbp->sb_blocklog) > ULONG_MAX) + max_index = max_bytes >> PAGE_SHIFT; + + if (max_index > ULONG_MAX) return -EFBIG; return 0; }