Re: [PATCH v2 1/2] mm: move mmap/vma locking logic into specific files
From: Lorenzo Stoakes
Date: Wed Apr 16 2025 - 10:44:19 EST
On Wed, Apr 16, 2025 at 04:39:50PM +0200, Vlastimil Babka wrote:
> On 4/16/25 12:38, Lorenzo Stoakes wrote:
> > Currently the VMA and mmap locking logic is entangled in two of the most
> > overwrought files in mm - include/linux/mm.h and mm/memory.c. Separate this
> > logic out so we can more easily make changes and create an appropriate
> > MAINTAINERS entry that spans only the logic relating to locking.
> >
> > This should have no functional change. Care is taken to avoid dependency
> > loops, we must regrettably keep release_fault_lock() and
> > assert_fault_locked() in mm.h as a result due to the dependence on the
> > vm_fault type.
> >
> > Additionally we must declare rcuwait_wake_up() manually to avoid a
> > dependency cycle on linux/rcuwait.h.
> >
> > Additionally move the nommu implementatino of lock_mm_and_find_vma() to
> > mmap_lock.c so everything lock-related is in one place.
> >
> > Signed-off-by: Lorenzo Stoakes <lorenzo.stoakes@xxxxxxxxxx>
> > Reviewed-by: Suren Baghdasaryan <surenb@xxxxxxxxxx>
>
> Reviewed-by: Vlastimil Babka <vbabka@xxxxxxx>
Thanks!
>
> > diff --git a/mm/mmap_lock.c b/mm/mmap_lock.c
> > index e7dbaf96aa17..5f725cc67334 100644
> > --- a/mm/mmap_lock.c
> > +++ b/mm/mmap_lock.c
> > @@ -42,3 +42,276 @@ void __mmap_lock_do_trace_released(struct mm_struct *mm, bool write)
> > }
> > EXPORT_SYMBOL(__mmap_lock_do_trace_released);
> > #endif /* CONFIG_TRACING */
> > +
> > +#ifdef CONFIG_MMU
> > +#ifdef CONFIG_PER_VMA_LOCK
>
> CONFIG_MMU is implied by CONFIG_PER_VMA_LOCK so you could move the first
> #ifdef later to make only #ifdef CONFIG_LOCK_MM_AND_FIND_VMA nested in it.
> But doesn't matter that much.
>
Yeah, as I said to Suren, I really like to be super-explicit about this,
nommu is such a painful and horrible thing that I like to really clearly
mark when we are doing a workaround for it rather than have it implicit.
Obviously I take the point, and we often do things implicitly, but I feel
overall it's better to spell it out super clearly here!