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 71FA3A2EFC for ; Mon, 14 Oct 2019 02:02:09 +0200 (CEST) Received: from [92.243.14.124] (localhost [127.0.0.1]) by dpdk.org (Postfix) with ESMTP id 3204E1C1D9; Mon, 14 Oct 2019 02:01:39 +0200 (CEST) Received: from rnd-relay.smtp.broadcom.com (rnd-relay.smtp.broadcom.com [192.19.229.170]) by dpdk.org (Postfix) with ESMTP id DBB621BF12; Mon, 14 Oct 2019 02:01:25 +0200 (CEST) Received: from mail-irv-17.broadcom.com (mail-irv-17.lvn.broadcom.net [10.75.242.48]) by rnd-relay.smtp.broadcom.com (Postfix) with ESMTP id 0258130C117; Sun, 13 Oct 2019 16:59:41 -0700 (PDT) DKIM-Filter: OpenDKIM Filter v2.10.3 rnd-relay.smtp.broadcom.com 0258130C117 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=broadcom.com; s=dkimrelay; t=1571011181; bh=sMFHPbNQT0XSwrMVCHyuhwt7r58riwQzOH9CFKGP1jg=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=F48r+ryzNSokG4jTA1475Yfy+HMza7z6harzrxCnWqp5umkMH9+orRfaiiPBne4nZ xuVYJlLgGTw10wDX8YgKYDc3P/SEXUY/lNxsmxvRcS5vlIbkFep+YHiVGE/juuJ+i1 UvlcdDrycHMYlKCajLgn7cDzuRPynkSefx33PaN8= Received: from localhost.localdomain (unknown [10.230.30.225]) by mail-irv-17.broadcom.com (Postfix) with ESMTP id 6A03314008C; Sun, 13 Oct 2019 17:01:24 -0700 (PDT) From: Ajit Khaparde To: dev@dpdk.org Cc: ferruh.yigit@intel.com, Somnath Kotur , stable@dpdk.org, Kalesh AP Date: Sun, 13 Oct 2019 17:01:18 -0700 Message-Id: <20191014000120.3020-6-ajit.khaparde@broadcom.com> X-Mailer: git-send-email 2.20.1 (Apple Git-117) In-Reply-To: <20191014000120.3020-1-ajit.khaparde@broadcom.com> References: <20191014000120.3020-1-ajit.khaparde@broadcom.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Subject: [dpdk-dev] [PATCH 5/7] net/bnxt: fix race between interrupt handler and dev config 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" From: Somnath Kotur Fix a possible that while interrupt handler is in the middle of processing, dev_configure_op() might come in and try to destroy/realloc the default completion ring on which interrupt completions arrive. Synchronize the two so they don't race each other Fixes: 7bc8e9a227cc ("net/bnxt: support async link notification") Cc: stable@dpdk.org Signed-off-by: Somnath Kotur Signed-off-by: Kalesh AP Reviewed-by: Ajit Khaparde --- drivers/net/bnxt/bnxt.h | 1 + drivers/net/bnxt/bnxt_ethdev.c | 19 +++++++++++++++++-- drivers/net/bnxt/bnxt_irq.c | 7 ++++++- 3 files changed, 24 insertions(+), 3 deletions(-) diff --git a/drivers/net/bnxt/bnxt.h b/drivers/net/bnxt/bnxt.h index 189f693b06..e5bdf63602 100644 --- a/drivers/net/bnxt/bnxt.h +++ b/drivers/net/bnxt/bnxt.h @@ -574,6 +574,7 @@ struct bnxt { void *hwrm_short_cmd_req_addr; rte_iova_t hwrm_short_cmd_req_dma_addr; rte_spinlock_t hwrm_lock; + pthread_mutex_t def_cp_lock; uint16_t max_req_len; uint16_t max_resp_len; uint16_t hwrm_max_ext_req_len; diff --git a/drivers/net/bnxt/bnxt_ethdev.c b/drivers/net/bnxt/bnxt_ethdev.c index b58a875c7d..e7ec99e15d 100644 --- a/drivers/net/bnxt/bnxt_ethdev.c +++ b/drivers/net/bnxt/bnxt_ethdev.c @@ -627,6 +627,9 @@ static int bnxt_dev_configure_op(struct rte_eth_dev *eth_dev) * resource reservation. This will ensure the resource counts * are calculated correctly. */ + + pthread_mutex_lock(&bp->def_cp_lock); + if (!BNXT_HAS_NQ(bp) && bp->async_cp_ring) { bnxt_disable_int(bp); bnxt_free_cp_ring(bp, bp->async_cp_ring); @@ -635,15 +638,20 @@ static int bnxt_dev_configure_op(struct rte_eth_dev *eth_dev) rc = bnxt_hwrm_func_reserve_vf_resc(bp, false); if (rc) { PMD_DRV_LOG(ERR, "HWRM resource alloc fail:%x\n", rc); + pthread_mutex_unlock(&bp->def_cp_lock); return -ENOSPC; } if (!BNXT_HAS_NQ(bp) && bp->async_cp_ring) { rc = bnxt_alloc_async_cp_ring(bp); - if (rc) + if (rc) { + pthread_mutex_unlock(&bp->def_cp_lock); return rc; + } bnxt_enable_int(bp); } + + pthread_mutex_unlock(&bp->def_cp_lock); } else { /* legacy driver needs to get updated values */ rc = bnxt_hwrm_func_qcaps(bp); @@ -4585,8 +4593,14 @@ bnxt_init_locks(struct bnxt *bp) int err; err = pthread_mutex_init(&bp->flow_lock, NULL); - if (err) + if (err) { PMD_DRV_LOG(ERR, "Unable to initialize flow_lock\n"); + return err; + } + + err = pthread_mutex_init(&bp->def_cp_lock, NULL); + if (err) + PMD_DRV_LOG(ERR, "Unable to initialize def_cp_lock\n"); return err; } @@ -4735,6 +4749,7 @@ static void bnxt_uninit_locks(struct bnxt *bp) { pthread_mutex_destroy(&bp->flow_lock); + pthread_mutex_destroy(&bp->def_cp_lock); } static int diff --git a/drivers/net/bnxt/bnxt_irq.c b/drivers/net/bnxt/bnxt_irq.c index 6c5bcfb623..4feb637e22 100644 --- a/drivers/net/bnxt/bnxt_irq.c +++ b/drivers/net/bnxt/bnxt_irq.c @@ -30,9 +30,12 @@ void bnxt_int_handler(void *param) return; raw_cons = cpr->cp_raw_cons; + pthread_mutex_lock(&bp->def_cp_lock); while (1) { - if (!cpr || !cpr->cp_ring_struct || !cpr->cp_db.doorbell) + if (!cpr || !cpr->cp_ring_struct || !cpr->cp_db.doorbell) { + pthread_mutex_unlock(&bp->def_cp_lock); return; + } cons = RING_CMP(cpr->cp_ring_struct, raw_cons); cmp = &cpr->cp_desc_ring[cons]; @@ -49,6 +52,8 @@ void bnxt_int_handler(void *param) bnxt_db_nq_arm(cpr); else B_CP_DB_REARM(cpr, cpr->cp_raw_cons); + + pthread_mutex_unlock(&bp->def_cp_lock); } int bnxt_free_int(struct bnxt *bp) -- 2.20.1 (Apple Git-117)