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

From: David Hildenbrand

Date: Mon Oct 27 2025 - 05:27:21 EST


On 27.10.25 09:20, Hugh Dickins wrote:
On Thu, 23 Oct 2025, 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;

Sorry for coming in late as usual, and complicating matters.


No problem, we CCed you on earlier versions to get your input, and we were speculating that shmem behavior might be intended (one way or the other).


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")

ACK to restoring the correct POSIX behaviour to those filesystems
which are being given large folios beyond EOF transparently,
without any huge= mount option to permit it.

Fixes: 800d8c63b2e9 ("shmem: add huge pages support")

But NAK to regressing the intentional behaviour of huge=always
on shmem/tmpfs: the page size, whenever possible, is PMD-sized. In
6.18-rc huge=always is currently (thanks to Baolin) behaving correctly
again, as it had done for nine years: I insist we do not re-break it.

Just so we are on the same page: this is not about which folio sizes we allocate (like what Baolin fixed) but what/how much to map.

I guess this patch here would imply the following changes

1) A file with a size that is not PMD aligned will have the last (unaligned part) not mapped by PMDs.

2) Once growing a file, the previously-last-part would not be mapped by PMDs.


Of course, we would have only mapped the last part of the file by PMDs if the VMA would have been large enough in the first place. I'm curious, is that something that is commonly done by applications with shmem files (map beyond eof)?

--
Cheers

David / dhildenb