From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mails.dpdk.org (mails.dpdk.org [217.70.189.124]) by inbox.dpdk.org (Postfix) with ESMTP id B29F243B5E; Thu, 22 Feb 2024 14:35:46 +0100 (CET) Received: from mails.dpdk.org (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id 4932340281; Thu, 22 Feb 2024 14:35:46 +0100 (CET) Received: from szxga05-in.huawei.com (szxga05-in.huawei.com [45.249.212.191]) by mails.dpdk.org (Postfix) with ESMTP id 09BAE4027F; Thu, 22 Feb 2024 14:35:43 +0100 (CET) Received: from mail.maildlp.com (unknown [172.19.88.163]) by szxga05-in.huawei.com (SkyGuard) with ESMTP id 4TgYxl0Whnz1h0QQ; Thu, 22 Feb 2024 21:33:31 +0800 (CST) Received: from dggpemm500008.china.huawei.com (unknown [7.185.36.136]) by mail.maildlp.com (Postfix) with ESMTPS id B8F4C18002F; Thu, 22 Feb 2024 21:35:40 +0800 (CST) Received: from localhost (10.174.242.157) by dggpemm500008.china.huawei.com (7.185.36.136) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2507.35; Thu, 22 Feb 2024 21:35:40 +0800 From: Yunjian Wang To: CC: , , , Yunjian Wang , Subject: [PATCH v2] net/af_xdp: fix resources leak when xsk configure fails Date: Thu, 22 Feb 2024 21:35:39 +0800 Message-ID: <1708608939-14440-1-git-send-email-wangyunjian@huawei.com> X-Mailer: git-send-email 1.9.5.msysgit.1 In-Reply-To: <1708571262-48380-1-git-send-email-wangyunjian@huawei.com> References: <1708571262-48380-1-git-send-email-wangyunjian@huawei.com> MIME-Version: 1.0 Content-Type: text/plain X-Originating-IP: [10.174.242.157] X-ClientProxiedBy: dggems705-chm.china.huawei.com (10.3.19.182) To dggpemm500008.china.huawei.com (7.185.36.136) X-BeenThere: dev@dpdk.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: DPDK patches and discussions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: dev-bounces@dpdk.org 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 --- 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