Re: [PATCH] mm/hugetlb: avoid recursive i_mmap_rwsem in PMD sharing

From: David Hildenbrand (Arm)

Date: Sat Oct 10 2026 - 09:22:25 EST


On 10/10/26 08:37, Li Zhe wrote:
> On 10/10/26 2:05 AM, David Hildenbrand (Arm) wrote:
>> On 10/9/26 13:52, Lorenzo Stoakes (ARM) wrote:
>>> Yeah I don't see why not! I don't think there's anything that needs to be
>>> private here.
>> Li, see below, can you work with the below?
>
>
> Thanks for the patch. I tested it with my original mremap reproducer, and
> I can no longer reproduce the hung task.
>
> I also checked the hugetlb_change_protection() / uffd-wp path Jose
> mentioned. That path can reach hugetlb_change_protection() and
> huge_pte_alloc(), but it does not enter huge_pmd_share(), because
> VM_UFFD_WP makes want_pmd_share() return false via
> uffd_disable_huge_pmd_share().
>
> My understanding of your patch is that we preallocate the destination
> hugetlb page tables before taking the mapping's i_mmap_rwsem in write
> mode. Then, while holding i_mmap_rwsem, we only walk the preallocated
> destination PTEs and move the source huge PTEs over. This avoids calling
> huge_pte_alloc(), and therefore huge_pmd_share(), while already holding
> i_mmap_rwsem for write.
>
> Does that match your intended direction? If so, I will go through the
> details and make sure there are no issues, then send a v2 based on this
> approach.

Yes, please. make sure to keep Lorenzo's SOB/authorship. If you perform
modifications (patch/commit message) add your co-developed-by + SOB when sending
it out.

--
Cheers,

David