Re: [PATCH v9 08/69] mm: start tracking VMAs with maple tree

Liam Howlett
2022-05-12T17:51:36Z

* Qian Cai <quic_qiancai@quicinc.com> [220512 13:01]:
> On Wed, May 04, 2022 at 01:07:52AM +0000, Liam Howlett wrote:
> > From: "Liam R. Howlett" <Liam.Howlett@Oracle.com>
> >
> > Start tracking the VMAs with the new maple tree structure in parallel with
> > the rb_tree. Add debug and trace events for maple tree operations and
> > duplicate the rb_tree that is created on forks into the maple tree.
> >
> > The maple tree is added to the mm_struct including the mm_init struct,
> > added support in required mm/mmap functions, added tracking in kernel/fork
> > for process forking, and used to find the unmapped_area and checked
> > against what the rbtree finds.
> >
> > This also moves the mmap_lock() in exit_mmap() since the oom reaper call
> > does walk the VMAs. Otherwise lockdep will be unhappy if oom happens.
> >
> > Signed-off-by: Liam R. Howlett <Liam.Howlett@Oracle.com>
> > Signed-off-by: Matthew Wilcox (Oracle) <willy@infradead.org>
> ...
> > @@ -2479,9 +2693,14 @@ int expand_downwards(struct vm_area_struct *vma,
> > return -ENOMEM;
> > }
> >
> > + if (mas_preallocate(&mas, vma, GFP_KERNEL))
>
> We have thousands of leaks reports here from kmemleak while running some
> syscall fuzzers on today's linux-next tree.

Thanks for the report. Yes, this is mine. I am testing a fix now.

>
> unreferenced object 0xffff0803c0063d00 (size 256):
> comm "trinity-c25", pid 177739, jiffies 4297781293 (age 354.988s)
> hex dump (first 32 bytes):
> 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ................
> 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ................
> backtrace:
> slab_post_alloc_hook
> kmem_cache_alloc_bulk
> mas_alloc_nodes
> mas_preallocate
> mas_preallocate at lib/maple_tree.c:5579
> expand_downwards
> expand_downwards at mm/mmap.c:2094
> expand_stack
> do_page_fault
> do_translation_fault
> do_mem_abort
> el1_abort
> el1h_64_sync_handler
> el1h_64_sync
> handle_futex_death
> exit_robust_list
> futex_exit_release
> exit_mm_release
>
> > + return -ENOMEM;
> > +
> > /* We must make sure the anon_vma is allocated. */
> > - if (unlikely(anon_vma_prepare(vma)))
> > + if (unlikely(anon_vma_prepare(vma))) {
> > + mas_destroy(&mas);
> > return -ENOMEM;
> > + }
> >
> > /*
> > * vma->vm_start/vm_end cannot change under us because the caller