From patchwork Thu Aug 22 13:50:17 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: 13773530 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 0F785C3DA4A for ; Thu, 22 Aug 2024 13:51:20 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 8BC998002F; Thu, 22 Aug 2024 09:51:19 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 843838001E; Thu, 22 Aug 2024 09:51:19 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 697638002F; Thu, 22 Aug 2024 09:51:19 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0011.hostedemail.com [216.40.44.11]) by kanga.kvack.org (Postfix) with ESMTP id 499318001E for ; Thu, 22 Aug 2024 09:51:19 -0400 (EDT) Received: from smtpin13.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay01.hostedemail.com (Postfix) with ESMTP id F2B051C55B2 for ; Thu, 22 Aug 2024 13:51:18 +0000 (UTC) X-FDA: 82480018236.13.DDBC0DF Received: from mout-p-202.mailbox.org (mout-p-202.mailbox.org [80.241.56.172]) by imf02.hostedemail.com (Postfix) with ESMTP id 4F2628001B for ; Thu, 22 Aug 2024 13:51:17 +0000 (UTC) Authentication-Results: imf02.hostedemail.com; dkim=pass header.d=pankajraghav.com header.s=MBO0001 header.b=TFVIL2wP; dmarc=pass (policy=quarantine) header.from=pankajraghav.com; spf=pass (imf02.hostedemail.com: domain of kernel@pankajraghav.com designates 80.241.56.172 as permitted sender) smtp.mailfrom=kernel@pankajraghav.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1724334611; a=rsa-sha256; cv=none; b=BdAidgA9QJWOEzkeehkfQt+d9sqkum3K8LFY8uG+3FUPFIVLMixiL8jNLvuDEbY81vQH1q bGJqLQ5VVeymOW1Oyc6P5MT2IVat5w3Twbo8ewtxmlIm1I/dzjoBQkYNZaYrSE22T+92Qz TqLSVNcT6f/C5bk9R9RoyNWrETm5kzk= ARC-Authentication-Results: i=1; imf02.hostedemail.com; dkim=pass header.d=pankajraghav.com header.s=MBO0001 header.b=TFVIL2wP; dmarc=pass (policy=quarantine) header.from=pankajraghav.com; spf=pass (imf02.hostedemail.com: domain of kernel@pankajraghav.com designates 80.241.56.172 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=1724334611; 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=1ozFSw0VKp3lEYXFYZx/2ZlNzn9N/XDTd1B2LuBlJ2IvU4hPxkgUyzEalkQq44YE7bjEAQ ulQndxNDGwQRtRQzgYudK7V+li2PCBtVbqDG2XHfW9BlyFZ1SXn6OPEzl5Y86BeBKs4Nkq q0lrchilOhaC2IBvje9wcFdd2QJ7k9Y= Received: from smtp1.mailbox.org (smtp1.mailbox.org [10.196.197.1]) (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-202.mailbox.org (Postfix) with ESMTPS id 4WqPkB0fTWz9t9B; Thu, 22 Aug 2024 15:51:14 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=pankajraghav.com; s=MBO0001; t=1724334673; 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=TFVIL2wPAsMgSBP+VSo4hX8ZaDG/obLodnzi7AQrGoZhvWUcCm54/Pk/SnjurnYnn6DHHn 38k4im4iaU87lWQJZTscaY35ujnCbQHLGJtLOy/BkGiPKq5hK565nW0/1J84B7Tp9O5trG rZxTkr8gmKHQVOT0PxEdNhgDGiDwNW50ejNpocmMvxotg9dvxejbrdh4xhIK2tbidOyMPH DpOt+Kr0H8aIc6wW5NWQfofcgUu9u6hxDTzbK+RN59gH7OcI2aYlHFhjwsJ4V4TriGYlCv J/IbBakQr9Li0ijK8nTSg147afO6Yp2EkKqBOQ4bThDUNRhdhtiwCcwWFAZZkg== From: "Pankaj Raghav (Samsung)" To: brauner@kernel.org, akpm@linux-foundation.org Cc: chandan.babu@oracle.com, linux-fsdevel@vger.kernel.org, djwong@kernel.org, hare@suse.de, gost.dev@samsung.com, linux-xfs@vger.kernel.org, kernel@pankajraghav.com, hch@lst.de, david@fromorbit.com, Zi Yan , yang@os.amperecomputing.com, linux-kernel@vger.kernel.org, linux-mm@kvack.org, willy@infradead.org, john.g.garry@oracle.com, cl@os.amperecomputing.com, p.raghav@samsung.com, mcgrof@kernel.org, ryan.roberts@arm.com, Dave Chinner Subject: [PATCH v13 09/10] xfs: make the calculation generic in xfs_sb_validate_fsb_count() Date: Thu, 22 Aug 2024 15:50:17 +0200 Message-ID: <20240822135018.1931258-10-kernel@pankajraghav.com> In-Reply-To: <20240822135018.1931258-1-kernel@pankajraghav.com> References: <20240822135018.1931258-1-kernel@pankajraghav.com> MIME-Version: 1.0 X-Rspamd-Server: rspam12 X-Rspamd-Queue-Id: 4F2628001B X-Stat-Signature: sexrz7sedhzfgoyekkkuubfcs53xftcn X-Rspam-User: X-HE-Tag: 1724334677-584969 X-HE-Meta: U2Fsd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U9s/eVHuKhQx5u/jSMPErEOC6i81XafSSmvEtGsVcTdcgugnGX20TnZs7CeqPJhzCRqnHWOW1x7KaLXaZW5kFRwbfJRH3ceHA1Q9Pp3ZG4BtxySeS2rvXIz82bDjYzzmIWoo6qe3kDiVm9b7xN+08ZxHzejHoFLnCYHI1LSdlCc0y17x42MZ4XpMXOBzpSkTIBUVXzQeROsnCsZXeZdpsizVf7B8aRMe4+SsE+iHGc3lL4WuML1b1V+FuX0/QoRNAGcaUXdCWiukA== 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; }