Re: [PATCH v3 1/5] mm: Make per-VMA locks available universally
From: Suren Baghdasaryan
Date: Mon Aug 03 2026 - 13:52:47 EST
On Mon, Aug 3, 2026 at 10:41 AM Suren Baghdasaryan <surenb@xxxxxxxxxx> wrote:
>
> On Mon, Aug 3, 2026 at 9:08 AM Lorenzo Stoakes (ARM) <ljs@xxxxxxxxxx> wrote:
> >
> > On Mon, Aug 03, 2026 at 08:24:44AM -0700, Suren Baghdasaryan wrote:
> > > On Sun, Aug 2, 2026 at 2:55 PM Suren Baghdasaryan <surenb@xxxxxxxxxx> wrote:
> > > >
> > > > From: Dave Hansen <dave.hansen@xxxxxxxxxxxxxxx>
> > > >
> > > > The per-VMA locks have been around for several years. They've had some
> > > > bugs worked out of them and have seen quite wide use. However, they
> > > > are still only available when architectures explicitly enable them.
> > > > Remove the conditional compilation around the per-VMA locks, making
> > > > them available on all architectures and configs.
> > > >
> > > > The approach up to now seemed to be to add ARCH_SUPPORTS_PER_VMA_LOCK
> > > > when the architecture started using per-VMA locks in the fault
> > > > handler. But, contrary to the naming, the Kconfig option does not
> > > > really indicate whether the architecture supports per-VMA locks or
> > > > not. It is more of a marker for whether the architecture is likely to
> > > > benefit from per-VMA locks.
> > > >
> > > > To me, the most important thing side-effect of universal availability
> > > > is letting per-VMA locks be used in SMP=n configs. This lets us use
> > > > per-VMA locking in all x86 code without fallbacks.
> > > >
> > > > Overall, this just generally makes the kernel simpler. Just look at
> > > > the diffstat. It also opens the door to users that want to use the
> > > > per-VMA locks in common code. Doing *that* brings additional
> > > > simplifications.
> > > >
> > > > The downside of this is adding some fields to vm_area_struct and
> > > > mm_struct. There are likely ways to optimize this, especially for
> > > > things like SMP=n configs. For now, do the simplest thing: use the
> > > > same implementation everywhere.
> > > >
> > > > Signed-off-by: Dave Hansen <dave.hansen@xxxxxxxxxxxxxxx>
> > > > Signed-off-by: Suren Baghdasaryan <surenb@xxxxxxxxxx>
> > > > Cc: Suren Baghdasaryan <surenb@xxxxxxxxxx>
> > > > Cc: Andrew Morton <akpm@xxxxxxxxxxxxxxxxxxxx>
> > > > Cc: "Liam R. Howlett" <Liam.Howlett@xxxxxxxxxx>
> > > > Cc: Lorenzo Stoakes <ljs@xxxxxxxxxx>
> > > > Cc: Vlastimil Babka <vbabka@xxxxxxxxxx>
> > > > Cc: Shakeel Butt <shakeel.butt@xxxxxxxxx>
> > > > Cc: linux-mm@xxxxxxxxx
> > > > Cc: Greg Kroah-Hartman <gregkh@xxxxxxxxxxxxxxxxxxx>
> > > > Cc: Arve Hjønnevåg <arve@xxxxxxxxxxx>
> > > > Cc: Todd Kjos <tkjos@xxxxxxxxxxx>
> > > > Cc: Christian Brauner <christian@xxxxxxxxxx>
> > > > Cc: Carlos Llamas <cmllamas@xxxxxxxxxx>
> > > > Cc: Alice Ryhl <aliceryhl@xxxxxxxxxx>
> > > > Cc: "David S. Miller" <davem@xxxxxxxxxxxxx>
> > > > Cc: David Ahern <dsahern@xxxxxxxxxx>
> > > > Cc: netdev@xxxxxxxxxxxxxxx
> > > > ---
> >
> > <snip>
> >
> > > > -#endif /* CONFIG_PER_VMA_LOCK */
> > >
> > > Now that I'm looking closer into this, I think we would break NOMMU
> > > case because nommu.c does not take VMA write locks at all. So,
> > > lock_vma_under_rcu() for example would always succeed.
> >
> > I don't think anything's broken actually.
> >
> > Per-VMA locks was gated on CONFIG_MMU so nothing there assumes per-VMA flags,
> > but now you have stuff that happens that didn't before but:
> >
> > * vm_area_free() -> vma_assert_detached() - fine - it's always detached in nommu.
> > * vm_area_dup() -> vma_lock_init() - no asserts, just sets refcount to 0 (correct).
> >
> > AFAICT nothing else.
> >
> > So seems fine to me?
>
> One place that needs fixing is in BPF iterators. They use
> lock_vma_under_rcu() which would always succeeds even if the VMA is
> being modified. Instead of removing !IS_ENABLED(CONFIG_PER_VMA_LOCK)
> check in bpf_iter_task_vma_new() I'll need to change it to
> !IS_ENABLED(CONFIG_MMU).
> I'll look into other parts and try to verify they do not affect NOMMU
> but ultimately I would like to run some tests with this config, which
> is not trivial...
>
> >
> > >
> > > Extra per_VMA lock-related fields in the vm_area_struct and mm_struct
> > > would also inflate NOMMU structure sizes without them being used. I'm
> > > not sure if this is an issue we should consider.
> >
> > As nommu co-maintainer, no it's not :) I won't have that stuff blocking
> > important changes for real arches.
> >
> > Go ahead! :)
Thanks for confirmation!
> >
> > --
> > Cheers, Lorenzo