From: "David Hildenbrand (Arm)" <david@kernel.org>
To: harrison@crosse.dev, 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>,
Yeoreum Yun <yeoreum.yun@arm.com>
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>,
stable@vger.kernel.org
Subject: Re: [PATCH 1/2] mm/gup: make mlock() and MAP_POPULATE handle VM_FAULT_RETRY properly
Date: Thu, 19 Nov 2026 00:25:31 +0100 [thread overview]
Message-ID: <e32482de-295a-4e26-b6ae-5b8b58f8b98c@kernel.org> (raw)
In-Reply-To: <20261118-mmpop-populate-v1-1-9c561d178d11@crosse.dev>
On 11/18/26 22:56, Harrison Crosse via B4 Relay wrote:
> From: Harrison Crosse <harrison@crosse.dev>
>
> If every read of a page of a file mapping fails, mmap(MAP_POPULATE)
> and mlock() of that mapping do not return: the task spins in
> __mm_populate(), submitting a new read of the page on each iteration,
> until it gets a fatal signal. Touching the same page gets SIGBUS, and
> madvise(MADV_POPULATE_READ) fails with -EFAULT.
>
> The first fault on the page reaches filemap_fault() with
> FAULT_FLAG_ALLOW_RETRY and without FAULT_FLAG_TRIED. filemap_fault()
> releases the mmap_lock to read the page and, because it released the
> lock, returns VM_FAULT_RETRY before it looks at the result of the read.
> It cannot report the error then: a fault that has released the lock
> returns VM_FAULT_RETRY or VM_FAULT_COMPLETED, and neither carries an
> error. faultin_page() turns VM_FAULT_RETRY into -EBUSY, so
> __get_user_pages() stops at that page without an error, and
> __mm_populate() calls populate_vma_page_range() again at that address,
> again without FOLL_TRIED. The page fault handlers and
> __get_user_pages_locked() retry with FAULT_FLAG_TRIED instead, and on
> that attempt filemap_fault() reads the page with the lock held and
> returns VM_FAULT_SIGBUS if the read fails.
>
> Commit 631426ba1d45 ("mm/madvise: make MADV_POPULATE_(READ|WRITE) handle
> VM_FAULT_RETRY properly") fixed the same loop for MADV_POPULATE_* by
> calling __get_user_pages_locked(). That does not fit here:
> __get_user_pages_locked() retakes the mmap_lock itself and carries on
> with the GUP flags it was given, while populate_vma_page_range()
> derives those flags from the VMA that __mm_populate() looks up again,
> and may skip, after each unlock. Retrying with a NULL locked instead
> would drop FAULT_FLAG_ALLOW_RETRY and FAULT_FLAG_KILLABLE, so a
> userfaultfd range would fail rather than wait, and folio lock waits
> would not be killable.
>
> Instead, have __mm_populate() remember the address of the page whose
> fault released the mmap_lock. When the next iteration starts at that
> address, fault in that page alone with FOLL_TRIED, as
> __get_user_pages_locked() does, then continue with the rest of the
> range as before. The retry reads the page with the mmap_lock held, as
> filemap_fault() did for a page that was not uptodate before v5.1, and
> as the other GUP retries do. With a persistent read error the retry
> fails with -EFAULT: mlock() returns -ENOMEM
> (__mlock_posix_error_return() maps -EFAULT to it), and MAP_POPULATE,
> which ignores populate errors, returns the mapping. A fatal signal
> still ends the loop, with -EINTR from __get_user_pages() or, if it
> interrupts the FOLL_TRIED read, with -EFAULT. The other callers of
> populate_vma_page_range() pass a NULL locked, so they cannot get
> VM_FAULT_RETRY and are unchanged.
>
> Reproduced with ext4 on dm-linear over a loop device, with the eight
> sectors of one page of a file mapped to the dm "error" target, on arm64
> (Debian's 6.12.116 and v7.4-rc3) and x86_64 (v7.4-rc3): mmap(MAP_POPULATE)
> and mlock() of the file were still running in the kernel after 5 seconds
> and ended when sent SIGKILL. On 6.12.116, the block layer tracepoints
> showed about 280,000 bios a second being submitted and failed.
>
> The analysis, the patch and this changelog were prepared with the help
> of an AI coding assistant (Claude).
Yes, that's rather obvious from looking at it, thanks for documenting that :)
Thanks for the report!
[...]
> + *
> + * filemap_fault() reports a read error only when
> + * FAULT_FLAG_TRIED is set: on a first attempt it releases the
> + * mmap_lock for the read and returns VM_FAULT_RETRY whatever
> + * the result. So when the last call released the lock at
> + * nstart, retry that page with FOLL_TRIED, and only that page,
> + * so that later pages still get a first attempt that releases
> + * the lock for the read. Compare the address because nstart
> + * moves past that page if it is no longer mapped, or its VMA
> + * is skipped, when the lock is retaken.
> */
> - ret = populate_vma_page_range(vma, nstart, nend, &locked);
> + tried = retry && nstart == retry_addr;
> + ret = __populate_vma_page_range(vma, nstart,
> + tried ? nstart + PAGE_SIZE : nend,
> + &locked, tried);
Yeah, that's quite the ugly code. Let me take care of this (or find someone more
familiar with that code that can help).
@Yeoreum, do you have some spare cycles?
--
Cheers,
David
next prev parent reply other threads:[~2026-11-18 23:25 UTC|newest]
Thread overview: 9+ messages / expand[flat|nested] mbox.gz Atom feed top
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 ` Harrison Crosse
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 ` Harrison Crosse
2026-11-18 23:25 ` David Hildenbrand (Arm) [this message]
2026-11-18 23:59 ` Harrison Crosse
2026-11-19 9:43 ` Yeoreum Yun
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
2026-11-18 21:56 ` Harrison Crosse
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=e32482de-295a-4e26-b6ae-5b8b58f8b98c@kernel.org \
--to=david@kernel.org \
--cc=akpm@linux-foundation.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 \
--cc=yeoreum.yun@arm.com \
/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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.