DPDK patches and discussions
 help / color / mirror / Atom feed
From: Rasesh Mody <rmody@marvell.com>
To: <dev@dpdk.org>
Cc: Rasesh Mody <rmody@marvell.com>, <ferruh.yigit@intel.com>,
	<GR-Everest-DPDK-Dev@marvell.com>, <stable@dpdk.org>
Subject: [dpdk-dev] [PATCH 5/6] net/bnx2x: fix race for periodic flags
Date: Thu, 11 Apr 2019 18:47:41 -0700	[thread overview]
Message-ID: <1555033662-22935-5-git-send-email-rmody@marvell.com> (raw)
In-Reply-To: <1555033662-22935-1-git-send-email-rmody@marvell.com>

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 <rmody@marvell.com>
---
 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) {
-- 
1.7.10.3

  parent reply	other threads:[~2019-04-12  1:48 UTC|newest]

Thread overview: 14+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-04-12  1:47 [dpdk-dev] [PATCH 1/6] net/bnx2x: fix eth dev MTU Rasesh Mody
2019-04-12  1:47 ` Rasesh Mody
2019-04-12  1:47 ` [dpdk-dev] [PATCH 2/6] net/bnx2x: fix memory leak Rasesh Mody
2019-04-12  1:47   ` Rasesh Mody
2019-04-12  1:47 ` [dpdk-dev] [PATCH 3/6] net/bnx2x: fix ramrod timeout Rasesh Mody
2019-04-12  1:47   ` Rasesh Mody
2019-04-12  1:47 ` [dpdk-dev] [PATCH 4/6] net/bnx2x: fix DMAE timeout Rasesh Mody
2019-04-12  1:47   ` Rasesh Mody
2019-04-12  1:47 ` Rasesh Mody [this message]
2019-04-12  1:47   ` [dpdk-dev] [PATCH 5/6] net/bnx2x: fix race for periodic flags Rasesh Mody
2019-04-12  1:47 ` [dpdk-dev] [PATCH 6/6] net/bnx2x: fix optic module verification Rasesh Mody
2019-04-12  1:47   ` Rasesh Mody
2019-04-15  8:01 ` [dpdk-dev] [PATCH 1/6] net/bnx2x: fix eth dev MTU Ferruh Yigit
2019-04-15  8:01   ` Ferruh Yigit

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1555033662-22935-5-git-send-email-rmody@marvell.com \
    --to=rmody@marvell.com \
    --cc=GR-Everest-DPDK-Dev@marvell.com \
    --cc=dev@dpdk.org \
    --cc=ferruh.yigit@intel.com \
    --cc=stable@dpdk.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).