net/af_xdp: fix resources leak when xsk configure fails

Message ID 1708571262-48380-1-git-send-email-wangyunjian@huawei.com (mailing list archive)
State Changes Requested, archived
Delegated to: Ferruh Yigit
Headers
Series 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-mellanox-Performance success Performance Testing PASS
ci/intel-Functional success Functional PASS
ci/iol-abi-testing success Testing PASS
ci/github-robot: build success github build: passed
ci/iol-compile-amd64-testing success Testing PASS
ci/iol-unit-amd64-testing success Testing PASS
ci/iol-unit-arm64-testing success Testing PASS
ci/iol-sample-apps-testing success Testing PASS
ci/iol-compile-arm64-testing success Testing PASS
ci/iol-intel-Functional success Functional 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, 3:07 a.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>
---
 drivers/net/af_xdp/rte_eth_af_xdp.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)
  

Comments

Maryam Tahhan Feb. 22, 2024, 9:54 a.m. UTC | #1
On 22/02/2024 03:07, 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>
> ---
>   drivers/net/af_xdp/rte_eth_af_xdp.c | 4 +++-
>   1 file changed, 3 insertions(+), 1 deletion(-)
>
> diff --git a/drivers/net/af_xdp/rte_eth_af_xdp.c b/drivers/net/af_xdp/rte_eth_af_xdp.c
> index 2d151e45c7..8b8b2cff9f 100644
> --- a/drivers/net/af_xdp/rte_eth_af_xdp.c
> +++ b/drivers/net/af_xdp/rte_eth_af_xdp.c
> @@ -1723,8 +1723,10 @@ xsk_configure(struct pmd_internals *internals, struct pkt_rx_queue *rxq,
>   out_xsk:
>   	xsk_socket__delete(rxq->xsk);
>   out_umem:
> -	if (__atomic_fetch_sub(&rxq->umem->refcnt, 1, __ATOMIC_ACQUIRE) - 1 == 0)
> +	if (__atomic_fetch_sub(&rxq->umem->refcnt, 1, __ATOMIC_ACQUIRE) - 1 == 0) {
> +		(void)xsk_umem__delete(rxq->umem->umem);
>   		xdp_umem_destroy(rxq->umem);
> +	}
>   
>   	return ret;
>   }

Does it make sense to: move `xsk_umem__delete()` inside `xdp_umem_destroy()` to be invoked after a NULL check for `umem->umem`
and then fixup the places where both functions are called to only invoke `xdp_umem_destroy()`? (Keeping all the umem cleanup code
in one place)

@Yunjian WDYT?

@Ciara WDYT?
  
Loftus, Ciara Feb. 22, 2024, 11:05 a.m. UTC | #2
> 
> On 22/02/2024 03:07, 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: mailto:stable@dpdk.org
> 
> Signed-off-by: Yunjian Wang mailto:wangyunjian@huawei.com
> ---
>  drivers/net/af_xdp/rte_eth_af_xdp.c | 4 +++-
>  1 file changed, 3 insertions(+), 1 deletion(-)
> 
> diff --git a/drivers/net/af_xdp/rte_eth_af_xdp.c
> b/drivers/net/af_xdp/rte_eth_af_xdp.c
> index 2d151e45c7..8b8b2cff9f 100644
> --- a/drivers/net/af_xdp/rte_eth_af_xdp.c
> +++ b/drivers/net/af_xdp/rte_eth_af_xdp.c
> @@ -1723,8 +1723,10 @@ xsk_configure(struct pmd_internals *internals,
> struct pkt_rx_queue *rxq,
>  out_xsk:
>  	xsk_socket__delete(rxq->xsk);
>  out_umem:
> -	if (__atomic_fetch_sub(&rxq->umem->refcnt, 1,
> __ATOMIC_ACQUIRE) - 1 == 0)
> +	if (__atomic_fetch_sub(&rxq->umem->refcnt, 1,
> __ATOMIC_ACQUIRE) - 1 == 0) {
> +		(void)xsk_umem__delete(rxq->umem->umem);
>  		xdp_umem_destroy(rxq->umem);
> +	}
> 
>  	return ret;
>  }
> 
> Does it make sense to: move `xsk_umem__delete()` inside
> `xdp_umem_destroy()` to be invoked after a NULL check for `umem->umem`
> and then fixup the places where both functions are called to only invoke
> `xdp_umem_destroy()`? (Keeping all the umem cleanup code
> in one place)
> @Yunjian WDYT?
> 
> @Ciara WDYT?

