lib/test_bpf: Call page_address() on page acquired with GFP_KERNEL flag
Subsystems (2)
PATCH v2 1/1 lib/test_bpf: Call page_address() on page acquired with GFP_KERNEL flag
generate_test_data() acquires a page with alloc_page(GFP_KERNEL). Pages allocated with GFP_KERNEL cannot come from Highmem. This is why there is no need to call kmap() on them.
Therefore, use a plain page_address() on that page.
---
Changes in v2:
- Remove the kmap() call and call page_address() instead.
- Change the commit subject and message.
lib/test_bpf.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-)
lib/test_bpf.c +1 -2
@@ -14388,11 +14388,10 @@ static void *generate_test_data(struct bpf_test *test, int sub)if (!page) goto err_kfree_skb; - ptr =kmap (page); + ptr =page_address (page);if (!ptr) goto err_free_page;memcpy (ptr, test->frag_data,MAX_DATA ); -kunmap (page);skb_add_rx_frag (skb,0 , page,0 ,MAX_DATA ,MAX_DATA ); }
Signature · 1 line
2.25.1
Quoted 4 lines · On martedì 13 giugno 2023 09:17:56 CEST Sumitra Sharma wrote:
generate_test_data()acquires a page withalloc_page(GFP_KERNEL). Pages allocated withGFP_KERNELcannot come from Highmem. This is why there is no need to callkmap()on them.
Quoted 8 lines
Therefore, use a plain
page_address()on that page.Suggested-by Fabio M. De Francesco <[email protected]>Signed-off-by Sumitra Sharma <[email protected]>---
Changes in v2:
- Remove thekmap()call and callpage_address()instead.
NIT: Give credit to whom asked you for this removal and explain why the mapping is not required.
Quoted 10 lines
- Change the commit subject and message.
lib/test_bpf.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-)lib/test_bpf.c +0
-0
lib/test_bpf.c static void *generate_test_data(struct bpf_test · line 14393
Quoted 7 lines
lib/test_bpf.c +1
-1@@ -14388,11 +14388,10 @@ static void *generate_test_data(struct bpf_test *test, int sub) if (!page) goto err_kfree_skb; - ptr =kmap (page); + ptr =page_address (page);if (!ptr) goto err_free_page;
What is the reason of this test? Could "ptr" ever be NULL? What is the code checking just few lines above this latter test?
Please, take a deeper look at this function as a whole.
Fabio
Quoted 7 lines
lib/test_bpf.c +0
-2memcpy (ptr, test->frag_data,MAX_DATA ); -kunmap (page);skb_add_rx_frag (skb,0 , page,0 ,MAX_DATA ,MAX_DATA ); } --2.25.1
Quoted 31 lines · Fabio M. De Francesco
Quoted 4 lines · On martedì 13 giugno 2023 09:17:56 CEST Sumitra Sharma wrote:
generate_test_data()acquires a page withalloc_page(GFP_KERNEL). Pages allocated withGFP_KERNELcannot come from Highmem. This is why there is no need to callkmap()on them.Quoted 8 lines
Therefore, use a plain
page_address()on that page.Suggested-by Fabio M. De Francesco <[email protected]>Signed-off-by Sumitra Sharma <[email protected]>---
Changes in v2:
- Remove thekmap()call and callpage_address()instead.NIT: Give credit to whom asked you for this removal and explain why the mapping is not required.
Quoted 13 lines
- Change the commit subject and message.
lib/test_bpf.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-)lib/test_bpf.c +0
-0@@ -14388,11 +14388,10 @@ static void *generate_test_data(struct bpf_test *test, int sub) if (!page) goto err_kfree_skb;
Quoted 8 lines
lib/test_bpf.c static void *generate_test_data(struct bpf_test *test, int sub) · line 14393
Quoted 4 lines
lib/test_bpf.c +1
-1- ptr =kmap (page); + ptr =page_address (page);if (!ptr) goto err_free_page;What is the reason of this test? Could "ptr" ever be NULL? What is the code checking just few lines above this latter test?
The code is allocating a page using alloc_page() with the GFP_KERNEL flag to obtain a kernel page frame. The checks if (!page) and if (!ptr) are verifying if the page allocation or the mapping operation were successful.
If the pages obtained through page_address() are not from the highmem zone, the page_address() function will always return a valid kernel virtual address and will not return NULL. Hence, the check !ptr can be ignored while the !page must remain.
I will be working on the v2 patch.
I will also add the credits and add new lines to commit message explaining why the mapping is not required.
Thank you for the help.
Thanks & regards
Sumitra
Quoted 15 lines
Please, take a deeper look at this function as a whole.
Fabio
Quoted 7 lines
lib/test_bpf.c +0
-2memcpy (ptr, test->frag_data,MAX_DATA ); -kunmap (page);skb_add_rx_frag (skb,0 , page,0 ,MAX_DATA ,MAX_DATA ); } --2.25.1