Skip to contentSkip to conversation

iavf reset path fixes

PATCH Superseded Ciara Loftus 2 participants 20 messages Nov 4 – Nov 10 Network drivers

lore
Share & tools
lore
#0 lore raw

v2 cover iavf reset path fixes

Three fixes related to the reset path in iavf. The first patch was submitted as a standalone patch [1], but I've grouped it into this series.

[1] https://patches.dpdk.org/project/dpdk/patch/[email protected]/

Ciara Loftus (3):
net/iavf: fix crash in Tx drain on PF reset net/iavf: fix event handler leak on init failure net/iavf: fix watchdog clearing reset state during recovery

 drivers/net/intel/iavf/iavf.h        |  4 ++-
 drivers/net/intel/iavf/iavf_ethdev.c | 21 +++++++++---
 drivers/net/intel/iavf/iavf_rxtx.c   |  8 ++---
 drivers/net/intel/iavf/iavf_vchnl.c  | 48 ++++++++++++++++++++--------
 4 files changed, 56 insertions(+), 25 deletions(-)
Signature · 1 line
2.43.0
#1 lore raw

PATCH v2 1/3 net/iavf: fix crash in Tx drain on PF reset

The Tx cleanup helpers check the DD bit of the descriptor at the next RS boundary and assume software has already posted it. The burst path guarantees this by only cleaning up when nb_tx_free drops below tx_free_thresh, but iavf_dev_tx_drain() called the helpers on any non-empty queue.

With fewer than tx_rs_thresh descriptors outstanding, that descriptor still held the DESC_DONE value set by reset_tx_queue(), so the helpers treated the block as complete and freed NULL (or already freed) mbufs, crashing on PF reset.

Only clean up a queue once a full RS block is outstanding.

Fixes 30e1aab01bae ("net/iavf: drain in-flight Tx before reset")
---
 drivers/net/intel/iavf/iavf_rxtx.c | 8 +++-----
 1 file changed, 3 insertions(+), 5 deletions(-)
drivers/net/intel/iavf/iavf_rxtx.c +3 -5
index 84b931e78a..8c84991b86 100644
@@ -4098,11 +4098,9 @@ iavf_dev_tx_drain(struct rte_eth_dev *dev)
 				RTE_ETH_QUEUE_STATE_STARTED)
 				continue;
 
-			/*
-			 * nb_tx_free == nb_tx_desc - 1 means the ring is
-			 * empty (one descriptor is always reserved).
-			 */
-			if (txq->nb_tx_free >= txq->nb_tx_desc - 1)
+			/* Only clean up once a full RS block is outstanding. */
+			if ((uint16_t)(txq->nb_tx_desc - 1 - txq->nb_tx_free) <
+			    txq->tx_rs_thresh)
 				continue;
 
 			any_pending = true;
Signature · 1 line
2.43.0
Acked-by on v2 1/3
#2 lore raw

Re: [PATCH v2 1/3] net/iavf: fix crash in Tx drain on PF reset

Quoted 13 lines · Ciara Loftus

The Tx cleanup helpers check the DD bit of the descriptor at the next RS boundary and assume software has already posted it. The burst path guarantees this by only cleaning up when nb_tx_free drops below tx_free_thresh, but iavf_dev_tx_drain() called the helpers on any non-empty queue.

With fewer than tx_rs_thresh descriptors outstanding, that descriptor still held the DESC_DONE value set by reset_tx_queue(), so the helpers treated the block as complete and freed NULL (or already freed) mbufs, crashing on PF reset.

Only clean up a queue once a full RS block is outstanding.

Quoted 8 lines
Fixes 30e1aab01bae ("net/iavf: drain in-flight Tx before reset")
---
 drivers/net/intel/iavf/iavf_rxtx.c | 8 +++-----
 1 file changed, 3 insertions(+), 5 deletions(-)
#3 lore raw

PATCH v2 2/3 net/iavf: fix event handler leak on init failure

In reply to Ciara Loftus

iavf_dev_init() takes a reference on the shared event handler, but does not release it if initialisation subsequently fails. The event thread and its pipe are then never released.

Release the reference on these error paths. Skip it during reset recovery, where no reference is taken.

Fixes cb5c1b91f76f ("net/iavf: add thread for event callbacks")
---
 drivers/net/intel/iavf/iavf_ethdev.c | 5 +++++
 1 file changed, 5 insertions(+)
drivers/net/intel/iavf/iavf_ethdev.c +5 -0
index fd1067c252..38bf2e502a 100644
@@ -3089,6 +3089,8 @@ iavf_dev_init(struct rte_eth_dev *eth_dev)
 
 	if (iavf_init_vf(eth_dev) != 0) {
 		PMD_INIT_LOG(ERR, "Init vf failed");
+		if (!rte_atomic_load_explicit(&vf->in_reset_recovery, rte_memory_order_relaxed))
+			iavf_dev_event_handler_fini();
 		return -1;
 	}
 
@@ -3185,6 +3187,9 @@ iavf_dev_init(struct rte_eth_dev *eth_dev)
 
 	eth_dev->data->mac_addrs = NULL;
 
+	if (!rte_atomic_load_explicit(&vf->in_reset_recovery, rte_memory_order_relaxed))
+		iavf_dev_event_handler_fini();
+
 init_vf_err:
 	iavf_uninit_vf(eth_dev);
 
Signature · 1 line
2.43.0
Acked-by on v2 2/3
#4 lore raw

