From patchwork Fri Jul 26 11:59:55 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: 13742708 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 8FD07C3DA7F for ; Fri, 26 Jul 2024 12:00:53 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 2F9E76B00B6; Fri, 26 Jul 2024 08:00:52 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 281196B00B7; Fri, 26 Jul 2024 08:00:52 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 121446B00B8; Fri, 26 Jul 2024 08:00:52 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0012.hostedemail.com [216.40.44.12]) by kanga.kvack.org (Postfix) with ESMTP id E49306B00B6 for ; Fri, 26 Jul 2024 08:00:51 -0400 (EDT) Received: from smtpin25.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay01.hostedemail.com (Postfix) with ESMTP id 880D51C1318 for ; Fri, 26 Jul 2024 12:00:51 +0000 (UTC) X-FDA: 82381762302.25.1CF4D76 Received: from mout-p-202.mailbox.org (mout-p-202.mailbox.org [80.241.56.172]) by imf10.hostedemail.com (Postfix) with ESMTP id ACA58C0030 for ; Fri, 26 Jul 2024 12:00:49 +0000 (UTC) Authentication-Results: imf10.hostedemail.com; dkim=pass header.d=pankajraghav.com header.s=MBO0001 header.b=qj6gQzzY; spf=pass (imf10.hostedemail.com: domain of kernel@pankajraghav.com designates 80.241.56.172 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=1721995200; 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=5pxFAAjn24zwjo//fjtjdxxaSomIS1TQ02PtzegMNpC5K/sSa3SYzH3FEQI3+1HzilqwuY 2JdZLHThEQefIFYAvd4MHaTQPfUfVGj7aeA1YrNyZR8BCsee6DqvRFRs5eSj7HeGt7far4 QboJScvLxRmVg6wavb+qLPIuPt02uh8= ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1721995200; a=rsa-sha256; cv=none; b=QrUReior9yA9oEYRoj/19z+Jer594RDkL6rQGwPfNWhN6h3+dhB8O4ZwkySvoOht34ViLV 0oajUAzv/oyWwnmmKt1JvASzGOX1nzIFjiS1aCTBRV+CeEj+Nxvhky80HHMGMFqxgyfH6q YgC3tNjGOP39rxURIvWsfA4GBzTplYs= ARC-Authentication-Results: i=1; imf10.hostedemail.com; dkim=pass header.d=pankajraghav.com header.s=MBO0001 header.b=qj6gQzzY; spf=pass (imf10.hostedemail.com: domain of kernel@pankajraghav.com designates 80.241.56.172 as permitted sender) smtp.mailfrom=kernel@pankajraghav.com; dmarc=pass (policy=quarantine) header.from=pankajraghav.com 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-202.mailbox.org (Postfix) with ESMTPS id 4WVmYB3Fs6z9t0P; Fri, 26 Jul 2024 14:00:46 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=pankajraghav.com; s=MBO0001; t=1721995246; 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=qj6gQzzYjN9Zakp2rV1btHRBF4MwxpplHYSFNtQ3E+vJk34EKw5Sp8/mrqhBBwj1McnfKu GBxMa28j4v9xwaS6NioIYBZOh2Df0NSrn+lZrtJyyHecW9F9GX5guzxEYav+Hijg7/Re3S Ozy2tLCNgKiVA/H32MKmTQQlN55sZ00Q5fRsEe8nzr01Xj7jELk//lcCP2Dyf0SqIIxzmt DMGClEnuHQQnmK8cwbZLuOeB7iqtTwvAEy8BHwzQFS2RuHetelvNnHCoaN4dsiUKxVm4jR egGJEghTAqte+Qm9c5NzXkWMAeMQ6p0CAXgJsbt94fT/rGImaNC4iyCCAmgdlw== 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: yang@os.amperecomputing.com, linux-kernel@vger.kernel.org, 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 v11 09/10] xfs: make the calculation generic in xfs_sb_validate_fsb_count() Date: Fri, 26 Jul 2024 13:59:55 +0200 Message-ID: <20240726115956.643538-10-kernel@pankajraghav.com> In-Reply-To: <20240726115956.643538-1-kernel@pankajraghav.com> References: <20240726115956.643538-1-kernel@pankajraghav.com> MIME-Version: 1.0 X-Rspam-User: X-Rspamd-Server: rspam04 X-Rspamd-Queue-Id: ACA58C0030 X-Stat-Signature: mcmy8ij3wjjijkxc68apkt1spxs9cnqi X-HE-Tag: 1721995249-334870 X-HE-Meta: U2FsdG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AeM7hFIc+TOFm/YskFoSy7V2qG/rwi1OwU6EE+kqveALLYrMgkVxIiew10l8b19ybfUeUGTF6eQAFMlSb0ui1BeW09BBEEp7fksKd2+bIUd2n4IVV6RV01LTU9L03DzuztFsP239V1uAsYmT35EKIE7u7jaPEySJfpR85JcnKHi3WmUyHOVTsfLovHcqkg0NJHVQyFdOEvMVteUIW4qiPOOYbOqmVkrns7SQkfLimtjLEjIkWjUiOw5hIesIi7F0ggZUaQPFik1j+bgOoCv5hBwCxyNWAgDCg== 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; }