From patchwork Thu Aug 15 09:08:48 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: 13764602 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 72197C3DA7F for ; Thu, 15 Aug 2024 09:09:51 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id AB4746B00B3; Thu, 15 Aug 2024 05:09:50 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id A63466B00B4; Thu, 15 Aug 2024 05:09:50 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 903E36B00B5; Thu, 15 Aug 2024 05:09:50 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0010.hostedemail.com [216.40.44.10]) by kanga.kvack.org (Postfix) with ESMTP id 707E56B00B3 for ; Thu, 15 Aug 2024 05:09:50 -0400 (EDT) Received: from smtpin22.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay04.hostedemail.com (Postfix) with ESMTP id 2DF481A13E5 for ; Thu, 15 Aug 2024 09:09:50 +0000 (UTC) X-FDA: 82453907340.22.98C2796 Received: from mout-p-101.mailbox.org (mout-p-101.mailbox.org [80.241.56.151]) by imf28.hostedemail.com (Postfix) with ESMTP id 78FDCC000A for ; Thu, 15 Aug 2024 09:09:48 +0000 (UTC) Authentication-Results: imf28.hostedemail.com; dkim=pass header.d=pankajraghav.com header.s=MBO0001 header.b="c/Cm76OC"; dmarc=pass (policy=quarantine) header.from=pankajraghav.com; spf=pass (imf28.hostedemail.com: domain of kernel@pankajraghav.com designates 80.241.56.151 as permitted sender) smtp.mailfrom=kernel@pankajraghav.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1723712929; a=rsa-sha256; cv=none; b=1150ai76UAiUzSWG4l75D1KUklsiXql7EoDBctTE0ywCbykwFepGSN5KGG4kGbP3z9lx+F TpDVST55MV8TS1+ptn+/oD6uY7hW4rmrVPeN99it7w+qXbvQAIaD0fZkeN/+AKOXJUwAsd sdmBqOK8Uht3q6Kapo/PHer8+uePfdY= ARC-Authentication-Results: i=1; imf28.hostedemail.com; dkim=pass header.d=pankajraghav.com header.s=MBO0001 header.b="c/Cm76OC"; dmarc=pass (policy=quarantine) header.from=pankajraghav.com; spf=pass (imf28.hostedemail.com: domain of kernel@pankajraghav.com designates 80.241.56.151 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=1723712929; 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=6bkHkkZtAV+DG4IWlq79Eu9R2bG2bBzOuWYizM/QYF9Vzp7dZ7RYc7FjVCpFjxXA7lBDQP YuJsEMIytWF+Wtp3L5jtpN9OugKXxPLDf1E5ProzRitR3I4E0ZRUL7kt2zry0vEVvYzoy9 7au33T5CmgC+HZbb63BgoLE6kIRvBsM= Received: from smtp2.mailbox.org (smtp2.mailbox.org [IPv6:2001:67c:2050:b231:465::2]) (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 4Wkzpd2nKNz9sm9; Thu, 15 Aug 2024 11:09:45 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=pankajraghav.com; s=MBO0001; t=1723712985; 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=c/Cm76OCsVt/jPPWiybltnErHwWq1YcAHCumkSV/l5LKaePNcC2BzBsm8KQ6L0X8fdfyn8 EeBOSKS8RDJjFGfJ75F7VMmHGKAAdolGxU6fzaXPbt52fdYHipcBlC79eAtGJCTKXBO/bY MFnXDpERLCOsPUS71Crm9Sc2s9EgbAGYskJDH8MzKHDEtR57r1yW+izLXkszYZYVwaODlj wVM8cbzkXGLidGKw+PGYDsfFbIxwBSDUlbWqOwnvWDdkBmPhI9GTHo3QZyEDOHc6uqa64h mE0P2ifINx+h2Xtmwb9M0l4xCapVFXOjIamAyb0if99OqJgLW8lTsaT7s9z8BA== 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 v12 09/10] xfs: make the calculation generic in xfs_sb_validate_fsb_count() Date: Thu, 15 Aug 2024 11:08:48 +0200 Message-ID: <20240815090849.972355-10-kernel@pankajraghav.com> In-Reply-To: <20240815090849.972355-1-kernel@pankajraghav.com> References: <20240815090849.972355-1-kernel@pankajraghav.com> MIME-Version: 1.0 X-Rspamd-Server: rspam12 X-Rspamd-Queue-Id: 78FDCC000A X-Stat-Signature: t7i7z7ssjay8qsgbii61eccbw5zseg7g X-Rspam-User: X-HE-Tag: 1723712988-26065 X-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DAZzayllMSH4XQw6vW1e0RNyu3VAkjWk+Ip61V+CAiZnWM31ohkgqwgKOpKBUR/RZ87FVLtR/ScwcveZXaQj/S2JHouWA6u5cGJLGOHQ/XZTR41ZmXg6JWTZFUj3wcVIty206BkFIba/RSTzLkfY32IqhlVmmQ6fRDDe90L3/3CzclMwrr173U78BQqP0v6fJIwj3tMDk8S1ctseqZTCa1nKUhAtw5XFAUnaDgMr5LlgtfH4c90j6ueD3ECOq7AdEbhpe87/lMKPceOC6ktgtU04RGmv1sLoYT2T0/zAwmyG8I9SYJehASepihc= 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; }