From: "David Hildenbrand (Arm)" <david@kernel.org>
To: junho.cha@xcena.com, Andrew Morton <akpm@linux-foundation.org>
Cc: "Matthew Wilcox (Oracle)" <willy@infradead.org>,
"Jan Kara" <jack@suse.cz>, "Zi Yan" <ziy@nvidia.com>,
"Alistair Popple" <apopple@nvidia.com>,
"Matthew Brost" <matthew.brost@intel.com>,
"Thomas Hellström" <thomas.hellstrom@linux.intel.com>,
"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>,
linux-mm@kvack.org, linux-kernel@vger.kernel.org
Subject: Re: [PATCH] mm/migrate: drop the fault lock and wait killably for migration entries
Date: Tue, 17 Nov 2026 10:46:24 +0100 [thread overview]
Message-ID: <d463af46-13c3-47f7-8b26-702a8edcd140@kernel.org> (raw)
In-Reply-To: <20261117-junhomax-fix-mm-migrate-killable-v1-1-f6e7b135a159@xcena.com>
On 11/17/26 10:26, Junho Cha via B4 Relay wrote:
> From: Junho Cha <junho.cha@xcena.com>
>
> A fault that finds a migration entry sleeps in
> softleaf_entry_wait_on_locked() until the entry goes away. So does a
> fault on a device-private entry whose folio is locked by another
> thread, since commit b570f37a2ce4 ("mm: Fix a hmm_range_fault()
> livelock / starvation problem"). The wait is in TASK_UNINTERRUPTIBLE
> and keeps the mmap_lock or per-VMA lock held throughout.
>
> That is fine while a migration takes microseconds. It is not when the
> migration is slow:
>
> - The wait cannot be killed. The signal_pending_state() check in the
> wait loop never fires, because TASK_UNINTERRUPTIBLE contains neither
> TASK_INTERRUPTIBLE nor TASK_WAKEKILL. For example, if the
> migrate_to_ram() handler of a device-private folio waits for a
> device that has stalled, every other thread that faults on the page
> sits in D state, and the only symptom is a hung task warning.
>
> - The fault lock is held across the wait. This matters when the
> migration itself runs without that lock, as for move_pages(),
> compaction or memory offlining. A writer that arrives in the
> meantime, such as munmap() of another page in the same VMA, waits
> for the migration to finish, and faults that come after the writer
> queue behind it. migrate_to_ram() is called with the fault lock
> held, so for device-private folios only the first point applies.
>
> Making the wait killable alone is not enough. A fault that returns 0
> is retried, so a kernel-mode fault from a uaccess routine would fault
> again on the same entry, return at once because the signal is still
> pending, and spin until the migration completes. The fault has to
> return VM_FAULT_RETRY so that fault_signal_pending() can end it.
>
> Handle the fault lock the way __folio_lock_or_retry() does. Pass the
> vm_fault to softleaf_entry_wait_on_locked() from do_swap_page(). On the
> first attempt of a retryable fault, drop the fault lock before sleeping
> and return VM_FAULT_RETRY, or return at once for
> FAULT_FLAG_RETRY_NOWAIT. A FAULT_FLAG_KILLABLE fault sleeps in
> TASK_KILLABLE, and if a fatal signal ends a wait that still holds the
> lock, drop it and return VM_FAULT_RETRY.
>
> Dropping the lock there is safe. The wait entry is queued before the
> ptl is released, and the entry can only be removed under that ptl, so
> no wake up is missed. Nothing after that uses the vma, and
> folio_waitqueue() points into a global hash table, not into the folio.
>
> Callers outside the fault path (hmm, userfaultfd, huge_memory) and the
> PMD and hugetlb waits pass NULL and keep the current behaviour.
>
> Tested by holding the migration entries for 8 seconds, with a delay
> added after the unmap step of move_pages() and in test_hmm's
> migrate_to_ram():
>
> - SIGKILL to a process waiting on the entry, from user mode or from a
> write() that copies from the page, ends it within a millisecond
> instead of after the migration. The same holds for a thread waiting
> on a device-private folio.
> - munmap() of another page in the same VMA no longer waits for the
> migration.
> - Without a signal, the write() completes after the migration with
> the right data, using under a millisecond of system time.
> - hmm-tests results are unchanged, and lockdep reports nothing.
>
> Signed-off-by: Junho Cha <junho.cha@xcena.com>
> ---
Hi,
I assume
* this was not hit in the wild but found with an LLM.
* Most of the code and patch description were written with an LLM.
Correct?
--
Cheers,
David
prev parent reply other threads:[~2026-11-17 9:46 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-11-17 9:26 [PATCH] mm/migrate: drop the fault lock and wait killably for migration entries Junho Cha via B4 Relay
2026-11-17 9:46 ` David Hildenbrand (Arm) [this message]
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=d463af46-13c3-47f7-8b26-702a8edcd140@kernel.org \
--to=david@kernel.org \
--cc=akpm@linux-foundation.org \
--cc=apopple@nvidia.com \
--cc=jack@suse.cz \
--cc=junho.cha@xcena.com \
--cc=liam@infradead.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-mm@kvack.org \
--cc=ljs@kernel.org \
--cc=matthew.brost@intel.com \
--cc=mhocko@suse.com \
--cc=rppt@kernel.org \
--cc=surenb@google.com \
--cc=thomas.hellstrom@linux.intel.com \
--cc=vbabka@kernel.org \
--cc=willy@infradead.org \
--cc=ziy@nvidia.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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox