netdev.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH net] net/smc: Fix memory leak when using percpu refs
@ 2024-10-10 11:56 Kai Shen
  2024-10-10 12:17 ` Dust Li
                   ` (2 more replies)
  0 siblings, 3 replies; 4+ messages in thread
From: Kai Shen @ 2024-10-10 11:56 UTC (permalink / raw)
  To: kgraul, wenjia, jaka, guwen, kuba
  Cc: davem, tonylu, netdev, linux-s390, linux-rdma

This patch adds missing percpu_ref_exit when releasing percpu refs.
When releasing percpu refs, percpu_ref_exit should be called.
Otherwise, memory leak happens.

Fixes: 79a22238b4f2 ("net/smc: Use percpu ref for wr tx reference")
Signed-off-by: Kai Shen <KaiShen@linux.alibaba.com>
---
 net/smc/smc_wr.c | 6 +++++-
 1 file changed, 5 insertions(+), 1 deletion(-)

diff --git a/net/smc/smc_wr.c b/net/smc/smc_wr.c
index 0021065a600a..994c0cd4fddb 100644
--- a/net/smc/smc_wr.c
+++ b/net/smc/smc_wr.c
@@ -648,8 +648,10 @@ void smc_wr_free_link(struct smc_link *lnk)
 	smc_wr_tx_wait_no_pending_sends(lnk);
 	percpu_ref_kill(&lnk->wr_reg_refs);
 	wait_for_completion(&lnk->reg_ref_comp);
+	percpu_ref_exit(&lnk->wr_reg_refs);
 	percpu_ref_kill(&lnk->wr_tx_refs);
 	wait_for_completion(&lnk->tx_ref_comp);
