From patchwork Thu Aug 15 09:08:44 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: 13764598 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 8F3FAC3DA7F for ; Thu, 15 Aug 2024 09:09:34 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 1D95B6B00AA; Thu, 15 Aug 2024 05:09:34 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 18A976B00AB; Thu, 15 Aug 2024 05:09:34 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 029EC6B00AC; Thu, 15 Aug 2024 05:09:33 -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 D96196B00AA for ; Thu, 15 Aug 2024 05:09:33 -0400 (EDT) Received: from smtpin25.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay06.hostedemail.com (Postfix) with ESMTP id 9CBB6A7CE7 for ; Thu, 15 Aug 2024 09:09:33 +0000 (UTC) X-FDA: 82453906626.25.C26E5E0 Received: from mout-p-102.mailbox.org (mout-p-102.mailbox.org [80.241.56.152]) by imf20.hostedemail.com (Postfix) with ESMTP id D497A1C0025 for ; Thu, 15 Aug 2024 09:09:31 +0000 (UTC) Authentication-Results: imf20.hostedemail.com; dkim=pass header.d=pankajraghav.com header.s=MBO0001 header.b=h0itYGBR; dmarc=pass (policy=quarantine) header.from=pankajraghav.com; spf=pass (imf20.hostedemail.com: domain of kernel@pankajraghav.com designates 80.241.56.152 as permitted sender) smtp.mailfrom=kernel@pankajraghav.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1723712913; a=rsa-sha256; cv=none; b=Y63+9tnGgDxSoywM1/zgQTGGn+gfkdFDpUd8Mjpv78fLGipSfTGQ3nZXJgVkb7+fmzg4Rf lj25qIY59Kc/DMideMvQl/CB5pSyUCaHRaQLWK4BCEqm1cX/5uus6hqG7vxre4EeFDoo+A EWCYds030WPEycu/Gzoem14rt1zY+0A= ARC-Authentication-Results: i=1; imf20.hostedemail.com; dkim=pass header.d=pankajraghav.com header.s=MBO0001 header.b=h0itYGBR; dmarc=pass (policy=quarantine) header.from=pankajraghav.com; spf=pass (imf20.hostedemail.com: domain of kernel@pankajraghav.com designates 80.241.56.152 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=1723712913; 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=uyP45Kb7uBDSBwQgasBASrViJg6ERuo2M5WpPhAgxr4=; b=U0rbnEVHTuWfvfm5QF0nQC3w6a98FNPgX+ZZNSe6kL9NRC3zKTHyofgt1TkUg86hmAWRxV 5xyf6Mom5gPk28iPFEIUPS6t3ifQUcecnl83m8b3biaAksa+QJoDLI+xVFJXV3K72qxVZF 2d1LNCoFQdUzEHVDlVEi53mz4+zbGqo= Received: from smtp1.mailbox.org (smtp1.mailbox.org [10.196.197.1]) (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-102.mailbox.org (Postfix) with ESMTPS id 4WkzpJ4rC9z9tH1; Thu, 15 Aug 2024 11:09:28 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=pankajraghav.com; s=MBO0001; t=1723712968; 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=uyP45Kb7uBDSBwQgasBASrViJg6ERuo2M5WpPhAgxr4=; b=h0itYGBR7U+eC3xJ2So8OH0XdSTYBdmL35lQJMwkKF+iuOzPpkOY+ABh+helnpAAAYjPxB nVXT4JJpXSfCLV7fZSCcjLv8XmQaubCtfdBrlyehhLz42F6N98P9j3xsHbyVZZS64K2WrW wImghDfD/gq8n8QqqP58PqtoNmQC8HJpgB1SDaC4wa2Fb0zGe3qh/Fro+VmwaIVbH1bWrk HL+K612QaE0qBAWtOyZPZwlgA4iQHFDNkVgYbuFUuIRoLDsc/Dr2gGgj4+i3N68a7fpflh rRlzgGphpd0taYzgyKwhcVwZnY4xcEMK3ZjpmT0U/irphQ2jMAQIK5Nykxy8YA== 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 Subject: [PATCH v12 05/10] filemap: cap PTE range to be created to allowed zero fill in folio_map_range() Date: Thu, 15 Aug 2024 11:08:44 +0200 Message-ID: <20240815090849.972355-6-kernel@pankajraghav.com> In-Reply-To: <20240815090849.972355-1-kernel@pankajraghav.com> References: <20240815090849.972355-1-kernel@pankajraghav.com> MIME-Version: 1.0 X-Rspamd-Server: rspam12 X-Rspamd-Queue-Id: D497A1C0025 X-Stat-Signature: tgoyedudeefxz7fxyqct6wx9b3kef8g1 X-Rspam-User: X-HE-Tag: 1723712971-120847 X-HE-Meta: U2Fs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dC2/IpqQRjSUpahnp9Xwzi2LJLqSTOA2+HTurDRcvFX0ata1vksgwUVyi8Wa4azCF8sgOz7Yp9zhQeeXT6Hm/R9qz9D7FBOV9lUpW/7migPY3lhLnE5QQbUanliAVaj2cDyAORg3lPRzc5FiC9MFAU59Ip/23b3rNEQqyNpdPDk8PgWShcRXd7fqYFSmd+fR8qQC/ttZM4CY2zVpB3wUlSrsOm7pR583uXBYzgXuWXP/bimfjaB6Yog5sDO7y8fRwNOo+Mt8gA5IMtH2qZfNU7lp86HMqZtyTQ+9fe4rof4= 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. While doing a read, do_fault_around() can create PTEs for pages that lie beyond the EOF leading to incorrect error return when accessing a page beyond the mapped file. Cap the PTE range to be created for the page cache up to the end of file(EOF) in filemap_map_pages() so that return error codes are consistent with POSIX[1] for LBS configurations. generic/749 has been created to trigger this edge case. This also fixes generic/749 for tmpfs with huge=always on systems with 4k base page size. [1](from mmap(2)) SIGBUS Attempted access to a page of the buffer that lies beyond the end of the mapped file. For an explanation of the treatment of the bytes in the page that corresponds to the end of a mapped file that is not a multiple of the page size, see NOTES. Signed-off-by: Luis Chamberlain Signed-off-by: Pankaj Raghav Reviewed-by: Hannes Reinecke Reviewed-by: Matthew Wilcox (Oracle) Reviewed-by: Darrick J. Wong --- mm/filemap.c | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/mm/filemap.c b/mm/filemap.c index 623c0f988da79..77b583a7aabd1 100644 --- a/mm/filemap.c +++ b/mm/filemap.c @@ -3608,7 +3608,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; @@ -3634,6 +3634,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;