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/20241211202538.168311-1-willy@infradead.org Fixes: b944afc ("mm: add a VM_MAP_PUT_PAGES flag for vmap") Signed-off-by: Matthew Wilcox (Oracle) <willy@infradead.org> Acked-by: Johannes Weiner <hannes@cmpxchg.org> Reviewed-by: Shakeel Butt <shakeel.butt@linux.dev> Reviewed-by: Balbir Singh <balbirs@nvidia.com> Acked-by: Michal Hocko <mhocko@suse.com> Cc: Christoph Hellwig <hch@lst.de> Cc: Muchun Song <muchun.song@linux.dev> Cc: Roman Gushchin <roman.gushchin@linux.dev> Cc: "Uladzislau Rezki (Sony)" <urezki@gmail.com> Cc: <stable@vger.kernel.org> Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
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)