Skip to content

Commit a2e740e

Browse files
Matthew Wilcox (Oracle)akpm00
authored andcommitted
vmalloc: fix accounting with i915
If the caller of vmap() specifies VM_MAP_PUT_PAGES (currently only the i915 driver), we will decrement nr_vmalloc_pages and MEMCG_VMALLOC in vfree(). These counters are incremented by vmalloc() but not by vmap() so this will cause an underflow. Check the VM_MAP_PUT_PAGES flag before decrementing either counter. Link: https://lkml.kernel.org/r/[email protected] Fixes: b944afc ("mm: add a VM_MAP_PUT_PAGES flag for vmap") Signed-off-by: Matthew Wilcox (Oracle) <[email protected]> Acked-by: Johannes Weiner <[email protected]> Reviewed-by: Shakeel Butt <[email protected]> Reviewed-by: Balbir Singh <[email protected]> Acked-by: Michal Hocko <[email protected]> Cc: Christoph Hellwig <[email protected]> Cc: Muchun Song <[email protected]> Cc: Roman Gushchin <[email protected]> Cc: "Uladzislau Rezki (Sony)" <[email protected]> Cc: <[email protected]> Signed-off-by: Andrew Morton <[email protected]>
1 parent faeec8e commit a2e740e

File tree

1 file changed

+4
-2
lines changed

1 file changed

+4
-2
lines changed

mm/vmalloc.c

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3374,15 +3374,17 @@ void vfree(const void *addr)
33743374
struct page *page = vm->pages[i];
33753375

33763376
BUG_ON(!page);
3377-
mod_memcg_page_state(page, MEMCG_VMALLOC, -1);
3377+
if (!(vm->flags & VM_MAP_PUT_PAGES))
3378+
mod_memcg_page_state(page, MEMCG_VMALLOC, -1);
33783379
/*
33793380
* High-order allocs for huge vmallocs are split, so
33803381
* can be freed as an array of order-0 allocations
33813382
*/
33823383
__free_page(page);
33833384
cond_resched();
33843385
}
3385-
atomic_long_sub(vm->nr_pages, &nr_vmalloc_pages);
3386+
if (!(vm->flags & VM_MAP_PUT_PAGES))
3387+
atomic_long_sub(vm->nr_pages, &nr_vmalloc_pages);
33863388
kvfree(vm->pages);
33873389
kfree(vm);
33883390
}

0 commit comments

Comments
 (0)