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 90FD5A046B for ; Tue, 23 Jul 2019 03:03:45 +0200 (CEST) Received: from [92.243.14.124] (localhost [127.0.0.1]) by dpdk.org (Postfix) with ESMTP id 84A291BFA1; Tue, 23 Jul 2019 03:03:45 +0200 (CEST) Received: from mellanox.co.il (mail-il-dmz.mellanox.com [193.47.165.129]) by dpdk.org (Postfix) with ESMTP id CBCB11BFA1 for ; Tue, 23 Jul 2019 03:03:44 +0200 (CEST) Received: from Internal Mail-Server by MTLPINE2 (envelope-from yskoh@mellanox.com) with ESMTPS (AES256-SHA encrypted); 23 Jul 2019 04:03:41 +0300 Received: from scfae-sc-2.mti.labs.mlnx (scfae-sc-2.mti.labs.mlnx [10.101.0.96]) by labmailer.mlnx (8.13.8/8.13.8) with ESMTP id x6N11Hg7026580; Tue, 23 Jul 2019 04:03:40 +0300 From: Yongseok Koh To: Rasesh Mody Cc: dpdk stable Date: Mon, 22 Jul 2019 18:00:48 -0700 Message-Id: <20190723010115.6446-81-yskoh@mellanox.com> X-Mailer: git-send-email 2.21.0 In-Reply-To: <20190723010115.6446-1-yskoh@mellanox.com> References: <20190723010115.6446-1-yskoh@mellanox.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Subject: [dpdk-stable] patch 'net/bnx2x: fix race for periodic flags' has been queued to LTS release 17.11.7 X-BeenThere: stable@dpdk.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: patches for DPDK stable branches List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: stable-bounces@dpdk.org Sender: "stable" Hi, FYI, your patch has been queued to LTS release 17.11.7 Note it hasn't been pushed to http://dpdk.org/browse/dpdk-stable yet. It will be pushed if I get no objection by 07/27/19. So please shout if anyone has objection. Also note that after the patch there's a diff of the upstream commit vs the patch applied to the branch. This will indicate if there was any rebasing needed to apply to the stable branch. If there were code changes for rebasing (ie: not only metadata diffs), please double check that the rebase was correctly done. Thanks. Yongseok --- >From df8a13f3b793ed4cd6d9c01e2c8f47c8a3b544cb Mon Sep 17 00:00:00 2001 From: Rasesh Mody Date: Thu, 11 Apr 2019 18:47:41 -0700 Subject: [PATCH] net/bnx2x: fix race for periodic flags [ upstream commit c19eafccb22e1b1ca52439a936908cfd6fd12ff1 ] 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") 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 997e9ba1a0..efd6fd6c6a 100644 --- a/drivers/net/bnx2x/bnx2x_ethdev.c +++ b/drivers/net/bnx2x/bnx2x_ethdev.c @@ -164,14 +164,15 @@ bnx2x_link_update(struct rte_eth_dev *dev) } 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, @@ -188,9 +189,7 @@ bnx2x_interrupt_handler(void *param) 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); } @@ -201,7 +200,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); @@ -221,6 +220,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"); } /* @@ -310,8 +311,10 @@ bnx2x_dev_start(struct rte_eth_dev *dev) 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) { -- 2.21.0 --- Diff of the applied patch vs upstream commit (please double-check if non-empty: --- --- - 2019-07-22 17:55:10.836916169 -0700 +++ 0081-net-bnx2x-fix-race-for-periodic-flags.patch 2019-07-22 17:55:06.350473000 -0700 @@ -1,8 +1,10 @@ -From c19eafccb22e1b1ca52439a936908cfd6fd12ff1 Mon Sep 17 00:00:00 2001 +From df8a13f3b793ed4cd6d9c01e2c8f47c8a3b544cb Mon Sep 17 00:00:00 2001 From: Rasesh Mody Date: Thu, 11 Apr 2019 18:47:41 -0700 Subject: [PATCH] net/bnx2x: fix race for periodic flags +[ upstream commit c19eafccb22e1b1ca52439a936908cfd6fd12ff1 ] + 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 @@ -14,7 +16,6 @@ value. Fixes: 0f6ebeee2402 ("net/bnx2x: fix call to link handling periodic function") -Cc: stable@dpdk.org Signed-off-by: Rasesh Mody --- @@ -22,10 +23,10 @@ 1 file changed, 10 insertions(+), 7 deletions(-) diff --git a/drivers/net/bnx2x/bnx2x_ethdev.c b/drivers/net/bnx2x/bnx2x_ethdev.c -index f85766c687..3063aea647 100644 +index 997e9ba1a0..efd6fd6c6a 100644 --- a/drivers/net/bnx2x/bnx2x_ethdev.c +++ b/drivers/net/bnx2x/bnx2x_ethdev.c -@@ -108,14 +108,15 @@ bnx2x_link_update(struct rte_eth_dev *dev) +@@ -164,14 +164,15 @@ bnx2x_link_update(struct rte_eth_dev *dev) } static void @@ -43,7 +44,7 @@ bnx2x_periodic_callout(sc); link_status = REG_RD(sc, sc->link_params.shmem_base + offsetof(struct shmem_region, -@@ -132,9 +133,7 @@ bnx2x_interrupt_handler(void *param) +@@ -188,9 +189,7 @@ bnx2x_interrupt_handler(void *param) PMD_DEBUG_PERIODIC_LOG(INFO, sc, "Interrupt handled"); @@ -54,7 +55,7 @@ rte_intr_enable(&sc->pci_dev->intr_handle); } -@@ -145,7 +144,7 @@ static void bnx2x_periodic_start(void *param) +@@ -201,7 +200,7 @@ static void bnx2x_periodic_start(void *param) int ret = 0; atomic_store_rel_long(&sc->periodic_flags, PERIODIC_GO); @@ -63,7 +64,7 @@ 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) +@@ -221,6 +220,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); @@ -72,7 +73,7 @@ } /* -@@ -226,8 +227,10 @@ bnx2x_dev_start(struct rte_eth_dev *dev) +@@ -310,8 +311,10 @@ bnx2x_dev_start(struct rte_eth_dev *dev) PMD_INIT_FUNC_TRACE(sc); /* start the periodic callout */