From patchwork Fri Jun 7 14:59:01 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: 13690336 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 7244BC27C5F for ; Fri, 7 Jun 2024 15:00:04 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 00F3A6B00B3; Fri, 7 Jun 2024 11:00:04 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id F01366B00B4; Fri, 7 Jun 2024 11:00:03 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id DC99C6B00B5; Fri, 7 Jun 2024 11:00:03 -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 B0C456B00B3 for ; Fri, 7 Jun 2024 11:00:03 -0400 (EDT) Received: from smtpin21.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay03.hostedemail.com (Postfix) with ESMTP id 6204CA0535 for ; Fri, 7 Jun 2024 15:00:03 +0000 (UTC) X-FDA: 82204402686.21.064EC4C Received: from mout-p-103.mailbox.org (mout-p-103.mailbox.org [80.241.56.161]) by imf03.hostedemail.com (Postfix) with ESMTP id 4D89D20052 for ; Fri, 7 Jun 2024 14:59:58 +0000 (UTC) Authentication-Results: imf03.hostedemail.com; dkim=pass header.d=pankajraghav.com header.s=MBO0001 header.b="Cn0j/AWN"; dmarc=pass (policy=quarantine) header.from=pankajraghav.com; spf=pass (imf03.hostedemail.com: domain of kernel@pankajraghav.com designates 80.241.56.161 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=1717772398; 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=Bne/CkGLFb5Q+0r/mTCjdzHVWDyDH0TqoTxmXgBXKCE=; b=DuCGTpX7pbwdD6Byif/vA+Tq4J6XwuAaFbsP6ZFwsSRoNjyL+QtSk+zBc977Q5QS3GfflO Jz3Oyz9EMSlyVaxHXVwepCkx+YEWPYK65+RkgCNcaOfVUMK6irEItEnUX+O4LkK/GxYmTY 6gnDFfuvoGLLpz7IE89U98m3IO5e1D0= ARC-Authentication-Results: i=1; imf03.hostedemail.com; dkim=pass header.d=pankajraghav.com header.s=MBO0001 header.b="Cn0j/AWN"; dmarc=pass (policy=quarantine) header.from=pankajraghav.com; spf=pass (imf03.hostedemail.com: domain of kernel@pankajraghav.com designates 80.241.56.161 as permitted sender) smtp.mailfrom=kernel@pankajraghav.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1717772398; a=rsa-sha256; cv=none; b=Q7w30KlHy/pSi7wJzmLjN/EbD2V7wCfLfpPkahznBV9CMqJg41WexGgUECWixOYsW/5GL9 NY8BM12/qJRl6x2mTFI4/HXJWo6GTOgXq3K0+mBnnzB6DTcELg08mWHhj4NmRiB1H4ufif dHClk8vBB48d2w/mqvD3DgEjmbXuTi0= 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-103.mailbox.org (Postfix) with ESMTPS id 4VwkrP1CCjz9snn; Fri, 7 Jun 2024 16:59:49 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=pankajraghav.com; s=MBO0001; t=1717772389; 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=Bne/CkGLFb5Q+0r/mTCjdzHVWDyDH0TqoTxmXgBXKCE=; b=Cn0j/AWNicr8OHAovh1eFeMf2drV755n5F+zvZ1MdbQyUkqzCsMz2XxYhmPOC2AHubjaPN By+3Lnr4JK0aS27yj94k9MEkCJckWgq9jK1c1j3LFluOxy7/JDiNmX3uKasP8JO2jy6GXs qtnId+YktikV8HX2Fv9n7TpvJhdGTgqufWtf8fk40FJTjnJd+iomWBoBupp3MQc3ELjc3X lWt6MxodQqcZvTxBpdTkn7wBci1296lYMYsDoQYaUOU31D2WNUvNG6Mk1PrmUiDTt3/QKy Q7qtduMYWr9zGNNdSdW+wsgGejLyBrAGbz1EjEttBWc9C32hcnrBwyRzNil4Ng== From: "Pankaj Raghav (Samsung)" To: david@fromorbit.com, djwong@kernel.org, chandan.babu@oracle.com, brauner@kernel.org, akpm@linux-foundation.org, willy@infradead.org Cc: mcgrof@kernel.org, linux-mm@kvack.org, hare@suse.de, linux-kernel@vger.kernel.org, yang@os.amperecomputing.com, Zi Yan , linux-xfs@vger.kernel.org, p.raghav@samsung.com, linux-fsdevel@vger.kernel.org, kernel@pankajraghav.com, hch@lst.de, gost.dev@samsung.com, cl@os.amperecomputing.com, john.g.garry@oracle.com Subject: [PATCH v7 10/11] xfs: make the calculation generic in xfs_sb_validate_fsb_count() Date: Fri, 7 Jun 2024 14:59:01 +0000 Message-ID: <20240607145902.1137853-11-kernel@pankajraghav.com> In-Reply-To: <20240607145902.1137853-1-kernel@pankajraghav.com> References: <20240607145902.1137853-1-kernel@pankajraghav.com> MIME-Version: 1.0 X-Rspamd-Queue-Id: 4D89D20052 X-Stat-Signature: muw6tuxeidx4bqib7xgnzwncd9u9cisf X-Rspam-User: X-Rspamd-Server: rspam08 X-HE-Tag: 1717772398-437388 X-HE-Meta: U2F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bZyA9JVPqYQwSDmgM5YIO/dwev8Z2ETdy/btLVISLOctBha6lv4uHAWgj4b/ixXYBCJEbk4NV0dQe7iFXqxtsQHeIg6Au4BWrW+6D1/v4DezaDSb+XOD2MUzj4uzIOuW/pYQOuahbIzD6x7HobiaOwoigG2lYwhmNpaEA5C3DO7h2Fiw4PT6yQ8CnqU10i+Q5ZnGEka2wFGa40p8zfdvFDZj9M7ii3YQA74b3u2+PsMVmIQ5Jd9x78E6g= X-Bogosity: Ham, tests=bogofilter, spamicity=0.000027, 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. Reviewed-by: Darrick J. Wong Signed-off-by: Pankaj Raghav --- fs/xfs/xfs_mount.c | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/fs/xfs/xfs_mount.c b/fs/xfs/xfs_mount.c index 09eef1721ef4..46cb0384143b 100644 --- a/fs/xfs/xfs_mount.c +++ b/fs/xfs/xfs_mount.c @@ -132,11 +132,19 @@ xfs_sb_validate_fsb_count( xfs_sb_t *sbp, uint64_t nblocks) { + uint64_t max_index; + 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) + max_index = max_bytes >> PAGE_SHIFT; + + if (max_index > ULONG_MAX) return -EFBIG; return 0; }