Received: by 2002:a05:6500:1b8f:b0:1fa:5c73:8e2d with SMTP id df15csp680083lqb; Wed, 29 May 2024 07:37:38 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCXBdEf8y6bxnR72YTWXF9jcn6Ude2jhWNzfHnaPZLhTFQa0Og7oXMcq1OXC8aY45jkHD9Q8DQUydkvgDp0PfIQfmk0w3oramwICR3Ti3g== X-Google-Smtp-Source: AGHT+IFV8l7FnmqvgDXOUgkG04sOeWA2MEgjisuYd8YyXTz55j5I5EF5d/6pbzncdVRZIh8GYDD7 X-Received: by 2002:a17:902:6504:b0:1f4:9468:38b0 with SMTP id d9443c01a7336-1f4946839e6mr77395005ad.61.1716993457827; Wed, 29 May 2024 07:37:37 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1716993457; cv=pass; d=google.com; s=arc-20160816; b=yLkTwckcGW3rFAdM+LrYPEHk/Ti/RYaQYY+2PpawBoM8PUXzkR9bCd8vZ1NI16hVHy 2DLKYkgIRJ3sTVTZHQr9KEANZK61aGJCUa31XxvPj0wU7Tu+y9hYsBOUSjlgee5xEXDJ dn1QqILsW9pYBTwuM7DaXSECKjgw2NjvI4clErpAKFt418vy6ti3+H4vuoa4aHfGXBpO oN0r6z5Ln3glRQ4UjPuM4YjdVoXtMWysOcnylZg2gUsv8o7Yih590R1n5mwy/Zz2ZHoo Vt89Jp59K6p85rPcuekN0k9SLvjfFHohCZD86lXuwb6BIDQIGslFThed3S2VvT9z7I0Y /5xQ== 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=XXfVdZswQrW+PJKNoyAg9m3URRhUBz2fB+d6rG/p16U=; fh=ZWBvF269YfmsGtLAEyLGw1eEKCt1wojF+D2dyuWPubY=; b=jxjc+01oFvGsLAecV7QRWxMpV84keztikIqQIAIkiSjne3OFJHVYt4kElTJFciyUSo OHcI40MSju1h18KppyMy+oWzUIQoJa0vgkj6/74xD6VJFEDf808XL0EmlIldrZf9F5Bu rEXqXRNgytoJEvplYScMJs52KyHULJ8foXOEa2Z+LKCgAaM2Hwv2SdYw22r1wn+XLl3k gPBmkgm90ub0MD8x0fkeQ7Mm/232uHd5POl1nYUaRsF+7xEm9Uz7iXrHgYEaiYbZRXv4 O4cV7cfB3WNlHml89R8+SO98b7ETYnJKNxS8K4n/IMog39cssdkMyi/c8A6qMCAV0aO1 aXow==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@pankajraghav.com header.s=MBO0001 header.b=Y7wlIk9q; 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-194202-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:40f1:3f00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-194202-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=pankajraghav.com Return-Path: Received: from sy.mirrors.kernel.org (sy.mirrors.kernel.org. [2604:1380:40f1:3f00::1]) by mx.google.com with ESMTPS id d9443c01a7336-1f44c9b7af3si103177135ad.460.2024.05.29.07.37.37 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 29 May 2024 07:37:37 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-194202-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:40f1:3f00::1 as permitted sender) client-ip=2604:1380:40f1:3f00::1; Authentication-Results: mx.google.com; dkim=pass header.i=@pankajraghav.com header.s=MBO0001 header.b=Y7wlIk9q; 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-194202-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:40f1:3f00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-194202-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 sy.mirrors.kernel.org (Postfix) with ESMTPS id D0DB9B25200 for ; Wed, 29 May 2024 13:49:14 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 891915490E; Wed, 29 May 2024 13:46:07 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=pankajraghav.com header.i=@pankajraghav.com header.b="Y7wlIk9q" Received: from mout-p-202.mailbox.org (mout-p-202.mailbox.org [80.241.56.172]) (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 5A7B653819; Wed, 29 May 2024 13:46:05 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=80.241.56.172 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1716990366; cv=none; b=i7rYzGEXRKTRZyNuU9cUCGzfG9QqX4co4SeVn60vrghVTunlI+HkUsI3Zf/tJZ7Y7p2OhJxtDXsBF6E9zq+z50B7gHC1i+ABTMChNLiDLUGwvw1HjzzInO+HotfTCWC9zci+arxCpltY49hV8RB7R67Xg8Eu9LrJi5j8Irf+R2U= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1716990366; c=relaxed/simple; bh=ZKSkZX/Igx8tQJcbS6vFoyLeWl4Gt0rFgfZbBvlRCIo=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=mRwiFJbzG09cnu9eBlk5Oyz1vmA9D+q1JAnnpsHaiM6ema5i3Rw7/tHyHMNBmJy3ixWS5QUyn2r9IEtSgOg2E6jKyicFWIvnOvwt7zRIuDQWmh0RZpZK0ErBtjbEWzm/lO682X4kPmf4KU/rjkRS5xXDvmA7pDUoCq3FB3BHvME= 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=Y7wlIk9q; arc=none smtp.client-ip=80.241.56.172 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 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-202.mailbox.org (Postfix) with ESMTPS id 4Vq9dP6J7Jz9spb; Wed, 29 May 2024 15:46:01 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=pankajraghav.com; s=MBO0001; t=1716990361; 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=XXfVdZswQrW+PJKNoyAg9m3URRhUBz2fB+d6rG/p16U=; b=Y7wlIk9qRzv7K4tdfjamyHbmXFm6kDedt5IbNXR0ASRzYBqQDbTiwUKWH3Nxn48ot+6Zak OfwiYNTnKui3W1HEuPH8HcTistKWS4bwj/E3yNgX5khyuQfsyhvO2ggmx3lY6yTPqRXknl 2oW31GzJVJ6uMqwvtNLujrnLYsvkcPp9YMr53PaMMp/OSKOl4sKnDi1N4nHbKwBz2JgO+P cppHvmzxJrjOOW+xIZhfVRkXwVUO4r9TilmrOj8FhcQmeytlubrh9IZpJB10UBCjnmbVVy XA4RkNV6f4o2hwdpIO9pw/Si9kSgaNhUS1QE8GB8Twgw4F0sHd1EOB49eUZPcQ== From: "Pankaj Raghav (Samsung)" To: david@fromorbit.com, chandan.babu@oracle.com, akpm@linux-foundation.org, brauner@kernel.org, willy@infradead.org, djwong@kernel.org Cc: linux-kernel@vger.kernel.org, hare@suse.de, john.g.garry@oracle.com, gost.dev@samsung.com, yang@os.amperecomputing.com, p.raghav@samsung.com, cl@os.amperecomputing.com, linux-xfs@vger.kernel.org, hch@lst.de, mcgrof@kernel.org, linux-mm@kvack.org, linux-fsdevel@vger.kernel.org Subject: [PATCH v6 10/11] xfs: make the calculation generic in xfs_sb_validate_fsb_count() Date: Wed, 29 May 2024 15:45:08 +0200 Message-Id: <20240529134509.120826-11-kernel@pankajraghav.com> In-Reply-To: <20240529134509.120826-1-kernel@pankajraghav.com> References: <20240529134509.120826-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 X-Rspamd-Queue-Id: 4Vq9dP6J7Jz9spb 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; } -- 2.34.1