* [PATCH v4] lib/test_bpf: Call page_address() on page acquired with GFP_KERNEL flag
@ 2023-06-23 15:16 Sumitra Sharma
2023-06-26 13:07 ` Fabio M. De Francesco
` (2 more replies)
0 siblings, 3 replies; 5+ messages in thread
From: Sumitra Sharma @ 2023-06-23 15:16 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, Sumitra Sharma
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/
Suggested-by: Fabio M. De Francesco <fmdefrancesco@gmail.com>
Signed-off-by: Sumitra Sharma <sumitraartsy@gmail.com>
---
- Link to v1: https://lore.kernel.org/bpf/20230613073020.GA359792@sumitra.com/T/
- Link to v2: https://lore.kernel.org/all/20230613071756.GA359746@sumitra.com/
- Link to v3: https://lore.kernel.org/all/20230622080729.GA426913@sumitra.com/
Changes in v4:
Reported-by: kernel test robot <lkp@intel.com>
Closes: https://lore.kernel.org/oe-kbuild-all/202306230559.hU5Aonpl-lkp@intel.com/
- Remove unused label 'err_free_page'.
Changes in v3:
Noted by: Fabio M. De Francesco<fmdefrancesco@gmail.com>
- Remove the check 'if (!ptr)'.
- Remove the unused variable 'ptr'.
- Change the commit message.
Changes in v2:
Noted by: Fabio M. De Francesco<fmdefrancesco@gmail.com>
- Remove the kmap() call and call page_address() instead.
- Change the commit subject and message.
lib/test_bpf.c | 10 +---------
1 file changed, 1 insertion(+), 9 deletions(-)
diff --git a/lib/test_bpf.c b/lib/test_bpf.c
index ade9ac672adb..a5cc5f9fc4e8 100644
--- a/lib/test_bpf.c
+++ b/lib/test_bpf.c
@@ -14381,25 +14381,17 @@ 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;
--
2.25.1
^ permalink raw reply related [flat|nested] 5+ messages in thread
* Re: [PATCH v4] lib/test_bpf: Call page_address() on page acquired with GFP_KERNEL flag
2023-06-23 15:16 [PATCH v4] lib/test_bpf: Call page_address() on page acquired with GFP_KERNEL flag Sumitra Sharma
@ 2023-06-26 13:07 ` Fabio M. De Francesco
2023-06-27 15:01 ` Sumitra Sharma
2023-06-26 20:43 ` Ira Weiny
2023-06-29 13:40 ` patchwork-bot+netdevbpf
2 siblings, 1 reply; 5+ messages in thread
From: Fabio M. De Francesco @ 2023-06-26 13: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, Sumitra Sharma
On venerdì 23 giugno 2023 17:16:44 CEST Sumitra Sharma wrote:
> 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/
>
> Suggested-by: Fabio M. De Francesco <fmdefrancesco@gmail.com>
I can't see no more things that prevent my tag, then it is...
Reviewed-by: Fabio M. De Francesco <fmdefrancesco@gmail.com>
Thanks for working on it for all the time it took to get to v4 and for
listening to what you've been suggested to change.
Well done :-)
Fabio
> Signed-off-by: Sumitra Sharma <sumitraartsy@gmail.com>
> ---
>
> - Link to v1:
> https://lore.kernel.org/bpf/20230613073020.GA359792@sumitra.com/T/ - Link to
> v2: https://lore.kernel.org/all/20230613071756.GA359746@sumitra.com/ - Link
> to v3: https://lore.kernel.org/all/20230622080729.GA426913@sumitra.com/
>
> Changes in v4:
> Reported-by: kernel test robot <lkp@intel.com>
> Closes:
> https://lore.kernel.org/oe-kbuild-all/202306230559.hU5Aonpl-lkp@intel.com/ -
> Remove unused label 'err_free_page'.
>
> Changes in v3:
> Noted by: Fabio M. De Francesco<fmdefrancesco@gmail.com>
> - Remove the check 'if (!ptr)'.
> - Remove the unused variable 'ptr'.
> - Change the commit message.
>
> Changes in v2:
> Noted by: Fabio M. De Francesco<fmdefrancesco@gmail.com>
> - Remove the kmap() call and call page_address() instead.
> - Change the commit subject and message.
>
> lib/test_bpf.c | 10 +---------
> 1 file changed, 1 insertion(+), 9 deletions(-)
>
> diff --git a/lib/test_bpf.c b/lib/test_bpf.c
> index ade9ac672adb..a5cc5f9fc4e8 100644
> --- a/lib/test_bpf.c
> +++ b/lib/test_bpf.c
> @@ -14381,25 +14381,17 @@ 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;
> --
> 2.25.1
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [PATCH v4] lib/test_bpf: Call page_address() on page acquired with GFP_KERNEL flag
2023-06-23 15:16 [PATCH v4] lib/test_bpf: Call page_address() on page acquired with GFP_KERNEL flag Sumitra Sharma
2023-06-26 13:07 ` Fabio M. De Francesco
@ 2023-06-26 20:43 ` Ira Weiny
2023-06-29 13:40 ` patchwork-bot+netdevbpf
2 siblings, 0 replies; 5+ messages in thread
From: Ira Weiny @ 2023-06-26 20:43 UTC (permalink / raw)
To: Sumitra Sharma, 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, Sumitra Sharma
Sumitra Sharma wrote:
> 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/
>
> Suggested-by: Fabio M. De Francesco <fmdefrancesco@gmail.com>
> Signed-off-by: Sumitra Sharma <sumitraartsy@gmail.com>
Just saw the report from kernel bot...
Better on this version than I saw before! :-D
Reviewed-by: Ira Weiny <ira.weiny@intel.com>
> ---
>
> - Link to v1: https://lore.kernel.org/bpf/20230613073020.GA359792@sumitra.com/T/
> - Link to v2: https://lore.kernel.org/all/20230613071756.GA359746@sumitra.com/
> - Link to v3: https://lore.kernel.org/all/20230622080729.GA426913@sumitra.com/
>
> Changes in v4:
> Reported-by: kernel test robot <lkp@intel.com>
> Closes: https://lore.kernel.org/oe-kbuild-all/202306230559.hU5Aonpl-lkp@intel.com/
> - Remove unused label 'err_free_page'.
>
> Changes in v3:
> Noted by: Fabio M. De Francesco<fmdefrancesco@gmail.com>
> - Remove the check 'if (!ptr)'.
> - Remove the unused variable 'ptr'.
> - Change the commit message.
>
> Changes in v2:
> Noted by: Fabio M. De Francesco<fmdefrancesco@gmail.com>
> - Remove the kmap() call and call page_address() instead.
> - Change the commit subject and message.
>
> lib/test_bpf.c | 10 +---------
> 1 file changed, 1 insertion(+), 9 deletions(-)
>
> diff --git a/lib/test_bpf.c b/lib/test_bpf.c
> index ade9ac672adb..a5cc5f9fc4e8 100644
> --- a/lib/test_bpf.c
> +++ b/lib/test_bpf.c
> @@ -14381,25 +14381,17 @@ 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;
> --
> 2.25.1
>
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [PATCH v4] lib/test_bpf: Call page_address() on page acquired with GFP_KERNEL flag
2023-06-26 13:07 ` Fabio M. De Francesco
@ 2023-06-27 15:01 ` Sumitra Sharma
0 siblings, 0 replies; 5+ messages in thread
From: Sumitra Sharma @ 2023-06-27 15:01 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 Mon, Jun 26, 2023 at 03:07:22PM +0200, Fabio M. De Francesco wrote:
> On venerdì 23 giugno 2023 17:16:44 CEST Sumitra Sharma wrote:
> > 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/
> >
> > Suggested-by: Fabio M. De Francesco <fmdefrancesco@gmail.com>
>
> I can't see no more things that prevent my tag, then it is...
>
> Reviewed-by: Fabio M. De Francesco <fmdefrancesco@gmail.com>
>
> Thanks for working on it for all the time it took to get to v4 and for
> listening to what you've been suggested to change.
>
> Well done :-)
Thank you, Fabio and Ira, for your tags and kind words :)
Thanks & regards
Sumitra
>
> Fabio
>
> > Signed-off-by: Sumitra Sharma <sumitraartsy@gmail.com>
> > ---
> >
> > - Link to v1:
> > https://lore.kernel.org/bpf/20230613073020.GA359792@sumitra.com/T/ - Link to
> > v2: https://lore.kernel.org/all/20230613071756.GA359746@sumitra.com/ - Link
> > to v3: https://lore.kernel.org/all/20230622080729.GA426913@sumitra.com/
> >
> > Changes in v4:
> > Reported-by: kernel test robot <lkp@intel.com>
> > Closes:
> > https://lore.kernel.org/oe-kbuild-all/202306230559.hU5Aonpl-lkp@intel.com/ -
> > Remove unused label 'err_free_page'.
> >
> > Changes in v3:
> > Noted by: Fabio M. De Francesco<fmdefrancesco@gmail.com>
> > - Remove the check 'if (!ptr)'.
> > - Remove the unused variable 'ptr'.
> > - Change the commit message.
> >
> > Changes in v2:
> > Noted by: Fabio M. De Francesco<fmdefrancesco@gmail.com>
> > - Remove the kmap() call and call page_address() instead.
> > - Change the commit subject and message.
> >
> > lib/test_bpf.c | 10 +---------
> > 1 file changed, 1 insertion(+), 9 deletions(-)
> >
> > diff --git a/lib/test_bpf.c b/lib/test_bpf.c
> > index ade9ac672adb..a5cc5f9fc4e8 100644
> > --- a/lib/test_bpf.c
> > +++ b/lib/test_bpf.c
> > @@ -14381,25 +14381,17 @@ 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;
> > --
> > 2.25.1
>
>
>
>
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [PATCH v4] lib/test_bpf: Call page_address() on page acquired with GFP_KERNEL flag
2023-06-23 15:16 [PATCH v4] lib/test_bpf: Call page_address() on page acquired with GFP_KERNEL flag Sumitra Sharma
2023-06-26 13:07 ` Fabio M. De Francesco
2023-06-26 20:43 ` Ira Weiny
@ 2023-06-29 13:40 ` patchwork-bot+netdevbpf
2 siblings, 0 replies; 5+ messages in thread
From: patchwork-bot+netdevbpf @ 2023-06-29 13:40 UTC (permalink / raw)
To: Sumitra Sharma
Cc: ast, daniel, andrii, martin.lau, song, yhs, john.fastabend,
kpsingh, sdf, haoluo, jolsa, bpf, linux-kernel, ira.weiny,
fmdefrancesco, drv
Hello:
This patch was applied to bpf/bpf-next.git (master)
by Daniel Borkmann <daniel@iogearbox.net>:
On Fri, 23 Jun 2023 08:16:44 -0700 you wrote:
> 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().
>
> [...]
Here is the summary with links:
- [v4] lib/test_bpf: Call page_address() on page acquired with GFP_KERNEL flag
https://git.kernel.org/bpf/bpf-next/c/da1a055d01ed
You are awesome, thank you!
--
Deet-doot-dot, I am a bot.
https://korg.docs.kernel.org/patchwork/pwbot.html
^ permalink raw reply [flat|nested] 5+ messages in thread
end of thread, other threads:[~2023-06-29 13:40 UTC | newest]
Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2023-06-23 15:16 [PATCH v4] lib/test_bpf: Call page_address() on page acquired with GFP_KERNEL flag Sumitra Sharma
2023-06-26 13:07 ` Fabio M. De Francesco
2023-06-27 15:01 ` Sumitra Sharma
2023-06-26 20:43 ` Ira Weiny
2023-06-29 13:40 ` patchwork-bot+netdevbpf
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox