linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH net] net: page_pool: add missing free_percpu when page_pool_init fail
@ 2023-10-30  9:12 Jijie Shao
  2023-10-30  9:31 ` Yunsheng Lin
                   ` (3 more replies)
  0 siblings, 4 replies; 5+ messages in thread
From: Jijie Shao @ 2023-10-30  9:12 UTC (permalink / raw)
  To: hawk, ilias.apalodimas, davem, edumazet, kuba, pabeni, jdamato
  Cc: shenjian15, wangjie125, liuyonglong, shaojijie, linyunsheng,
	netdev, linux-kernel

From: Jian Shen <shenjian15@huawei.com>

When ptr_ring_init() returns failure in page_pool_init(), free_percpu()
is not called to free pool->recycle_stats, which may cause memory
leak.

Fixes: ad6fa1e1ab1b ("page_pool: Add recycle stats")
Signed-off-by: Jian Shen <shenjian15@huawei.com>
Signed-off-by: Jijie Shao <shaojijie@huawei.com>
---
 net/core/page_pool.c | 6 +++++-
 1 file changed, 5 insertions(+), 1 deletion(-)

diff --git a/net/core/page_pool.c b/net/core/page_pool.c
index 77cb75e63aca..31f923e7b5c4 100644
--- a/net/core/page_pool.c
+++ b/net/core/page_pool.c
@@ -221,8 +221,12 @@ static int page_pool_init(struct page_pool *pool,
 		return -ENOMEM;
 #endif
 
-	if (ptr_ring_init(&pool->ring, ring_qsize, GFP_KERNEL) < 0)
+	if (ptr_ring_init(&pool->ring, ring_qsize, GFP_KERNEL) < 0) {
+#ifdef CONFIG_PAGE_POOL_STATS
+		free_percpu(pool->recycle_stats);
+#endif
 		return -ENOMEM;
+	}
 
 	atomic_set(&pool->pages_state_release_cnt, 0);
 
-- 
2.30.0


^ permalink raw reply related	[flat|nested] 5+ messages in thread

* Re: [PATCH net] net: page_pool: add missing free_percpu when page_pool_init fail
  2023-10-30  9:12 [PATCH net] net: page_pool: add missing free_percpu when page_pool_init fail Jijie Shao
@ 2023-10-30  9:31 ` Yunsheng Lin
  2023-10-30 12:07 ` Jiri Pirko
                   ` (2 subsequent siblings)
  3 siblings, 0 replies; 5+ messages in thread
From: Yunsheng Lin @ 2023-10-30  9:31 UTC (permalink / raw)
  To: Jijie Shao, hawk, ilias.apalodimas, davem, edumazet, kuba,
	pabeni, jdamato
  Cc: shenjian15, wangjie125, liuyonglong, netdev, linux-kernel

On 2023/10/30 17:12, Jijie Shao wrote:
> From: Jian Shen <shenjian15@huawei.com>
> 
> When ptr_ring_init() returns failure in page_pool_init(), free_percpu()
> is not called to free pool->recycle_stats, which may cause memory
> leak.

LGTM.
Reviewed-by: Yunsheng Lin <linyunsheng@huawei.com>

> 
> Fixes: ad6fa1e1ab1b ("page_pool: Add recycle stats")
> Signed-off-by: Jian Shen <shenjian15@huawei.com>
> Signed-off-by: Jijie Shao <shaojijie@huawei.com>
> ---
>  net/core/page_pool.c | 6 +++++-
>  1 file changed, 5 insertions(+), 1 deletion(-)
> 
> diff --git a/net/core/page_pool.c b/net/core/page_pool.c
> index 77cb75e63aca..31f923e7b5c4 100644
> --- a/net/core/page_pool.c
> +++ b/net/core/page_pool.c
> @@ -221,8 +221,12 @@ static int page_pool_init(struct page_pool *pool,
>  		return -ENOMEM;
>  #endif
>  
> -	if (ptr_ring_init(&pool->ring, ring_qsize, GFP_KERNEL) < 0)
> +	if (ptr_ring_init(&pool->ring, ring_qsize, GFP_KERNEL) < 0) {
> +#ifdef CONFIG_PAGE_POOL_STATS
> +		free_percpu(pool->recycle_stats);
> +#endif
>  		return -ENOMEM;
> +	}
>  
>  	atomic_set(&pool->pages_state_release_cnt, 0);
>  
> 

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [PATCH net] net: page_pool: add missing free_percpu when page_pool_init fail
  2023-10-30  9:12 [PATCH net] net: page_pool: add missing free_percpu when page_pool_init fail Jijie Shao
  2023-10-30  9:31 ` Yunsheng Lin
@ 2023-10-30 12:07 ` Jiri Pirko
  2023-11-01 11:11 ` Ilias Apalodimas
  2023-11-02 11:50 ` patchwork-bot+netdevbpf
  3 siblings, 0 replies; 5+ messages in thread
From: Jiri Pirko @ 2023-10-30 12:07 UTC (permalink / raw)
  To: Jijie Shao
  Cc: hawk, ilias.apalodimas, davem, edumazet, kuba, pabeni, jdamato,
	shenjian15, wangjie125, liuyonglong, linyunsheng, netdev,
	linux-kernel

Mon, Oct 30, 2023 at 10:12:56AM CET, shaojijie@huawei.com wrote:
>From: Jian Shen <shenjian15@huawei.com>
>
>When ptr_ring_init() returns failure in page_pool_init(), free_percpu()
>is not called to free pool->recycle_stats, which may cause memory
>leak.

Would be nice to see the use of imperative mood in the patch description
too, not only patch subject. Nevertheless, fix looks fine:

Reviewed-by: Jiri Pirko <jiri@nvidia.com>

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [PATCH net] net: page_pool: add missing free_percpu when page_pool_init fail
  2023-10-30  9:12 [PATCH net] net: page_pool: add missing free_percpu when page_pool_init fail Jijie Shao
  2023-10-30  9:31 ` Yunsheng Lin
  2023-10-30 12:07 ` Jiri Pirko
@ 2023-11-01 11:11 ` Ilias Apalodimas
  2023-11-02 11:50 ` patchwork-bot+netdevbpf
  3 siblings, 0 replies; 5+ messages in thread
From: Ilias Apalodimas @ 2023-11-01 11:11 UTC (permalink / raw)
  To: Jijie Shao
  Cc: hawk, davem, edumazet, kuba, pabeni, jdamato, shenjian15,
	wangjie125, liuyonglong, linyunsheng, netdev, linux-kernel

On Mon, 30 Oct 2023 at 11:17, Jijie Shao <shaojijie@huawei.com> wrote:
>
> From: Jian Shen <shenjian15@huawei.com>
>
> When ptr_ring_init() returns failure in page_pool_init(), free_percpu()
> is not called to free pool->recycle_stats, which may cause memory
> leak.
>
> Fixes: ad6fa1e1ab1b ("page_pool: Add recycle stats")
> Signed-off-by: Jian Shen <shenjian15@huawei.com>
> Signed-off-by: Jijie Shao <shaojijie@huawei.com>
> ---
>  net/core/page_pool.c | 6 +++++-
>  1 file changed, 5 insertions(+), 1 deletion(-)
>
> diff --git a/net/core/page_pool.c b/net/core/page_pool.c
> index 77cb75e63aca..31f923e7b5c4 100644
> --- a/net/core/page_pool.c
> +++ b/net/core/page_pool.c
> @@ -221,8 +221,12 @@ static int page_pool_init(struct page_pool *pool,
>                 return -ENOMEM;
>  #endif
>
> -       if (ptr_ring_init(&pool->ring, ring_qsize, GFP_KERNEL) < 0)
> +       if (ptr_ring_init(&pool->ring, ring_qsize, GFP_KERNEL) < 0) {
> +#ifdef CONFIG_PAGE_POOL_STATS
> +               free_percpu(pool->recycle_stats);
> +#endif
>                 return -ENOMEM;
> +       }
>
>         atomic_set(&pool->pages_state_release_cnt, 0);
>
> --
> 2.30.0
>
Reviewed-by: Ilias Apalodimas <ilias.apalodimas@linaro.org>

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [PATCH net] net: page_pool: add missing free_percpu when page_pool_init fail
  2023-10-30  9:12 [PATCH net] net: page_pool: add missing free_percpu when page_pool_init fail Jijie Shao
                   ` (2 preceding siblings ...)
  2023-11-01 11:11 ` Ilias Apalodimas
@ 2023-11-02 11:50 ` patchwork-bot+netdevbpf
  3 siblings, 0 replies; 5+ messages in thread
From: patchwork-bot+netdevbpf @ 2023-11-02 11:50 UTC (permalink / raw)
  To: Jijie Shao
  Cc: hawk, ilias.apalodimas, davem, edumazet, kuba, pabeni, jdamato,
	shenjian15, wangjie125, liuyonglong, linyunsheng, netdev,
	linux-kernel

Hello:

This patch was applied to netdev/net.git (main)
by Paolo Abeni <pabeni@redhat.com>:

On Mon, 30 Oct 2023 17:12:56 +0800 you wrote:
> From: Jian Shen <shenjian15@huawei.com>
> 
> When ptr_ring_init() returns failure in page_pool_init(), free_percpu()
> is not called to free pool->recycle_stats, which may cause memory
> leak.
> 
> Fixes: ad6fa1e1ab1b ("page_pool: Add recycle stats")
> Signed-off-by: Jian Shen <shenjian15@huawei.com>
> Signed-off-by: Jijie Shao <shaojijie@huawei.com>
> 
> [...]

Here is the summary with links:
  - [net] net: page_pool: add missing free_percpu when page_pool_init fail
    https://git.kernel.org/netdev/net/c/8ffbd1669ed1

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-11-02 11:50 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-10-30  9:12 [PATCH net] net: page_pool: add missing free_percpu when page_pool_init fail Jijie Shao
2023-10-30  9:31 ` Yunsheng Lin
2023-10-30 12:07 ` Jiri Pirko
2023-11-01 11:11 ` Ilias Apalodimas
2023-11-02 11:50 ` 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;
as well as URLs for NNTP newsgroup(s).