mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Harrison Crosse via B4 Relay <devnull+harrison.crosse.dev@kernel.org>
To: David Hildenbrand <david@kernel.org>,
	Jason Gunthorpe <jgg@ziepe.ca>,
	 John Hubbard <jhubbard@nvidia.com>, Peter Xu <peterx@redhat.com>,
	 Andrew Morton <akpm@linux-foundation.org>,
	Lorenzo Stoakes <ljs@kernel.org>,
	 "Liam R. Howlett" <liam@infradead.org>,
	Vlastimil Babka <vbabka@kernel.org>,
	 Mike Rapoport <rppt@kernel.org>,
	Suren Baghdasaryan <surenb@google.com>,
	 Michal Hocko <mhocko@suse.com>, Shuah Khan <shuah@kernel.org>
Cc: linux-mm@kvack.org, linux-kernel@vger.kernel.org,
	 linux-kselftest@vger.kernel.org,
	Josef Bacik <josef@toxicpanda.com>,
	 Johannes Weiner <hannes@cmpxchg.org>, Jan Kara <jack@suse.cz>,
	 Harrison Crosse <harrison@crosse.dev>,
	stable@vger.kernel.org
Subject: [PATCH 0/2] mm/gup: fix mlock() and MAP_POPULATE looping on read errors
Date: Wed, 18 Nov 2026 16:56:40 -0500	[thread overview]
Message-ID: <20261118-mmpop-populate-v1-0-9c561d178d11@crosse.dev> (raw)

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>



             reply	other threads:[~2026-11-18 21:59 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-11-18 21:56 Harrison Crosse via B4 Relay [this message]
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

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=20261118-mmpop-populate-v1-0-9c561d178d11@crosse.dev \
    --to=devnull+harrison.crosse.dev@kernel.org \
    --cc=akpm@linux-foundation.org \
    --cc=david@kernel.org \
    --cc=hannes@cmpxchg.org \
    --cc=harrison@crosse.dev \
    --cc=jack@suse.cz \
    --cc=jgg@ziepe.ca \
    --cc=jhubbard@nvidia.com \
    --cc=josef@toxicpanda.com \
    --cc=liam@infradead.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-kselftest@vger.kernel.org \
    --cc=linux-mm@kvack.org \
    --cc=ljs@kernel.org \
    --cc=mhocko@suse.com \
    --cc=peterx@redhat.com \
    --cc=rppt@kernel.org \
    --cc=shuah@kernel.org \
    --cc=stable@vger.kernel.org \
    --cc=surenb@google.com \
    --cc=vbabka@kernel.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

all inboxes | Powered by JetHome®