Re: [PATCH 19/21] mm/hugetlb: use the VMA lock to stabilize flags for PMD sharing
From: Suren Baghdasaryan
Date: Tue Dec 01 2026 - 12:17:15 EST
On Tue, Dec 1, 2026 at 8:51 AM Lorenzo Stoakes (ARM) <ljs@xxxxxxxxxx> 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?
>
> >
> > 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 :)
>
> >
> > 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.
>
> 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, it does not block on contention, it is designed to be used in a
fastpath with a fallback that would block.
>
> 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.
Completely agree.
This patch does not introduce a new trylock functionality. It just
exposes an internal function, namely vma_start_read() to the outside
world.
Sorry but NACK.
>
> 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 :)
>
> This seems like a perf optimisation rather than a bug fix so I think it's
> safe too.
>
> (Also not really all that worried about making PMD page table sharing less
> likely, that is a cursed broken thing in itself :P)
>
> --
> Cheers, Lorenzo