Re: [PATCH 19/21] mm/hugetlb: use the VMA lock to stabilize flags for PMD sharing
From: David Hildenbrand (Arm)
Date: Tue Dec 01 2026 - 12:16:12 EST
On 12/1/26 17:50, Lorenzo Stoakes (ARM) wrote:
> On Wed, Nov 25, 2026 at 11:33:17PM +0100, David Hildenbrand (Arm) wrote:
>> huge_pmd_share() currently only shares the page tables of another VMA if
>> it can read-lock the mmap lock of the corresponding mm. That refuses
>> sharing whenever that mm is write-locked or if the mmap lock is
>> contended.
>
> Is this much of a problem really? I'm not sure this change is really worth
> it?
We'll now no longer share PMD tables if the mmap lock of the target is write
locked or contented.
I'm not sure how much of a problem that will be in practice. I guess in the
worst case you end up with a couple of sets of PMD tables. So some more memory
consumption but likely still a clear benefit.
>
>>
>> mprotect() holds the VMA write lock while changing the flags and the
>> page table entries, so let's read-lock only that VMA instead. As we hold
>> i_mmap_rwsem, that VMA remains part of its mm and cannot go away.
>
> Ugh lord :)
Tell me about it ... :)
>
>>
>> Add vma_trylock_read(), a variant of vma_start_read(), that does not
>> require being called with the RCU read lock held, and will also not drop
>> it itself.
>
> (As discussed off-list)
>
> Hmm you're not adding a variant on vma_start_read(), you're creating a
> completely distinct API for obtaining a VMA read lock, without a fallback.
Right, no fallback needed, because we just skup in the caller as if trylocking
the mmap_lock would fail.
>
> And one that relies upon the caller getting things right re: dependent
> locks.
>
> And given what we've seen in BPF recently, it turns out people already find
> ways to open-code things to be broken so I fear what they might do with
> this.
>
> Also note that all VMA read locks are trylocks (yes I know a lot of the API
> stuff here is a mess :)
>
> Right now lock_vma_under_rcu() is the way (TM) to get a VMA lock without an
> mmap lock already held. For now I'd like to maintain it as that.
>
> So overall can we drop this patch? It doesn't seem critical and hugetlb
> screwing itself over by being built as a series of hacks-on-hacks seems
> like a hugetlb problem :)
I'm happy to drop it and to see if anybody complains. Using the vma lock when we
had one felt like the right thing to do, but if this exposes an API that is easy
to abuse by others, then we can just defer it until it is an actual problem.
Thanks!
--
Cheers,
David