From: David Hildenbrand <david@redhat.com>
To: Kiryl Shutsemau <kirill@shutemov.name>,
Andrew Morton <akpm@linux-foundation.org>,
Hugh Dickins <hughd@google.com>,
Matthew Wilcox <willy@infradead.org>,
Alexander Viro <viro@zeniv.linux.org.uk>,
Christian Brauner <brauner@kernel.org>,
Hugh Dickins <hughd@google.com>
Cc: Lorenzo Stoakes <lorenzo.stoakes@oracle.com>,
"Liam R. Howlett" <Liam.Howlett@oracle.com>,
Vlastimil Babka <vbabka@suse.cz>, Mike Rapoport <rppt@kernel.org>,
Suren Baghdasaryan <surenb@google.com>,
Michal Hocko <mhocko@suse.com>, Rik van Riel <riel@surriel.com>,
Harry Yoo <harry.yoo@oracle.com>,
Johannes Weiner <hannes@cmpxchg.org>,
Shakeel Butt <shakeel.butt@linux.dev>,
Baolin Wang <baolin.wang@linux.alibaba.com>,
"Darrick J. Wong" <djwong@kernel.org>,
linux-mm@kvack.org, linux-fsdevel@vger.kernel.org,
linux-kernel@vger.kernel.org, Kiryl Shutsemau <kas@kernel.org>
Subject: Re: [PATCH 1/2] mm/memory: Do not populate page table entries beyond i_size.
Date: Tue, 21 Oct 2025 14:08:44 +0200 [thread overview]
Message-ID: <8379d8cb-aec5-44f7-a5f0-2356b8aaaf00@redhat.com> (raw)
In-Reply-To: <20251021063509.1101728-1-kirill@shutemov.name>
On 21.10.25 08:35, Kiryl Shutsemau wrote:
> From: Kiryl Shutsemau <kas@kernel.org>
Subject: I'd drop the trailing "."
>
> Accesses within VMA, but beyond i_size rounded up to PAGE_SIZE are
> supposed to generate SIGBUS.
>
> Recent changes attempted to fault in full folio where possible. They did
> not respect i_size, which led to populating PTEs beyond i_size and
> breaking SIGBUS semantics.
>
> Darrick reported generic/749 breakage because of this.
>
> However, the problem existed before the recent changes. With huge=always
> tmpfs, any write to a file leads to PMD-size allocation. Following the
> fault-in of the folio will install PMD mapping regardless of i_size.
Right, there are some legacy oddities with shmem in that area (e.g.,
"within_size" vs. "always" THP allocation control).
Let me CC Hugh: the behavior for shmem seems to date back to 2016.
>
> Fix filemap_map_pages() and finish_fault() to not install:
> - PTEs beyond i_size;
> - PMD mappings across i_size;
Makes sense to me.
[...]
> +++ b/mm/memory.c
> @@ -5480,6 +5480,7 @@ vm_fault_t finish_fault(struct vm_fault *vmf)
> int type, nr_pages;
> unsigned long addr;
> bool needs_fallback = false;
> + pgoff_t file_end = -1UL;
>
> fallback:
> addr = vmf->address;
> @@ -5501,8 +5502,14 @@ vm_fault_t finish_fault(struct vm_fault *vmf)
> return ret;
> }
>
> + if (vma->vm_file) {
> + struct inode *inode = vma->vm_file->f_mapping->host;
empty line pleae
> + file_end = DIV_ROUND_UP(i_size_read(inode), PAGE_SIZE);
> + }
> +
> if (pmd_none(*vmf->pmd)) {
> - if (folio_test_pmd_mappable(folio)) {
> + if (folio_test_pmd_mappable(folio) &&
> + file_end >= folio_next_index(folio)) {
> ret = do_set_pmd(vmf, folio, page);
> if (ret != VM_FAULT_FALLBACK)
> return ret;
> @@ -5533,7 +5540,8 @@ vm_fault_t finish_fault(struct vm_fault *vmf)
> if (unlikely(vma_off < idx ||
> vma_off + (nr_pages - idx) > vma_pages(vma) ||
> pte_off < idx ||
> - pte_off + (nr_pages - idx) > PTRS_PER_PTE)) {
> + pte_off + (nr_pages - idx) > PTRS_PER_PTE ||
While at it you could fix the double space before the ">".
> + file_end < folio_next_index(folio))) {
> nr_pages = 1;
> } else {
> /* Now we can set mappings for the whole large folio. */
Nothing else jumped at me.
--
Cheers
David / dhildenb
next prev parent reply other threads:[~2025-10-21 12:08 UTC|newest]
Thread overview: 12+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-10-21 6:35 [PATCH 1/2] mm/memory: Do not populate page table entries beyond i_size Kiryl Shutsemau
2025-10-21 6:35 ` [PATCH 2/2] mm/truncate: Unmap large folio on split failure Kiryl Shutsemau
2025-10-21 9:44 ` David Hildenbrand
2025-10-21 9:47 ` David Hildenbrand
2025-10-21 11:31 ` Kiryl Shutsemau
2025-10-21 11:54 ` David Hildenbrand
2025-10-21 12:25 ` Kiryl Shutsemau
2025-10-21 12:33 ` David Hildenbrand
2025-10-21 12:58 ` Kiryl Shutsemau
2025-10-21 12:08 ` David Hildenbrand [this message]
2025-10-21 12:28 ` [PATCH 1/2] mm/memory: Do not populate page table entries beyond i_size Kiryl Shutsemau
-- strict thread matches above, loose matches on Subject: below --
2025-10-20 16:30 [RFC, PATCH 0/2] Large folios vs. SIGBUS semantics Kiryl Shutsemau
2025-10-20 16:30 ` [PATCH 1/2] mm/memory: Do not populate page table entries beyond i_size Kiryl Shutsemau
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=8379d8cb-aec5-44f7-a5f0-2356b8aaaf00@redhat.com \
--to=david@redhat.com \
--cc=Liam.Howlett@oracle.com \
--cc=akpm@linux-foundation.org \
--cc=baolin.wang@linux.alibaba.com \
--cc=brauner@kernel.org \
--cc=djwong@kernel.org \
--cc=hannes@cmpxchg.org \
--cc=harry.yoo@oracle.com \
--cc=hughd@google.com \
--cc=kas@kernel.org \
--cc=kirill@shutemov.name \
--cc=linux-fsdevel@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-mm@kvack.org \
--cc=lorenzo.stoakes@oracle.com \
--cc=mhocko@suse.com \
--cc=riel@surriel.com \
--cc=rppt@kernel.org \
--cc=shakeel.butt@linux.dev \
--cc=surenb@google.com \
--cc=vbabka@suse.cz \
--cc=viro@zeniv.linux.org.uk \
--cc=willy@infradead.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).