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

lib/test_bpf: Call page_address() on page acquired with GFP_KERNEL flag

generate_test_data() acquires a page with alloc_page(GFP_KERNEL).
The GFP_KERNEL is typical for kernel-internal allocations. The
caller requires ZONE_NORMAL or a lower zone for direct access.

Therefore the page cannot come from ZONE_HIGHMEM. Thus there's no
need to map it with kmap().

Also, the kmap() is being deprecated in favor of kmap_local_page() [1].

Hence, use a plain page_address() directly.

Since the page passed to the page_address() is not from the highmem
zone, the page_address() function will always return a valid kernel
virtual address and will not return NULL. Hence, remove the check
'if (!ptr)'.

Remove the unused variable 'ptr' and label 'err_free_page'.

[1] https://lore.kernel.org/all/20220813220034.806698-1-ira.weiny@intel.com/

Reported-by: kernel test robot <lkp@intel.com>
Suggested-by: Fabio M. De Francesco <fmdefrancesco@gmail.com>
Signed-off-by: Sumitra Sharma <sumitraartsy@gmail.com>
Signed-off-by: Daniel Borkmann <daniel@iogearbox.net>
Reviewed-by: Fabio M. De Francesco <fmdefrancesco@gmail.com>
Reviewed-by: Ira Weiny <ira.weiny@intel.com>
Link: https://lore.kernel.org/bpf/20230623151644.GA434468@sumitra.com

authored by

Sumitra Sharma and committed by
Daniel Borkmann
da1a055d 3a8a670e

+1 -11
+1 -11
lib/test_bpf.c
··· 14381 14381 * single fragment to the skb, filled with 14382 14382 * test->frag_data. 14383 14383 */ 14384 - void *ptr; 14385 - 14386 14384 page = alloc_page(GFP_KERNEL); 14387 - 14388 14385 if (!page) 14389 14386 goto err_kfree_skb; 14390 14387 14391 - ptr = kmap(page); 14392 - if (!ptr) 14393 - goto err_free_page; 14394 - memcpy(ptr, test->frag_data, MAX_DATA); 14395 - kunmap(page); 14388 + memcpy(page_address(page), test->frag_data, MAX_DATA); 14396 14389 skb_add_rx_frag(skb, 0, page, 0, MAX_DATA, MAX_DATA); 14397 14390 } 14398 14391 14399 14392 return skb; 14400 - 14401 - err_free_page: 14402 - __free_page(page); 14403 14393 err_kfree_skb: 14404 14394 kfree_skb(skb); 14405 14395 return NULL;