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: 13764591 Received: from mout-p-101.mailbox.org (mout-p-101.mailbox.org [80.241.56.151]) (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 B68511E3CDA; Thu, 15 Aug 2024 09:09:50 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=80.241.56.151 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1723712992; cv=none; b=KGHxjmc4aza67gLlY0TaG4rIiRrO5yRPpXtpiazflqzKs+i+hAPj8eg9TXykGSAPcNGPovJgPW22vh51x2FeI4fQFaltWpBPMAeUvkQpaH+uAmNxA9Ybkmp02NpIe4GVrUAV0WfYivEVW+Rt7o3Sxsd8e5WSPNVGxCIZu4FZd6Y= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1723712992; c=relaxed/simple; bh=oVLFbpMiPlCmMAMNE+tGeHJKbYbbrzfNiFNSfbDXslo=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=fMedt7+uRdUuoOVm+ZfcTKNXtHkVN0RGFh7NaQprSrePEmrXXBGAgjfWAsXJssz2f4o9JXQd5TZ0E7Bg04m3z0+IXqaPR6ptvBTtCsCe1W/VfudzZuqtZDIcaH/696uotceWifYWUI36x9t4xClAF8njHvNeoJJUP6zJ/idFB7c= 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=c/Cm76OC; arc=none smtp.client-ip=80.241.56.151 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 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=pankajraghav.com header.i=@pankajraghav.com header.b="c/Cm76OC" 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> Precedence: bulk X-Mailing-List: linux-fsdevel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-Rspamd-Queue-Id: 4Wkzpd2nKNz9sm9 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; }