Re: [PATCH v2 2/7] mm/vmalloc.c: add flags to mark vm_map_ram area

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On 12/17/22 at 11:44am, Lorenzo Stoakes wrote:
> On Sat, Dec 17, 2022 at 09:54:30AM +0800, Baoquan He wrote:
> > @@ -2229,8 +2236,12 @@ void vm_unmap_ram(const void *mem, unsigned int count)
> >  		return;
> >  	}
> >
> > -	va = find_vmap_area(addr);
> > +	spin_lock(&vmap_area_lock);
> > +	va = __find_vmap_area((unsigned long)addr, &vmap_area_root);
> >  	BUG_ON(!va);
> > +	if (va)
> > +		va->flags &= ~VMAP_RAM;
> > +	spin_unlock(&vmap_area_lock);
> >  	debug_check_no_locks_freed((void *)va->va_start,
> >  				    (va->va_end - va->va_start));
> >  	free_unmap_vmap_area(va);
> 
> Would it be better to perform the BUG_ON() after the lock is released? You
> already check if va exists before unmasking so it's safe.

It's a little unclear to me why we care BUG_ON() is performed before or
after the lock released. We won't have a stable kernel after BUG_ON()(),
right?
> 
> Also, do we want to clear VMAP_BLOCK here?

I do, but I don't find a good place to clear VMAP_BLOCK.

In v1, I tried to clear it in free_vmap_area_noflush() as below,
Uladzislau dislikes it. So I remove it. My thinking is when we unmap and
free the vmap area, the vmap_area is moved from vmap_area_root into
&free_vmap_area_root. When we allocate a new vmap_area via
alloc_vmap_area(), we will allocate a new va by kmem_cache_alloc_node(),
the va->flags must be 0. Seems not initializing it to 0 won't impact
thing.

diff --git a/mm/vmalloc.c b/mm/vmalloc.c
index 5d3fd3e6fe09..d6f376060d83 100644
--- a/mm/vmalloc.c
+++ b/mm/vmalloc.c
@@ -1815,6 +1815,7 @@ static void free_vmap_area_noflush(struct vmap_area *va)

        spin_lock(&vmap_area_lock);
        unlink_va(va, &vmap_area_root);
+       va->flags = 0;
        spin_unlock(&vmap_area_lock);

        nr_lazy = atomic_long_add_return((va->va_end - va->va_start) >>

> 





[Index of Archives]     [Linux ARM Kernel]     [Linux ARM]     [Linux Omap]     [Fedora ARM]     [IETF Annouce]     [Bugtraq]     [Linux OMAP]     [Linux MIPS]     [eCos]     [Asterisk Internet PBX]     [Linux API]

  Powered by Linux