Thanks for the patch Yunjian.

@Maryam +1 for the suggestion I think it would be a good optimisation for the cleanup code.

Thanks,
Ciara

>
  
Yunjian Wang Feb. 22, 2024, 11:52 a.m. UTC | #3
> -----Original Message-----
> From: Loftus, Ciara [mailto:ciara.loftus@intel.com]
> Sent: Thursday, February 22, 2024 7:06 PM
> To: Tahhan, Maryam <mtahhan@redhat.com>; wangyunjian
> <wangyunjian@huawei.com>
> Cc: dev@dpdk.org; ferruh.yigit@amd.com; stable@dpdk.org
> Subject: RE: [PATCH] net/af_xdp: fix resources leak when xsk configure fails
> 
> >
> > On 22/02/2024 03:07, 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: mailto:stable@dpdk.org
> >
> > Signed-off-by: Yunjian Wang mailto:wangyunjian@huawei.com
> > ---
> >  drivers/net/af_xdp/rte_eth_af_xdp.c | 4 +++-
> >  1 file changed, 3 insertions(+), 1 deletion(-)
> >
> > diff --git a/drivers/net/af_xdp/rte_eth_af_xdp.c
> > b/drivers/net/af_xdp/rte_eth_af_xdp.c
> > index 2d151e45c7..8b8b2cff9f 100644
> > --- a/drivers/net/af_xdp/rte_eth_af_xdp.c
> > +++ b/drivers/net/af_xdp/rte_eth_af_xdp.c
> > @@ -1723,8 +1723,10 @@ xsk_configure(struct pmd_internals *internals,
> > struct pkt_rx_queue *rxq,
> >  out_xsk:
> >  	xsk_socket__delete(rxq->xsk);
> >  out_umem:
> > -	if (__atomic_fetch_sub(&rxq->umem->refcnt, 1,
> > __ATOMIC_ACQUIRE) - 1 == 0)
> > +	if (__atomic_fetch_sub(&rxq->umem->refcnt, 1,
> > __ATOMIC_ACQUIRE) - 1 == 0) {
> > +		(void)xsk_umem__delete(rxq->umem->umem);
> >  		xdp_umem_destroy(rxq->umem);
> > +	}
> >
> >  	return ret;
> >  }
> >
> > Does it make sense to: move `xsk_umem__delete()` inside
> > `xdp_umem_destroy()` to be invoked after a NULL check for `umem->umem`
> > and then fixup the places where both functions are called to only
> > invoke `xdp_umem_destroy()`? (Keeping all the umem cleanup code in one
> > place) @Yunjian WDYT?
> >
> > @Ciara WDYT?
> 
> Thanks for the patch Yunjian.
> 
> @Maryam +1 for the suggestion I think it would be a good optimisation for the
> cleanup code.

OK, I will update it in next version.

> 
> Thanks,
> Ciara
> 
> >
  

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..8b8b2cff9f 100644
--- a/drivers/net/af_xdp/rte_eth_af_xdp.c
+++ b/drivers/net/af_xdp/rte_eth_af_xdp.c
@@ -1723,8 +1723,10 @@  xsk_configure(struct pmd_internals *internals, struct pkt_rx_queue *rxq,
 out_xsk:
 	xsk_socket__delete(rxq->xsk);
 out_umem:
-	if (__atomic_fetch_sub(&rxq->umem->refcnt, 1, __ATOMIC_ACQUIRE) - 1 == 0)
+	if (__atomic_fetch_sub(&rxq->umem->refcnt, 1, __ATOMIC_ACQUIRE) - 1 == 0) {
+		(void)xsk_umem__delete(rxq->umem->umem);
 		xdp_umem_destroy(rxq->umem);
+	}
 
 	return ret;
 }