[v2] net/af_xdp: fix resources leak when xsk configure fails

Message ID 1708608939-14440-1-git-send-email-wangyunjian@huawei.com (mailing list archive)
State Superseded, archived
Delegated to: Ferruh Yigit
Headers
Series [v2] net/af_xdp: fix resources leak when xsk configure fails |

Checks

Context Check Description
ci/checkpatch success coding style OK
ci/loongarch-compilation success Compilation OK
ci/loongarch-unit-testing success Unit Testing PASS
ci/Intel-compilation success Compilation OK
ci/intel-Testing success Testing PASS
ci/iol-intel-Performance success Performance Testing PASS
ci/iol-intel-Functional success Functional Testing PASS
ci/intel-Functional success Functional PASS
ci/iol-mellanox-Performance success Performance Testing PASS
ci/github-robot: build success github build: passed
ci/iol-abi-testing success Testing PASS
ci/iol-unit-amd64-testing fail Testing issues
ci/iol-compile-amd64-testing success Testing PASS
ci/iol-compile-arm64-testing success Testing PASS
ci/iol-unit-arm64-testing success Testing PASS
ci/iol-sample-apps-testing success Testing PASS
ci/iol-broadcom-Functional success Functional Testing PASS
ci/iol-broadcom-Performance success Performance Testing PASS

Commit Message

Yunjian Wang Feb. 22, 2024, 1:35 p.m. UTC
  In xdp_umem_configure() allocated some resources for the
xsk umem, we should delete them when xsk configure fails,
otherwise it will lead to resources leak.

Fixes: f1debd77efaf ("net/af_xdp: introduce AF_XDP PMD")
Cc: stable@dpdk.org

Signed-off-by: Yunjian Wang <wangyunjian@huawei.com>
---
v2: update code style as suggested by Maryam Tahhan
---
 drivers/net/af_xdp/rte_eth_af_xdp.c | 10 ++++++----
 1 file changed, 6 insertions(+), 4 deletions(-)
  

Comments

Ferruh Yigit Feb. 22, 2024, 3:54 p.m. UTC | #1
On 2/22/2024 1:35 PM, Yunjian Wang wrote:
> In xdp_umem_configure() allocated some resources for the
> xsk umem, we should delete them when xsk configure fails,
> otherwise it will lead to resources leak.
> 
> Fixes: f1debd77efaf ("net/af_xdp: introduce AF_XDP PMD")
> Cc: stable@dpdk.org
> 
> Signed-off-by: Yunjian Wang <wangyunjian@huawei.com>
> ---
> v2: update code style as suggested by Maryam Tahhan
> ---
>  drivers/net/af_xdp/rte_eth_af_xdp.c | 10 ++++++----
>  1 file changed, 6 insertions(+), 4 deletions(-)
> 
> diff --git a/drivers/net/af_xdp/rte_eth_af_xdp.c b/drivers/net/af_xdp/rte_eth_af_xdp.c
> index 2d151e45c7..b52513bd7e 100644
> --- a/drivers/net/af_xdp/rte_eth_af_xdp.c
> +++ b/drivers/net/af_xdp/rte_eth_af_xdp.c
> @@ -960,6 +960,11 @@ remove_xdp_program(struct pmd_internals *internals)
>  static void
>  xdp_umem_destroy(struct xsk_umem_info *umem)
>  {
> +	if (umem->umem) {
> +		(void)xsk_umem__delete(umem->umem);
> +		umem->umem = NULL;
> +	}
> +
>

NULL check can be eliminted, 'xsk_umem__delete()' already doing it
  
Loftus, Ciara Feb. 22, 2024, 3:58 p.m. UTC | #2
> Subject: [PATCH v2] net/af_xdp: fix resources leak when xsk configure fails
> 
> In xdp_umem_configure() allocated some resources for the
> xsk umem, we should delete them when xsk configure fails,
> otherwise it will lead to resources leak.
> 
> Fixes: f1debd77efaf ("net/af_xdp: introduce AF_XDP PMD")
> Cc: stable@dpdk.org
> 
> Signed-off-by: Yunjian Wang <wangyunjian@huawei.com>

Thanks!

Reviewed-by <ciara.loftus@intel.com>

> ---
> v2: update code style as suggested by Maryam Tahhan
> ---
>  drivers/net/af_xdp/rte_eth_af_xdp.c | 10 ++++++----
>  1 file changed, 6 insertions(+), 4 deletions(-)
> 
> diff --git a/drivers/net/af_xdp/rte_eth_af_xdp.c
> b/drivers/net/af_xdp/rte_eth_af_xdp.c
> index 2d151e45c7..b52513bd7e 100644
> --- a/drivers/net/af_xdp/rte_eth_af_xdp.c
> +++ b/drivers/net/af_xdp/rte_eth_af_xdp.c
> @@ -960,6 +960,11 @@ remove_xdp_program(struct pmd_internals
> *internals)
>  static void
>  xdp_umem_destroy(struct xsk_umem_info *umem)
>  {
> +	if (umem->umem) {
> +		(void)xsk_umem__delete(umem->umem);
> +		umem->umem = NULL;
> +	}
> +
>  #if defined(XDP_UMEM_UNALIGNED_CHUNK_FLAG)
>  	umem->mb_pool = NULL;
>  #else
> @@ -992,11 +997,8 @@ eth_dev_close(struct rte_eth_dev *dev)
>  			break;
>  		xsk_socket__delete(rxq->xsk);
> 
> -		if (__atomic_fetch_sub(&rxq->umem->refcnt, 1,
> __ATOMIC_ACQUIRE) - 1
> -				== 0) {
> -			(void)xsk_umem__delete(rxq->umem->umem);
> +		if (__atomic_fetch_sub(&rxq->umem->refcnt, 1,
> __ATOMIC_ACQUIRE) - 1 == 0)
>  			xdp_umem_destroy(rxq->umem);
> -		}
> 
>  		/* free pkt_tx_queue */
>  		rte_free(rxq->pair);
> --
> 2.41.0
  

Patch

diff --git a/drivers/net/af_xdp/rte_eth_af_xdp.c b/drivers/net/af_xdp/rte_eth_af_xdp.c
index 2d151e45c7..b52513bd7e 100644
--- a/drivers/net/af_xdp/rte_eth_af_xdp.c
+++ b/drivers/net/af_xdp/rte_eth_af_xdp.c
@@ -960,6 +960,11 @@  remove_xdp_program(struct pmd_internals *internals)
 static void
 xdp_umem_destroy(struct xsk_umem_info *umem)
 {
+	if (umem->umem) {
+		(void)xsk_umem__delete(umem->umem);
+		umem->umem = NULL;
+	}
+
 #if defined(XDP_UMEM_UNALIGNED_CHUNK_FLAG)
 	umem->mb_pool = NULL;
 #else
@@ -992,11 +997,8 @@  eth_dev_close(struct rte_eth_dev *dev)
 			break;
 		xsk_socket__delete(rxq->xsk);
 
-		if (__atomic_fetch_sub(&rxq->umem->refcnt, 1, __ATOMIC_ACQUIRE) - 1
-				== 0) {
-			(void)xsk_umem__delete(rxq->umem->umem);
+		if (__atomic_fetch_sub(&rxq->umem->refcnt, 1, __ATOMIC_ACQUIRE) - 1 == 0)
 			xdp_umem_destroy(rxq->umem);
-		}
 
 		/* free pkt_tx_queue */
 		rte_free(rxq->pair);