From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from dpdk.org (dpdk.org [92.243.14.124]) by inbox.dpdk.org (Postfix) with ESMTP id A64E1A04C3; Tue, 26 Nov 2019 11:50:14 +0100 (CET) Received: from [92.243.14.124] (localhost [127.0.0.1]) by dpdk.org (Postfix) with ESMTP id 44F7F2B88; Tue, 26 Nov 2019 11:50:13 +0100 (CET) Received: from mga04.intel.com (mga04.intel.com [192.55.52.120]) by dpdk.org (Postfix) with ESMTP id 6342A2A5D for ; Tue, 26 Nov 2019 11:50:11 +0100 (CET) X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False Received: from fmsmga003.fm.intel.com ([10.253.24.29]) by fmsmga104.fm.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 26 Nov 2019 02:50:10 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.69,245,1571727600"; d="scan'208";a="260664317" Received: from silpixa00399752.ir.intel.com (HELO silpixa00399752.ger.corp.intel.com) ([10.237.223.78]) by FMSMGA003.fm.intel.com with ESMTP; 26 Nov 2019 02:50:09 -0800 From: Ferruh Yigit To: Ferruh Yigit Cc: dev@dpdk.org Date: Tue, 26 Nov 2019 10:50:07 +0000 Message-Id: <20191126105007.62289-1-ferruh.yigit@intel.com> X-Mailer: git-send-email 2.21.0 MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Subject: [dpdk-dev] [PATCH] net/kni: fix crash caused by double stop X-BeenThere: dev@dpdk.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: DPDK patches and discussions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: dev-bounces@dpdk.org Sender: "dev" 'close()' calls 'stop()' and 'stop()' cancels pthread without any check. Calling 'stop()' & 'close()' sequentially tries to cancel pthread twice which will cause a crash. Adding a state check in 'stop()' before canceling the pthread to prevent multiple stop. Fixes: 696fbc7bb4fc ("net/kni: remove resources when port is closed") Signed-off-by: Ferruh Yigit --- drivers/net/kni/rte_eth_kni.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/drivers/net/kni/rte_eth_kni.c b/drivers/net/kni/rte_eth_kni.c index 7cba92e2e..d88cb1778 100644 --- a/drivers/net/kni/rte_eth_kni.c +++ b/drivers/net/kni/rte_eth_kni.c @@ -156,6 +156,8 @@ eth_kni_dev_start(struct rte_eth_dev *dev) } if (internals->no_request_thread == 0) { + internals->stop_thread = 0; + ret = rte_ctrl_thread_create(&internals->thread, "kni_handle_req", NULL, kni_handle_request, internals); @@ -177,7 +179,7 @@ eth_kni_dev_stop(struct rte_eth_dev *dev) struct pmd_internals *internals = dev->data->dev_private; int ret; - if (internals->no_request_thread == 0) { + if (internals->no_request_thread == 0 && internals->stop_thread == 0) { internals->stop_thread = 1; ret = pthread_cancel(internals->thread); @@ -187,8 +189,6 @@ eth_kni_dev_stop(struct rte_eth_dev *dev) ret = pthread_join(internals->thread, NULL); if (ret) PMD_LOG(ERR, "Can't join the thread"); - - internals->stop_thread = 0; } dev->data->dev_link.link_status = 0; -- 2.21.0