Re: [PATCH v2 2/3] net/iavf: fix event handler leak on init failure

Quoted 7 lines · Ciara Loftus

iavf_dev_init() takes a reference on the shared event handler, but does not release it if initialisation subsequently fails. The event thread and its pipe are then never released.

Release the reference on these error paths. Skip it during reset recovery, where no reference is taken.

Quoted 8 lines
Fixes cb5c1b91f76f ("net/iavf: add thread for event callbacks")
---
 drivers/net/intel/iavf/iavf_ethdev.c | 5 +++++
 1 file changed, 5 insertions(+)
#5 lore raw

PATCH v2 3/3 net/iavf: fix watchdog clearing reset state during recovery

In reply to Ciara Loftus

Since the watchdog is kept armed across a PF reset, it can clear vf_reset while the reset event is still queued or being handled, as VFGEN_RSTAT toggles while the PF resets the VF. iavf_dev_close() then skips re-enabling PCI bus mastering, which the VF reset cleared, so VIRTCHNL_OP_VERSION never reaches the PF, iavf_dev_init() fails and the port is left returning -EIO. Each toggle also posts a further reset event, causing redundant recovery cycles.

Count reset events from before vf_reset is set until they have been handled, and do not let the watchdog clear vf_reset while any are outstanding.

Fixes a0e296420a70 ("net/iavf: keep watchdog armed for the whole reset window")
---
 drivers/net/intel/iavf/iavf.h        |  4 ++-
 drivers/net/intel/iavf/iavf_ethdev.c | 16 +++++++---
 drivers/net/intel/iavf/iavf_vchnl.c  | 48 ++++++++++++++++++++--------
 3 files changed, 48 insertions(+), 20 deletions(-)
