From mboxrd@z Thu Jan 1 00:00:00 1970 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 D9558C27C53 for ; Wed, 12 Jun 2024 19:08:25 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 41D976B00A5; Wed, 12 Jun 2024 15:08:25 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 3CDB06B00A6; Wed, 12 Jun 2024 15:08:25 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 294A96B00A8; Wed, 12 Jun 2024 15:08:25 -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 0B1956B00A5 for ; Wed, 12 Jun 2024 15:08:25 -0400 (EDT) Received: from smtpin11.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay08.hostedemail.com (Postfix) with ESMTP id 76CE11418DB for ; Wed, 12 Jun 2024 19:08:24 +0000 (UTC) X-FDA: 82223172528.11.827B3E0 Received: from casper.infradead.org (casper.infradead.org [90.155.50.34]) by imf19.hostedemail.com (Postfix) with ESMTP id 228D51A0006 for ; Wed, 12 Jun 2024 19:08:21 +0000 (UTC) Authentication-Results: imf19.hostedemail.com; dkim=pass header.d=infradead.org header.s=casper.20170209 header.b=HCmF8r2F; spf=none (imf19.hostedemail.com: domain of willy@infradead.org has no SPF policy when checking 90.155.50.34) smtp.mailfrom=willy@infradead.org; dmarc=none ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1718219303; 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-type:content-transfer-encoding: in-reply-to:in-reply-to:references:references:dkim-signature; bh=nXMsYCyv4Yf7/Yu0L4W/RILlfgsgIycAWX2uQcsZwVg=; b=vn4S6kVX4ovk1XHHLvsNrIdRtlrCIH/ChQdFEKuMZREukym98IhcCE7hXhG7FuiNlrtvxn OSz/aBfsUZlDQ+YB7SY5wATiA05Ns9UpJvQSu8yyiGjFk4dNiU33fCGstlSyMDF3QYZs15 g6XTq1TuRo64nMxHrE8QPqvWZqUBvQc= ARC-Authentication-Results: i=1; imf19.hostedemail.com; dkim=pass header.d=infradead.org header.s=casper.20170209 header.b=HCmF8r2F; spf=none (imf19.hostedemail.com: domain of willy@infradead.org has no SPF policy when checking 90.155.50.34) smtp.mailfrom=willy@infradead.org; dmarc=none ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1718219303; a=rsa-sha256; cv=none; b=wNdW76K0nbvbVOG+Vdvu7jC7V+yHhphCudoEOKVw4Se6O2/n+OJScvThJzMCxKw6ivd6fV Iu1nZURe9X/GIi+h/h5uIeZpTL2pllfyXyVq1uHnEQ95f3ubhZ945dYt1vfMnaCZSTCQ+f fB7K5145Bcpf3xqN4Ruv4Vwn1Cf+SR4= DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=casper.20170209; h=In-Reply-To:Content-Type:MIME-Version: References:Message-ID:Subject:Cc:To:From:Date:Sender:Reply-To: Content-Transfer-Encoding:Content-ID:Content-Description; bh=nXMsYCyv4Yf7/Yu0L4W/RILlfgsgIycAWX2uQcsZwVg=; b=HCmF8r2FVSCYuICzIMuXFI/Cci kfi3EelJoIlhXTo027+7qAg8KPfT+I8Y9B1pRhU/mfiGb2/y88pqAAClO7sJERJU2KbJU4JuCfjvM aOjxzUtwo/hGHToL7VI98vwE3CbIyciALaQDc+hY5E5JxUvAgIqEZh23bB7efTVtkT4TYhHn6K2ja WWZBTD48mR+KKa8ou0/C4UJ7Iuo+E4fi0FpmuWZ9qC0zkiXRWyaS6V4FMxJT4Hs9yKOdHnquLTIdo xHtqx8pyTEu+jI9shrlDU3fAIUNfdDwY1VSzAr+iRxuMZgfSQk6riQ8PTkbEvW64WEnPlobIvlbqL fnSlGl7Q==; Received: from willy by casper.infradead.org with local (Exim 4.97.1 #2 (Red Hat Linux)) id 1sHTKR-0000000F0Aj-1j7U; Wed, 12 Jun 2024 19:08:15 +0000 Date: Wed, 12 Jun 2024 20:08:15 +0100 From: Matthew Wilcox To: "Pankaj Raghav (Samsung)" Cc: david@fromorbit.com, djwong@kernel.org, chandan.babu@oracle.com, brauner@kernel.org, akpm@linux-foundation.org, 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, hch@lst.de, gost.dev@samsung.com, cl@os.amperecomputing.com, john.g.garry@oracle.com Subject: Re: [PATCH v7 06/11] filemap: cap PTE range to be created to allowed zero fill in folio_map_range() Message-ID: References: <20240607145902.1137853-1-kernel@pankajraghav.com> <20240607145902.1137853-7-kernel@pankajraghav.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20240607145902.1137853-7-kernel@pankajraghav.com> X-Rspamd-Queue-Id: 228D51A0006 X-Rspam-User: X-Rspamd-Server: rspam09 X-Stat-Signature: d6bc1d8ngta4cio7j1a5f9t3j34nejth X-HE-Tag: 1718219301-391352 X-HE-Meta: U2FsdGVkX1/H9zzjnHEtbl8ustG/64I7wHae49IMzrvuVm9FMS+dMpJUurwDmRYDU8bbz9BMU4bOXmGbzNIcVUOJE7n1urtcsMq0Ue6kCh598BK+XbIwzx7N2Fdd4rMClItkQLOElgM6LvYdq5Kru25vnzoubg70SmmRX596wspMzmC5bZMc51dH+lb6FkFIqtdG5rLng74pgp8ZYtymkFH4k86Pd2/fIt1EV/XPgnZwuF7PDRf6QzKSeRAwRaEd9EWiEDMTOa2xKIsd/YWbVk/+Ot9Z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1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: List-Subscribe: List-Unsubscribe: On Fri, Jun 07, 2024 at 02:58:57PM +0000, Pankaj Raghav (Samsung) wrote: > 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. I think this is slightly misleading because we might well zero-fill to the end of the folio. The issue is that we're supposed to SIGBUS if userspace accesses pages which lie entirely beyond the end of this file. Can you rephrase this? (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. The code is good though. Reviewed-by: Matthew Wilcox (Oracle) > 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 > --- > 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; > -- > 2.44.1 >