From patchwork Wed May 29 13:45:04 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: 13678909 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 BB476C25B75 for ; Wed, 29 May 2024 13:45:49 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 46C8F6B00A9; Wed, 29 May 2024 09:45:49 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 3F3816B00AA; Wed, 29 May 2024 09:45:49 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 2213E6B00AB; Wed, 29 May 2024 09:45:49 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0010.hostedemail.com [216.40.44.10]) by kanga.kvack.org (Postfix) with ESMTP id EE2226B00A9 for ; Wed, 29 May 2024 09:45:48 -0400 (EDT) Received: from smtpin08.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay07.hostedemail.com (Postfix) with ESMTP id AD52B160702 for ; Wed, 29 May 2024 13:45:48 +0000 (UTC) X-FDA: 82171556376.08.7CBA5CC Received: from mout-p-202.mailbox.org (mout-p-202.mailbox.org [80.241.56.172]) by imf06.hostedemail.com (Postfix) with ESMTP id 0EA7C180010 for ; Wed, 29 May 2024 13:45:46 +0000 (UTC) Authentication-Results: imf06.hostedemail.com; dkim=pass header.d=pankajraghav.com header.s=MBO0001 header.b=TqtfP3YU; dmarc=pass (policy=quarantine) header.from=pankajraghav.com; spf=pass (imf06.hostedemail.com: domain of kernel@pankajraghav.com designates 80.241.56.172 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=1716990347; 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=IMIZWzID8Oa4XZs06SFDXCAlixk5rrqjrLjasnPiZuM=; b=0ptFLcycCIwCu/Xr5GYTjJXaMsSIMwJCgCbpDAilQsDWdDKQojepMPsMRjAlZVitekOhPR uh54a53KW7ZvuQlb6mfbG/y/T3ohrlxbVUvne8de6nYRFRv/gBAB+ZS9WR6H55gxTolRpE CTsSW2eYcOv/y9L+Ksz4+MaUxCSNH5M= ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1716990347; a=rsa-sha256; cv=none; b=XLqjBr0E55I8ImZ1H8cGlErbh1RtvZKlGE2a4yOLU8PRhOeEEjPzaNPHr5cRou/eb9NYKt kJKpTsl3bAReYL0OYeR8R8Yrk6UXOM9cDD4nkBHwfydEETuiVheJlWjCM2FwS/kpuZ8VtG +vfPMbrhHNlUB8uO0e1Bo45ZfmDOvuc= ARC-Authentication-Results: i=1; imf06.hostedemail.com; dkim=pass header.d=pankajraghav.com header.s=MBO0001 header.b=TqtfP3YU; dmarc=pass (policy=quarantine) header.from=pankajraghav.com; spf=pass (imf06.hostedemail.com: domain of kernel@pankajraghav.com designates 80.241.56.172 as permitted sender) smtp.mailfrom=kernel@pankajraghav.com Received: from smtp202.mailbox.org (smtp202.mailbox.org [IPv6:2001:67c:2050:b231:465::202]) (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 4Vq9d35L8bz9sSV; Wed, 29 May 2024 15:45:43 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=pankajraghav.com; s=MBO0001; t=1716990343; 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=IMIZWzID8Oa4XZs06SFDXCAlixk5rrqjrLjasnPiZuM=; b=TqtfP3YUwosVu7v0T47uciWkMe74vRAl8UvhaEbvYSJvKjyU80QI/rlEdo79J3hwSsOL+x XAzNTXip1JSRvFThNu6Ij0FFS31H5OKr3oEJjrdHGPRKRjrm7oADrjwiTliDERUr8dSzFr 397nhNEFSnybU26IOcKwVIlESyW3YXW3YHAGH8Xd5nDsexhkoksr/o9c6fRoDoDoluWCQQ dwmCJitjxvFOnbeJObIQDmb4xY7dATIx7ePqyMFspsBtIjcLi7pq4LGt4Onfz+1kklSG/M bZkjJPooW+suPUUkKtzq00x8pQ7Oo0j5Yh2i5xT/Tb9Y5zNSh0CxI/KsvapQNQ== 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 06/11] filemap: cap PTE range to be created to allowed zero fill in folio_map_range() Date: Wed, 29 May 2024 15:45:04 +0200 Message-Id: <20240529134509.120826-7-kernel@pankajraghav.com> In-Reply-To: <20240529134509.120826-1-kernel@pankajraghav.com> References: <20240529134509.120826-1-kernel@pankajraghav.com> MIME-Version: 1.0 X-Stat-Signature: 3znfxe6u5rq1qdy4d8wzmdsytn4p3w5b X-Rspamd-Queue-Id: 0EA7C180010 X-Rspam-User: X-Rspamd-Server: rspam01 X-HE-Tag: 1716990346-477627 X-HE-Meta: U2FsdGVkX1/xOxVoocyGkuHAkDVOukz6fFpxFTkPrhh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DqUiGbwUn0RFr4bXw6+WGm+Kmt/hbGKMm/ixigvsstx+bh7GAQdcxKYyRsJp8JArN39oIF0bimSUUMItzS9QwjCT5PxnbdtCXjKoMBchATEIjn9RqSs0WKIQwBJb4NK/JSq7L4hjmAABaIkNBmKKcVr/wi3Hso58VH//tbwHYOmwOa+MHnLCKP3kNk0qi7Q+v/zeWux7TGQYtXs= 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 up to the max allowed zero-fill file end, which is aligned to the PAGE_SIZE. An fstests test has been created to trigger this edge case [0]. [0] https://lore.kernel.org/fstests/20240415081054.1782715-1-mcgrof@kernel.org/ Signed-off-by: Luis Chamberlain Signed-off-by: Pankaj Raghav Reviewed-by: Hannes Reinecke --- mm/filemap.c | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/mm/filemap.c b/mm/filemap.c index 0914ef2e8256..e398fa7b2ef6 100644 --- a/mm/filemap.c +++ b/mm/filemap.c @@ -3610,7 +3610,7 @@ vm_fault_t filemap_map_pages(struct vm_fault *vmf, struct vm_area_struct *vma = vmf->vma; struct file *file = vma->vm_file; struct address_space *mapping = file->f_mapping; - pgoff_t last_pgoff = start_pgoff; + pgoff_t file_end, last_pgoff = start_pgoff; unsigned long addr; XA_STATE(xas, &mapping->i_pages, start_pgoff); struct folio *folio; @@ -3636,6 +3636,10 @@ vm_fault_t filemap_map_pages(struct vm_fault *vmf, goto out; } + file_end = DIV_ROUND_UP(i_size_read(mapping->host), PAGE_SIZE) - 1; + if (end_pgoff > file_end) + end_pgoff = file_end; + folio_type = mm_counter_file(folio); do { unsigned long end;