DPDK patches and discussions
 help / color / mirror / Atom feed
From: Zhichao Zeng <zhichaox.zeng@intel.com>
To: dev@dpdk.org
Cc: qi.z.zhang@intel.com, songx.jiale@intel.com,
	Zhichao Zeng <zhichaox.zeng@intel.com>,
	Jingjing Wu <jingjing.wu@intel.com>,
	Beilei Xing <beilei.xing@intel.com>
Subject: [PATCH v2] net/iavf: refactor part of watchdog
Date: Mon, 14 Aug 2023 17:09:31 +0800	[thread overview]
Message-ID: <20230814090931.1657971-1-zhichaox.zeng@intel.com> (raw)
In-Reply-To: <20230802071521.1842377-1-zhichaox.zeng@intel.com>

This commit refactors two parts of the watchdog:
1. Cancel the rte_eal_alarm when closing the watchdog to avoid
   ASAN heap-use-after-free error in some conditions.
2. Modify the logs when enabling and disabling the watchdog to be
   more detailed.

Fixes: af801b0374e3 ("net/iavf: add devargs to control watchdog")
Signed-off-by: Zhichao Zeng <zhichaox.zeng@intel.com>

---
v2: improve git log
---
 drivers/net/iavf/iavf_ethdev.c | 29 ++++++++++++++++++-----------
 1 file changed, 18 insertions(+), 11 deletions(-)

diff --git a/drivers/net/iavf/iavf_ethdev.c b/drivers/net/iavf/iavf_ethdev.c
index f2fc5a5621..c0ca733c67 100644
--- a/drivers/net/iavf/iavf_ethdev.c
+++ b/drivers/net/iavf/iavf_ethdev.c
@@ -324,24 +324,31 @@ iavf_dev_watchdog(void *cb_arg)
 void
 iavf_dev_watchdog_enable(struct iavf_adapter *adapter)
 {
-	if (adapter->devargs.watchdog_period && !adapter->vf.watchdog_enabled) {
-		PMD_DRV_LOG(INFO, "Enabling device watchdog, period is %dμs",
-					adapter->devargs.watchdog_period);
-		adapter->vf.watchdog_enabled = true;
-		if (rte_eal_alarm_set(adapter->devargs.watchdog_period,
-					&iavf_dev_watchdog, (void *)adapter))
-			PMD_DRV_LOG(ERR, "Failed to enabled device watchdog");
-	} else {
+	if (!adapter->devargs.watchdog_period) {
 		PMD_DRV_LOG(INFO, "Device watchdog is disabled");
+	} else {
+		if (!adapter->vf.watchdog_enabled) {
+			PMD_DRV_LOG(INFO, "Enabling device watchdog, period is %dμs",
+						adapter->devargs.watchdog_period);
+			adapter->vf.watchdog_enabled = true;
+			if (rte_eal_alarm_set(adapter->devargs.watchdog_period,
+						&iavf_dev_watchdog, (void *)adapter))
+				PMD_DRV_LOG(ERR, "Failed to enable device watchdog");
+		}
 	}
 }
 
 void
 iavf_dev_watchdog_disable(struct iavf_adapter *adapter)
 {
-	if (adapter->devargs.watchdog_period && adapter->vf.watchdog_enabled) {
-		PMD_DRV_LOG(INFO, "Disabling device watchdog");
-		adapter->vf.watchdog_enabled = false;
+	if (!adapter->devargs.watchdog_period) {
+		PMD_DRV_LOG(INFO, "Device watchdog is not enabled");
+	} else {
+		if (adapter->vf.watchdog_enabled) {
+			PMD_DRV_LOG(INFO, "Disabling device watchdog");
+			adapter->vf.watchdog_enabled = false;
+			rte_eal_alarm_cancel(&iavf_dev_watchdog, (void *)adapter);
+		}
 	}
 }
 
-- 
2.34.1


  reply	other threads:[~2023-08-14  9:03 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-08-02  7:15 [PATCH] net/iavf: fix ASan error caused by watchdog Zhichao Zeng
2023-08-14  9:09 ` Zhichao Zeng [this message]
2023-08-14 12:01   ` [PATCH v2] net/iavf: refactor part of watchdog Zhang, Qi Z

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=20230814090931.1657971-1-zhichaox.zeng@intel.com \
    --to=zhichaox.zeng@intel.com \
    --cc=beilei.xing@intel.com \
    --cc=dev@dpdk.org \
    --cc=jingjing.wu@intel.com \
    --cc=qi.z.zhang@intel.com \
    --cc=songx.jiale@intel.com \
    /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).