Skip to content

Commit 0818e73

Browse files
joelagnelakpm00
authored andcommitted
mm/vmalloc: add a safer version of find_vm_area() for debug
It is unsafe to dump vmalloc area information when trying to do so from some contexts. Add a safer trylock version of the same function to do a best-effort VMA finding and use it from vmalloc_dump_obj(). [applied test robot feedback on unused function fix.] [applied Uladzislau feedback on locking.] Link: https://lkml.kernel.org/r/[email protected] Fixes: 98f1808 ("mm: Make mem_dump_obj() handle vmalloc() memory") Signed-off-by: Joel Fernandes (Google) <[email protected]> Reviewed-by: Uladzislau Rezki (Sony) <[email protected]> Reported-by: Zhen Lei <[email protected]> Cc: Paul E. McKenney <[email protected]> Cc: Zqiang <[email protected]> Cc: <[email protected]> Cc: Matthew Wilcox (Oracle) <[email protected]> Signed-off-by: Andrew Morton <[email protected]>
1 parent 7f33105 commit 0818e73

File tree

1 file changed

+22
-4
lines changed

1 file changed

+22
-4
lines changed

mm/vmalloc.c

Lines changed: 22 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4278,14 +4278,32 @@ void pcpu_free_vm_areas(struct vm_struct **vms, int nr_vms)
42784278
#ifdef CONFIG_PRINTK
42794279
bool vmalloc_dump_obj(void *object)
42804280
{
4281-
struct vm_struct *vm;
42824281
void *objp = (void *)PAGE_ALIGN((unsigned long)object);
4282+
const void *caller;
4283+
struct vm_struct *vm;
4284+
struct vmap_area *va;
4285+
unsigned long addr;
4286+
unsigned int nr_pages;
42834287

4284-
vm = find_vm_area(objp);
4285-
if (!vm)
4288+
if (!spin_trylock(&vmap_area_lock))
4289+
return false;
4290+
va = __find_vmap_area((unsigned long)objp, &vmap_area_root);
4291+
if (!va) {
4292+
spin_unlock(&vmap_area_lock);
42864293
return false;
4294+
}
4295+
4296+
vm = va->vm;
4297+
if (!vm) {
4298+
spin_unlock(&vmap_area_lock);
4299+
return false;
4300+
}
4301+
addr = (unsigned long)vm->addr;
4302+
caller = vm->caller;
4303+
nr_pages = vm->nr_pages;
4304+
spin_unlock(&vmap_area_lock);
42874305
pr_cont(" %u-page vmalloc region starting at %#lx allocated at %pS\n",
4288-
vm->nr_pages, (unsigned long)vm->addr, vm->caller);
4306+
nr_pages, addr, caller);
42894307
return true;
42904308
}
42914309
#endif

0 commit comments

Comments
 (0)