Linux-mm Archive on lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH 0/2] mm/gup: fix mlock() and MAP_POPULATE looping on read errors
@ 2026-11-18 21:56 Harrison Crosse via B4 Relay
  2026-11-18 21:56 ` [PATCH 1/2] mm/gup: make mlock() and MAP_POPULATE handle VM_FAULT_RETRY properly Harrison Crosse via B4 Relay
  2026-11-18 21:56 ` [PATCH 2/2] selftests/mm: add a test for populating a page that cannot be read Harrison Crosse via B4 Relay
  0 siblings, 2 replies; 5+ messages in thread
From: Harrison Crosse via B4 Relay @ 2026-11-18 21:56 UTC (permalink / raw)
  To: David Hildenbrand, Jason Gunthorpe, John Hubbard, Peter Xu,
	Andrew Morton, Lorenzo Stoakes, Liam R. Howlett, Vlastimil Babka,
	Mike Rapoport, Suren Baghdasaryan, Michal Hocko, Shuah Khan
  Cc: linux-mm, linux-kernel, linux-kselftest, Josef Bacik,
	Johannes Weiner, Jan Kara, Harrison Crosse, stable

If every read of a page in a file mapping fails, mmap(MAP_POPULATE) and
mlock() of that mapping retry the read in the kernel until the task gets
a fatal signal. A load from the page gets SIGBUS, and MADV_POPULATE_READ
fails with EFAULT.

Patch 1 makes __mm_populate() pass FOLL_TRIED when retrying the page
whose fault released the mmap_lock, as __get_user_pages_locked() does,
so that a read error ends the loop. mlock() then fails with ENOMEM, and
mmap(MAP_POPULATE) returns the mapping. Patch 2 adds populate_eio, a
selftest that serves such a file over FUSE and fails without patch 1.
The series is based on v7.4-rc3.

The bug was reproduced with the ext4 setup described in patch 1 on
v7.4-rc3 (arm64 and x86_64), Debian 6.12.116 (arm64) and 6.6.162
(x86_64). Under QEMU TCG, populate_eio passes its MADV_POPULATE_READ
check and fails its mmap(MAP_POPULATE) and mlock() checks without
patch 1 on v7.4-rc3 (arm64 and x86_64) and on 6.12.117 (x86_64), and
passes all three checks with patch 1 on v7.4-rc3 on both architectures.

To reproduce, build and run populate_eio from patch 2 as root on a
kernel with CONFIG_FUSE_FS.

The fix was tested only on v7.4-rc3, on arm64 and x86_64 with 4K pages.
On arm64, only populate_eio was run on the patched kernel. Also not
tested: populate_eio in unprivileged user namespaces or on kernels older
than 6.12, the ext4 setup on kernels older than 6.6, and populate_eio
timing out or getting SIGKILL during a call on the patched kernel, where
every call returns at once. The notes in each patch list the other cases
that were not tested.

The analysis and the patches were prepared with the help of an AI coding
assistant (Claude).

Signed-off-by: Harrison Crosse <harrison@crosse.dev>
---
Harrison Crosse (2):
      mm/gup: make mlock() and MAP_POPULATE handle VM_FAULT_RETRY properly
      selftests/mm: add a test for populating a page that cannot be read

 mm/gup.c                                  |  36 ++-
 tools/testing/selftests/mm/Makefile       |   1 +
 tools/testing/selftests/mm/config         |   1 +
 tools/testing/selftests/mm/populate_eio.c | 410 ++++++++++++++++++++++++++++++
 tools/testing/selftests/mm/run_vmtests.sh |   1 +
 5 files changed, 445 insertions(+), 4 deletions(-)
---
base-commit: aebb7274476403040d582c61478df8f4a7bf9cd3
change-id: 20261118-mmpop-populate-8a385efa7e7f

Best regards,
--  
Harrison Crosse <harrison@crosse.dev>




^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2026-11-18 23:59 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-11-18 21:56 [PATCH 0/2] mm/gup: fix mlock() and MAP_POPULATE looping on read errors Harrison Crosse via B4 Relay
2026-11-18 21:56 ` [PATCH 1/2] mm/gup: make mlock() and MAP_POPULATE handle VM_FAULT_RETRY properly Harrison Crosse via B4 Relay
2026-11-18 23:25   ` David Hildenbrand (Arm)
2026-11-18 23:59     ` Harrison Crosse
2026-11-18 21:56 ` [PATCH 2/2] selftests/mm: add a test for populating a page that cannot be read Harrison Crosse via B4 Relay

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox