Skip to content

Commit 1c6a026

Browse files
puranjaymohanKernel Patches Daemon
authored andcommitted
bpf: arena: use kmalloc_nolock() in place of kvcalloc()
To make arena_alloc_pages() safe to be called from any context, replace kvcalloc() with kmalloc_nolock() so as it doesn't sleep or take any locks. Signed-off-by: Puranjay Mohan <[email protected]>
1 parent 50a4cbc commit 1c6a026

File tree

1 file changed

+3
-4
lines changed

1 file changed

+3
-4
lines changed

kernel/bpf/arena.c

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -506,8 +506,7 @@ static long arena_alloc_pages(struct bpf_arena *arena, long uaddr, long page_cnt
506506
return 0;
507507
}
508508

509-
/* zeroing is needed, since alloc_pages_bulk() only fills in non-zero entries */
510-
pages = kvcalloc(page_cnt, sizeof(struct page *), GFP_KERNEL);
509+
pages = kmalloc_nolock(page_cnt * sizeof(struct page *), __GFP_ZERO, -1);
511510
if (!pages)
512511
return 0;
513512

@@ -546,12 +545,12 @@ static long arena_alloc_pages(struct bpf_arena *arena, long uaddr, long page_cnt
546545
__free_page(pages[i]);
547546
goto out;
548547
}
549-
kvfree(pages);
548+
kfree_nolock(pages);
550549
return clear_lo32(arena->user_vm_start) + uaddr32;
551550
out:
552551
range_tree_set(&arena->rt, pgoff, page_cnt);
553552
out_free_pages:
554-
kvfree(pages);
553+
kfree_nolock(pages);
555554
return 0;
556555
}
557556

0 commit comments

Comments
 (0)