From patchwork Fri Jun 7 14:58:57 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: 13690332 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 E3229C27C53 for ; Fri, 7 Jun 2024 14:59:45 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 716786B00AA; Fri, 7 Jun 2024 10:59:45 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 6C4A16B00AB; Fri, 7 Jun 2024 10:59:45 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 5666C6B00AC; Fri, 7 Jun 2024 10:59:45 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0016.hostedemail.com [216.40.44.16]) by kanga.kvack.org (Postfix) with ESMTP id 369126B00AA for ; Fri, 7 Jun 2024 10:59:45 -0400 (EDT) Received: from smtpin16.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay05.hostedemail.com (Postfix) with ESMTP id DB7AA41967 for ; Fri, 7 Jun 2024 14:59:44 +0000 (UTC) X-FDA: 82204401888.16.0CDDF66 Received: from mout-p-202.mailbox.org (mout-p-202.mailbox.org [80.241.56.172]) by imf11.hostedemail.com (Postfix) with ESMTP id 6EA7640029 for ; Fri, 7 Jun 2024 14:59:37 +0000 (UTC) Authentication-Results: imf11.hostedemail.com; dkim=pass header.d=pankajraghav.com header.s=MBO0001 header.b="J8/R4PXX"; spf=pass (imf11.hostedemail.com: domain of kernel@pankajraghav.com designates 80.241.56.172 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=1717772378; 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=WZ8spY/tVuIWIrFMviERGy/5Qi8haMN3dT86BjfIdPw=; b=NY3on8A2ka/rLfjp763sS45Q2pzr7m4RbTZT+n9pzzMDF4vNS+DZF5PhljctSkDS5Uwhim 9Zik6MEytjeiFzAiadA481vkqgoEzD3i3NtD/1arRd+nELZnK0ISHOkcdzW49vWIY5c8op f+wfwKn3W1ORCWAXhA8SyAfrsc0B/CM= ARC-Authentication-Results: i=1; imf11.hostedemail.com; dkim=pass header.d=pankajraghav.com header.s=MBO0001 header.b="J8/R4PXX"; spf=pass (imf11.hostedemail.com: domain of kernel@pankajraghav.com designates 80.241.56.172 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=1717772378; a=rsa-sha256; cv=none; b=E1WVMS7R2qe2QqBGvUjZb39S2MaC5lwYCy9YN7MYLC+qfLGNRA59YRX07sFXa+wzPZcR2h 2DjY6//dtp/WB2/RWInOlqd1LNGybhkgPhb+xaHZEZUeX9j1BA7Z93AVcTQSszGkB8NKEV nV1a9w75q7pytjRO14qB/wTlTrYARyU= Received: from smtp2.mailbox.org (smtp2.mailbox.org [10.196.197.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 4Vwkr61KLfz9spm; Fri, 7 Jun 2024 16:59:34 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=pankajraghav.com; s=MBO0001; t=1717772374; 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=WZ8spY/tVuIWIrFMviERGy/5Qi8haMN3dT86BjfIdPw=; b=J8/R4PXXvkkbYJHQl7XbsXJeITLpZQv1B3Zo+xpZIlQ9Ut+9PsC2vT1rlqmadtHLrvo6rb zQOFhlJSqPC0bSLUvcoaqFYoWSUq9y324Ft40iYEiTvD8Gqy4dTQiwviA6QtV/5ausrBl9 YuOH5eZnKiQZYSaZMW2jyWegt9+fG8U0OoxOic/0njfB9gN5Sot38JjbEQI0Ikc0AQ2OGl sC40ZxMSHSlBRJwsKF/AxOJqEuwqlUVm/3p8+nMH2fa/fLOWTCS/SyVBd71MvC3DjUI8Z5 YxBU/uRO8gGE3g3g0dBUpfzCsla0Q1BrAs5G17j6X7vu91SRzTxSWlx4rMMy+Q== From: "Pankaj Raghav (Samsung)" To: david@fromorbit.com, djwong@kernel.org, chandan.babu@oracle.com, brauner@kernel.org, akpm@linux-foundation.org, willy@infradead.org Cc: mcgrof@kernel.org, linux-mm@kvack.org, hare@suse.de, linux-kernel@vger.kernel.org, yang@os.amperecomputing.com, Zi Yan , linux-xfs@vger.kernel.org, p.raghav@samsung.com, linux-fsdevel@vger.kernel.org, kernel@pankajraghav.com, hch@lst.de, gost.dev@samsung.com, cl@os.amperecomputing.com, john.g.garry@oracle.com Subject: [PATCH v7 06/11] filemap: cap PTE range to be created to allowed zero fill in folio_map_range() Date: Fri, 7 Jun 2024 14:58:57 +0000 Message-ID: <20240607145902.1137853-7-kernel@pankajraghav.com> In-Reply-To: <20240607145902.1137853-1-kernel@pankajraghav.com> References: <20240607145902.1137853-1-kernel@pankajraghav.com> MIME-Version: 1.0 X-Rspam-User: X-Rspamd-Server: rspam09 X-Rspamd-Queue-Id: 6EA7640029 X-Stat-Signature: 784z4het43tph1mfmd4qdxc7xpddio9p X-HE-Tag: 1717772377-228864 X-HE-Meta: U2FsdGVkX19BlVq5Q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mEdqnmN0kjN3IZAeE7ICfyITFu/uPcRsvOmAkriSD3zYhWvJztFjfJEw6/o3g0AsV3zpP25W+ollL/IgFr+cTuEWFZ28vS50wVkK2PIVGN9x+Zc6RKCg1MgEq4j2vXN7VkeS5cKxvxP4JZtmLdzx6Ssl4Bu78WaofQA+OAQMPxIAgwbJD4Os5o= 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 Reviewed-by: Hannes Reinecke Signed-off-by: Pankaj Raghav Reviewed-by: Matthew Wilcox (Oracle) --- mm/filemap.c | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/mm/filemap.c b/mm/filemap.c index 8bb0d2bc93c5..0e48491b3d10 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;