* [PATCH v2] lib/test_bpf: Call page_address() on page acquired with GFP_KERNEL flag
@ 2023-06-13 7:17 Sumitra Sharma
2023-06-18 5:07 ` Fabio M. De Francesco
0 siblings, 1 reply; 3+ messages in thread
From: Sumitra Sharma @ 2023-06-13 7:17 UTC (permalink / raw)
To: Alexei Starovoitov, Daniel Borkmann, Andrii Nakryiko,
Martin KaFai Lau, Song Liu, Yonghong Song, John Fastabend,
KP Singh, Stanislav Fomichev, Hao Luo, Jiri Olsa, bpf,
linux-kernel
Cc: Ira Weiny, Fabio, Deepak R Varma
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.
Suggested-by: Fabio M. De Francesco <fmdefrancesco@gmail.com>
Signed-off-by: Sumitra Sharma <sumitraartsy@gmail.com>
---
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(-)
diff --git a/lib/test_bpf.c b/lib/test_bpf.c
index ade9ac672adb..70fcd0bcf14b 100644
--- a/lib/test_bpf.c
+++ b/lib/test_bpf.c
@@ -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);
}
--
2.25.1
^ permalink raw reply related [flat|nested] 3+ messages in thread
* Re: [PATCH v2] lib/test_bpf: Call page_address() on page acquired with GFP_KERNEL flag
2023-06-13 7:17 [PATCH v2] lib/test_bpf: Call page_address() on page acquired with GFP_KERNEL flag Sumitra Sharma
@ 2023-06-18 5:07 ` Fabio M. De Francesco
2023-06-22 5:13 ` Sumitra Sharma
0 siblings, 1 reply; 3+ messages in thread
From: Fabio M. De Francesco @ 2023-06-18 5:07 UTC (permalink / raw)
To: Alexei Starovoitov, Daniel Borkmann, Andrii Nakryiko,
Martin KaFai Lau, Song Liu, Yonghong Song, John Fastabend,
KP Singh, Stanislav Fomichev, Hao Luo, Jiri Olsa, bpf,
linux-kernel, Sumitra Sharma
Cc: Ira Weiny, Deepak R Varma
On martedì 13 giugno 2023 09:17:56 CEST Sumitra Sharma wrote:
> 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.
>
> Suggested-by: Fabio M. De Francesco <fmdefrancesco@gmail.com>
> Signed-off-by: Sumitra Sharma <sumitraartsy@gmail.com>
> ---
>
> Changes in v2:
> - Remove the kmap() call and call page_address() instead.
NIT: Give credit to whom asked you for this removal and explain why the
mapping is not required.
> - Change the commit subject and message.
>
> lib/test_bpf.c | 3 +--
> 1 file changed, 1 insertion(+), 2 deletions(-)
>
> diff --git a/lib/test_bpf.c b/lib/test_bpf.c
> index ade9ac672adb..70fcd0bcf14b 100644
> --- a/lib/test_bpf.c
> +++ b/lib/test_bpf.c
> @@ -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
> memcpy(ptr, test->frag_data, MAX_DATA);
> - kunmap(page);
> skb_add_rx_frag(skb, 0, page, 0, MAX_DATA, MAX_DATA);
> }
>
> --
> 2.25.1
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: [PATCH v2] lib/test_bpf: Call page_address() on page acquired with GFP_KERNEL flag
2023-06-18 5:07 ` Fabio M. De Francesco
@ 2023-06-22 5:13 ` Sumitra Sharma
0 siblings, 0 replies; 3+ messages in thread
From: Sumitra Sharma @ 2023-06-22 5:13 UTC (permalink / raw)
To: Fabio M. De Francesco
Cc: Alexei Starovoitov, Daniel Borkmann, Andrii Nakryiko,
Martin KaFai Lau, Song Liu, Yonghong Song, John Fastabend,
KP Singh, Stanislav Fomichev, Hao Luo, Jiri Olsa, bpf,
linux-kernel, Ira Weiny, Deepak R Varma, Sumitra Sharma
On Sun, Jun 18, 2023 at 07:07:00AM +0200, Fabio M. De Francesco wrote:
> On martedì 13 giugno 2023 09:17:56 CEST Sumitra Sharma wrote:
> > 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.
> >
> > Suggested-by: Fabio M. De Francesco <fmdefrancesco@gmail.com>
> > Signed-off-by: Sumitra Sharma <sumitraartsy@gmail.com>
> > ---
> >
> > Changes in v2:
> > - Remove the kmap() call and call page_address() instead.
>
> NIT: Give credit to whom asked you for this removal and explain why the
> mapping is not required.
>
> > - Change the commit subject and message.
> >
> > lib/test_bpf.c | 3 +--
> > 1 file changed, 1 insertion(+), 2 deletions(-)
> >
> > diff --git a/lib/test_bpf.c b/lib/test_bpf.c
> > index ade9ac672adb..70fcd0bcf14b 100644
> > --- a/lib/test_bpf.c
> > +++ b/lib/test_bpf.c
> > @@ -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?
>
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
> Please, take a deeper look at this function as a whole.
>
> Fabio
>
> > memcpy(ptr, test->frag_data, MAX_DATA);
> > - kunmap(page);
> > skb_add_rx_frag(skb, 0, page, 0, MAX_DATA, MAX_DATA);
> > }
> >
> > --
> > 2.25.1
>
>
>
>
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2023-06-22 5:13 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-06-13 7:17 [PATCH v2] lib/test_bpf: Call page_address() on page acquired with GFP_KERNEL flag Sumitra Sharma
2023-06-18 5:07 ` Fabio M. De Francesco
2023-06-22 5:13 ` Sumitra Sharma
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).