lib/test_bpf: Call page_address() on page acquired with GFP_KERNEL flag
authorSumitra Sharma <sumitraartsy@gmail.com>
Fri, 23 Jun 2023 15:16:44 +0000 (08:16 -0700)
committerDaniel Borkmann <daniel@iogearbox.net>
Thu, 29 Jun 2023 13:32:25 +0000 (15:32 +0200)
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
lib/test_bpf.c

index fa0833410ac18e05c79eae785a3bf62608b09840..913a7a079239e136c54b03b2715a1db2de7a67b9 100644 (file)
@@ -14381,25 +14381,15 @@ static void *generate_test_data(struct bpf_test *test, int sub)
                 * single fragment to the skb, filled with
                 * test->frag_data.
                 */
-               void *ptr;
-
                page = alloc_page(GFP_KERNEL);
-
                if (!page)
                        goto err_kfree_skb;
 
-               ptr = kmap(page);
-               if (!ptr)
-                       goto err_free_page;
-               memcpy(ptr, test->frag_data, MAX_DATA);
-               kunmap(page);
+               memcpy(page_address(page), test->frag_data, MAX_DATA);
                skb_add_rx_frag(skb, 0, page, 0, MAX_DATA, MAX_DATA);
        }
 
        return skb;
-
-err_free_page:
-       __free_page(page);
 err_kfree_skb:
        kfree_skb(skb);
        return NULL;