[PATCH v1 8/9] mm/vma: Use unmap_desc in vms_clear_ptes() and exit_mmap()

Liam R. Howlett Liam.Howlett at oracle.com
Thu Sep 11 09:59:28 PDT 2025


* Suren Baghdasaryan <surenb at google.com> [250909 18:16]:
> On Tue, Sep 9, 2025 at 12:10 PM Liam R. Howlett <Liam.Howlett at oracle.com> wrote:
> >
> > vms_clear_ptes() is slightly different than other callers to
> > unmap_region() and so had the unmapping open-coded.  Using the new
> > structure it is now possible to special-case the struct setup instead of
> > having the open-coded function.
> >
> > exit_mmap() also calls unmap_vmas() with many arguemnts.  Using the
> > unmap_all_init() function to set the unmap descriptor for all vmas makes
> > this a bit easier to read.
> >
> > Update to the vma test code is necessary to ensure testing continues to
> > function.
> >
> > No functional changes intended.
> >
> > Signed-off-by: Liam R. Howlett <Liam.Howlett at oracle.com>
> > ---
> >  include/linux/mm.h               |  3 ---
> >  mm/internal.h                    |  3 +++
> >  mm/memory.c                      | 24 ++++++++------------
> >  mm/mmap.c                        |  5 +++-
> >  mm/vma.c                         | 39 ++++++++++++++++++--------------
> >  mm/vma.h                         | 14 ++++++++++++
> >  tools/testing/vma/vma_internal.h | 14 ++++--------
> >  7 files changed, 56 insertions(+), 46 deletions(-)

...

> >         struct vm_area_struct *vma;
> >         unsigned long nr_accounted = 0;
> >         VMA_ITERATOR(vmi, mm, 0);
> > +       struct unmap_desc unmap;
> >
> >         /* mm's last user has gone, and its about to be pulled down */
> >         mmu_notifier_release(mm);
> >
> > +       unmap.mm_wr_locked = false;
> 
> This will be reset by unmap_all_init() anyway, right?

Yes, I will drop that.  Thanks, I missed this when I rewrote to use a
different function.

> 
> >         mmap_read_lock(mm);
> >         arch_exit_mmap(mm);
> >
> > @@ -1295,11 +1297,12 @@ void exit_mmap(struct mm_struct *mm)
> >                 goto destroy;
> >         }
> >
> > +       unmap_all_init(&unmap, &vmi, vma);
> 
> Can we use a macro, something like DEFINE_UNMAP_ALL_REGIONS() instead
> of unmap_all_init()?

No, because the vma is unknown and we set up some of the unmap_desc from
the values in vma.

> 
> >         flush_cache_mm(mm);
> >         tlb_gather_mmu_fullmm(&tlb, mm);
> >         /* update_hiwater_rss(mm) here? but nobody should be looking */
> >         /* Use ULONG_MAX here to ensure all VMAs in the mm are unmapped */
> > -       unmap_vmas(&tlb, &vmi.mas, vma, 0, ULONG_MAX, ULONG_MAX, false);
> > +       unmap_vmas(&tlb, &unmap);
> >         mmap_read_unlock(mm);

...

Thanks,
Liam



More information about the maple-tree mailing list