From: "David Hildenbrand (Red Hat)" <david@kernel.org>
To: Jinchao Wang <wangjinchao600@gmail.com>
Cc: Matthew Wilcox <willy@infradead.org>,
Andrew Morton <akpm@linux-foundation.org>,
Zi Yan <ziy@nvidia.com>, Matthew Brost <matthew.brost@intel.com>,
Joshua Hahn <joshua.hahnjy@gmail.com>,
Rakie Kim <rakie.kim@sk.com>, Byungchul Park <byungchul@sk.com>,
Gregory Price <gourry@gourry.net>,
Ying Huang <ying.huang@linux.alibaba.com>,
Alistair Popple <apopple@nvidia.com>,
linux-mm@kvack.org, linux-kernel@vger.kernel.org,
syzbot+2d9c96466c978346b55f@syzkaller.appspotmail.com
Subject: Re: [PATCH] mm/migrate: fix hugetlbfs deadlock by respecting lock ordering
Date: Fri, 9 Jan 2026 15:18:37 +0100 [thread overview]
Message-ID: <e792db5f-5ec4-4960-a2f8-fde490e0e366@kernel.org> (raw)
In-Reply-To: <aWENkov0R-1nIB8M@ndev>
On 1/9/26 15:16, Jinchao Wang wrote:
> On Fri, Jan 09, 2026 at 02:39:08PM +0100, David Hildenbrand (Red Hat) wrote:
>> On 1/9/26 04:47, Jinchao Wang wrote:
>>> Fix an AB-BA deadlock between hugetlbfs_punch_hole() and page migration.
>>>
>>> The deadlock occurs because migration violates the lock ordering defined
>>> in mm/rmap.c for hugetlbfs:
>>>
>>> * hugetlbfs PageHuge() take locks in this order:
>>> * hugetlb_fault_mutex
>>> * vma_lock
>>> * mapping->i_mmap_rwsem
>>> * folio_lock
>>>
>>> The following trace illustrates the inversion:
>>>
>>> Task A (punch_hole): Task B (migration):
>>> -------------------- -------------------
>>> 1. i_mmap_lock_write(mapping) 1. folio_lock(folio)
>>> 2. folio_lock(folio) 2. i_mmap_lock_read(mapping)
>>> (blocks waiting for B) (blocks waiting for A)
>>>
>>> Task A is blocked in the punch-hole path:
>>> hugetlbfs_fallocate
>>> hugetlbfs_punch_hole
>>> hugetlbfs_zero_partial_page
>>> folio_lock
>>>
>>> Task B is blocked in the migration path:
>>> migrate_pages
>>> unmap_and_move_huge_page
>>> remove_migration_ptes
>>> __rmap_walk_file
>>> i_mmap_lock_read
>>>
>>> To fix this, adjust unmap_and_move_huge_page() to respect the established
>>> hierarchy. If i_mmap_rwsem is acquired during try_to_migrate(), hold it
>>
>>
>> I'm confused. Isn't it unmap_and_move_huge_page() that grabs the
>> i_mmap_rwsem during hugetlb_page_mapping_lock_write() (where we do a
>> try-lock)?
> Yes, but the lock is released before remove_migration_ptes().
>
> Task A can enter the race window between
> i_mmap_unlock_write(mapping)
> and
> remove_migration_ptes() -> i_mmap_lock_read(mapping).
>
> This window was introduced by the change below:
> https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/diff/mm/migrate.c?id=336bf30eb765
try_to_migrate() is not the problem, but remove_migration_ptes() ?
Anyhow, I saw that Willy sent out a version.
--
Cheers
David
next prev parent reply other threads:[~2026-01-09 14:18 UTC|newest]
Thread overview: 10+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-01-09 3:47 Jinchao Wang
2026-01-09 4:06 ` Matthew Wilcox
2026-01-09 5:17 ` Jinchao Wang
2026-01-09 6:37 ` Huang, Ying
2026-01-09 8:08 ` Jinchao Wang
2026-01-09 13:39 ` David Hildenbrand (Red Hat)
2026-01-09 14:16 ` Jinchao Wang
2026-01-09 14:18 ` David Hildenbrand (Red Hat) [this message]
2026-01-09 15:32 ` Jinchao Wang
2026-01-09 15:41 ` David Hildenbrand (Red Hat)
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=e792db5f-5ec4-4960-a2f8-fde490e0e366@kernel.org \
--to=david@kernel.org \
--cc=akpm@linux-foundation.org \
--cc=apopple@nvidia.com \
--cc=byungchul@sk.com \
--cc=gourry@gourry.net \
--cc=joshua.hahnjy@gmail.com \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-mm@kvack.org \
--cc=matthew.brost@intel.com \
--cc=rakie.kim@sk.com \
--cc=syzbot+2d9c96466c978346b55f@syzkaller.appspotmail.com \
--cc=wangjinchao600@gmail.com \
--cc=willy@infradead.org \
--cc=ying.huang@linux.alibaba.com \
--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