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

Message ID 1708652745-18556-1-git-send-email-wangyunjian@huawei.com (mailing list archive)
State Accepted, archived
Delegated to: Ferruh Yigit
Headers
Series [v3] 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/intel-Functional success Functional PASS
ci/github-robot: build success github build: passed
ci/iol-testing warning apply patch failure

Commit Message

Yunjian Wang Feb. 23, 2024, 1:45 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>
---
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(-)
  

Comments

Ferruh Yigit Feb. 23, 2024, 11:42 a.m. UTC | #1
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.
  

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..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);