From patchwork Thu Apr 25 11:37:41 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: 13643183 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 8D182C19F4F for ; Thu, 25 Apr 2024 11:38:20 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 574CA6B0098; Thu, 25 Apr 2024 07:38:19 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 4FD976B0099; Thu, 25 Apr 2024 07:38:19 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 39DE56B009A; Thu, 25 Apr 2024 07:38:19 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0017.hostedemail.com [216.40.44.17]) by kanga.kvack.org (Postfix) with ESMTP id 1B6946B0098 for ; Thu, 25 Apr 2024 07:38:19 -0400 (EDT) Received: from smtpin20.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay05.hostedemail.com (Postfix) with ESMTP id CCC7E41219 for ; Thu, 25 Apr 2024 11:38:18 +0000 (UTC) X-FDA: 82047855876.20.0102313 Received: from mout-p-101.mailbox.org (mout-p-101.mailbox.org [80.241.56.151]) by imf09.hostedemail.com (Postfix) with ESMTP id 2ABC2140023 for ; Thu, 25 Apr 2024 11:38:16 +0000 (UTC) Authentication-Results: imf09.hostedemail.com; dkim=pass header.d=pankajraghav.com header.s=MBO0001 header.b=jCmWig6I; spf=pass (imf09.hostedemail.com: domain of kernel@pankajraghav.com designates 80.241.56.151 as permitted sender) smtp.mailfrom=kernel@pankajraghav.com; dmarc=pass (policy=quarantine) header.from=pankajraghav.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1714045097; a=rsa-sha256; cv=none; b=PQ2QUd0RKyHIQZ03vcn4NIXQKRL2m0H8v+nydq32xP+RpuHAZ2wOMW2j+5yBiG3ztt3asU 9RC7SxFjGAZW0TEzx9Cj3gT6imOzU+I0JQvKZr6I6binQYcVTvvfAqz08doksOIp7hSh+a 3SX0M2Yg3ej7gj4He+LqStmLKj7N19E= ARC-Authentication-Results: i=1; imf09.hostedemail.com; dkim=pass header.d=pankajraghav.com header.s=MBO0001 header.b=jCmWig6I; spf=pass (imf09.hostedemail.com: domain of kernel@pankajraghav.com designates 80.241.56.151 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=1714045097; 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=czSPhYVZqlifLCbGSVD4LN8Jicbe+9jxrg74bkE8W+M=; b=Q3oKidI7M6bFoLNj9AhBCQOw1xNuxyBp940fNRWYPasREA1ugc+KfO7w7IOvzs69SaVAHX zB8XoFmKSwudtv4Cab3NBPxEclmTH6b0UB4MsT7PIqjx50LzQBiz/V9oI4+7F1xyqqgBrY O4m3q4tZsaeIAyfXqr06upUiz4g9Sqo= 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-101.mailbox.org (Postfix) with ESMTPS id 4VQDPd5S7kz9sc2; Thu, 25 Apr 2024 13:38:13 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=pankajraghav.com; s=MBO0001; t=1714045093; 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=czSPhYVZqlifLCbGSVD4LN8Jicbe+9jxrg74bkE8W+M=; b=jCmWig6I8MmC4tVVnlqLI5vW94Wwlz9pRSUJiLooHMkOOe7ErsyVoFx2VhJY/WmdTxbbRT 3dzg1UBlN4MP4RmAdPxL20o+ed6dhEyL92yPfrr/KbjbRfO3NVL1umnag6JzyRlRB6r5zC q4tIjG3KF/flynDrsYPmLRPtC8lMuVFbc3cQXAl6p3O/gubiU3hUBvII5ArCSxnWG3PUIL SCX71g1J51gObsRKmh9vM7WMGb8WM5/CcZazYgw6T63Kl7NB5sOhnSNIvvGue/BhWjHzoo P4xXrijI969rMXgdWqBJooEzEPQorZWYJq7MfcKRzA79aD6/EfPrL4zxXw/Skw== 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 06/11] filemap: cap PTE range to be created to i_size in folio_map_range() Date: Thu, 25 Apr 2024 13:37:41 +0200 Message-Id: <20240425113746.335530-7-kernel@pankajraghav.com> In-Reply-To: <20240425113746.335530-1-kernel@pankajraghav.com> References: <20240425113746.335530-1-kernel@pankajraghav.com> MIME-Version: 1.0 X-Rspamd-Server: rspam09 X-Rspamd-Queue-Id: 2ABC2140023 X-Stat-Signature: ugx8xt7gskhu44faes6zzqpzgwp4zukf X-Rspam-User: X-HE-Tag: 1714045096-562367 X-HE-Meta: U2FsdGVkX1+ULcJf2Arg3ZeaKBeFW8+2ThGWVSWBsgjGXQi4k5M++Qk+ZrBFj2gZeVocXoQ2bG1omDmAWQ9ThMnX+ValkjN1MoCjKh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YQTA74Gobo+UGmTG4TwQinyggxC+naHhoTEcpWrR3gqzSAQxw2lEmHV8V5qnezGCWeFwfBc8N4nvfs06VZ5yS/4WqxDqqZ+KFheDFCcXw= 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 Usually the page cache does not extend beyond the size of the inode, therefore, no PTEs are created for folios that extend beyond the size. But with LBS support, we might extend page cache beyond the size of the inode as we need to guarantee folios of minimum order. Cap the PTE range to be created for the page cache by i_size. A fstest has been created to trigger this edge case[1]. [1]https://lore.kernel.org/fstests/20240415081054.1782715-1-mcgrof@kernel.org/ Signed-off-by: Pankaj Raghav Co-Developed-by: Luis Chamberlain Signed-off-by: Luis Chamberlain --- mm/filemap.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/mm/filemap.c b/mm/filemap.c index f0c0cfbbd134..259531dd297b 100644 --- a/mm/filemap.c +++ b/mm/filemap.c @@ -3600,12 +3600,15 @@ vm_fault_t filemap_map_pages(struct vm_fault *vmf, } do { unsigned long end; + unsigned long i_size; addr += (xas.xa_index - last_pgoff) << PAGE_SHIFT; vmf->pte += xas.xa_index - last_pgoff; last_pgoff = xas.xa_index; end = folio_next_index(folio) - 1; - nr_pages = min(end, end_pgoff) - xas.xa_index + 1; + i_size = DIV_ROUND_UP(i_size_read(mapping->host), + PAGE_SIZE) - 1; + nr_pages = min3(end, end_pgoff, i_size) - xas.xa_index + 1; if (!folio_test_large(folio)) ret |= filemap_map_order0_folio(vmf,