From patchwork Fri Apr 12 01:47:41 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Rasesh Mody X-Patchwork-Id: 52660 X-Patchwork-Delegate: ferruh.yigit@amd.com Return-Path: X-Original-To: patchwork@dpdk.org Delivered-To: patchwork@dpdk.org Received: from [92.243.14.124] (localhost [127.0.0.1]) by dpdk.org (Postfix) with ESMTP id 86C4458EC; Fri, 12 Apr 2019 03:48:35 +0200 (CEST) Received: from mx0b-0016f401.pphosted.com (mx0a-0016f401.pphosted.com [67.231.148.174]) by dpdk.org (Postfix) with ESMTP id 027A74F98; Fri, 12 Apr 2019 03:48:23 +0200 (CEST) Received: from pps.filterd (m0045849.ppops.net [127.0.0.1]) by mx0a-0016f401.pphosted.com (8.16.0.27/8.16.0.27) with SMTP id x3C1jcHX004288; Thu, 11 Apr 2019 18:48:23 -0700 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=marvell.com; h=from : to : cc : subject : date : message-id : in-reply-to : references : mime-version : content-type; s=pfpt0818; bh=taQYdfv7g8z262BXRfPA1/AqS0Z6UUEE2BNza069tm0=; b=XVoN6ls6zw8AggnqDfa2Zm98dDpfczBsBS4SG2xtggZbg7kzpVUea1jyH2cepE+9wF7j Q1imD+LVgauMtn+eaV/TpiE6DQMcmfZzVQDOZWziB3Do0VsxM15Xm3FgNBO2KVyVX2Rl ue8erpsY1uHbfyrxp2ccc4o4MsbPWjfMPPt/MTuv4FTjYBALWGzLn0OJ2dQgMStVmbvf rROy9SnwE5VFldlxoHAHNDUBaMFvS/Jylo05VCU3zVTraV/moWhStJVq7XeDjBRoY520 +o6OWXaTZTyWJWYBSKvucVmpITcjCDZbobaP1BEOMlHx4UNZxK+Za9i2LqOqh2WnWSdo CQ== Received: from sc-exch01.marvell.com ([199.233.58.181]) by mx0a-0016f401.pphosted.com with ESMTP id 2rt7b8j6y8-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-SHA384 bits=256 verify=NOT); Thu, 11 Apr 2019 18:48:22 -0700 Received: from SC-EXCH01.marvell.com (10.93.176.81) by SC-EXCH01.marvell.com (10.93.176.81) with Microsoft SMTP Server (TLS) id 15.0.1367.3; Thu, 11 Apr 2019 18:48:22 -0700 Received: from maili.marvell.com (10.93.176.43) by SC-EXCH01.marvell.com (10.93.176.81) with Microsoft SMTP Server id 15.0.1367.3 via Frontend Transport; Thu, 11 Apr 2019 18:48:22 -0700 Received: from irv1user08.caveonetworks.com (unknown [10.104.116.105]) by maili.marvell.com (Postfix) with ESMTP id D0BF03F7040; Thu, 11 Apr 2019 18:48:21 -0700 (PDT) Received: (from rmody@localhost) by irv1user08.caveonetworks.com (8.14.4/8.14.4/Submit) id x3C1mLUe023004; Thu, 11 Apr 2019 18:48:21 -0700 X-Authentication-Warning: irv1user08.caveonetworks.com: rmody set sender to rmody@marvell.com using -f From: Rasesh Mody To: CC: Rasesh Mody , , , Date: Thu, 11 Apr 2019 18:47:41 -0700 Message-ID: <1555033662-22935-5-git-send-email-rmody@marvell.com> X-Mailer: git-send-email 1.7.10.3 In-Reply-To: <1555033662-22935-1-git-send-email-rmody@marvell.com> References: <1555033662-22935-1-git-send-email-rmody@marvell.com> MIME-Version: 1.0 X-Proofpoint-Virus-Version: vendor=fsecure engine=2.50.10434:, , definitions=2019-04-12_01:, , signatures=0 Subject: [dpdk-dev] [PATCH 5/6] net/bnx2x: fix race for periodic flags 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" The periodic callout function and the interrupt handler both modify the periodic flags. There is a possible race condition when an application is going through dev_stop()/dev_start() and an interrupt handler is invoked. We also need to ensure that periodic polling is not invoked in interrupt context. This patch handles such case by using separate variable to check for interrupt context. Also, atomically load and store the periodic flag value. Fixes: 0f6ebeee2402 ("net/bnx2x: fix call to link handling periodic function") Cc: stable@dpdk.org Signed-off-by: Rasesh Mody --- drivers/net/bnx2x/bnx2x_ethdev.c | 17 ++++++++++------- 1 file changed, 10 insertions(+), 7 deletions(-) diff --git a/drivers/net/bnx2x/bnx2x_ethdev.c b/drivers/net/bnx2x/bnx2x_ethdev.c index f85766c..3063aea 100644 --- a/drivers/net/bnx2x/bnx2x_ethdev.c +++ b/drivers/net/bnx2x/bnx2x_ethdev.c @@ -108,14 +108,15 @@ struct rte_bnx2x_xstats_name_off { } static void -bnx2x_interrupt_action(struct rte_eth_dev *dev) +bnx2x_interrupt_action(struct rte_eth_dev *dev, int intr_cxt) { struct bnx2x_softc *sc = dev->data->dev_private; uint32_t link_status; bnx2x_intr_legacy(sc); - if (sc->periodic_flags & PERIODIC_GO) + if ((atomic_load_acq_long(&sc->periodic_flags) == PERIODIC_GO) && + !intr_cxt) bnx2x_periodic_callout(sc); link_status = REG_RD(sc, sc->link_params.shmem_base + offsetof(struct shmem_region, @@ -132,9 +133,7 @@ struct rte_bnx2x_xstats_name_off { PMD_DEBUG_PERIODIC_LOG(INFO, sc, "Interrupt handled"); - atomic_store_rel_long(&sc->periodic_flags, PERIODIC_STOP); - bnx2x_interrupt_action(dev); - atomic_store_rel_long(&sc->periodic_flags, PERIODIC_GO); + bnx2x_interrupt_action(dev, 1); rte_intr_enable(&sc->pci_dev->intr_handle); } @@ -145,7 +144,7 @@ static void bnx2x_periodic_start(void *param) int ret = 0; atomic_store_rel_long(&sc->periodic_flags, PERIODIC_GO); - bnx2x_interrupt_action(dev); + bnx2x_interrupt_action(dev, 0); if (IS_PF(sc)) { ret = rte_eal_alarm_set(BNX2X_SP_TIMER_PERIOD, bnx2x_periodic_start, (void *)dev); @@ -165,6 +164,8 @@ void bnx2x_periodic_stop(void *param) atomic_store_rel_long(&sc->periodic_flags, PERIODIC_STOP); rte_eal_alarm_cancel(bnx2x_periodic_start, (void *)dev); + + PMD_DRV_LOG(DEBUG, sc, "Periodic poll stopped"); } /* @@ -226,8 +227,10 @@ void bnx2x_periodic_stop(void *param) PMD_INIT_FUNC_TRACE(sc); /* start the periodic callout */ - if (sc->periodic_flags & PERIODIC_STOP) + if (atomic_load_acq_long(&sc->periodic_flags) == PERIODIC_STOP) { bnx2x_periodic_start(dev); + PMD_DRV_LOG(DEBUG, sc, "Periodic poll re-started"); + } ret = bnx2x_init(sc); if (ret) {