From patchwork Mon Jul 15 09:44:56 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: 13733202 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 A351DC3DA59 for ; Mon, 15 Jul 2024 09:45:54 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 359226B00A1; Mon, 15 Jul 2024 05:45:54 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 2E4CC6B00A2; Mon, 15 Jul 2024 05:45:54 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 10FBF6B00A4; Mon, 15 Jul 2024 05:45:54 -0400 (EDT) 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 E21AC6B00A1 for ; Mon, 15 Jul 2024 05:45:53 -0400 (EDT) Received: from smtpin17.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay06.hostedemail.com (Postfix) with ESMTP id 6C5D6A527A for ; Mon, 15 Jul 2024 09:45:53 +0000 (UTC) X-FDA: 82341505386.17.1346ED8 Received: from mout-p-101.mailbox.org (mout-p-101.mailbox.org [80.241.56.151]) by imf12.hostedemail.com (Postfix) with ESMTP id B78574000C for ; Mon, 15 Jul 2024 09:45:51 +0000 (UTC) Authentication-Results: imf12.hostedemail.com; dkim=pass header.d=pankajraghav.com header.s=MBO0001 header.b=LjKjycMp; spf=pass (imf12.hostedemail.com: domain of kernel@pankajraghav.com designates 80.241.56.151 as permitted sender) smtp.mailfrom=kernel@pankajraghav.com; dmarc=pass (policy=quarantine) header.from=pankajraghav.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1721036702; 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=8rdOu+47Xth5hXKbmOu06fRFiMFY0Pwf2tkrEBizRPk=; b=O8opNfVNoqbFf4cXSd3fpqX8TCXsVBB6VAXJJied+fSXns1ZrgjxU3Z0pd0DzDM7k0eDtr ZsXzDWGxBllIPde5eGIcgL8bAq5AA5s1hYbt167zeQULn8SWZ1zUV9HreR6VHpZMLTgOpc bot1isJNwb06eUu96Osc+L0qUDyoP0c= ARC-Authentication-Results: i=1; imf12.hostedemail.com; dkim=pass header.d=pankajraghav.com header.s=MBO0001 header.b=LjKjycMp; spf=pass (imf12.hostedemail.com: domain of kernel@pankajraghav.com designates 80.241.56.151 as permitted sender) smtp.mailfrom=kernel@pankajraghav.com; dmarc=pass (policy=quarantine) header.from=pankajraghav.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1721036702; a=rsa-sha256; cv=none; b=7aRxRDuoMGKx4xO/34u8HJmifu5XEwit2HoQj5hcticTpcMjjWZ42pEAJKpKKiIG8b0Ey6 aeqP4hWwuVLCTRko8iiYs2UqCb+yH4aeLglMVOvLUzt5u2HCCMfVN83VtARxfu0QHitC32 0UVnlj5wYFrC08MsRdoVKfOFlV7kULo= 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-101.mailbox.org (Postfix) with ESMTPS id 4WMy4X3K9Nz9sSR; Mon, 15 Jul 2024 11:45:48 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=pankajraghav.com; s=MBO0001; t=1721036748; 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=8rdOu+47Xth5hXKbmOu06fRFiMFY0Pwf2tkrEBizRPk=; b=LjKjycMp1JEsvMEyQlRKY5b/IKkTDm817V3NAYJL7hkSwZxP8p0DtgxH5w0EzV+A3e8FeM JgyJbWsnMJ0ZfuAPMJShVoGTe68pSeNk1rmVA17mRSdMS9NAFECJUUrgXDX7B9FzXlwp4v dpgEJZg8kbjiCzq0n/dCNmzooXD0JNv8a2+fCuDng9DC6lJ8J7up51X4kjlyHP7koCSBno fgOPG0ASE7GOusgq/KlzStXXfMBbPnkM6bhdB1B9oM3+UoPWjir3nzjxHZYQJF4QktB+/s j8trDYX3s1AYR5wqHb3hZWnNV7YSZ8CHiQp1ZrcUgzruRmiPVt3ffkTRsiwEUA== From: "Pankaj Raghav (Samsung)" To: david@fromorbit.com, willy@infradead.org, chandan.babu@oracle.com, djwong@kernel.org, brauner@kernel.org, akpm@linux-foundation.org Cc: linux-kernel@vger.kernel.org, yang@os.amperecomputing.com, linux-mm@kvack.org, john.g.garry@oracle.com, linux-fsdevel@vger.kernel.org, hare@suse.de, p.raghav@samsung.com, mcgrof@kernel.org, gost.dev@samsung.com, cl@os.amperecomputing.com, linux-xfs@vger.kernel.org, kernel@pankajraghav.com, ryan.roberts@arm.com, hch@lst.de, Zi Yan , Dave Chinner Subject: [PATCH v10 09/10] xfs: make the calculation generic in xfs_sb_validate_fsb_count() Date: Mon, 15 Jul 2024 11:44:56 +0200 Message-ID: <20240715094457.452836-10-kernel@pankajraghav.com> In-Reply-To: <20240715094457.452836-1-kernel@pankajraghav.com> References: <20240715094457.452836-1-kernel@pankajraghav.com> MIME-Version: 1.0 X-Rspamd-Server: rspam06 X-Rspamd-Queue-Id: B78574000C X-Stat-Signature: ot6izjp99xa6qmpia55xsr8tmmojugy3 X-Rspam-User: X-HE-Tag: 1721036751-637319 X-HE-Meta: U2FsdG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tgiGe7Rbdyvd+/16bKqIFTx5udTs+BHmmLzNwvZGAEfg43HxZ3qy4FC6246gTF2SWXxTxda4eBgNascpU6jzjIml6GGfy0EtCK1bWh5l1FjCc4g/KkWHMFSYfSO7dV4F9BqkLNgnSxZRm2QuIdglwhQtxM9J3P3j7JIDFYwJMFHh1gFMT7Zp9B4GUzXgCU/OdGlKXEKOjd3xsKflRoXAM4bMPw6HL17sij69x1eSq/Afcm1ThmqCUmLze9S6V45WbWi/jg== X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, 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 Reviewed-by: Dave Chinner --- fs/xfs/xfs_mount.c | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/fs/xfs/xfs_mount.c b/fs/xfs/xfs_mount.c index 09eef1721ef4f..3949f720b5354 100644 --- a/fs/xfs/xfs_mount.c +++ b/fs/xfs/xfs_mount.c @@ -132,11 +132,16 @@ xfs_sb_validate_fsb_count( xfs_sb_t *sbp, uint64_t nblocks) { + uint64_t max_bytes; + ASSERT(PAGE_SHIFT >= sbp->sb_blocklog); ASSERT(sbp->sb_blocklog >= BBSHIFT); + 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) + if (max_bytes >> PAGE_SHIFT > ULONG_MAX) return -EFBIG; return 0; }