+	percpu_ref_exit(&lnk->wr_tx_refs);
 
 	if (lnk->wr_rx_dma_addr) {
 		ib_dma_unmap_single(ibdev, lnk->wr_rx_dma_addr,
@@ -912,11 +914,13 @@ int smc_wr_create_link(struct smc_link *lnk)
 	init_waitqueue_head(&lnk->wr_reg_wait);
 	rc = percpu_ref_init(&lnk->wr_reg_refs, smcr_wr_reg_refs_free, 0, GFP_KERNEL);
 	if (rc)
-		goto dma_unmap;
+		goto cancel_ref;
 	init_completion(&lnk->reg_ref_comp);
 	init_waitqueue_head(&lnk->wr_rx_empty_wait);
 	return rc;
 
+cancel_ref:
+	percpu_ref_exit(&lnk->wr_tx_refs);
 dma_unmap:
 	if (lnk->wr_rx_v2_dma_addr) {
 		ib_dma_unmap_single(ibdev, lnk->wr_rx_v2_dma_addr,
-- 
2.31.1


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

* Re: [PATCH net] net/smc: Fix memory leak when using percpu refs
  2024-10-10 11:56 [PATCH net] net/smc: Fix memory leak when using percpu refs Kai Shen
@ 2024-10-10 12:17 ` Dust Li
  2024-10-10 16:09 ` Wenjia Zhang
  2024-10-15  1:10 ` patchwork-bot+netdevbpf
  2 siblings, 0 replies; 4+ messages in thread
From: Dust Li @ 2024-10-10 12:17 UTC (permalink / raw)
  To: Kai Shen, kgraul, wenjia, jaka, guwen, kuba
  Cc: davem, tonylu, netdev, linux-s390, linux-rdma

On 2024-10-10 11:56:24, Kai Shen wrote:
>This patch adds missing percpu_ref_exit when releasing percpu refs.
>When releasing percpu refs, percpu_ref_exit should be called.
>Otherwise, memory leak happens.
>
>Fixes: 79a22238b4f2 ("net/smc: Use percpu ref for wr tx reference")
>Signed-off-by: Kai Shen <KaiShen@linux.alibaba.com>

Reviewed-by: Dust Li <dust.li@linux.alibaba.com>


>---
> net/smc/smc_wr.c | 6 +++++-
> 1 file changed, 5 insertions(+), 1 deletion(-)
>
>diff --git a/net/smc/smc_wr.c b/net/smc/smc_wr.c
>index 0021065a600a..994c0cd4fddb 100644
>--- a/net/smc/smc_wr.c
>+++ b/net/smc/smc_wr.c
>@@ -648,8 +648,10 @@ void smc_wr_free_link(struct smc_link *lnk)
> 	smc_wr_tx_wait_no_pending_sends(lnk);
> 	percpu_ref_kill(&lnk->wr_reg_refs);
> 	wait_for_completion(&lnk->reg_ref_comp);
>+	percpu_ref_exit(&lnk->wr_reg_refs);
> 	percpu_ref_kill(&lnk->wr_tx_refs);
> 	wait_for_completion(&lnk->tx_ref_comp);
>+	percpu_ref_exit(&lnk->wr_tx_refs);
> 
> 	if (lnk->wr_rx_dma_addr) {
> 		ib_dma_unmap_single(ibdev, lnk->wr_rx_dma_addr,
>@@ -912,11 +914,13 @@ int smc_wr_create_link(struct smc_link *lnk)
> 	init_waitqueue_head(&lnk->wr_reg_wait);
> 	rc = percpu_ref_init(&lnk->wr_reg_refs, smcr_wr_reg_refs_free, 0, GFP_KERNEL);
> 	if (rc)
>-		goto dma_unmap;
>+		goto cancel_ref;
> 	init_completion(&lnk->reg_ref_comp);
> 	init_waitqueue_head(&lnk->wr_rx_empty_wait);
> 	return rc;
> 
>+cancel_ref:
>+	percpu_ref_exit(&lnk->wr_tx_refs);
> dma_unmap:
> 	if (lnk->wr_rx_v2_dma_addr) {
> 		ib_dma_unmap_single(ibdev, lnk->wr_rx_v2_dma_addr,
>-- 
>2.31.1
>

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

* Re: [PATCH net] net/smc: Fix memory leak when using percpu refs
  2024-10-10 11:56 [PATCH net] net/smc: Fix memory leak when using percpu refs Kai Shen
  2024-10-10 12:17 ` Dust Li
@ 2024-10-10 16:09 ` Wenjia Zhang
  2024-10-15  1:10 ` patchwork-bot+netdevbpf
  2 siblings, 0 replies; 4+ messages in thread
From: Wenjia Zhang @ 2024-10-10 16:09 UTC (permalink / raw)
  To: Kai Shen, kgraul, jaka, guwen, kuba
  Cc: davem, tonylu, netdev, linux-s390, linux-rdma



On 10.10.24 13:56, Kai Shen wrote:
> This patch adds missing percpu_ref_exit when releasing percpu refs.
> When releasing percpu refs, percpu_ref_exit should be called.
> Otherwise, memory leak happens.
> 
> Fixes: 79a22238b4f2 ("net/smc: Use percpu ref for wr tx reference")
> Signed-off-by: Kai Shen <KaiShen@linux.alibaba.com>
> ---
>   net/smc/smc_wr.c | 6 +++++-
>   1 file changed, 5 insertions(+), 1 deletion(-)
> 
> diff --git a/net/smc/smc_wr.c b/net/smc/smc_wr.c
> index 0021065a600a..994c0cd4fddb 100644
> --- a/net/smc/smc_wr.c
> +++ b/net/smc/smc_wr.c
> @@ -648,8 +648,10 @@ void smc_wr_free_link(struct smc_link *lnk)
>   	smc_wr_tx_wait_no_pending_sends(lnk);
>   	percpu_ref_kill(&lnk->wr_reg_refs);
>   	wait_for_completion(&lnk->reg_ref_comp);
> +	percpu_ref_exit(&lnk->wr_reg_refs);
>   	percpu_ref_kill(&lnk->wr_tx_refs);
>   	wait_for_completion(&lnk->tx_ref_comp);
> +	percpu_ref_exit(&lnk->wr_tx_refs);
>   
>   	if (lnk->wr_rx_dma_addr) {
>   		ib_dma_unmap_single(ibdev, lnk->wr_rx_dma_addr,
> @@ -912,11 +914,13 @@ int smc_wr_create_link(struct smc_link *lnk)
>   	init_waitqueue_head(&lnk->wr_reg_wait);
>   	rc = percpu_ref_init(&lnk->wr_reg_refs, smcr_wr_reg_refs_free, 0, GFP_KERNEL);
>   	if (rc)
> -		goto dma_unmap;
> +		goto cancel_ref;
>   	init_completion(&lnk->reg_ref_comp);
>   	init_waitqueue_head(&lnk->wr_rx_empty_wait);
>   	return rc;
>   
> +cancel_ref:
> +	percpu_ref_exit(&lnk->wr_tx_refs);
>   dma_unmap:
>   	if (lnk->wr_rx_v2_dma_addr) {
>   		ib_dma_unmap_single(ibdev, lnk->wr_rx_v2_dma_addr,

It looks reasonable to me. Thanks for the fix!
Reviewed-by: Wenjia Zhang <wenjia@linux.ibm.com>

Thanks,
Wenjia


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

* Re: [PATCH net] net/smc: Fix memory leak when using percpu refs
  2024-10-10 11:56 [PATCH net] net/smc: Fix memory leak when using percpu refs Kai Shen
  2024-10-10 12:17 ` Dust Li
  2024-10-10 16:09 ` Wenjia Zhang
@ 2024-10-15  1:10 ` patchwork-bot+netdevbpf
  2 siblings, 0 replies; 4+ messages in thread
From: patchwork-bot+netdevbpf @ 2024-10-15  1:10 UTC (permalink / raw)
  To: Kai Shen
  Cc: kgraul, wenjia, jaka, guwen, kuba, davem, tonylu, netdev,
	linux-s390, linux-rdma

Hello:

This patch was applied to netdev/net.git (main)
by Jakub Kicinski <kuba@kernel.org>:

On Thu, 10 Oct 2024 11:56:24 +0000 you wrote:
> This patch adds missing percpu_ref_exit when releasing percpu refs.
> When releasing percpu refs, percpu_ref_exit should be called.
> Otherwise, memory leak happens.
> 
> Fixes: 79a22238b4f2 ("net/smc: Use percpu ref for wr tx reference")
> Signed-off-by: Kai Shen <KaiShen@linux.alibaba.com>
> 
> [...]

Here is the summary with links:
  - [net] net/smc: Fix memory leak when using percpu refs
    https://git.kernel.org/netdev/net/c/25c12b459db8

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] 4+ messages in thread

end of thread, other threads:[~2024-10-15  1:10 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2024-10-10 11:56 [PATCH net] net/smc: Fix memory leak when using percpu refs Kai Shen
2024-10-10 12:17 ` Dust Li
2024-10-10 16:09 ` Wenjia Zhang
2024-10-15  1:10 ` 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).