drivers/net/intel/iavf/iavf.h +3 -1
index 8b826662c6..9cbbb5263a 100644
@@ -290,6 +290,7 @@ struct iavf_info {
 	struct iavf_tm_conf tm_conf;
 
 	RTE_ATOMIC(bool)in_reset_recovery;
+	RTE_ATOMIC(uint32_t)reset_events_pending;
 	bool reset_pending;
 	bool pf_reset_in_progress;
 	bool start_pending;
@@ -454,9 +455,10 @@ struct iavf_cmd_info {
 
 int iavf_check_api_version(struct iavf_adapter *adapter);
 int iavf_get_vf_resource(struct iavf_adapter *adapter);
-void iavf_dev_event_post(struct rte_eth_dev *dev,
+int iavf_dev_event_post(struct rte_eth_dev *dev,
 		enum rte_eth_event_type event,
 		void *param, size_t param_alloc_size);
+void iavf_dev_reset_event_post(struct rte_eth_dev *dev);
 void iavf_dev_event_handler_fini(void);
 int iavf_dev_event_handler_init(void);
 void iavf_handle_virtchnl_msg(struct rte_eth_dev *dev);
drivers/net/intel/iavf/iavf_ethdev.c +11 -5
index 38bf2e502a..e57a018906 100644
@@ -336,11 +336,14 @@ iavf_dev_watchdog(void *cb_arg)
 
 	/* If in reset then poll vfr_inprogress register for completion */
 	if (adapter->vf.vf_reset) {
+		/* pair with the release fence before vf_reset is set */
+		rte_atomic_thread_fence(rte_memory_order_acquire);
 		vfr_inprogress = iavf_vfr_inprogress(hw);
 
-		if (!vfr_inprogress) {
-			PMD_DRV_LOG(INFO, "VF \"%s\" reset has completed",
-				dev->data->name);
+		if (!vfr_inprogress &&
+		    rte_atomic_load_explicit(&adapter->vf.reset_events_pending,
+				rte_memory_order_acquire) == 0) {
+			PMD_DRV_LOG(INFO, "VF \"%s\" reset has completed", dev->data->name);
 			adapter->vf.vf_reset = false;
 			iavf_set_no_poll(adapter, false);
 		}
@@ -354,12 +357,15 @@ iavf_dev_watchdog(void *cb_arg)
 				dev->data->name);
 
 			/* enter reset state with VFLR event */
+			rte_atomic_fetch_add_explicit(&adapter->vf.reset_events_pending, 1,
+					rte_memory_order_relaxed);
+			/* publish the count before vf_reset is visible */
+			rte_atomic_thread_fence(rte_memory_order_release);
 			adapter->vf.vf_reset = true;
 			iavf_set_no_poll(adapter, false);
 			adapter->vf.link_up = false;
 
-			iavf_dev_event_post(dev, RTE_ETH_EVENT_INTR_RESET,
-				NULL, 0);
+			iavf_dev_reset_event_post(dev);
 		}
 	}
 
drivers/net/intel/iavf/iavf_vchnl.c +34 -14

95 lines not on this page · raw message

Signature · 1 line
2.43.0
#6 lore raw

Re: [PATCH v2 3/3] net/iavf: fix watchdog clearing reset state during recovery

Quoted 15 lines · Ciara Loftus

Since the watchdog is kept armed across a PF reset, it can clear vf_reset while the reset event is still queued or being handled, as VFGEN_RSTAT toggles while the PF resets the VF. iavf_dev_close() then skips re-enabling PCI bus mastering, which the VF reset cleared, so VIRTCHNL_OP_VERSION never reaches the PF, iavf_dev_init() fails and the port is left returning -EIO. Each toggle also posts a further reset event, causing redundant recovery cycles.

Count reset events from before vf_reset is set until they have been handled, and do not let the watchdog clear vf_reset while any are outstanding.

Fixes a0e296420a70 ("net/iavf: keep watchdog armed for the whole reset window")
Quoted 8 lines
---
 drivers/net/intel/iavf/iavf.h        |  4 ++-
 drivers/net/intel/iavf/iavf_ethdev.c | 16 +++++++---
 drivers/net/intel/iavf/iavf_vchnl.c  | 48 ++++++++++++++++++++--------
 3 files changed, 48 insertions(+), 20 deletions(-)

While the AI review in CI shows no issues, my own AI review flags that there is potentially a problem due to vf_reset not being declared atomic.

/Bruce

---

The producer and watchdog can run concurrently: the PF reset path handles messages in the interrupt callback (iavf_ethdev.c:2847), while the watchdog runs separately.

A concrete interleaving is:

1. The event path increments reset_events_pending, executes the release fence, then writes vf_reset = true (iavf_vchnl.c:349).

2. The watchdog reads vf_reset as true, checks that hardware reset is no longer in progress, then loads reset_events_pending (iavf_ethdev.c:338).

3. That acquire load is allowed to observe the old zero value: it synchronizes with the increment only if it reads from that increment. The plain vf_reset read does not provide the atomic synchronization, because the field is still declared as bool (iavf.h:264). The watchdog can therefore clear vf_reset while the reset event remains pending, which is exactly the state this commit aims to prevent. The release/acquire fences don’t fix this: they do not make the plain flag accesses atomic or guarantee that observing the flag publishes the counter.

The fix should make vf_reset atomic and use atomic release stores/acquire loads consistently at its concurrent access sites.

#7 lore raw

v3 cover iavf reset path fixes

In reply to Ciara Loftus

Four fixes related to the reset path in iavf.

v3:
* Patch 3: made the vf_reset flag atomic and moved entry to the reset state into a helper.
* Added patch 4, fixing a race between watchdog enable and disable.

Ciara Loftus (4):
net/iavf: fix crash in Tx drain on PF reset net/iavf: fix event handler leak on init failure net/iavf: fix watchdog clearing reset state during recovery net/iavf: fix watchdog enable racing disable

 drivers/net/intel/iavf/iavf.h        |   7 +-
 drivers/net/intel/iavf/iavf_ethdev.c |  74 +++++++++--------
 drivers/net/intel/iavf/iavf_rxtx.c   |   8 +-
 drivers/net/intel/iavf/iavf_vchnl.c  | 120 ++++++++++++++++++---------
 4 files changed, 128 insertions(+), 81 deletions(-)
Signature · 1 line
2.43.0
#8 lore raw

PATCH v3 1/4 net/iavf: fix crash in Tx drain on PF reset

The Tx cleanup helpers check the DD bit of the descriptor at the next RS boundary and assume software has already posted it. The burst path guarantees this by only cleaning up when nb_tx_free drops below tx_free_thresh, but iavf_dev_tx_drain() called the helpers on any non-empty queue.

With fewer than tx_rs_thresh descriptors outstanding, that descriptor still held the DESC_DONE value set by reset_tx_queue(), so the helpers treated the block as complete and freed NULL (or already freed) mbufs, crashing on PF reset.

Only clean up a queue once a full RS block is outstanding.

Fixes 30e1aab01bae ("net/iavf: drain in-flight Tx before reset")
---
 drivers/net/intel/iavf/iavf_rxtx.c | 8 +++-----
 1 file changed, 3 insertions(+), 5 deletions(-)
drivers/net/intel/iavf/iavf_rxtx.c +3 -5
index 84b931e78a..8c84991b86 100644
@@ -4098,11 +4098,9 @@ iavf_dev_tx_drain(struct rte_eth_dev *dev)
 				RTE_ETH_QUEUE_STATE_STARTED)
 				continue;
 
-			/*
-			 * nb_tx_free == nb_tx_desc - 1 means the ring is
-			 * empty (one descriptor is always reserved).
-			 */
-			if (txq->nb_tx_free >= txq->nb_tx_desc - 1)
+			/* Only clean up once a full RS block is outstanding. */
+			if ((uint16_t)(txq->nb_tx_desc - 1 - txq->nb_tx_free) <
+			    txq->tx_rs_thresh)
 				continue;
 
 			any_pending = true;
Signature · 1 line
2.43.0
#9 lore raw

PATCH v3 2/4 net/iavf: fix event handler leak on init failure

In reply to Ciara Loftus

iavf_dev_init() takes a reference on the shared event handler, but does not release it if initialisation subsequently fails. The event thread and its pipe are then never released.

Release the reference on these error paths. Skip it during reset recovery, where no reference is taken.

Fixes cb5c1b91f76f ("net/iavf: add thread for event callbacks")
---
 drivers/net/intel/iavf/iavf_ethdev.c | 5 +++++
 1 file changed, 5 insertions(+)
drivers/net/intel/iavf/iavf_ethdev.c +5 -0
index 47aa6ecb6f..05b90a6230 100644
@@ -3089,6 +3089,8 @@ iavf_dev_init(struct rte_eth_dev *eth_dev)
 
 	if (iavf_init_vf(eth_dev) != 0) {
 		PMD_INIT_LOG(ERR, "Init vf failed");
+		if (!rte_atomic_load_explicit(&vf->in_reset_recovery, rte_memory_order_relaxed))
+			iavf_dev_event_handler_fini();
 		return -1;
 	}
 
@@ -3190,6 +3192,9 @@ iavf_dev_init(struct rte_eth_dev *eth_dev)
 
 	eth_dev->data->mac_addrs = NULL;
 
+	if (!rte_atomic_load_explicit(&vf->in_reset_recovery, rte_memory_order_relaxed))
+		iavf_dev_event_handler_fini();
+
 init_vf_err:
 	iavf_uninit_vf(eth_dev);
 
Signature · 1 line
2.43.0
#10 lore raw

PATCH v3 3/4 net/iavf: fix watchdog clearing reset state during recovery

In reply to Ciara Loftus

Since the watchdog is kept armed across a PF reset, it can clear the vf_reset flag while the reset event is still queued or being handled, as VFGEN_RSTAT toggles while the PF resets the VF. iavf_dev_close() then skips re-enabling PCI bus mastering, which the VF reset cleared, so VIRTCHNL_OP_VERSION never reaches the PF, iavf_dev_init() fails and the port is left returning -EIO. Each toggle also posts a further reset event, causing redundant recovery cycles.

Count reset events from before vf_reset is set until they have been handled, and do not let the watchdog clear the flag while any are outstanding. Also make the vf_reset flag atomic, as it is accessed from multiple places: the watchdog alarm, the interrupt thread and the virtchnl polling path.

Fixes a0e296420a70 ("net/iavf: keep watchdog armed for the whole reset window")

---
v3:
* make vf_reset flag atomic
* add helper functions

---
 drivers/net/intel/iavf/iavf.h        |   6 +-
 drivers/net/intel/iavf/iavf_ethdev.c |  32 ++++---
 drivers/net/intel/iavf/iavf_vchnl.c  | 120 ++++++++++++++++++---------
 3 files changed, 97 insertions(+), 61 deletions(-)
drivers/net/intel/iavf/iavf.h +4 -2
index 5550e57c35..04c2900afe 100644
@@ -261,7 +261,7 @@ struct iavf_info {
 	uint16_t mc_addrs_num;   /* Multicast mac addresses number */
 
 	struct iavf_vsi vsi;
-	bool vf_reset;	/* true for VF reset pending, false for no VF reset */
+	RTE_ATOMIC(bool)vf_reset; /* true for VF reset pending, false for no VF reset */
 	iavf_pre_reset_cb_t pre_reset_cb; /* Pre reset callback function ptr */
 	iavf_post_reset_cb_t post_reset_cb; /* Post reset callback function ptr */
 	void *pre_reset_cb_arg; /* Pre reset callback argument */
@@ -290,6 +290,7 @@ struct iavf_info {
 	struct iavf_tm_conf tm_conf;
 
 	RTE_ATOMIC(bool)in_reset_recovery;
+	RTE_ATOMIC(uint32_t)reset_events_pending;
 	bool reset_pending;
 	bool pf_reset_in_progress;
 	bool start_pending;
@@ -455,9 +456,10 @@ struct iavf_cmd_info {
 
 int iavf_check_api_version(struct iavf_adapter *adapter);
 int iavf_get_vf_resource(struct iavf_adapter *adapter);
-void iavf_dev_event_post(struct rte_eth_dev *dev,
+int iavf_dev_event_post(struct rte_eth_dev *dev,
 		enum rte_eth_event_type event,
 		void *param, size_t param_alloc_size);
+bool iavf_dev_enter_reset(struct rte_eth_dev *dev, bool drain_tx);
 void iavf_dev_event_handler_fini(void);
 int iavf_dev_event_handler_init(void);
 void iavf_handle_virtchnl_msg(struct rte_eth_dev *dev);
drivers/net/intel/iavf/iavf_ethdev.c +14 -18
index 05b90a6230..83470a636d 100644
@@ -335,32 +335,27 @@ iavf_dev_watchdog(void *cb_arg)
 		return;
 
 	/* If in reset then poll vfr_inprogress register for completion */
-	if (adapter->vf.vf_reset) {
+	if (rte_atomic_load_explicit(&adapter->vf.vf_reset, rte_memory_order_acquire)) {
 		vfr_inprogress = iavf_vfr_inprogress(hw);
 
-		if (!vfr_inprogress) {
+		if (!vfr_inprogress &&
+		    rte_atomic_load_explicit(&adapter->vf.reset_events_pending,
+				rte_memory_order_acquire) == 0) {
 			PMD_DRV_LOG(INFO, "VF \"%s\" reset has completed",
 				dev->data->name);
-			adapter->vf.vf_reset = false;
+			rte_atomic_store_explicit(&adapter->vf.vf_reset, false,
+					rte_memory_order_release);
 			iavf_set_no_poll(adapter, false);
 		}
 	/* If not in reset then poll vfr_inprogress register for VFLR event */
 	} else {
 		vfr_inprogress = iavf_vfr_inprogress(hw);
 
-		if (vfr_inprogress) {
+		/* enter reset state with VFLR event */
+		if (vfr_inprogress && iavf_dev_enter_reset(dev, false))
 			PMD_DRV_LOG(INFO,
 				"VF \"%s\" reset event detected by watchdog",
 				dev->data->name);
-
-			/* enter reset state with VFLR event */
-			adapter->vf.vf_reset = true;
-			iavf_set_no_poll(adapter, false);
-			adapter->vf.link_up = false;
-
-			iavf_dev_event_post(dev, RTE_ETH_EVENT_INTR_RESET,
-				NULL, 0);
-		}
 	}
 
 	if (adapter->devargs.watchdog_period) {
@@ -3320,8 +3315,9 @@ iavf_dev_close(struct rte_eth_dev *dev)
 	 * effect.
 	 */
 out:
-	if (vf->vf_reset && !rte_pci_set_bus_master(pci_dev, true)) {
-		vf->vf_reset = false;
+	if (rte_atomic_load_explicit(&vf->vf_reset, rte_memory_order_acquire) &&
+	    !rte_pci_set_bus_master(pci_dev, true)) {
+		rte_atomic_store_explicit(&vf->vf_reset, false, rte_memory_order_release);
 		iavf_set_no_poll(adapter, false);
 	}
 
@@ -3657,7 +3653,7 @@ iavf_set_no_poll(struct iavf_adapter *adapter, bool link_change)
 	bool no_poll;
 
 	no_poll = (link_change & !vf->link_up) ||
-		vf->vf_reset ||
+		rte_atomic_load_explicit(&vf->vf_reset, rte_memory_order_acquire) ||
 		rte_atomic_load_explicit(&vf->in_reset_recovery, rte_memory_order_relaxed);
 
 	rte_atomic_store_explicit(&adapter->no_poll, no_poll,
@@ -3740,8 +3736,8 @@ iavf_resume_pending_start(struct rte_eth_dev *dev)
 	if (!vf->start_pending)
 		return;
 
-	if (vf->vf_reset || rte_atomic_load_explicit(&vf->in_reset_recovery,
-			rte_memory_order_acquire))
+	if (rte_atomic_load_explicit(&vf->vf_reset, rte_memory_order_acquire) ||
+	    rte_atomic_load_explicit(&vf->in_reset_recovery, rte_memory_order_acquire))
 		return;
 
 	/*
drivers/net/intel/iavf/iavf_vchnl.c +79 -41

193 lines not on this page · raw message

Signature · 1 line
2.43.0
#11 lore raw

PATCH v3 4/4 net/iavf: fix watchdog enable racing disable

In reply to Ciara Loftus

iavf_dev_watchdog_enable() runs on the interrupt thread from the link change and reset impending handlers, while iavf_dev_watchdog_disable() runs on a control thread from dev_stop and dev_close. Disable clears watchdog_enabled before cancelling the alarm. An enable landing in between sets the flag again and arms a new alarm, which the cancel then removes. The flag is left set with no alarm armed, so every later enable is a no-op and the watchdog is dead until the port is re-probed.

Serialise enable and disable with a spinlock held across the flag update and the alarm set or cancel.

Fixes 4c9b1d2ff616 ("net/iavf: refactor watchdog")
---
 drivers/net/intel/iavf/iavf.h        |  1 +
 drivers/net/intel/iavf/iavf_ethdev.c | 37 +++++++++++++++++-----------
 2 files changed, 23 insertions(+), 15 deletions(-)
drivers/net/intel/iavf/iavf.h +1 -0
index 04c2900afe..0c98ae28e1 100644
@@ -247,6 +247,7 @@ struct iavf_info {
 
 	/** iAVF watchdog enable */
 	bool watchdog_enabled;
+	rte_spinlock_t watchdog_lock;
 
 	/* Event from pf */
 	bool dev_closed;
drivers/net/intel/iavf/iavf_ethdev.c +22 -15
index 83470a636d..10069feae2 100644
@@ -374,16 +374,19 @@ iavf_dev_watchdog_enable(struct iavf_adapter *adapter)
 {
 	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");
-		}
+		return;
+	}
+
+	rte_spinlock_lock(&adapter->vf.watchdog_lock);
+	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");
 	}
+	rte_spinlock_unlock(&adapter->vf.watchdog_lock);
 }
 
 void
@@ -391,13 +394,16 @@ iavf_dev_watchdog_disable(struct iavf_adapter *adapter)
 {
 	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);
-		}
+		return;
+	}
+
+	rte_spinlock_lock(&adapter->vf.watchdog_lock);
+	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);
 	}
+	rte_spinlock_unlock(&adapter->vf.watchdog_lock);
 }
 
 static int
@@ -3077,6 +3083,7 @@ iavf_dev_init(struct rte_eth_dev *eth_dev)
 	adapter->mac_primary_set = false;
 	adapter->tpid = RTE_ETHER_TYPE_VLAN; /* VLAN TPID set to 0x8100 by default */
 	rte_spinlock_init(&adapter->phc_sync_lock);
+	rte_spinlock_init(&vf->watchdog_lock);
 
 	if (!rte_atomic_load_explicit(&vf->in_reset_recovery, rte_memory_order_relaxed) &&
 	    iavf_dev_event_handler_init())
Signature · 1 line
2.43.0
#12 lore raw

v4 cover iavf reset path fixes

In reply to Ciara Loftus

Four fixes related to the reset path in iavf.

v4 ( patch 3):
* Remove overly defensive check after reset callback
* Added a log on event post failure

Ciara Loftus (4):
net/iavf: fix crash in Tx drain on PF reset net/iavf: fix event handler leak on init failure net/iavf: fix watchdog clearing reset state during recovery net/iavf: fix watchdog enable racing disable

 drivers/net/intel/iavf/iavf.h        |   7 +-
 drivers/net/intel/iavf/iavf_ethdev.c |  74 +++++++++--------
 drivers/net/intel/iavf/iavf_rxtx.c   |   8 +-
 drivers/net/intel/iavf/iavf_vchnl.c  | 117 +++++++++++++++++----------
 4 files changed, 125 insertions(+), 81 deletions(-)
Signature · 1 line
2.43.0
#13 lore raw

PATCH v4 1/4 net/iavf: fix crash in Tx drain on PF reset

The Tx cleanup helpers check the DD bit of the descriptor at the next RS boundary and assume software has already posted it. The burst path guarantees this by only cleaning up when nb_tx_free drops below tx_free_thresh, but iavf_dev_tx_drain() called the helpers on any non-empty queue.

With fewer than tx_rs_thresh descriptors outstanding, that descriptor still held the DESC_DONE value set by reset_tx_queue(), so the helpers treated the block as complete and freed NULL (or already freed) mbufs, crashing on PF reset.

Only clean up a queue once a full RS block is outstanding.

Fixes 30e1aab01bae ("net/iavf: drain in-flight Tx before reset")
---
 drivers/net/intel/iavf/iavf_rxtx.c | 8 +++-----
 1 file changed, 3 insertions(+), 5 deletions(-)
drivers/net/intel/iavf/iavf_rxtx.c +3 -5
index 84b931e78a..8c84991b86 100644
@@ -4098,11 +4098,9 @@ iavf_dev_tx_drain(struct rte_eth_dev *dev)
 				RTE_ETH_QUEUE_STATE_STARTED)
 				continue;
 
-			/*
-			 * nb_tx_free == nb_tx_desc - 1 means the ring is
-			 * empty (one descriptor is always reserved).
-			 */
-			if (txq->nb_tx_free >= txq->nb_tx_desc - 1)
+			/* Only clean up once a full RS block is outstanding. */
+			if ((uint16_t)(txq->nb_tx_desc - 1 - txq->nb_tx_free) <
+			    txq->tx_rs_thresh)
 				continue;
 
 			any_pending = true;
Signature · 1 line
2.43.0
#14 lore raw

PATCH v4 2/4 net/iavf: fix event handler leak on init failure

In reply to Ciara Loftus

iavf_dev_init() takes a reference on the shared event handler, but does not release it if initialisation subsequently fails. The event thread and its pipe are then never released.

Release the reference on these error paths. Skip it during reset recovery, where no reference is taken.

Fixes cb5c1b91f76f ("net/iavf: add thread for event callbacks")
---
 drivers/net/intel/iavf/iavf_ethdev.c | 5 +++++
 1 file changed, 5 insertions(+)
drivers/net/intel/iavf/iavf_ethdev.c +5 -0
index 47aa6ecb6f..05b90a6230 100644
@@ -3089,6 +3089,8 @@ iavf_dev_init(struct rte_eth_dev *eth_dev)
 
 	if (iavf_init_vf(eth_dev) != 0) {
 		PMD_INIT_LOG(ERR, "Init vf failed");
+		if (!rte_atomic_load_explicit(&vf->in_reset_recovery, rte_memory_order_relaxed))
+			iavf_dev_event_handler_fini();
 		return -1;
 	}
 
@@ -3190,6 +3192,9 @@ iavf_dev_init(struct rte_eth_dev *eth_dev)
 
 	eth_dev->data->mac_addrs = NULL;
 
+	if (!rte_atomic_load_explicit(&vf->in_reset_recovery, rte_memory_order_relaxed))
+		iavf_dev_event_handler_fini();
+
 init_vf_err:
 	iavf_uninit_vf(eth_dev);
 
Signature · 1 line
2.43.0
#15 lore raw

PATCH v4 3/4 net/iavf: fix watchdog clearing reset state during recovery

In reply to Ciara Loftus

Since the watchdog is kept armed across a PF reset, it can clear the vf_reset flag while the reset event is still queued or being handled, as VFGEN_RSTAT toggles while the PF resets the VF. iavf_dev_close() then skips re-enabling PCI bus mastering, which the VF reset cleared, so VIRTCHNL_OP_VERSION never reaches the PF, iavf_dev_init() fails and the port is left returning -EIO. Each toggle also posts a further reset event, causing redundant recovery cycles.

Count reset events from before vf_reset is set until they have been handled, and do not let the watchdog clear the flag while any are outstanding. Also make the vf_reset flag atomic, as it is accessed from multiple places: the watchdog alarm, the interrupt thread and the virtchnl polling path.

Fixes a0e296420a70 ("net/iavf: keep watchdog armed for the whole reset window")

---
v4:
* Remove overly defensive check after reset callback
* Added a log on event post failure

---
 drivers/net/intel/iavf/iavf.h        |   6 +-
 drivers/net/intel/iavf/iavf_ethdev.c |  32 ++++----
 drivers/net/intel/iavf/iavf_vchnl.c  | 117 +++++++++++++++++----------
 3 files changed, 94 insertions(+), 61 deletions(-)
drivers/net/intel/iavf/iavf.h +4 -2
index 5550e57c35..04c2900afe 100644
@@ -261,7 +261,7 @@ struct iavf_info {
 	uint16_t mc_addrs_num;   /* Multicast mac addresses number */
 
 	struct iavf_vsi vsi;
-	bool vf_reset;	/* true for VF reset pending, false for no VF reset */
+	RTE_ATOMIC(bool)vf_reset; /* true for VF reset pending, false for no VF reset */
 	iavf_pre_reset_cb_t pre_reset_cb; /* Pre reset callback function ptr */
 	iavf_post_reset_cb_t post_reset_cb; /* Post reset callback function ptr */
 	void *pre_reset_cb_arg; /* Pre reset callback argument */
@@ -290,6 +290,7 @@ struct iavf_info {
 	struct iavf_tm_conf tm_conf;
 
 	RTE_ATOMIC(bool)in_reset_recovery;
+	RTE_ATOMIC(uint32_t)reset_events_pending;
 	bool reset_pending;
 	bool pf_reset_in_progress;
 	bool start_pending;
@@ -455,9 +456,10 @@ struct iavf_cmd_info {
 
 int iavf_check_api_version(struct iavf_adapter *adapter);
 int iavf_get_vf_resource(struct iavf_adapter *adapter);
-void iavf_dev_event_post(struct rte_eth_dev *dev,
+int iavf_dev_event_post(struct rte_eth_dev *dev,
 		enum rte_eth_event_type event,
 		void *param, size_t param_alloc_size);
+bool iavf_dev_enter_reset(struct rte_eth_dev *dev, bool drain_tx);
 void iavf_dev_event_handler_fini(void);
 int iavf_dev_event_handler_init(void);
 void iavf_handle_virtchnl_msg(struct rte_eth_dev *dev);
drivers/net/intel/iavf/iavf_ethdev.c +14 -18
index 05b90a6230..83470a636d 100644
@@ -335,32 +335,27 @@ iavf_dev_watchdog(void *cb_arg)
 		return;
 
 	/* If in reset then poll vfr_inprogress register for completion */
-	if (adapter->vf.vf_reset) {
+	if (rte_atomic_load_explicit(&adapter->vf.vf_reset, rte_memory_order_acquire)) {
 		vfr_inprogress = iavf_vfr_inprogress(hw);
 
-		if (!vfr_inprogress) {
+		if (!vfr_inprogress &&
+		    rte_atomic_load_explicit(&adapter->vf.reset_events_pending,
+				rte_memory_order_acquire) == 0) {
 			PMD_DRV_LOG(INFO, "VF \"%s\" reset has completed",
 				dev->data->name);
-			adapter->vf.vf_reset = false;
+			rte_atomic_store_explicit(&adapter->vf.vf_reset, false,
+					rte_memory_order_release);
 			iavf_set_no_poll(adapter, false);
 		}
 	/* If not in reset then poll vfr_inprogress register for VFLR event */
 	} else {
 		vfr_inprogress = iavf_vfr_inprogress(hw);
 
-		if (vfr_inprogress) {
+		/* enter reset state with VFLR event */
+		if (vfr_inprogress && iavf_dev_enter_reset(dev, false))
 			PMD_DRV_LOG(INFO,
 				"VF \"%s\" reset event detected by watchdog",
 				dev->data->name);
-
-			/* enter reset state with VFLR event */
-			adapter->vf.vf_reset = true;
-			iavf_set_no_poll(adapter, false);
-			adapter->vf.link_up = false;
-
-			iavf_dev_event_post(dev, RTE_ETH_EVENT_INTR_RESET,
-				NULL, 0);
-		}
 	}
 
 	if (adapter->devargs.watchdog_period) {
@@ -3320,8 +3315,9 @@ iavf_dev_close(struct rte_eth_dev *dev)
 	 * effect.
 	 */
 out:
-	if (vf->vf_reset && !rte_pci_set_bus_master(pci_dev, true)) {
-		vf->vf_reset = false;
+	if (rte_atomic_load_explicit(&vf->vf_reset, rte_memory_order_acquire) &&
+	    !rte_pci_set_bus_master(pci_dev, true)) {
+		rte_atomic_store_explicit(&vf->vf_reset, false, rte_memory_order_release);
 		iavf_set_no_poll(adapter, false);
 	}
 
@@ -3657,7 +3653,7 @@ iavf_set_no_poll(struct iavf_adapter *adapter, bool link_change)
 	bool no_poll;
 
 	no_poll = (link_change & !vf->link_up) ||
-		vf->vf_reset ||
+		rte_atomic_load_explicit(&vf->vf_reset, rte_memory_order_acquire) ||
 		rte_atomic_load_explicit(&vf->in_reset_recovery, rte_memory_order_relaxed);
 
 	rte_atomic_store_explicit(&adapter->no_poll, no_poll,
@@ -3740,8 +3736,8 @@ iavf_resume_pending_start(struct rte_eth_dev *dev)
 	if (!vf->start_pending)
 		return;
 
-	if (vf->vf_reset || rte_atomic_load_explicit(&vf->in_reset_recovery,
-			rte_memory_order_acquire))
+	if (rte_atomic_load_explicit(&vf->vf_reset, rte_memory_order_acquire) ||
+	    rte_atomic_load_explicit(&vf->in_reset_recovery, rte_memory_order_acquire))
 		return;
 
 	/*
drivers/net/intel/iavf/iavf_vchnl.c +76 -41

190 lines not on this page · raw message

Signature · 1 line
2.43.0
Acked-by on v4 3/4
#16 lore raw

Re: [PATCH v4 3/4] net/iavf: fix watchdog clearing reset state during recovery

Quoted 23 lines · Ciara Loftus

Since the watchdog is kept armed across a PF reset, it can clear the vf_reset flag while the reset event is still queued or being handled, as VFGEN_RSTAT toggles while the PF resets the VF. iavf_dev_close() then skips re-enabling PCI bus mastering, which the VF reset cleared, so VIRTCHNL_OP_VERSION never reaches the PF, iavf_dev_init() fails and the port is left returning -EIO. Each toggle also posts a further reset event, causing redundant recovery cycles.

Count reset events from before vf_reset is set until they have been handled, and do not let the watchdog clear the flag while any are outstanding. Also make the vf_reset flag atomic, as it is accessed from multiple places: the watchdog alarm, the interrupt thread and the virtchnl polling path.

Fixes a0e296420a70 ("net/iavf: keep watchdog armed for the whole reset window")

---
v4:
* Remove overly defensive check after reset callback
* Added a log on event post failure

Quoted 6 lines
---
 drivers/net/intel/iavf/iavf.h        |   6 +-
 drivers/net/intel/iavf/iavf_ethdev.c |  32 ++++----
 drivers/net/intel/iavf/iavf_vchnl.c  | 117 +++++++++++++++++----------
 3 files changed, 94 insertions(+), 61 deletions(-)
#17 lore raw

PATCH v4 4/4 net/iavf: fix watchdog enable racing disable

In reply to Ciara Loftus

iavf_dev_watchdog_enable() runs on the interrupt thread from the link change and reset impending handlers, while iavf_dev_watchdog_disable() runs on a control thread from dev_stop and dev_close. Disable clears watchdog_enabled before cancelling the alarm. An enable landing in between sets the flag again and arms a new alarm, which the cancel then removes. The flag is left set with no alarm armed, so every later enable is a no-op and the watchdog is dead until the port is re-probed.

Serialise enable and disable with a spinlock held across the flag update and the alarm set or cancel.

Fixes 4c9b1d2ff616 ("net/iavf: refactor watchdog")
---
 drivers/net/intel/iavf/iavf.h        |  1 +
 drivers/net/intel/iavf/iavf_ethdev.c | 37 +++++++++++++++++-----------
 2 files changed, 23 insertions(+), 15 deletions(-)
drivers/net/intel/iavf/iavf.h +1 -0
index 04c2900afe..0c98ae28e1 100644
@@ -247,6 +247,7 @@ struct iavf_info {
 
 	/** iAVF watchdog enable */
 	bool watchdog_enabled;
+	rte_spinlock_t watchdog_lock;
 
 	/* Event from pf */
 	bool dev_closed;
drivers/net/intel/iavf/iavf_ethdev.c +22 -15
index 83470a636d..10069feae2 100644
@@ -374,16 +374,19 @@ iavf_dev_watchdog_enable(struct iavf_adapter *adapter)
 {
 	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");
-		}
+		return;
+	}
+
+	rte_spinlock_lock(&adapter->vf.watchdog_lock);
+	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");
 	}
+	rte_spinlock_unlock(&adapter->vf.watchdog_lock);
 }
 
 void
@@ -391,13 +394,16 @@ iavf_dev_watchdog_disable(struct iavf_adapter *adapter)
 {
 	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);
-		}
+		return;
+	}
+
+	rte_spinlock_lock(&adapter->vf.watchdog_lock);
+	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);
 	}
+	rte_spinlock_unlock(&adapter->vf.watchdog_lock);
 }
 
 static int
@@ -3077,6 +3083,7 @@ iavf_dev_init(struct rte_eth_dev *eth_dev)
 	adapter->mac_primary_set = false;
 	adapter->tpid = RTE_ETHER_TYPE_VLAN; /* VLAN TPID set to 0x8100 by default */
 	rte_spinlock_init(&adapter->phc_sync_lock);
+	rte_spinlock_init(&vf->watchdog_lock);
 
 	if (!rte_atomic_load_explicit(&vf->in_reset_recovery, rte_memory_order_relaxed) &&
 	    iavf_dev_event_handler_init())
Signature · 1 line
2.43.0
Acked-by on v4 4/4
#18 lore raw

Re: [PATCH v4 4/4] net/iavf: fix watchdog enable racing disable

Quoted 11 lines · Ciara Loftus

iavf_dev_watchdog_enable() runs on the interrupt thread from the link change and reset impending handlers, while iavf_dev_watchdog_disable() runs on a control thread from dev_stop and dev_close. Disable clears watchdog_enabled before cancelling the alarm. An enable landing in between sets the flag again and arms a new alarm, which the cancel then removes. The flag is left set with no alarm armed, so every later enable is a no-op and the watchdog is dead until the port is re-probed.

Serialise enable and disable with a spinlock held across the flag update and the alarm set or cancel.

Quoted 9 lines
Fixes 4c9b1d2ff616 ("net/iavf: refactor watchdog")
---
 drivers/net/intel/iavf/iavf.h        |  1 +
 drivers/net/intel/iavf/iavf_ethdev.c | 37 +++++++++++++++++-----------
 2 files changed, 23 insertions(+), 15 deletions(-)
#19 lore raw
In reply to Ciara Loftus
Quoted 6 lines · Ciara Loftus

Four fixes related to the reset path in iavf.

v4 ( patch 3):
* Remove overly defensive check after reset callback
* Added a log on event post failure

Quoted 6 lines

Ciara Loftus (4):
net/iavf: fix crash in Tx drain on PF reset net/iavf: fix event handler leak on init failure net/iavf: fix watchdog clearing reset state during recovery net/iavf: fix watchdog enable racing disable

Series applied to dpdk-next-net-intel.

Thanks,
/Bruce