Re: [PATCHv2 1/2] mm/memory: Do not populate page table entries beyond i_size

From: David Hildenbrand
Date: Fri Oct 24 2025 - 11:43:03 EST


On 23.10.25 11:32, Kiryl Shutsemau wrote:
From: Kiryl Shutsemau <kas@xxxxxxxxxx>

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.

Fix filemap_map_pages() and finish_fault() to not install:
- PTEs beyond i_size;
- PMD mappings across i_size;

Signed-off-by: Kiryl Shutsemau <kas@xxxxxxxxxx>
Fixes: 19773df031bc ("mm/fault: try to map the entire file folio in finish_fault()")
Fixes: 357b92761d94 ("mm/filemap: map entire large folio faultaround")
Fixes: 800d8c63b2e9 ("shmem: add huge pages support")
Reported-by: "Darrick J. Wong" <djwong@xxxxxxxxxx>
---

Some of the code in here might deserve some cleanups IMHO :)

[...]

addr0 = addr - start * PAGE_SIZE;
if (folio_within_vma(folio, vmf->vma) &&
- (addr0 & PMD_MASK) == ((addr0 + folio_size(folio) - 1) & PMD_MASK)) {
+ (addr0 & PMD_MASK) == ((addr0 + folio_size(folio) - 1) & PMD_MASK) &&

Isn't this just testing whether addr0 is aligned to folio_size(folio)? (given that we don't support folios > PMD_SIZE), like

IS_ALIGNED(addr0, folio_size(folio))

Anyhow, unrelated to this patch ...



Acked-by: David Hildenbrand <david@xxxxxxxxxx>

--
Cheers

David / dhildenb