Re: [PATCH v3] mm/vmalloc: fix data race in show_numa_info()

From: Jeongjun Park
Date: Thu May 08 2025 - 00:47:51 EST


Andrew Morton <akpm@xxxxxxxxxxxxxxxxxxxx> wrote:
>
> On Wed, 7 May 2025 23:25:52 +0900 Jeongjun Park <aha310510@xxxxxxxxx> wrote:
>
> > The following data-race was found in show_numa_info():
> >
> > ...
> >
> >
> > According to this report, there is a read/write data-race because m->private
> > is accessible to multiple CPUs. To fix this, instead of allocating the heap
> > in proc_vmalloc_init() and passing the heap address to m->private,
> > show_numa_info() should allocate the heap.
> >
> > One thing to note is that show_numa_info() is called in a critical section
> > of a spinlock, so it must be allocated on the heap with GFP_ATOMIC flag.
>
> GFP_ATOMIC is unfortunate. Can vmalloc_info_show() allocate the
> storage outside the lock and pass that pointer into show_numa_info()?
> That way will be more efficient also, less allocating and freeing.
>
>

That's good idea! Definitely, if you modify vmalloc_info_show() to
allocate the heap before taking the spinlock and initialize the heap
to 0 at the beginning of the loop, we don't need to use GFP_ATOMIC,
and we only need to allocate the heap once, which is much more efficient.

I'll send you v4 patch that reflects this right away.

Regards,

Jeongjun Park