From patchwork Thu Jul 4 11:23:19 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: 13723629 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 049F2C31D97 for ; Thu, 4 Jul 2024 11:24:08 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 9212C6B00DA; Thu, 4 Jul 2024 07:24:07 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 8CD756B00DB; Thu, 4 Jul 2024 07:24:07 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 746A06B00DC; Thu, 4 Jul 2024 07:24:07 -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 50B5D6B00DA for ; Thu, 4 Jul 2024 07:24:07 -0400 (EDT) Received: from smtpin11.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay09.hostedemail.com (Postfix) with ESMTP id 0F94381258 for ; Thu, 4 Jul 2024 11:24:07 +0000 (UTC) X-FDA: 82301836134.11.80C3B2A Received: from mout-p-201.mailbox.org (mout-p-201.mailbox.org [80.241.56.171]) by imf23.hostedemail.com (Postfix) with ESMTP id 656BC140008 for ; Thu, 4 Jul 2024 11:24:05 +0000 (UTC) Authentication-Results: imf23.hostedemail.com; dkim=pass header.d=pankajraghav.com header.s=MBO0001 header.b=MAKSFZlI; spf=pass (imf23.hostedemail.com: domain of kernel@pankajraghav.com designates 80.241.56.171 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=1720092220; 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=0bYRmlZ5qMLukdHRrGxIiUVqhHrjPbnNAlZt18v7lpRBPqqzaeWZGrC0X3NSsSxavpVhZo kfvUwtG+bTbv0JyzvAO9KUPqb6Mj0+F7laqcZKJAJ//i75CYjDB8YbrYXekGYDaGyo8eO0 sfkkEC/q/DRnn8Hm2G/tdU3jmrcLlWM= ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1720092220; a=rsa-sha256; cv=none; b=GZ6i8bAOJi9skSzJdSjbZvkYLVgdbs5jvaQkr8Z+70l9bZBQ0s8E6s8IMLoaClJsJnRpsY Guj+YHeRgLE5z02Ue8Fw9jt2cVInu9QIj884xBIgLOmLQ0iSLTENOlFftuwR7zEfUR6+Su 8y8nVqEYQ+5ygJcC0QBvYuf8q2keZXU= ARC-Authentication-Results: i=1; imf23.hostedemail.com; dkim=pass header.d=pankajraghav.com header.s=MBO0001 header.b=MAKSFZlI; spf=pass (imf23.hostedemail.com: domain of kernel@pankajraghav.com designates 80.241.56.171 as permitted sender) smtp.mailfrom=kernel@pankajraghav.com; dmarc=pass (policy=quarantine) header.from=pankajraghav.com Received: from smtp2.mailbox.org (smtp2.mailbox.org [10.196.197.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-201.mailbox.org (Postfix) with ESMTPS id 4WFDmy24b9z9tVW; Thu, 4 Jul 2024 13:24:02 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=pankajraghav.com; s=MBO0001; t=1720092242; 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=MAKSFZlI7ZaAEYyHpa4m+b6rHiU+P6QyeLCjZz23UGlI5WftoQSBRtyro7pc9FWT+MVPTZ kfKxyyXsGG9jZvTH11CKc9vmmNALVet9Y+7E4B5uSi4gC6mPXQUtTJnRM/JHxSECvsY+gU pGJWw57f7jZQbI1thzo6E30jiHbzhQ/iRu5h5APgIs+q8rRhj+zrnctYxJphX872+JkCg2 rycOGh+225y6SHWO9xoN2nzzQ1LpK3UVAqWeLnjHldadfIH2mjbp5D7bcFTv2OpMzmgqWO VYqqRkLd0wF9NvRr5dW0ElnU0AKRa+o0BgzLlkMmwEW5UVXUk0QDizQhRF4Tgg== 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, hch@lst.de, Zi Yan , Dave Chinner Subject: [PATCH v9 09/10] xfs: make the calculation generic in xfs_sb_validate_fsb_count() Date: Thu, 4 Jul 2024 11:23:19 +0000 Message-ID: <20240704112320.82104-10-kernel@pankajraghav.com> In-Reply-To: <20240704112320.82104-1-kernel@pankajraghav.com> References: <20240704112320.82104-1-kernel@pankajraghav.com> MIME-Version: 1.0 X-Rspam-User: X-Rspamd-Server: rspam04 X-Rspamd-Queue-Id: 656BC140008 X-Stat-Signature: ea7kipneeo8xscmq9co9m4znow9pub86 X-HE-Tag: 1720092245-724238 X-HE-Meta: U2Fsd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oIHAAXC8WrwP8XM3zReuoQ0mTt+9EhHmSSCaRjlS4hmrLqeLdXS7e3RZTyDhu6/XrzjWlrBtPqpheIu86KaVi0HPHGSDH0ZO21oHR2eeSP2sMLS5SgaJyy/feRbzDFmq+SRCFRoZd2N0qcw/vToD6SVCqK5cSSicSCPNhjwll961MkSRcKPeIg9yATF7ph6CFcwALd3pndDCWvdyIKaoDy/IvPNArEq0TgXlAQCsQTjGc5F2fnsF6EeoZzAIPCHlz5+jXmp9kCgH7zX06AO+9HnFBw== 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; }