From patchwork Wed May 18 14:39:40 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Zhichao Zeng X-Patchwork-Id: 111272 X-Patchwork-Delegate: thomas@monjalon.net Return-Path: X-Original-To: patchwork@inbox.dpdk.org Delivered-To: patchwork@inbox.dpdk.org Received: from mails.dpdk.org (mails.dpdk.org [217.70.189.124]) by inbox.dpdk.org (Postfix) with ESMTP id 11E15A0503; Wed, 18 May 2022 08:40:15 +0200 (CEST) Received: from [217.70.189.124] (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id E937B40156; Wed, 18 May 2022 08:40:14 +0200 (CEST) Received: from mga01.intel.com (mga01.intel.com [192.55.52.88]) by mails.dpdk.org (Postfix) with ESMTP id 60B3B400D6 for ; Wed, 18 May 2022 08:40:13 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1652856013; x=1684392013; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=b87bL004pHtpQsCpBTt6voAzNyCgyIhmLELfy7q8lJY=; b=UxuxPpgVkYJeymdMATuHbHDJnbBOMvj4CXLhdjEnvXrHWDt0tBvMUrzp iiFzbVDUO32YVoYUGAwIWmEZSf+7gA7GsCfO/JBg3GOMAncXRtphgrtJR KWWLCxPo3WcFUVUMf3avztMaXWFIrknQcN2rpwPwYD9cTJuWIfE+acaCh N7iMpM3KJUKmCeoc8DRcBGYyij8B8Ix5ZedK02GGkk0cZjKLt5xLnSor3 NqbtE6H25sCbck7uHVi9/QHV/EfUzIb4znL22P0UavSThs70DKA7TpOv1 x9wJas0dml170QTIaUMrkykZOUi6OUzTEFYMDAFsl1o/8B3Qk3FYXruNe Q==; X-IronPort-AV: E=McAfee;i="6400,9594,10350"; a="296796990" X-IronPort-AV: E=Sophos;i="5.91,234,1647327600"; d="scan'208";a="296796990" Received: from orsmga008.jf.intel.com ([10.7.209.65]) by fmsmga101.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 17 May 2022 23:40:12 -0700 X-IronPort-AV: E=Sophos;i="5.91,234,1647327600"; d="scan'208";a="597573007" Received: from unknown (HELO localhost.localdomain) ([10.239.251.103]) by orsmga008-auth.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 17 May 2022 23:40:10 -0700 From: zhichaox.zeng@intel.com To: dev@dpdk.org, qiming.yang@intel.com Cc: Zhichao Zeng , Bruce Richardson , Harman Kalra Subject: [DPDK v2] lib/eal: fix segfaults due to thread exit order Date: Wed, 18 May 2022 14:39:40 +0000 Message-Id: <20220518143940.597724-1-zhichaox.zeng@intel.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20220517160444.413819-1-zhichaox.zeng@intel.com> References: <20220517160444.413819-1-zhichaox.zeng@intel.com> MIME-Version: 1.0 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 From: Zhichao Zeng The eal-intr-thread is not closed before exiting the main thread. There is a small probability that when the eal-intr-thread is about to use some pointers, the pointers were just released in the process of exiting, which cause the segment fault error caught by ASan. Close the eal-intr-thread before exiting the mian thread to avoid segment fault. Signed-off-by: Zhichao Zeng --- lib/eal/common/eal_private.h | 7 +++++++ lib/eal/freebsd/eal.c | 1 + lib/eal/freebsd/eal_interrupts.c | 11 +++++++++++ lib/eal/linux/eal.c | 1 + lib/eal/linux/eal_interrupts.c | 12 ++++++++++++ 5 files changed, 32 insertions(+) diff --git a/lib/eal/common/eal_private.h b/lib/eal/common/eal_private.h index 44d14241f0..7adf41b7d7 100644 --- a/lib/eal/common/eal_private.h +++ b/lib/eal/common/eal_private.h @@ -152,6 +152,13 @@ int rte_eal_tailqs_init(void); */ int rte_eal_intr_init(void); +/** + * Destroy interrupt handling thread. + * + * This function is private to EAL. + */ +void rte_eal_intr_destroy(void); + /** * Close the default log stream * diff --git a/lib/eal/freebsd/eal.c b/lib/eal/freebsd/eal.c index a6b20960f2..0a6bd0efa3 100644 --- a/lib/eal/freebsd/eal.c +++ b/lib/eal/freebsd/eal.c @@ -893,6 +893,7 @@ rte_eal_cleanup(void) eal_get_internal_configuration(); rte_service_finalize(); rte_mp_channel_cleanup(); + rte_eal_intr_destroy(); /* after this point, any DPDK pointers will become dangling */ rte_eal_memory_detach(); rte_eal_alarm_cleanup(); diff --git a/lib/eal/freebsd/eal_interrupts.c b/lib/eal/freebsd/eal_interrupts.c index 9f720bdc8f..f9ea59720c 100644 --- a/lib/eal/freebsd/eal_interrupts.c +++ b/lib/eal/freebsd/eal_interrupts.c @@ -648,6 +648,17 @@ rte_eal_intr_init(void) return ret; } +void +rte_eal_intr_destroy() +{ + /* cancel the host thread */ + pthread_cancel(intr_thread); + pthread_join(intr_thread, NULL); + + close(kq); + kq = -1; +} + int rte_intr_rx_ctl(struct rte_intr_handle *intr_handle, int epfd, int op, unsigned int vec, void *data) diff --git a/lib/eal/linux/eal.c b/lib/eal/linux/eal.c index 1ef263434a..b310681acf 100644 --- a/lib/eal/linux/eal.c +++ b/lib/eal/linux/eal.c @@ -1266,6 +1266,7 @@ rte_eal_cleanup(void) vfio_mp_sync_cleanup(); #endif rte_mp_channel_cleanup(); + rte_eal_intr_destroy(); /* after this point, any DPDK pointers will become dangling */ rte_eal_memory_detach(); eal_mp_dev_hotplug_cleanup(); diff --git a/lib/eal/linux/eal_interrupts.c b/lib/eal/linux/eal_interrupts.c index d52ec8eb4c..b246b87273 100644 --- a/lib/eal/linux/eal_interrupts.c +++ b/lib/eal/linux/eal_interrupts.c @@ -1199,6 +1199,18 @@ rte_eal_intr_init(void) return ret; } +void +rte_eal_intr_destroy(void) +{ + /* cancel the host thread */ + pthread_cancel(intr_thread); + pthread_join(intr_thread, NULL); + + /* close the pipe used by epoll */ + close(intr_pipe.writefd); + close(intr_pipe.readfd); +} + static void eal_intr_proc_rxtx_intr(int fd, const struct rte_intr_handle *intr_handle) {