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 ACFC6427F0; Wed, 22 Mar 2023 07:01:09 +0100 (CET) Received: from mails.dpdk.org (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id 48FAC410D1; Wed, 22 Mar 2023 07:01:09 +0100 (CET) Received: from mga01.intel.com (mga01.intel.com [192.55.52.88]) by mails.dpdk.org (Postfix) with ESMTP id E5B7840F18; Wed, 22 Mar 2023 07:01:07 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1679464868; x=1711000868; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=qeXJsbEMp+7E4PttZi5wL9Gk61l3Wxj6nHFFMRqWt+Y=; b=E1BLRdUx46YS1QWSMc4h3JUythr23TgZNoB4xq/ObkbWz9VSOdQWoYU+ jI96M+HmPJqm4R+j6wgA5oVNkiQ4exZpNggHYTuDBKhwL4oTaH87vdDQK E8i8YpPI7IzlCDNjTiUQoyzbBGjTMQyH7UI04OXokX0KqQKV4caOGrnnL zDAduHgC/D86fWNm6UkSBqHU+cHke5kk7WScjuZSHG59M88hykia7Jlai wGzgwUTl/3mIcpLjJ88zKI+PfEa4JyWK5MUs2JLVXFEkW1emGzkoUhrT+ S+gLaCfaliMO6prGbFABThZoEdu9/TCPoUEqMOCMIbPuM9nD/BGlIv+O8 Q==; X-IronPort-AV: E=McAfee;i="6600,9927,10656"; a="366871703" X-IronPort-AV: E=Sophos;i="5.98,280,1673942400"; d="scan'208";a="366871703" Received: from orsmga005.jf.intel.com ([10.7.209.41]) by fmsmga101.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 21 Mar 2023 23:01:03 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=McAfee;i="6600,9927,10656"; a="856002037" X-IronPort-AV: E=Sophos;i="5.98,280,1673942400"; d="scan'208";a="856002037" Received: from unknown (HELO localhost.localdomain) ([10.239.252.253]) by orsmga005-auth.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 21 Mar 2023 23:01:00 -0700 From: Mingjin Ye To: dev@dpdk.org Cc: qiming.yang@intel.com, stable@dpdk.org, yidingx.zhou@intel.com, Mingjin Ye , Ke Zhang , Qi Zhang Subject: [PATCH v6] net/ice: fix ice dcf control thread crash Date: Wed, 22 Mar 2023 05:56:06 +0000 Message-Id: <20230322055606.84874-1-mingjinx.ye@intel.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20230320094030.18949-1-mingjinx.ye@intel.com> References: <20230320094030.18949-1-mingjinx.ye@intel.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit 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 The control thread accesses the hardware resources after the resources were released, which results in a segment error. The 'ice-reset' threads are detached, so thread resources cannot be reclaimed by `pthread_join` calls. This commit synchronizes the number of "ice-reset" threads by adding a variable ("vsi_update_thread_num") to the "struct ice_dcf_hw" and performing an atomic operation on this variable. When releasing HW resources, we wait for the number of "ice-reset" threads to be reduced to 0 before releasing the resources. Fixes: c7e1a1a3bfeb ("net/ice: refactor DCF VLAN handling") Fixes: 7564d5509611 ("net/ice: add DCF hardware initialization") Fixes: 0b02c9519432 ("net/ice: handle PF initialization by DCF") Cc: stable@dpdk.org Signed-off-by: Ke Zhang Signed-off-by: Mingjin Ye --- v2: add pthread_exit() for windows --- v3: Optimization. It is unsafe for a thread to forcibly exit, which will cause the spin lock to not be released correctly --- v4: Safely wait for all event threads to end --- v5: Spinlock moved to struct ice_dcf_hw --- v6: Spinlock changed to atomic --- drivers/net/ice/ice_dcf.c | 9 +++++++++ drivers/net/ice/ice_dcf.h | 2 ++ drivers/net/ice/ice_dcf_parent.c | 6 ++++++ 3 files changed, 17 insertions(+) diff --git a/drivers/net/ice/ice_dcf.c b/drivers/net/ice/ice_dcf.c index 1c3d22ae0f..adf2cf2cb6 100644 --- a/drivers/net/ice/ice_dcf.c +++ b/drivers/net/ice/ice_dcf.c @@ -32,6 +32,8 @@ #define ICE_DCF_ARQ_MAX_RETRIES 200 #define ICE_DCF_ARQ_CHECK_TIME 2 /* msecs */ +#define ICE_DCF_CHECK_INTERVAL 100 /* 100ms */ + #define ICE_DCF_VF_RES_BUF_SZ \ (sizeof(struct virtchnl_vf_resource) + \ IAVF_MAX_VF_VSI * sizeof(struct virtchnl_vsi_resource)) @@ -639,6 +641,8 @@ ice_dcf_init_hw(struct rte_eth_dev *eth_dev, struct ice_dcf_hw *hw) rte_spinlock_init(&hw->vc_cmd_queue_lock); TAILQ_INIT(&hw->vc_cmd_queue); + __atomic_store_n(&hw->vsi_update_thread_num, 0, __ATOMIC_RELAXED); + hw->arq_buf = rte_zmalloc("arq_buf", ICE_DCF_AQ_BUF_SZ, 0); if (hw->arq_buf == NULL) { PMD_INIT_LOG(ERR, "unable to allocate AdminQ buffer memory"); @@ -760,6 +764,11 @@ ice_dcf_uninit_hw(struct rte_eth_dev *eth_dev, struct ice_dcf_hw *hw) rte_intr_callback_unregister(intr_handle, ice_dcf_dev_interrupt_handler, hw); + /* Wait for all `ice-thread` threads to exit. */ + while (__atomic_load_n(&hw->vsi_update_thread_num, + __ATOMIC_ACQUIRE) != 0) + rte_delay_ms(ICE_DCF_CHECK_INTERVAL); + ice_dcf_mode_disable(hw); iavf_shutdown_adminq(&hw->avf); diff --git a/drivers/net/ice/ice_dcf.h b/drivers/net/ice/ice_dcf.h index 7f42ebabe9..7becf6d187 100644 --- a/drivers/net/ice/ice_dcf.h +++ b/drivers/net/ice/ice_dcf.h @@ -105,6 +105,8 @@ struct ice_dcf_hw { void (*vc_event_msg_cb)(struct ice_dcf_hw *dcf_hw, uint8_t *msg, uint16_t msglen); + int vsi_update_thread_num; + uint8_t *arq_buf; uint16_t num_vfs; diff --git a/drivers/net/ice/ice_dcf_parent.c b/drivers/net/ice/ice_dcf_parent.c index 01e390ddda..6ee0fbcd2b 100644 --- a/drivers/net/ice/ice_dcf_parent.c +++ b/drivers/net/ice/ice_dcf_parent.c @@ -154,6 +154,9 @@ ice_dcf_vsi_update_service_handler(void *param) free(param); + __atomic_fetch_sub(&hw->vsi_update_thread_num, 1, + __ATOMIC_RELEASE); + return NULL; } @@ -183,6 +186,9 @@ start_vsi_reset_thread(struct ice_dcf_hw *dcf_hw, bool vfr, uint16_t vf_id) PMD_DRV_LOG(ERR, "Failed to start the thread for reset handling"); free(param); } + + __atomic_fetch_add(&dcf_hw->vsi_update_thread_num, 1, + __ATOMIC_RELAXED); } static uint32_t -- 2.25.1