Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

mm/kasan: support non-blocking GFP in kasan_populate_vmalloc()

A "gfp_mask" is already passed to kasan_populate_vmalloc() as an argument
to respect GFPs from callers and KASAN uses it for its internal
allocations.

But apply_to_page_range() function ignores GFP flags due to a hard-coded
mask.

Wrap the call with memalloc_apply_gfp_scope()/memalloc_restore_scope() so
that non-blocking GFP flags(GFP_ATOMIC, GFP_NOWAIT) are respected.

Link: https://lkml.kernel.org/r/20251007122035.56347-7-urezki@gmail.com
Signed-off-by: Uladzislau Rezki (Sony) <urezki@gmail.com>
Reviewed-by: Baoquan He <bhe@redhat.com>
Reviewed-by: Andrey Ryabinin <ryabinin.a.a@gmail.com>
Cc: Alexander Potapenko <glider@google.com>
Cc: Marco Elver <elver@google.com>
Cc: Michal Hocko <mhocko@kernel.org>
Cc: Michal Hocko <mhocko@suse.com>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>

authored by

Uladzislau Rezki (Sony) and committed by
Andrew Morton
ad435e79 8da89ba1

+2 -10
+2 -10
mm/kasan/shadow.c
··· 377 377 * page tables allocations ignore external gfp mask, enforce it 378 378 * by the scope API 379 379 */ 380 - if ((gfp_mask & (__GFP_FS | __GFP_IO)) == __GFP_IO) 381 - flags = memalloc_nofs_save(); 382 - else if ((gfp_mask & (__GFP_FS | __GFP_IO)) == 0) 383 - flags = memalloc_noio_save(); 384 - 380 + flags = memalloc_apply_gfp_scope(gfp_mask); 385 381 ret = apply_to_page_range(&init_mm, start, nr_pages * PAGE_SIZE, 386 382 kasan_populate_vmalloc_pte, &data); 387 - 388 - if ((gfp_mask & (__GFP_FS | __GFP_IO)) == __GFP_IO) 389 - memalloc_nofs_restore(flags); 390 - else if ((gfp_mask & (__GFP_FS | __GFP_IO)) == 0) 391 - memalloc_noio_restore(flags); 383 + memalloc_restore_scope(flags); 392 384 393 385 ___free_pages_bulk(data.pages, nr_pages); 394 386 if (ret)