* [PATCH] net/af_xdp: fix resources leak when xsk configure fails
@ 2024-02-22 3:07 Yunjian Wang
2024-02-22 9:54 ` Maryam Tahhan
2024-02-22 13:35 ` [PATCH v2] " Yunjian Wang
0 siblings, 2 replies; 9+ messages in thread
From: Yunjian Wang @ 2024-02-22 3:07 UTC (permalink / raw)
To: dev; +Cc: ferruh.yigit, ciara.loftus, xudingke, Yunjian Wang, stable
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;
}
--
2.41.0
^ permalink raw reply [flat|nested] 9+ messages in thread
* Re: [PATCH] net/af_xdp: fix resources leak when xsk configure fails
2024-02-22 3:07 [PATCH] net/af_xdp: fix resources leak when xsk configure fails Yunjian Wang
@ 2024-02-22 9:54 ` Maryam Tahhan
2024-02-22 11:05 ` Loftus, Ciara
2024-02-22 13:35 ` [PATCH v2] " Yunjian Wang
1 sibling, 1 reply; 9+ messages in thread
From: Maryam Tahhan @ 2024-02-22 9:54 UTC (permalink / raw)
To: Yunjian Wang, Ciara Loftus; +Cc: dev, ferruh.yigit, stable
[-- Attachment #1: Type: text/plain, Size: 1401 bytes --]
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?
[-- Attachment #2: Type: text/html, Size: 2000 bytes --]
^ permalink raw reply [flat|nested] 9+ messages in thread
* RE: [PATCH] net/af_xdp: fix resources leak when xsk configure fails
2024-02-22 9:54 ` Maryam Tahhan
@ 2024-02-22 11:05 ` Loftus, Ciara
2024-02-22 11:52 ` wangyunjian
0 siblings, 1 reply; 9+ messages in thread
From: Loftus, Ciara @ 2024-02-22 11:05 UTC (permalink / raw)
To: Tahhan, Maryam, Yunjian Wang; +Cc: dev, ferruh.yigit, stable
>
> 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
>
^ permalink raw reply [flat|nested] 9+ messages in thread
* RE: [PATCH] net/af_xdp: fix resources leak when xsk configure fails
2024-02-22 11:05 ` Loftus, Ciara
@ 2024-02-22 11:52 ` wangyunjian
0 siblings, 0 replies; 9+ messages in thread
From: wangyunjian @ 2024-02-22 11:52 UTC (permalink / raw)
To: Loftus, Ciara, Tahhan, Maryam; +Cc: dev, ferruh.yigit, stable
> -----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
>
> >
^ permalink raw reply [flat|nested] 9+ messages in thread
* [PATCH v2] net/af_xdp: fix resources leak when xsk configure fails
2024-02-22 3:07 [PATCH] net/af_xdp: fix resources leak when xsk configure fails Yunjian Wang
2024-02-22 9:54 ` Maryam Tahhan
@ 2024-02-22 13:35 ` Yunjian Wang
2024-02-22 15:54 ` Ferruh Yigit
` (2 more replies)
1 sibling, 3 replies; 9+ messages in thread
From: Yunjian Wang @ 2024-02-22 13:35 UTC (permalink / raw)
To: dev; +Cc: ferruh.yigit, ciara.loftus, xudingke, Yunjian Wang, stable
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;
+ }
+
#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
^ permalink raw reply [flat|nested] 9+ messages in thread
* Re: [PATCH v2] net/af_xdp: fix resources leak when xsk configure fails
2024-02-22 13:35 ` [PATCH v2] " Yunjian Wang
@ 2024-02-22 15:54 ` Ferruh Yigit
2024-02-22 15:58 ` Loftus, Ciara
2024-02-23 1:45 ` [PATCH v3] " Yunjian Wang
2 siblings, 0 replies; 9+ messages in thread
From: Ferruh Yigit @ 2024-02-22 15:54 UTC (permalink / raw)
To: Yunjian Wang, dev; +Cc: ciara.loftus, xudingke, stable
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
^ permalink raw reply [flat|nested] 9+ messages in thread
* RE: [PATCH v2] net/af_xdp: fix resources leak when xsk configure fails
2024-02-22 13:35 ` [PATCH v2] " Yunjian Wang
2024-02-22 15:54 ` Ferruh Yigit
@ 2024-02-22 15:58 ` Loftus, Ciara
2024-02-23 1:45 ` [PATCH v3] " Yunjian Wang
2 siblings, 0 replies; 9+ messages in thread
From: Loftus, Ciara @ 2024-02-22 15:58 UTC (permalink / raw)
To: Yunjian Wang, dev; +Cc: ferruh.yigit, xudingke, stable
> 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
^ permalink raw reply [flat|nested] 9+ messages in thread
* [PATCH v3] net/af_xdp: fix resources leak when xsk configure fails
2024-02-22 13:35 ` [PATCH v2] " Yunjian Wang
2024-02-22 15:54 ` Ferruh Yigit
2024-02-22 15:58 ` Loftus, Ciara
@ 2024-02-23 1:45 ` Yunjian Wang
2024-02-23 11:42 ` Ferruh Yigit
2 siblings, 1 reply; 9+ messages in thread
From: Yunjian Wang @ 2024-02-23 1:45 UTC (permalink / raw)
To: dev; +Cc: ferruh.yigit, ciara.loftus, xudingke, Yunjian Wang, stable
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>
---
v3: remove unnecessary null check
v2: update code style as suggested by Maryam Tahhan
---
drivers/net/af_xdp/rte_eth_af_xdp.c | 7 +++----
1 file changed, 3 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..93c6f3b723 100644
--- a/drivers/net/af_xdp/rte_eth_af_xdp.c
+++ b/drivers/net/af_xdp/rte_eth_af_xdp.c
@@ -960,6 +960,8 @@ remove_xdp_program(struct pmd_internals *internals)
static void
xdp_umem_destroy(struct xsk_umem_info *umem)
{
+ (void)xsk_umem__delete(umem->umem);
+ umem->umem = NULL;
#if defined(XDP_UMEM_UNALIGNED_CHUNK_FLAG)
umem->mb_pool = NULL;
#else
@@ -992,11 +994,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
^ permalink raw reply [flat|nested] 9+ messages in thread
* Re: [PATCH v3] net/af_xdp: fix resources leak when xsk configure fails
2024-02-23 1:45 ` [PATCH v3] " Yunjian Wang
@ 2024-02-23 11:42 ` Ferruh Yigit
0 siblings, 0 replies; 9+ messages in thread
From: Ferruh Yigit @ 2024-02-23 11:42 UTC (permalink / raw)
To: Yunjian Wang, dev; +Cc: ciara.loftus, xudingke, stable
On 2/23/2024 1:45 AM, 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>
>
Moving from previous version:
Reviewed-by: Ciara Loftus <ciara.loftus@intel.com>
Acked-by: Ferruh Yigit <ferruh.yigit@amd.com>
Applied to dpdk-next-net/main, thanks.
^ permalink raw reply [flat|nested] 9+ messages in thread
end of thread, other threads:[~2024-02-23 11:42 UTC | newest]
Thread overview: 9+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2024-02-22 3:07 [PATCH] net/af_xdp: fix resources leak when xsk configure fails Yunjian Wang
2024-02-22 9:54 ` Maryam Tahhan
2024-02-22 11:05 ` Loftus, Ciara
2024-02-22 11:52 ` wangyunjian
2024-02-22 13:35 ` [PATCH v2] " Yunjian Wang
2024-02-22 15:54 ` Ferruh Yigit
2024-02-22 15:58 ` Loftus, Ciara
2024-02-23 1:45 ` [PATCH v3] " Yunjian Wang
2024-02-23 11:42 ` Ferruh Yigit
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).