Received: by 2002:a89:48b:0:b0:1f5:f2ab:c469 with SMTP id a11csp1043934lqd; Thu, 25 Apr 2024 04:40:21 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCU+Ol7Q9CPrd9cc3lAC5BWSBAgRWED7aSz80QQdweQRufx/1Q+OHeVeum3c9l5Df0Dy/4aOCjZsCfMhfBXgEoDLDSxg7xBb1wXJqa9Zyg== X-Google-Smtp-Source: AGHT+IEoHAOvMhH5aYjQVF7cV4jxMYgND5O+98ehcvUo8uyO93AWpupMsd22Z/0fsroLKEvVNSHF X-Received: by 2002:a17:90a:6b47:b0:2ad:dd1c:6dc2 with SMTP id x7-20020a17090a6b4700b002addd1c6dc2mr4899840pjl.29.1714045220558; Thu, 25 Apr 2024 04:40:20 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1714045220; cv=pass; d=google.com; s=arc-20160816; b=kO0rE5rGL88+KdEWedKn59/qOjBQ48iufoMi+qrIvXt02KkRCI/E7NWgtTxHQtbqXD pD8RjjO7pk5A6y969C3FMG34FTzC9TX27xoGk/kh112VvB7Pfhl6mjMpqCjGbuixrQbR s/o3H6Ak6yn+7OhYMLcN2gzSvUPfgh13nuqWyOLGMRAZ/IDeGFez/i8DxlG13/sc8xpS 9Hoxr9YCgW+So0IoAcHDfeyMST5+pAu4of4pNCT8IxErNJAScflFdRy6Vmld81jphXte FoPD122QozwOPCqfmrFpQ9n1Cj64o87XKmisvXl0pWCtWLzQqqm+/OQKeZsGrkLblk0P AoWg== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:references:in-reply-to:message-id :date:subject:cc:to:from:dkim-signature; bh=7L6awWLepRreCjOlDARDMkw2Tlyq8BMiql1zMtjdTDw=; fh=AC6j17aBHSL5HsK8cY4ELsf/ZPirpNG+gef8M2C/TAc=; b=0ycZIh854vrI186CO9xeesDMfk1UkTBoazqjHKu9uK8qn6P6mJfh4scsXQdYPip6n+ zAO0r8/GxktVUI5Xk8uQNeoooO0t63uGa+cUxJON/UlGniabtoRL7hUtSU1cDfiruwqT vHT2iiTsLOGKZ7DDu+BUH3fm4739Bvi2m/AgTIEcA9vydCR/E4VH8D723EVVlDLE6w/q Nf/7YcO0eh/kuKeu1k95qvc+KIP3M/qSiaPu6YCnjkUmGgRC5tlNipeVofVBOqtiMNHX OEAaFu94bCL0a4HO0ZyLfP3+CA6hXMsjtpSv+ravs0fsTq1NZ8+kOxhqfMVipapj7Hf2 7lYA==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@pankajraghav.com header.s=MBO0001 header.b=iUOZlanZ; arc=pass (i=1 spf=pass spfdomain=pankajraghav.com dkim=pass dkdomain=pankajraghav.com dmarc=pass fromdomain=pankajraghav.com); spf=pass (google.com: domain of linux-kernel+bounces-158463-linux.lists.archive=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) smtp.mailfrom="linux-kernel+bounces-158463-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=pankajraghav.com Return-Path: Received: from sv.mirrors.kernel.org (sv.mirrors.kernel.org. [139.178.88.99]) by mx.google.com with ESMTPS id kk6-20020a17090b4a0600b002a6162536aesi2174118pjb.182.2024.04.25.04.40.20 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 25 Apr 2024 04:40:20 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-158463-linux.lists.archive=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) client-ip=139.178.88.99; Authentication-Results: mx.google.com; dkim=pass header.i=@pankajraghav.com header.s=MBO0001 header.b=iUOZlanZ; arc=pass (i=1 spf=pass spfdomain=pankajraghav.com dkim=pass dkdomain=pankajraghav.com dmarc=pass fromdomain=pankajraghav.com); spf=pass (google.com: domain of linux-kernel+bounces-158463-linux.lists.archive=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) smtp.mailfrom="linux-kernel+bounces-158463-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=pankajraghav.com Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by sv.mirrors.kernel.org (Postfix) with ESMTPS id 351D72824CF for ; Thu, 25 Apr 2024 11:40:20 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 4336012DD88; Thu, 25 Apr 2024 11:38:36 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=pankajraghav.com header.i=@pankajraghav.com header.b="iUOZlanZ" Received: from mout-p-103.mailbox.org (mout-p-103.mailbox.org [80.241.56.161]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id C19FD12D757; Thu, 25 Apr 2024 11:38:33 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=80.241.56.161 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1714045115; cv=none; b=BhACvAIeRT195VFcyEsiDr/S7FljJRGoD9hPkeHM7PtsJaQPmmJq8kvzSuQX6fQuGMqzspLiBsPyDssodDo4k/0GmMjIkWEq57ehk5qx/hJpp6FDsoZDXMkY7Cup2xt3zP3bQUoZdLkv6WxFg5BJomAyCfJPUFs3q4anqg+53tE= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1714045115; c=relaxed/simple; bh=LOG1uIi2Kur+Bl8EXQ2K17O8DkU858vtOXODZaKzses=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=I3BnmdqUUHSVx306rxnsr12jtDmpVqsv7jbTdGo1gAdubtk095hToR38KiiyUNUh0xFvcB/Pm9eX9lVh30aQKj2PMh3369xLsy9zswfTMi7cU/uNR2W64g4R65qMtasFf2HMrN5Pioe/KyujKRBsMLqLNhUi34iW5XNzbg9nCIM= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=pankajraghav.com; spf=pass smtp.mailfrom=pankajraghav.com; dkim=pass (2048-bit key) header.d=pankajraghav.com header.i=@pankajraghav.com header.b=iUOZlanZ; arc=none smtp.client-ip=80.241.56.161 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=pankajraghav.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=pankajraghav.com Received: from smtp102.mailbox.org (smtp102.mailbox.org [10.196.197.102]) (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 4VQDPy34JRz9s7Q; Thu, 25 Apr 2024 13:38:30 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=pankajraghav.com; s=MBO0001; t=1714045110; 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=7L6awWLepRreCjOlDARDMkw2Tlyq8BMiql1zMtjdTDw=; b=iUOZlanZ2C3/jZz2S8ABbp1qPpO2hBWafHSyLzmGwpJXYKBBM8sP2yDLliwXN8E31p5Sm8 pXxktiBVBG9c/vnRc3jIanZQ7+QirXLJ4CE+3CC+ctJRrk5MY5schTRVXhHiQTLxJkV4RO c/tOp1e03rMQKQ/PQfLmkA1ODo58Njdtw8zsPmf0KQum0MFlRpkd6Qyf+RN49/2sImpc/b 4mMPhHbF5Z9qmwgtpMU2ltkFqJdHcPvxkiocluP7yumz76XrCgrCJcQXZtH24p6XHSkbhI hGXfFkOa6pEt/ZQyEsK/MDTurV+oXp9dwW14zJA9Q5DjnJhld/76witYmemPeg== From: "Pankaj Raghav (Samsung)" To: willy@infradead.org, djwong@kernel.org, brauner@kernel.org, david@fromorbit.com, chandan.babu@oracle.com, akpm@linux-foundation.org Cc: linux-fsdevel@vger.kernel.org, hare@suse.de, linux-kernel@vger.kernel.org, linux-mm@kvack.org, linux-xfs@vger.kernel.org, mcgrof@kernel.org, gost.dev@samsung.com, p.raghav@samsung.com Subject: [PATCH v4 10/11] xfs: make the calculation generic in xfs_sb_validate_fsb_count() Date: Thu, 25 Apr 2024 13:37:45 +0200 Message-Id: <20240425113746.335530-11-kernel@pankajraghav.com> In-Reply-To: <20240425113746.335530-1-kernel@pankajraghav.com> References: <20240425113746.335530-1-kernel@pankajraghav.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit 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 --- fs/xfs/xfs_mount.c | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/fs/xfs/xfs_mount.c b/fs/xfs/xfs_mount.c index df370eb5dc15..56d71282972a 100644 --- a/fs/xfs/xfs_mount.c +++ b/fs/xfs/xfs_mount.c @@ -133,9 +133,16 @@ xfs_sb_validate_fsb_count( { ASSERT(PAGE_SHIFT >= sbp->sb_blocklog); ASSERT(sbp->sb_blocklog >= BBSHIFT); + uint64_t max_index; + uint64_t max_bytes; + + 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; } -- 2.34.1