Skip to contentSkip to conversation

Fix i40e/ice/iavf VF bonding after netdev lock changes

PATCH In review Jose Ignacio Tornos Martinez 5 participants 13 messages Jun 23 – Jul 30

Subsystems (4)
lore
Share & tools
lore
#0 lore raw

v7 cover Fix i40e/ice/iavf VF bonding after netdev lock changes

This series fixes VF bonding failures introduced by commit ad7c7b2172c3 ("net: hold netdev instance lock during sysfs operations").

When adding VFs to a bond immediately after setting trust mode, MAC address changes fail with -EAGAIN, preventing bonding setup. This affects both i40e (700-series) and ice (800-series) Intel NICs.

The core issue is lock contention: iavf_set_mac() is now called with the netdev lock held and waits for MAC change completion while holding it. However, both the watchdog task that sends the request and the adminq_task that processes PF responses also need this lock, creating a deadlock where neither can run, causing timeouts.

Additionally, setting VF trust triggers an unnecessary ~10 second VF reset in i40e driver that delays bonding setup, even though filter synchronization happens naturally during normal VF operation. For ice driver, the delay is not so big, but in the same way the operation is not necessary.

This series:
1. Adds safety guard to prevent MAC changes during reset or early initialization (before VF is ready)
2. Eliminates unnecessary VF reset when setting trust in i40e (reset only if revoking trust and VF has advanced features configured).
3. Fixes lock contention by polling admin queue synchronously
4. Eliminates unnecessary VF reset when setting trust in ice, (reset only if revoking trust and VF has advanced features configured).

The key fix (patch 3/4) implements a synchronous MAC change operation similar to the approach used for ndo_change_mtu deadlock fix:
https://lore.kernel.org/intel-wired-lan/[email protected]/
Instead of scheduling work and waiting, it:

- Sends the virtchnl message directly (not via watchdog)
- Polls the admin queue hardware directly for responses
- Processes all messages inline (including non-MAC messages)
- Returns when complete or times out

This allows the operation to complete synchronously while holding netdev_lock, without relying on watchdog or adminq_task.

The function can sleep for up to 2.5 seconds polling hardware, but this is acceptable since netdev_lock is per-device and only serializes operations on the same interface.

Testing shows VF bonding now works reliably in ~5 seconds vs 15+ seconds before (i40e), without timeouts or errors (i40e and ice).

Tested on Intel 700-series (i40e) and 800-series (ice) dual-port NICs with iavf driver.

Thanks to Jan Tluka <[email protected]> and Yuying Ma <[email protected]> for reporting the issues.

Jose Ignacio Tornos Martinez (4):
iavf: return EBUSY if reset in progress or not ready during MAC change
i40e: skip unnecessary VF reset when setting trust
iavf: send MAC change request synchronously
ice: skip unnecessary VF reset when setting trust

All patches tested successfully with bonding setup.
---
v7:
- Patches 1/4, 2/4 and 4/4: No changes from v6
- Patch 3/4:
Rebase on current net tree
Remove the multi-batch processing loop from version 6 according to Przemek Kitszel review: the loop cannot work without polling between iterations since the second call would fail the current_op check. Multi-batch scenario is extremely rare; send first batch and let watchdog handle remainder as v5 did
v6: https://lore.kernel.org/all/[email protected]/

--
2.43.0

#1 lore raw

PATCH v7 1/4 iavf: return EBUSY if reset in progress or not ready during MAC change

When a MAC address change is requested while the VF is resetting or still initializing, return -EBUSY immediately instead of attempting the operation.

Additionally, during early initialization states (before __IAVF_DOWN), the PF may be slow to respond to MAC change requests, causing long delays. Only allow MAC changes once the VF reaches __IAVF_DOWN state or later, when the watchdog is running and the VF is ready for operations.

After commit ad7c7b2172c3 ("net: hold netdev instance lock during sysfs operations"), MAC changes are called with the netdev lock held, so we should not wait with the lock held during reset or initialization. This allows the caller to retry or handle the busy state appropriately without blocking other operations.

---
v7: Rebase on current net tree (no code changes from v6)
v6: https://lore.kernel.org/all/[email protected]/

 drivers/net/ethernet/intel/iavf/iavf_main.c | 3 +++
 1 file changed, 3 insertions(+)
drivers/net/ethernet/intel/iavf/iavf_main.c +3 -0
index dad001abc908..67aa14350b1b 100644
@@ -1060,6 +1060,9 @@ static int iavf_set_mac(struct net_device *netdev, void *p)
 	struct sockaddr *addr = p;
 	int ret;
 
+	if (iavf_is_reset_in_progress(adapter) || adapter->state < __IAVF_DOWN)
+		return -EBUSY;
+
 	if (!is_valid_ether_addr(addr->sa_data))
 		return -EADDRNOTAVAIL;
 
Signature · 1 line
2.53.0
#2 lore raw

PATCH v7 2/4 i40e: skip unnecessary VF reset when setting trust

In reply to Jose Ignacio Tornos Martinez

The current implementation triggers a VF reset when changing the trust setting, causing a ~10 second delay during bonding setup.

In all the cases, the reset causes a ~10 second delay during which:
- VF must reinitialize completely
- Any in-progress operations (like bonding enslave) fail with timeouts
- VF is unavailable

When granting trust, no reset is needed - we can just set the capability flag to allow privileged operations.

When revoking trust, we only need to reset (conservative approach) if the VF has actually configured advanced features that require cleanup (ADQ/cloud filters, promiscuous mode). For VFs in a clean state, we can safely change the trust setting without the disruptive reset.

When we don't reset, we manually handle capability flag via helper function, eliminating the delay.

---
v7: Rebase on current net tree (no code changes from v6)
v6: https://lore.kernel.org/all/[email protected]/

 .../ethernet/intel/i40e/i40e_virtchnl_pf.c    | 38 ++++++++++++++-----
 1 file changed, 28 insertions(+), 10 deletions(-)
drivers/net/ethernet/intel/i40e/i40e_virtchnl_pf.c +28 -10
index a26c3d47ec15..0cc434b26eb8 100644
@@ -4943,6 +4943,23 @@ int i40e_ndo_set_vf_spoofchk(struct net_device *netdev, int vf_id, bool enable)
 	return ret;
 }
 
+/**
+ * i40e_setup_vf_trust - Enable/disable VF trust mode without reset
+ * @vf: VF to configure
+ * @setting: trust setting
+ *
+ * Update VF flags when changing trust without performing a VF reset.
+ * This is only called when it's safe to skip the reset (VF has no advanced
+ * features configured that need cleanup).
+ */
+static void i40e_setup_vf_trust(struct i40e_vf *vf, bool setting)
+{
+	if (setting)
+		set_bit(I40E_VIRTCHNL_VF_CAP_PRIVILEGE, &vf->vf_caps);
+	else
+		clear_bit(I40E_VIRTCHNL_VF_CAP_PRIVILEGE, &vf->vf_caps);
+}
+
 /**
  * i40e_ndo_set_vf_trust
  * @netdev: network interface device structure of the pf
@@ -4987,19 +5004,20 @@ int i40e_ndo_set_vf_trust(struct net_device *netdev, int vf_id, bool setting)
 	set_bit(__I40E_MACVLAN_SYNC_PENDING, pf->state);
 	pf->vsi[vf->lan_vsi_idx]->flags |= I40E_VSI_FLAG_FILTER_CHANGED;
 
-	i40e_vc_reset_vf(vf, true);
+	/* Reset only if revoking trust and VF has advanced features configured */
+	if (!setting &&
+	    (vf->adq_enabled || vf->num_cloud_filters > 0 ||
+	     test_bit(I40E_VF_STATE_UC_PROMISC, &vf->vf_states) ||
+	     test_bit(I40E_VF_STATE_MC_PROMISC, &vf->vf_states))) {
+		i40e_vc_reset_vf(vf, true);
+		i40e_del_all_cloud_filters(vf);
+	} else {
+		i40e_setup_vf_trust(vf, setting);
+	}
+
 	dev_info(&pf->pdev->dev, "VF %u is now %strusted\n",
 		 vf_id, setting ? "" : "un");
 
-	if (vf->adq_enabled) {
-		if (!vf->trusted) {
-			dev_info(&pf->pdev->dev,
-				 "VF %u no longer Trusted, deleting all cloud filters\n",
-				 vf_id);
-			i40e_del_all_cloud_filters(vf);
-		}
-	}
-
 out:
 	clear_bit(__I40E_VIRTCHNL_OP_PENDING, pf->state);
 	return ret;
Signature · 1 line
2.53.0
reviewer
#3 lore raw

Re: [Intel-wired-lan] [PATCH net v7 2/4] i40e: skip unnecessary VF reset when setting trust

This is an AI-generated review of your patch. The human sending this email has considered the AI review valid, or at least plausible. Full review at: https://netdev-ai.bots.linux.dev/sashiko/
---
i40e: skip unnecessary VF reset when setting trust

This patch avoids the ~10 second VF reset delay on trust changes by flipping the I40E_VIRTCHNL_VF_CAP_PRIVILEGE bit directly, and only resorting to a full reset when revoking trust from a VF that has advanced features (ADQ, cloud filters, UC/MC promisc) configured.

Quoted 5 lines
drivers/net/ethernet/intel/i40e/i40e_virtchnl_pf.c +0 -0
index a26c3d47ec15..0cc434b26eb8 100644

drivers/net/ethernet/intel/i40e/i40e_virtchnl_pf.c int i40e_ndo_set_vf_trust(struct net_device *netdev, int vf_id, bool setting) · line 5011

Quoted 9 lines
drivers/net/ethernet/intel/i40e/i40e_virtchnl_pf.c +5 -1
@@ -4987,19 +5004,20 @@ int i40e_ndo_set_vf_trust(struct net_device *netdev, int vf_id, bool setting)
 	set_bit(__I40E_MACVLAN_SYNC_PENDING, pf->state);
 	pf->vsi[vf->lan_vsi_idx]->flags |= I40E_VSI_FLAG_FILTER_CHANGED;
 
-	i40e_vc_reset_vf(vf, true);
+	/* Reset only if revoking trust and VF has advanced features configured */
+	if (!setting &&
+	    (vf->adq_enabled || vf->num_cloud_filters > 0 ||
+	     test_bit(I40E_VF_STATE_UC_PROMISC, &vf->vf_states) ||
+	     test_bit(I40E_VF_STATE_MC_PROMISC, &vf->vf_states))) {

[High]
Does this revoke-trust heuristic miss MAC/VLAN filters that were only installable while the VF was trusted?

A trusted VF is allowed to add many more MAC addresses than I40E_VC_MAX_MAC_ADDR_PER_VF (i40e_check_vf_permission() uses I40E_VC_MAX_MACVLAN_PER_TRUSTED_VF) and more than I40E_VC_MAX_VLAN_PER_VF VLANs. These quotas are enforced only at add-time.

The previous always-reset path went through i40e_vc_reset_vf() -> i40e_cleanup_reset_vf() -> i40e_free_vf_res() -> i40e_vsi_release(), which destroyed the VSI and its mac_filter_hash, and reset vf->num_vlan = 0.

The new fast path only flips the PRIVILEGE bit, leaving any trusted-quota MAC/VLAN filters installed in hardware on an now-untrusted VF. Should the heuristic also check vf->num_vlan > I40E_VC_MAX_VLAN_PER_VF or the size of the lan VSI's MAC filter hash before taking the no-reset branch?

[Medium]
Is the sampling of vf->adq_enabled, vf->num_cloud_filters and the UC/MC_PROMISC bits race-free against the admin queue worker?

i40e_ndo_set_vf_trust() runs under rtnl_lock and __I40E_VIRTCHNL_OP_PENDING, but i40e_vc_process_vf_msg() (called from i40e_clean_adminq_subtask() in the service workqueue) takes neither. A virtchnl handler such as i40e_vc_config_promiscuous_mode_msg(), i40e_vc_add_cloud_filter() or i40e_vc_add_qch_msg() can be running concurrently and may have already passed its CAP_PRIVILEGE gate but not yet set vf_states / num_cloud_filters / adq_enabled when this ndo samples them.

In that window the ndo would observe a "clean" VF, take the no-reset branch, and clear CAP_PRIVILEGE while the in-flight handler still goes on to enable promisc / install a cloud filter / set adq_enabled = true on the now-untrusted VF.

The previous always-reset behaviour masked this because the reset moved the VF to I40E_VF_STATE_DISABLED, after which i40e_vc_process_vf_msg() rejects further messages. Is some additional serialization (or a recheck after clearing the bit) needed here?

Quoted 8 lines
drivers/net/ethernet/intel/i40e/i40e_virtchnl_pf.c +6 -0
+		i40e_vc_reset_vf(vf, true);
+		i40e_del_all_cloud_filters(vf);
+	} else {
+		i40e_setup_vf_trust(vf, setting);
+	}
+
 	dev_info(&pf->pdev->dev, "VF %u is now %strusted\n",
 		 vf_id, setting ? "" : "un");

drivers/net/ethernet/intel/i40e/i40e_virtchnl_pf.c int i40e_ndo_set_vf_trust(struct net_device *netdev, int vf_id, bool setting) · line 5002

Quoted 10 lines
drivers/net/ethernet/intel/i40e/i40e_virtchnl_pf.c +0 -9
 
-	if (vf->adq_enabled) {
-		if (!vf->trusted) {
-			dev_info(&pf->pdev->dev,
-				 "VF %u no longer Trusted, deleting all cloud filters\n",
-				 vf_id);
-			i40e_del_all_cloud_filters(vf);
-		}
-	}
-

[Low]
The dedicated "VF %u no longer Trusted, deleting all cloud filters" dev_info() is dropped in this hunk, and the commit message does not mention the logging change. Operators or log scrapers that key on this specific string for audit of cloud filter teardown will no longer see it; only the generic "VF %u is now untrusted" line remains. Was removing this message intentional, and if so could that be called out in the changelog?

Quoted 3 lines
drivers/net/ethernet/intel/i40e/i40e_virtchnl_pf.c +0 -0
 out:
 	clear_bit(__I40E_VIRTCHNL_OP_PENDING, pf->state);
 	return ret;
maintainer
#4 lore raw

Re: [Intel-wired-lan] [PATCH net v7 2/4] i40e: skip unnecessary VF reset when setting trust

Quoted 19 lines · Simon Horman

This is an AI-generated review of your patch. The human sending this email has considered the AI review valid, or at least plausible. Full review at: https://netdev-ai.bots.linux.dev/sashiko/
---
i40e: skip unnecessary VF reset when setting trust

This patch avoids the ~10 second VF reset delay on trust changes by flipping the I40E_VIRTCHNL_VF_CAP_PRIVILEGE bit directly, and only resorting to a full reset when revoking trust from a VF that has advanced features (ADQ, cloud filters, UC/MC promisc) configured.

Quoted 8 lines
drivers/net/ethernet/intel/i40e/i40e_virtchnl_pf.c +0 -0
index a26c3d47ec15..0cc434b26eb8 100644
@@ -4987,19 +5004,20 @@ int i40e_ndo_set_vf_trust(struct net_device *netdev, int vf_id, bool setting)
  	set_bit(__I40E_MACVLAN_SYNC_PENDING, pf->state);
  	pf->vsi[vf->lan_vsi_idx]->flags |= I40E_VSI_FLAG_FILTER_CHANGED;
 
Quoted 10 lines

drivers/net/ethernet/intel/i40e/i40e_virtchnl_pf.c int i40e_ndo_set_vf_trust(struct net_device *netdev, int vf_id, bool setting) · line 5011

Quoted 6 lines
drivers/net/ethernet/intel/i40e/i40e_virtchnl_pf.c +5 -1
-	i40e_vc_reset_vf(vf, true);
+	/* Reset only if revoking trust and VF has advanced features configured */
+	if (!setting &&
+	    (vf->adq_enabled || vf->num_cloud_filters > 0 ||
+	     test_bit(I40E_VF_STATE_UC_PROMISC, &vf->vf_states) ||
+	     test_bit(I40E_VF_STATE_MC_PROMISC, &vf->vf_states))) {

[High]
Does this revoke-trust heuristic miss MAC/VLAN filters that were only installable while the VF was trusted?

No.

Quoted 10 lines

A trusted VF is allowed to add many more MAC addresses than I40E_VC_MAX_MAC_ADDR_PER_VF (i40e_check_vf_permission() uses I40E_VC_MAX_MACVLAN_PER_TRUSTED_VF) and more than I40E_VC_MAX_VLAN_PER_VF VLANs. These quotas are enforced only at add-time.

The previous always-reset path went through i40e_vc_reset_vf() -> i40e_cleanup_reset_vf() -> i40e_free_vf_res() -> i40e_vsi_release(), which destroyed the VSI and its mac_filter_hash, and reset vf->num_vlan = 0.

Current "reset only on revoke" does exactly the same.

Quoted 2 lines

The new fast path only flips the PRIVILEGE bit, leaving any

NOPE.
New "fast path" only *TESTS* the PRIVILEGE bit,
it does not "clear" it in fast path.

This is just negated/wrong/inverted logic on AI side

#5 lore raw

PATCH v7 3/4 iavf: send MAC change request synchronously

In reply to Jose Ignacio Tornos Martinez

After commit ad7c7b2172c3 ("net: hold netdev instance lock during sysfs operations"), iavf_set_mac() is called with the netdev instance lock already held.

The function queues a MAC address change request via iavf_replace_primary_mac() and then waits for completion. However, in the current flow, the actual virtchnl message is sent by the watchdog task, which also needs to acquire the netdev lock to run. Additionally, the adminq_task which processes virtchnl responses also needs the netdev lock.

This creates a deadlock scenario:
1. iavf_set_mac() holds netdev lock and waits for MAC change
2. Watchdog needs netdev lock to send the request -> blocked
3. Even if request is sent, adminq_task needs netdev lock to process PF response -> blocked
4. MAC change times out after 2.5 seconds
5. iavf_set_mac() returns -EAGAIN

This particularly affects VFs during bonding setup when multiple VFs are enslaved in quick succession.

Fix by implementing a synchronous MAC change operation similar to the approach used in commit fdadbf6e84c4 ("iavf: fix incorrect reset handling in callbacks").

The solution:
1. Send the virtchnl ADD_ETH_ADDR message directly (not via watchdog)
2. Poll the admin queue hardware directly for responses
3. Process all received messages (including non-MAC messages)
4. Return when MAC change completes or times out

A new generic function iavf_poll_virtchnl_response() is introduced that can be reused for any future synchronous virtchnl operations. It takes a callback to check completion, allowing flexible condition checking.

This allows the operation to complete synchronously while holding netdev_lock, without relying on watchdog or adminq_task. The function can sleep for up to 2.5 seconds polling hardware, but this is acceptable since netdev_lock is per-device and only serializes operations on the same interface.

To support this, change iavf_add_ether_addrs() to return an error code instead of void, allowing callers to detect failures. Additionally, export iavf_mac_add_reject() to enable proper rollback on local failures (timeouts, send errors) - PF rejections are already handled automatically by iavf_virtchnl_completion().

Remove vc_waitqueue entirely because iavf_set_mac was the only waiter on this waitqueue and after the changes it is not needed.

Fixes ad7c7b2172c3 ("net: hold netdev instance lock during sysfs operations")

---
v7: Rebase on current net tree
Remove the multi-batch processing loop from version 6 according to Przemek Kitszel review: the loop cannot work without polling between iterations since the second call would fail the current_op check. Multi-batch scenario is extremely rare; send first batch and let watchdog handle remainder as v5 did
v6: https://lore.kernel.org/all/[email protected]/

 drivers/net/ethernet/intel/iavf/iavf.h        | 11 ++-
 drivers/net/ethernet/intel/iavf/iavf_main.c   | 85 ++++++++++++----
 .../net/ethernet/intel/iavf/iavf_virtchnl.c   | 99 +++++++++++++++++--
 3 files changed, 165 insertions(+), 30 deletions(-)
drivers/net/ethernet/intel/iavf/iavf.h +9 -2
index 050f8241ef5e..5fcbfa0ca855 100644
@@ -259,7 +259,6 @@ struct iavf_adapter {
 	struct work_struct adminq_task;
 	struct work_struct finish_config;
 	wait_queue_head_t down_waitqueue;
-	wait_queue_head_t vc_waitqueue;
 	struct iavf_q_vector *q_vectors;
 	struct list_head vlan_filter_list;
 	int num_vlan_filters;
@@ -588,8 +587,9 @@ void iavf_configure_queues(struct iavf_adapter *adapter);
 void iavf_enable_queues(struct iavf_adapter *adapter);
 void iavf_disable_queues(struct iavf_adapter *adapter);
 void iavf_map_queues(struct iavf_adapter *adapter);
-void iavf_add_ether_addrs(struct iavf_adapter *adapter);
+int iavf_add_ether_addrs(struct iavf_adapter *adapter);
 void iavf_del_ether_addrs(struct iavf_adapter *adapter);
+void iavf_mac_add_reject(struct iavf_adapter *adapter);
 void iavf_add_vlans(struct iavf_adapter *adapter);
 void iavf_del_vlans(struct iavf_adapter *adapter);
 void iavf_set_promiscuous(struct iavf_adapter *adapter);
@@ -606,6 +606,13 @@ void iavf_disable_vlan_stripping(struct iavf_adapter *adapter);
 void iavf_virtchnl_completion(struct iavf_adapter *adapter,
 			      enum virtchnl_ops v_opcode,
 			      enum iavf_status v_retval, u8 *msg, u16 msglen);
+int iavf_poll_virtchnl_response(struct iavf_adapter *adapter,
+				struct iavf_arq_event_info *event,
+				bool (*condition)(struct iavf_adapter *adapter,
+						  const void *data,
+						  enum virtchnl_ops v_op),
+				const void *cond_data,
+				unsigned int timeout_ms);
 int iavf_config_rss(struct iavf_adapter *adapter);
 void iavf_cfg_queues_bw(struct iavf_adapter *adapter);
 void iavf_cfg_queues_quanta_size(struct iavf_adapter *adapter);
drivers/net/ethernet/intel/iavf/iavf_main.c +67 -18

107 lines not on this page · raw message

drivers/net/ethernet/intel/iavf/iavf_virtchnl.c +89 -10

163 lines not on this page · raw message

Signature · 1 line
2.54.0
maintainer Reviewed-by on v7 3/4
#6 lore raw

Re: [PATCH net v7 3/4] iavf: send MAC change request synchronously

Quoted 54 lines · Jose Ignacio Tornos Martinez

After commit ad7c7b2172c3 ("net: hold netdev instance lock during sysfs operations"), iavf_set_mac() is called with the netdev instance lock already held.

The function queues a MAC address change request via iavf_replace_primary_mac() and then waits for completion. However, in the current flow, the actual virtchnl message is sent by the watchdog task, which also needs to acquire the netdev lock to run. Additionally, the adminq_task which processes virtchnl responses also needs the netdev lock.

This creates a deadlock scenario:
1. iavf_set_mac() holds netdev lock and waits for MAC change
2. Watchdog needs netdev lock to send the request -> blocked
3. Even if request is sent, adminq_task needs netdev lock to process

    PF response -> blocked

4. MAC change times out after 2.5 seconds
5. iavf_set_mac() returns -EAGAIN

This particularly affects VFs during bonding setup when multiple VFs are enslaved in quick succession.

Fix by implementing a synchronous MAC change operation similar to the approach used in commit fdadbf6e84c4 ("iavf: fix incorrect reset handling in callbacks").

The solution:
1. Send the virtchnl ADD_ETH_ADDR message directly (not via watchdog)
2. Poll the admin queue hardware directly for responses
3. Process all received messages (including non-MAC messages)
4. Return when MAC change completes or times out

A new generic function iavf_poll_virtchnl_response() is introduced that can be reused for any future synchronous virtchnl operations. It takes a callback to check completion, allowing flexible condition checking.

This allows the operation to complete synchronously while holding netdev_lock, without relying on watchdog or adminq_task. The function can sleep for up to 2.5 seconds polling hardware, but this is acceptable since netdev_lock is per-device and only serializes operations on the same interface.

To support this, change iavf_add_ether_addrs() to return an error code instead of void, allowing callers to detect failures. Additionally, export iavf_mac_add_reject() to enable proper rollback on local failures (timeouts, send errors) - PF rejections are already handled automatically by iavf_virtchnl_completion().

Remove vc_waitqueue entirely because iavf_set_mac was the only waiter on this waitqueue and after the changes it is not needed.

Fixes ad7c7b2172c3 ("net: hold netdev instance lock during sysfs operations")
Quoted 7 lines

---
v7: Rebase on current net tree
Remove the multi-batch processing loop from version 6 according to Przemek Kitszel review: the loop cannot work without polling between iterations since the second call would fail the current_op check. Multi-batch scenario is extremely rare; send first batch and let watchdog handle remainder as v5 did

I was fine with v5 already, so:

(we will see if Sashiko reads changelog notes (--- section here))

reviewer
#7 lore raw

Re: [PATCH net v7 3/4] iavf: send MAC change request synchronously

In reply to Jose Ignacio Tornos Martinez

This is an AI-generated review of your patch. The human sending this email has considered the AI review valid, or at least plausible. Full review at: https://sashiko.dev
---
iavf: send MAC change request synchronously

This commit fixes a deadlock in iavf_set_mac() by making the MAC address change synchronous. It introduces iavf_poll_virtchnl_response() to directly poll the admin queue instead of waiting on the watchdog task.

Quoted 4 lines
drivers/net/ethernet/intel/iavf/iavf_main.c +0 -0
index 630388e9d28cb..3fa288e3798ae 100644

[ ... ]

Quoted 28 lines
drivers/net/ethernet/intel/iavf/iavf_main.c +9 -12
@@ -1049,25 +1103,23 @@ static int iavf_set_mac(struct net_device *netdev, void *p)
 		return -EADDRNOTAVAIL;
 
 	ret = iavf_replace_primary_mac(adapter, addr->sa_data);
-
 	if (ret)
 		return ret;
 
-	ret = wait_event_interruptible_timeout(adapter->vc_waitqueue,
-					       iavf_is_mac_set_handled(netdev, addr->sa_data),
-					       msecs_to_jiffies(2500));
-
-	/* If ret < 0 then it means wait was interrupted.
-	 * If ret == 0 then it means we got a timeout.
-	 * else it means we got response for set MAC from PF,
-	 * check if netdev MAC was updated to requested MAC,
-	 * if yes then set MAC succeeded otherwise it failed return -EACCES
-	 */
-	if (ret < 0)
+	ret = iavf_set_mac_sync(adapter, addr->sa_data);
+	if (ret) {
+		/* Rollback only if send failed (message never reached PF).
+		 * Don't rollback on timeout (-EAGAIN) because the message was
+		 * sent and PF will eventually respond. When the response arrives,
+		 * iavf_virtchnl_completion() will handle rollback (on PF error)
+		 * or acceptance (on PF success) automatically.
+		 */
+		if (ret != -EAGAIN) {

drivers/net/ethernet/intel/iavf/iavf_main.c static int iavf_set_mac(struct net_device *netdev, void *p) · line 1124

Quoted 10 lines
drivers/net/ethernet/intel/iavf/iavf_main.c +3 -3
+			iavf_mac_add_reject(adapter);
+			ether_addr_copy(adapter->hw.mac.addr, netdev->dev_addr);
+		}
 		return ret;
-
-	if (!ret)
-		return -EAGAIN;
 
 	if (!ether_addr_equal(netdev->dev_addr, addr->sa_data))
 		return -EACCES;

[Severity: High]
Will this cause a persistent state mismatch if a timeout is followed by a retry?

If iavf_set_mac_sync() times out, it returns -EAGAIN and bypasses this rollback, leaving adapter->hw.mac.addr updated but netdev->dev_addr at the old MAC.

If the user then retries before the PF asynchronously completes the original request, iavf_add_ether_addrs() returns -EBUSY. Since -EBUSY != -EAGAIN, the rollback runs, forcibly reverting adapter->hw.mac.addr to the old MAC.

When the PF's delayed success response finally arrives, iavf_virtchnl_completion() sees the old MAC in both hw.mac.addr and netdev->dev_addr, bypassing the netdev MAC update. The PF hardware is now programmed with the new MAC, but the kernel retains the old MAC, dropping traffic.

Quoted 4 lines
drivers/net/ethernet/intel/iavf/iavf_virtchnl.c +0 -0
index ec234cc8bd9db..e6b7e8f82c7c1 100644

[ ... ]

Quoted 15 lines
drivers/net/ethernet/intel/iavf/iavf_virtchnl.c +4 -2
@@ -555,20 +556,23 @@ iavf_set_mac_addr_type(struct virtchnl_ether_addr *virtchnl_ether_addr,
  * @adapter: adapter structure
  *
  * Request that the PF add one or more addresses to our filters.
- **/
-void iavf_add_ether_addrs(struct iavf_adapter *adapter)
+ *
+ * Return: 0 on success, negative on failure
+ */
+int iavf_add_ether_addrs(struct iavf_adapter *adapter)
 {
 	struct virtchnl_ether_addr_list *veal;
 	struct iavf_mac_filter *f;
 	int i = 0, count = 0;
 	bool more = false;

drivers/net/ethernet/intel/iavf/iavf_virtchnl.c iavf_set_mac_addr_type(struct virtchnl_ether_addr *virtchnl_ether_addr, · line 576

Quoted 10 lines
drivers/net/ethernet/intel/iavf/iavf_virtchnl.c +2 -1
 	size_t len;
+	int ret;
 
 	if (adapter->current_op != VIRTCHNL_OP_UNKNOWN) {
 		/* bail because we already have a command pending */
 		dev_err(&adapter->pdev->dev, "Cannot add filters, command %d pending\n",
 			adapter->current_op);
-		return;
+		return -EBUSY;
 	}

[Severity: High]
Could routine background tasks cause MAC changes to frequently fail?

The watchdog task routinely sets adapter->current_op for background commands like VIRTCHNL_OP_GET_STATS. If iavf_set_mac() is called during this window, iavf_set_mac_sync() will hit this check and immediately fail the MAC change with -EBUSY.

Because there is no retry logic in iavf_set_mac(), this error propagates directly to userspace, making MAC address configuration randomly fail based on watchdog timing.

[ ... ]

drivers/net/ethernet/intel/iavf/iavf_virtchnl.c static void iavf_mac_add_ok(struct iavf_adapter *adapter) · line 731

Quoted 11 lines
drivers/net/ethernet/intel/iavf/iavf_virtchnl.c +2 -2
@@ -712,8 +724,8 @@ static void iavf_mac_add_ok(struct iavf_adapter *adapter)
  * @adapter: adapter structure
  *
  * Remove filters from list based on PF response.
- **/
-static void iavf_mac_add_reject(struct iavf_adapter *adapter)
+ */
+void iavf_mac_add_reject(struct iavf_adapter *adapter)
 {
 	struct net_device *netdev = adapter->netdev;
 	struct iavf_mac_filter *f, *ftmp;

[Severity: Medium]
Does exporting and reusing iavf_mac_add_reject() for local rollback cause unintended background MAC changes?

When the user requests a MAC address that is already in the filter list (e.g., a secondary MAC), iavf_add_filter() sets f->is_new_mac = false and f->add = true, and flags IAVF_FLAG_AQ_ADD_MAC_FILTER.

If the synchronous operation fails locally (like the -EBUSY return above), iavf_set_mac() calls this function. However, iavf_mac_add_reject() only clears the pending state and removes the filter if f->is_new_mac is true:

    if (f->is_new_mac) {
        list_del(&f->list);
        kfree(f);
    }

Reused filters are ignored, leaving f->add = true and the IAVF_FLAG_AQ_ADD_MAC_FILTER flag active. The background watchdog task will eventually process this flag and blindly send the MAC configuration to the PF, even though the VF already aborted the operation locally.

#8 lore raw

Re: [PATCH net v7 3/4] iavf: send MAC change request synchronously

Quoted 15 lines
Quoted 2 lines
      if (!ether_addr_equal(netdev->dev_addr, addr->sa_data))
              return -EACCES;

[Severity: High]
Will this cause a persistent state mismatch if a timeout is followed by a retry?

If iavf_set_mac_sync() times out, it returns -EAGAIN and bypasses this rollback, leaving adapter->hw.mac.addr updated but netdev->dev_addr at the old MAC.

If the user then retries before the PF asynchronously completes the original request, iavf_add_ether_addrs() returns -EBUSY. Since -EBUSY != -EAGAIN, the rollback runs, forcibly reverting adapter->hw.mac.addr to the old MAC.

Quoted 5 lines

When the PF's delayed success response finally arrives, iavf_virtchnl_completion() sees the old MAC in both hw.mac.addr and netdev->dev_addr, bypassing the netdev MAC update. The PF hardware is now programmed with the new MAC, but the kernel retains the old MAC, dropping traffic.

This scenario requires an extremely narrow timing window: a 2.5s PF timeout (rare in normal operation, PF typically responds much faster), followed by an immediate retry before adminq_task clears current_op (microsecond window).

Even if this race occurs, it's recoverable - the retry fails with -EBUSY and the user retries again successfully. This is a transient failure, not permanent state corruption.

Quoted 11 lines

drivers/net/ethernet/intel/iavf/iavf_virtchnl.c iavf_set_mac_addr_type(struct virtchnl_ether_addr *virtchnl_ether_addr, · line 576

Quoted 7 lines
      if (adapter->current_op != VIRTCHNL_OP_UNKNOWN) {
              /* bail because we already have a command pending */
              dev_err(&adapter->pdev->dev, "Cannot add filters, command %d pending\n",
                     adapter->current_op);
drivers/net/ethernet/intel/iavf/iavf_virtchnl.c +1 -1
-             return;
+             return -EBUSY;
      }

[Severity: High]
Could routine background tasks cause MAC changes to frequently fail?

Quoted 8 lines

The watchdog task routinely sets adapter->current_op for background commands like VIRTCHNL_OP_GET_STATS. If iavf_set_mac() is called during this window, iavf_set_mac_sync() will hit this check and immediately fail the MAC change with -EBUSY.

Because there is no retry logic in iavf_set_mac(), this error propagates directly to userspace, making MAC address configuration randomly fail based on watchdog timing.

Background virtchnl operations (like GET_STATS) complete quickly, typically within milliseconds. The collision window is very small.

Fail-fast with -EBUSY is semantically correct and allows user-space retry. If a collision occurs, it's spurious and recoverable immediately on retry. This is acceptable compared to the complexity and deadlock risks of queuing or waiting for background operations to complete while holding netdev_lock.

Quoted 24 lines

drivers/net/ethernet/intel/iavf/iavf_virtchnl.c static void iavf_mac_add_ok(struct iavf_adapter *adapter) · line 731

Quoted 6 lines
drivers/net/ethernet/intel/iavf/iavf_virtchnl.c +2 -1
-static void iavf_mac_add_reject(struct iavf_adapter *adapter)
+ */
+void iavf_mac_add_reject(struct iavf_adapter *adapter)
 {
      struct net_device *netdev = adapter->netdev;
      struct iavf_mac_filter *f, *ftmp;

[Severity: Medium]
Does exporting and reusing iavf_mac_add_reject() for local rollback cause unintended background MAC changes?

When the user requests a MAC address that is already in the filter list (e.g., a secondary MAC), iavf_add_filter() sets f->is_new_mac = false and f->add = true, and flags IAVF_FLAG_AQ_ADD_MAC_FILTER.

If the synchronous operation fails locally (like the -EBUSY return above), iavf_set_mac() calls this function. However, iavf_mac_add_reject() only clears the pending state and removes the filter if f->is_new_mac is true:

   if (f->is_new_mac) {
       list_del(&f->list);
       kfree(f);
   }
Quoted 4 lines

Reused filters are ignored, leaving f->add = true and the IAVF_FLAG_AQ_ADD_MAC_FILTER flag active. The background watchdog task will eventually process this flag and blindly send the MAC configuration to the PF, even though the VF already aborted the operation locally.

This scenario only occurs when setting the primary MAC to an address that already exists as a secondary MAC in the filter list - an extremely rare configuration.

Even if this occurs and the watchdog later sends the MAC to the PF, it is
harmless: the MAC is already configured on the PF (as a secondary), so the redundant ADD_ETH_ADDR message has no adverse effect.

The common case - changing primary MAC to a new address - uses is_new_mac = true and is handled correctly by the rollback logic.

These concerns represent theoretical edge cases that are extremely unlikely in practice. The synchronous approach fixes a reproducible deadlock affecting all users in production, allowing the user to retry and complete the operation. The trade-off is justified.

#9 lore raw

RE: [Intel-wired-lan] [PATCH net v7 3/4] iavf: send MAC change request synchronously

In reply to Jose Ignacio Tornos Martinez
Quoted 201 lines

-----Original Message-----
From: Intel-wired-lan <[email protected]> On Behalf Of Jose Ignacio Tornos Martinez
Sent: Tuesday, June 23, 2026 12:18 PM
To: [email protected]
Cc: [email protected]; Kitszel, Przemyslaw <[email protected]>; Loktionov, Aleksandr <[email protected]>; Keller, Jacob E <[email protected]>; [email protected]; Nguyen, Anthony L <[email protected]>; [email protected]; [email protected]; [email protected]; [email protected]; Jose Ignacio Tornos Martinez <[email protected]>; [email protected]
Subject: [Intel-wired-lan] [PATCH net v7 3/4] iavf: send MAC change request synchronously

After commit ad7c7b2172c3 ("net: hold netdev instance lock during sysfs operations"), iavf_set_mac() is called with the netdev instance lock already held.

The function queues a MAC address change request via
iavf_replace_primary_mac() and then waits for completion. However, in the current flow, the actual virtchnl message is sent by the watchdog task, which also needs to acquire the netdev lock to run. Additionally, the adminq_task which processes virtchnl responses also needs the netdev lock.

This creates a deadlock scenario:
1. iavf_set_mac() holds netdev lock and waits for MAC change 2. Watchdog needs netdev lock to send the request -> blocked 3. Even if request is sent, adminq_task needs netdev lock to process PF response -> blocked
4. MAC change times out after 2.5 seconds 5. iavf_set_mac() returns -EAGAIN

This particularly affects VFs during bonding setup when multiple VFs are enslaved in quick succession.

Fix by implementing a synchronous MAC change operation similar to the approach used in commit fdadbf6e84c4 ("iavf: fix incorrect reset handling in callbacks").

The solution:
1. Send the virtchnl ADD_ETH_ADDR message directly (not via watchdog) 2. Poll the admin queue hardware directly for responses 3. Process all received messages (including non-MAC messages) 4. Return when MAC change completes or times out

A new generic function iavf_poll_virtchnl_response() is introduced that can be reused for any future synchronous virtchnl operations. It takes a callback to check completion, allowing flexible condition checking.

This allows the operation to complete synchronously while holding netdev_lock, without relying on watchdog or adminq_task. The function can sleep for up to 2.5 seconds polling hardware, but this is acceptable since netdev_lock is per-device and only serializes operations on the same interface.

To support this, change iavf_add_ether_addrs() to return an error code instead of void, allowing callers to detect failures. Additionally, export iavf_mac_add_reject() to enable proper rollback on local failures (timeouts, send errors) - PF rejections are already handled automatically by iavf_virtchnl_completion().

Remove vc_waitqueue entirely because iavf_set_mac was the only waiter on this waitqueue and after the changes it is not needed.

Fixes ad7c7b2172c3 ("net: hold netdev instance lock during sysfs operations")

---
v7: Rebase on current net tree
Remove the multi-batch processing loop from version 6 according to Przemek Kitszel review: the loop cannot work without polling between iterations since the second call would fail the current_op check. Multi-batch scenario is extremely rare; send first batch and let watchdog handle remainder as v5 did
v6: https://lore.kernel.org/all/[email protected]/

drivers/net/ethernet/intel/iavf/iavf.h        | 11 ++-
drivers/net/ethernet/intel/iavf/iavf_main.c   | 85 ++++++++++++----
.../net/ethernet/intel/iavf/iavf_virtchnl.c   | 99 +++++++++++++++++--
3 files changed, 165 insertions(+), 30 deletions(-)
drivers/net/ethernet/intel/iavf/iavf.h +9 -1
index 050f8241ef5e..5fcbfa0ca855 100644
@@ -259,7 +259,6 @@ struct iavf_adapter {
 	struct work_struct adminq_task;
 	struct work_struct finish_config;
 	wait_queue_head_t down_waitqueue;
-	wait_queue_head_t vc_waitqueue;
 	struct iavf_q_vector *q_vectors;
 	struct list_head vlan_filter_list;
 	int num_vlan_filters;
@@ -588,8 +587,9 @@ void iavf_configure_queues(struct iavf_adapter *adapter);  void iavf_enable_queues(struct iavf_adapter *adapter);  void iavf_disable_queues(struct iavf_adapter *adapter);  void iavf_map_queues(struct iavf_adapter *adapter); -void iavf_add_ether_addrs(struct iavf_adapter *adapter);
+int iavf_add_ether_addrs(struct iavf_adapter *adapter);
 void iavf_del_ether_addrs(struct iavf_adapter *adapter);
+void iavf_mac_add_reject(struct iavf_adapter *adapter);
 void iavf_add_vlans(struct iavf_adapter *adapter);  void iavf_del_vlans(struct iavf_adapter *adapter);  void iavf_set_promiscuous(struct iavf_adapter *adapter); @@ -606,6 +606,13 @@ void iavf_disable_vlan_stripping(struct iavf_adapter *adapter);  void iavf_virtchnl_completion(struct iavf_adapter *adapter,
 			      enum virtchnl_ops v_opcode,
 			      enum iavf_status v_retval, u8 *msg, u16 msglen);
+int iavf_poll_virtchnl_response(struct iavf_adapter *adapter,
+				struct iavf_arq_event_info *event,
+				bool (*condition)(struct iavf_adapter *adapter,
+						  const void *data,
+						  enum virtchnl_ops v_op),
+				const void *cond_data,
+				unsigned int timeout_ms);

int iavf_config_rss(struct iavf_adapter *adapter); void iavf_cfg_queues_bw(struct iavf_adapter *adapter); void iavf_cfg_queues_quanta_size(struct iavf_adapter *adapter); diff --git a/drivers/net/ethernet/intel/iavf/iavf_main.c b/drivers/net/ethernet/intel/iavf/iavf_main.c index 630388e9d28c..3fa288e3798a 100644

drivers/net/ethernet/intel/iavf/iavf_main.c +49 -0
@@ -1029,6 +1029,60 @@ static bool iavf_is_mac_set_handled(struct net_device *netdev,
 	return ret;
 }
 
+/**
+ * iavf_mac_change_done - Check if MAC change completed
+ * @adapter: board private structure
+ * @data: MAC address being checked (as const void *)
+ * @v_op: virtchnl opcode from processed message
+ *
+ * Callback for iavf_poll_virtchnl_response() to check if MAC change completed.
+ *
+ * Return: true if MAC change completed, false otherwise  */ static 
+bool iavf_mac_change_done(struct iavf_adapter *adapter,
+				 const void *data, enum virtchnl_ops v_op) {
+	const u8 *addr = data;
+
+	return iavf_is_mac_set_handled(adapter->netdev, addr); }
+
+/**
+ * iavf_set_mac_sync - Synchronously change MAC address
+ * @adapter: board private structure
+ * @addr: MAC address to set
+ *
+ * Send MAC change request to PF and poll admin queue for response.
+ * Caller must hold netdev_lock. This can sleep for up to 2.5 seconds.
+ * Event buffer is allocated before sending to avoid state mismatch if
+ * allocation fails after message is sent to PF.
+ *
+ * Return: 0 on success, negative on failure  */ static int 
+iavf_set_mac_sync(struct iavf_adapter *adapter, const u8 *addr) {
+	struct iavf_arq_event_info event;
+	int ret;
+
+	netdev_assert_locked(adapter->netdev);
+
+	event.buf_len = IAVF_MAX_AQ_BUF_SIZE;
+	event.msg_buf = kzalloc(event.buf_len, GFP_KERNEL);
+	if (!event.msg_buf)
+		return -ENOMEM;
+
+	ret = iavf_add_ether_addrs(adapter);
+	if (ret)
+		goto out;
+
+	ret = iavf_poll_virtchnl_response(adapter, &event,
+					  iavf_mac_change_done, addr, 2500);
+
+out:
+	kfree(event.msg_buf);
+	return ret;
+}
+
 /**
 * iavf_set_mac - NDO callback to set port MAC address
 * @netdev: network interface device structure @@ -1049,25 +1103,23 @@ static int iavf_set_mac(struct net_device *netdev, void *p)
		return -EADDRNOTAVAIL;

	ret = iavf_replace_primary_mac(adapter, addr->sa_data);
-
	if (ret)
		return ret;
drivers/net/ethernet/intel/iavf/iavf_main.c +12 -11
-	ret = wait_event_interruptible_timeout(adapter->vc_waitqueue,
-					       iavf_is_mac_set_handled(netdev, addr->sa_data),
-					       msecs_to_jiffies(2500));
-
-	/* If ret < 0 then it means wait was interrupted.
-	 * If ret == 0 then it means we got a timeout.
-	 * else it means we got response for set MAC from PF,
-	 * check if netdev MAC was updated to requested MAC,
-	 * if yes then set MAC succeeded otherwise it failed return -EACCES
-	 */
-	if (ret < 0)
+	ret = iavf_set_mac_sync(adapter, addr->sa_data);
+	if (ret) {
+		/* Rollback only if send failed (message never reached PF).
+		 * Don't rollback on timeout (-EAGAIN) because the message was
+		 * sent and PF will eventually respond. When the response arrives,
+		 * iavf_virtchnl_completion() will handle rollback (on PF error)
+		 * or acceptance (on PF success) automatically.
+		 */
+		if (ret != -EAGAIN) {
+			iavf_mac_add_reject(adapter);
+			ether_addr_copy(adapter->hw.mac.addr, netdev->dev_addr);
+		}
		return ret;
drivers/net/ethernet/intel/iavf/iavf_main.c +1 -3
-
-	if (!ret)
-		return -EAGAIN;
+	}
	if (!ether_addr_equal(netdev->dev_addr, addr->sa_data))
		return -EACCES;
drivers/net/ethernet/intel/iavf/iavf_main.c +0 -3
@@ -5397,9 +5449,6 @@ static int iavf_probe(struct pci_dev *pdev, const struct pci_device_id *ent)
 	/* Setup the wait queue for indicating transition to down status */
 	init_waitqueue_head(&adapter->down_waitqueue);
 
-	/* Setup the wait queue for indicating virtchannel events */
-	init_waitqueue_head(&adapter->vc_waitqueue);
-
 	INIT_LIST_HEAD(&adapter->ptp.aq_cmds);
 	init_waitqueue_head(&adapter->ptp.phc_time_waitqueue);
 	mutex_init(&adapter->ptp.aq_cmd_lock);
drivers/net/ethernet/intel/iavf/iavf_virtchnl.c +1 -2
index ec234cc8bd9d..e6b7e8f82c7c 100644
@@ -2,6 +2,7 @@
 /* Copyright(c) 2013 - 2018 Intel Corporation. */
 
 #include <linux/net/intel/libie/rx.h>
+#include <net/netdev_lock.h>
 
 #include "iavf.h"
 #include "iavf_ptp.h"
@@ -555,20 +556,23 @@ iavf_set_mac_addr_type(struct virtchnl_ether_addr *virtchnl_ether_addr,
 * @adapter: adapter structure
 *
 * Request that the PF add one or more addresses to our filters.
- **/
-void iavf_add_ether_addrs(struct iavf_adapter *adapter)

drivers/net/ethernet/intel/iavf/iavf_virtchnl.c iavf_set_mac_addr_type(struct virtchnl_ether_addr *virtchnl_ether_addr, · line 568

Quoted 10 lines
drivers/net/ethernet/intel/iavf/iavf_virtchnl.c +4 -0
+ *
+ * Return: 0 on success, negative on failure  */ int 
+iavf_add_ether_addrs(struct iavf_adapter *adapter)
 {
 	struct virtchnl_ether_addr_list *veal;
 	struct iavf_mac_filter *f;
 	int i = 0, count = 0;
 	bool more = false;
 	size_t len;
+	int ret;

The patch looks good. Minor suggestion:
- int i = 0, count = 0;
+ int i = 0, count = 0, ret;
Please retain RCT.
Thank you.
Piotr

Quoted 107 lines
drivers/net/ethernet/intel/iavf/iavf_virtchnl.c +4 -3
 	if (adapter->current_op != VIRTCHNL_OP_UNKNOWN) {
 		/* bail because we already have a command pending */
 		dev_err(&adapter->pdev->dev, "Cannot add filters, command %d pending\n",
 			adapter->current_op);
-		return;
+		return -EBUSY;
 	}
 
 	spin_lock_bh(&adapter->mac_vlan_list_lock);
@@ -580,7 +584,7 @@ void iavf_add_ether_addrs(struct iavf_adapter *adapter)
 	if (!count) {
 		adapter->aq_required &= ~IAVF_FLAG_AQ_ADD_MAC_FILTER;
 		spin_unlock_bh(&adapter->mac_vlan_list_lock);
-		return;
+		return 0;
 	}
 	adapter->current_op = VIRTCHNL_OP_ADD_ETH_ADDR;
 
@@ -594,8 +598,9 @@ void iavf_add_ether_addrs(struct iavf_adapter *adapter)
 
 	veal = kzalloc(len, GFP_ATOMIC);
 	if (!veal) {
+		adapter->current_op = VIRTCHNL_OP_UNKNOWN;
 		spin_unlock_bh(&adapter->mac_vlan_list_lock);
-		return;
+		return -ENOMEM;
 	}
 
 	veal->vsi_id = adapter->vsi_res->vsi_id; @@ -615,8 +620,15 @@ void iavf_add_ether_addrs(struct iavf_adapter *adapter)
	spin_unlock_bh(&adapter->mac_vlan_list_lock);
drivers/net/ethernet/intel/iavf/iavf_virtchnl.c +2 -1
-	iavf_send_pf_msg(adapter, VIRTCHNL_OP_ADD_ETH_ADDR, (u8 *)veal, len);
+	ret = iavf_send_pf_msg(adapter, VIRTCHNL_OP_ADD_ETH_ADDR, (u8 *)veal, 
+len);
	kfree(veal);
drivers/net/ethernet/intel/iavf/iavf_virtchnl.c +7 -0
+	if (ret) {
+		dev_err(&adapter->pdev->dev,
+			"Unable to send ADD_ETH_ADDR message to PF, error %d\n", ret);
+		adapter->current_op = VIRTCHNL_OP_UNKNOWN;
+	}
+
+	return ret;

}

/**

drivers/net/ethernet/intel/iavf/iavf_virtchnl.c +2 -3
@@ -712,8 +724,8 @@ static void iavf_mac_add_ok(struct iavf_adapter *adapter)
 * @adapter: adapter structure
 *
 * Remove filters from list based on PF response.
- **/
-static void iavf_mac_add_reject(struct iavf_adapter *adapter)
+ */
+void iavf_mac_add_reject(struct iavf_adapter *adapter)
 {
 	struct net_device *netdev = adapter->netdev;
 	struct iavf_mac_filter *f, *ftmp;
@@ -2364,7 +2376,6 @@ void iavf_virtchnl_completion(struct iavf_adapter *adapter,
 			iavf_mac_add_reject(adapter);
 			/* restore administratively set MAC address */
 			ether_addr_copy(adapter->hw.mac.addr, netdev->dev_addr);
-			wake_up(&adapter->vc_waitqueue);
 			break;
 		case VIRTCHNL_OP_DEL_ETH_ADDR:
 			dev_err(&adapter->pdev->dev, "Failed to delete MAC filter, error %s\n", @@ -2555,7 +2566,6 @@ void iavf_virtchnl_completion(struct iavf_adapter *adapter,
			eth_hw_addr_set(netdev, adapter->hw.mac.addr);
			netif_addr_unlock_bh(netdev);
		}
drivers/net/ethernet/intel/iavf/iavf_virtchnl.c +0 -1
-		wake_up(&adapter->vc_waitqueue);
		break;
	case VIRTCHNL_OP_GET_STATS: {
		struct iavf_eth_stats *stats =
drivers/net/ethernet/intel/iavf/iavf_virtchnl.c +31 -0
@@ -2950,3 +2960,72 @@ void iavf_virtchnl_completion(struct iavf_adapter *adapter,
 	} /* switch v_opcode */
 	adapter->current_op = VIRTCHNL_OP_UNKNOWN;  }
+
+/**
+ * iavf_poll_virtchnl_response - Poll admin queue for virtchnl response
+ * @adapter: adapter structure
+ * @event: pre-allocated event buffer to use for polling
+ * @condition: callback to check if desired response received
+ * @cond_data: context data passed to condition callback
+ * @timeout_ms: maximum time to wait in milliseconds
+ *
+ * Polls the admin queue and processes all incoming virtchnl messages.
+ * After processing each valid message, calls the condition callback to 
+check
+ * if the expected response has been received. The callback receives 
+the opcode
+ * of the processed message to identify which response was received. 
+Continues
+ * polling until the callback returns true or timeout expires.
+ *
+ * Caller must allocate event buffer before sending any messages to PF 
+to avoid
+ * state mismatch if allocation fails after message is sent.
+ *
+ * Caller must hold netdev_lock. This can sleep for up to timeout_ms 
+while
+ * polling hardware.
+ *
+ * Return: 0 on success (condition met), -EAGAIN on timeout, or error 
+code  */ int iavf_poll_virtchnl_response(struct iavf_adapter *adapter,
+				struct iavf_arq_event_info *event,
+				bool (*condition)(struct iavf_adapter *adapter,
+						  const void *data,

drivers/net/ethernet/intel/iavf/iavf_virtchnl.c void iavf_virtchnl_completion(struct iavf_adapter *adapter, · line 3002

Quoted 10 lines
drivers/net/ethernet/intel/iavf/iavf_virtchnl.c +10 -0
+						  enum virtchnl_ops v_op),
+				const void *cond_data,
+				unsigned int timeout_ms)
+{
+	struct iavf_hw *hw = &adapter->hw;
+	enum virtchnl_ops received_op;
+	unsigned long timeout;
+	int ret = -EAGAIN;
+	u16 pending = 0;
+	u32 v_retval;

Most of these variables may be declared inside the below statements. Reviewed-by Piotr Kwapulinski <[email protected]> Piotr

Quoted 36 lines
drivers/net/ethernet/intel/iavf/iavf_virtchnl.c +32 -1
+
+	netdev_assert_locked(adapter->netdev);
+
+	timeout = jiffies + msecs_to_jiffies(timeout_ms);
+	do {
+		if (!pending)
+			usleep_range(50, 75);
+
+		if (iavf_clean_arq_element(hw, event, &pending) == IAVF_SUCCESS) {
+			received_op = (enum virtchnl_ops)le32_to_cpu(event->desc.cookie_high);
+			if (received_op != VIRTCHNL_OP_UNKNOWN) {
+				v_retval = le32_to_cpu(event->desc.cookie_low);
+
+				iavf_virtchnl_completion(adapter, received_op,
+							 (enum iavf_status)v_retval,
+							 event->msg_buf, event->msg_len);
+
+				if (condition(adapter, cond_data, received_op)) {
+					ret = 0;
+					break;
+				}
+			}
+
+			memset(event->msg_buf, 0, IAVF_MAX_AQ_BUF_SIZE);
+
+			if (pending)
+				continue;
+		}
+	} while (time_before(jiffies, timeout));
+
+	return ret;
+}
--

2.54.0

#10 lore raw

RE: [Intel-wired-lan] [PATCH net v7 3/4] iavf: send MAC change request synchronously

Quoted 134 lines

-----Original Message-----
From: Intel-wired-lan <[email protected]> On Behalf Of Kwapulinski, Piotr
Sent: Friday, June 26, 2026 5:04 PM
To: Jose Ignacio Tornos Martinez <[email protected]>; [email protected]
Cc: [email protected]; Kitszel, Przemyslaw <[email protected]>; Loktionov, Aleksandr <[email protected]>; Keller, Jacob E <[email protected]>; [email protected]; Nguyen, Anthony L <[email protected]>; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]
Subject: Re: [Intel-wired-lan] [PATCH net v7 3/4] iavf: send MAC change request synchronously

Quoted 10 lines

-----Original Message-----
From: Intel-wired-lan <[email protected]> On Behalf Of Jose Ignacio Tornos Martinez
Sent: Tuesday, June 23, 2026 12:18 PM
To: [email protected]
Cc: [email protected]; Kitszel, Przemyslaw <[email protected]>; Loktionov, Aleksandr <[email protected]>; Keller, Jacob E <[email protected]>; [email protected]; Nguyen, Anthony L <[email protected]>; [email protected];

[email protected];

Quoted 6 lines

[email protected]; [email protected]; Jose Ignacio Tornos Martinez <[email protected]>; [email protected]
Subject: [Intel-wired-lan] [PATCH net v7 3/4] iavf: send MAC change request synchronously

After commit ad7c7b2172c3 ("net: hold netdev instance lock during sysfs

operations"), iavf_set_mac() is called with the netdev instance lock already held.

Quoted 3 lines

The function queues a MAC address change request via iavf_replace_primary_mac() and then waits for completion. However, in the

current flow, the actual virtchnl message is sent by the watchdog task, which also needs to acquire the netdev lock to run. Additionally, the adminq_task which processes virtchnl responses also needs the netdev lock.

Quoted 3 lines

This creates a deadlock scenario:
1. iavf_set_mac() holds netdev lock and waits for MAC change 2. Watchdog

needs netdev lock to send the request -> blocked 3. Even if request is sent, adminq_task needs netdev lock to process

Quoted 5 lines

PF response -> blocked
4. MAC change times out after 2.5 seconds 5. iavf_set_mac() returns -EAGAIN

This particularly affects VFs during bonding setup when multiple VFs are

enslaved in quick succession.

Quoted 2 lines

Fix by implementing a synchronous MAC change operation similar to the

approach used in commit fdadbf6e84c4 ("iavf: fix incorrect reset handling in callbacks").

Quoted 8 lines

The solution:
1. Send the virtchnl ADD_ETH_ADDR message directly (not via watchdog)
2. Poll the admin queue hardware directly for responses 3. Process all received messages (including non-MAC messages) 4. Return when MAC change completes or times out

A new generic function iavf_poll_virtchnl_response() is introduced that can be

reused for any future synchronous virtchnl operations. It takes a callback to check completion, allowing flexible condition checking.

Quoted 2 lines

This allows the operation to complete synchronously while holding netdev_lock,

without relying on watchdog or adminq_task. The function can sleep for up to 2.5 seconds polling hardware, but this is acceptable since netdev_lock is per-device and only serializes operations on the same interface.

Quoted 2 lines

To support this, change iavf_add_ether_addrs() to return an error code instead

of void, allowing callers to detect failures. Additionally, export iavf_mac_add_reject() to enable proper rollback on local failures (timeouts, send errors) - PF rejections are already handled automatically by iavf_virtchnl_completion().

Quoted 2 lines

Remove vc_waitqueue entirely because iavf_set_mac was the only waiter on

this waitqueue and after the changes it is not needed.

Quoted 35 lines
Fixes ad7c7b2172c3 ("net: hold netdev instance lock during sysfs

operations")

---
v7: Rebase on current net tree
Remove the multi-batch processing loop from version 6 according to Przemek Kitszel review: the loop cannot work without polling between iterations since the second call would fail the current_op check. Multi-batch scenario is extremely rare; send first batch and let watchdog handle remainder as v5 did
v6:
https://lore.kernel.org/all/[email protected]/

drivers/net/ethernet/intel/iavf/iavf.h        | 11 ++-
drivers/net/ethernet/intel/iavf/iavf_main.c   | 85 ++++++++++++----
.../net/ethernet/intel/iavf/iavf_virtchnl.c   | 99 +++++++++++++++++--
3 files changed, 165 insertions(+), 30 deletions(-)
drivers/net/ethernet/intel/iavf/iavf.h +0 -1
index 050f8241ef5e..5fcbfa0ca855 100644
@@ -259,7 +259,6 @@ struct iavf_adapter {
 	struct work_struct adminq_task;
 	struct work_struct finish_config;
 	wait_queue_head_t down_waitqueue;
-	wait_queue_head_t vc_waitqueue;
 	struct iavf_q_vector *q_vectors;
 	struct list_head vlan_filter_list;
 	int num_vlan_filters;
@@ -588,8 +587,9 @@ void iavf_configure_queues(struct iavf_adapter
 *adapter);  void iavf_enable_queues(struct iavf_adapter *adapter);
Quoted 7 lines

void iavf_disable_queues(struct iavf_adapter *adapter); void iavf_map_queues(struct iavf_adapter *adapter); -void iavf_add_ether_addrs(struct iavf_adapter *adapter);
+int iavf_add_ether_addrs(struct iavf_adapter *adapter);
void iavf_del_ether_addrs(struct iavf_adapter *adapter);
+void iavf_mac_add_reject(struct iavf_adapter *adapter);
void iavf_add_vlans(struct iavf_adapter *adapter); void iavf_del_vlans(struct

iavf_adapter *adapter); void iavf_set_promiscuous(struct iavf_adapter *adapter); @@ -606,6 +606,13 @@ void iavf_disable_vlan_stripping(struct iavf_adapter *adapter); void iavf_virtchnl_completion(struct iavf_adapter *adapter,

Quoted 10 lines
			      enum virtchnl_ops v_opcode,
			      enum iavf_status v_retval, u8 *msg, u16 msglen);
drivers/net/ethernet/intel/iavf/iavf.h +7 -0
+int iavf_poll_virtchnl_response(struct iavf_adapter *adapter,
+				struct iavf_arq_event_info *event,
+				bool (*condition)(struct iavf_adapter *adapter,
+						  const void *data,
+						  enum virtchnl_ops v_op),
+				const void *cond_data,
+				unsigned int timeout_ms);

int iavf_config_rss(struct iavf_adapter *adapter); void

Quoted 8 lines

drivers/net/ethernet/intel/iavf/iavf_main.c static bool iavf_is_mac_set_handled(struct

Quoted 8 lines

iavf_cfg_queues_bw(struct iavf_adapter *adapter); void iavf_cfg_queues_quanta_size(struct iavf_adapter *adapter); diff --git a/drivers/net/ethernet/intel/iavf/iavf_main.c b/drivers/net/ethernet/intel/iavf/iavf_main.c
index 630388e9d28c..3fa288e3798a 100644

drivers/net/ethernet/intel/iavf/iavf_main.c +0 -0
@@ -1029,6 +1029,60 @@ static bool iavf_is_mac_set_handled(struct
#11 lore raw

PATCH v7 4/4 ice: skip unnecessary VF reset when setting trust

In reply to Jose Ignacio Tornos Martinez

Similar to the i40e fix, ice_set_vf_trust() unconditionally calls ice_reset_vf() when the trust setting changes. While the delay is smaller than i40e, this reset is still unnecessary in most cases.

When granting trust, no reset is needed - we can just set the capability flag to allow privileged operations.

When revoking trust, we only need to reset (conservative approach) if the VF has actually configured advanced features that require cleanup (MAC LLDP filters, promiscuous mode). For VFs in a clean state, we can safely change the trust setting without the disruptive reset.

When we do reset, we maintain the original ice pattern that has been reliable in production: cleanup LLDP filters first, then set vf->trusted, then reset. This ensures the privilege capability bit is handled correctly during reset rebuild.

When we don't reset, we manually handle the capability flag via helper function, eliminating the delay.

---
v7: Rebase on current net tree (no code changes from v6)
v6: https://lore.kernel.org/all/[email protected]/

 drivers/net/ethernet/intel/ice/ice_sriov.c | 33 +++++++++++++++++++---
 1 file changed, 29 insertions(+), 4 deletions(-)
drivers/net/ethernet/intel/ice/ice_sriov.c +30 -5
index 7e00e091756d..XXXXXXXXXXXXXXXX 100644
@@ -1364,6 +1364,23 @@ int ice_set_vf_mac(struct net_device *netdev, int vf_id, u8 *mac)
 	return __ice_set_vf_mac(ice_netdev_to_pf(netdev), vf_id, mac);
 }
 
+/**
+ * ice_setup_vf_trust - Enable/disable VF trust mode without reset
+ * @vf: VF to configure
+ * @setting: trust setting
+ *
+ * Update VF flags when changing trust without performing a VF reset.
+ * This is only called when it's safe to skip the reset (VF has no advanced
+ * features configured that need cleanup).
+ */
+static void ice_setup_vf_trust(struct ice_vf *vf, bool setting)
+{
+	if (setting)
+		set_bit(ICE_VIRTCHNL_VF_CAP_PRIVILEGE, &vf->vf_caps);
+	else
+		clear_bit(ICE_VIRTCHNL_VF_CAP_PRIVILEGE, &vf->vf_caps);
+}
+
 /**
  * ice_set_vf_trust
  * @netdev: network interface device structure
@@ -1399,11 +1416,19 @@ int ice_set_vf_trust(struct net_device *netdev, int vf_id, bool trusted)
 
 	mutex_lock(&vf->cfg_lock);
 
-	while (!trusted && vf->num_mac_lldp)
-		ice_vf_update_mac_lldp_num(vf, ice_get_vf_vsi(vf), false);
-
+	/* Reset only if revoking trust and VF has advanced features configured */
+	if (!trusted &&
+	    (vf->num_mac_lldp > 0 ||
+	     test_bit(ICE_VF_STATE_UC_PROMISC, vf->vf_states) ||
+	     test_bit(ICE_VF_STATE_MC_PROMISC, vf->vf_states))) {
+		while (vf->num_mac_lldp)
+			ice_vf_update_mac_lldp_num(vf, ice_get_vf_vsi(vf), false);
+		vf->trusted = trusted;
+		ice_reset_vf(vf, ICE_VF_RESET_NOTIFY);
+	} else {
+		vf->trusted = trusted;
+		ice_setup_vf_trust(vf, trusted);
+	}
-	vf->trusted = trusted;
-	ice_reset_vf(vf, ICE_VF_RESET_NOTIFY);
 	dev_info(ice_pf_to_dev(pf), "VF %u is now %strusted\n",
 		 vf_id, trusted ? "" : "un");
 

--
2.43.0

Tested-by on v7 4/4
#12 lore raw

RE: [Intel-wired-lan] [PATCH net v7 4/4] ice: skip unnecessary VF reset when setting trust

drivers/net/ethernet/intel/ice/ice_sriov.c int ice_set_vf_mac(struct net_device *netdev, int

Quoted 48 lines

-----Original Message-----
From: Intel-wired-lan <[email protected]> On Behalf Of Jose Ignacio Tornos Martinez
Sent: Tuesday, June 23, 2026 12:18 PM
To: [email protected]
Cc: [email protected]; Kitszel, Przemyslaw <[email protected]>; Loktionov, Aleksandr <[email protected]>; Keller, Jacob E <[email protected]>; [email protected]; Nguyen, Anthony L <[email protected]>; [email protected]; [email protected]; [email protected]; [email protected]; Jose Ignacio Tornos Martinez <[email protected]>
Subject: [Intel-wired-lan] [PATCH net v7 4/4] ice: skip unnecessary VF reset when setting trust

Similar to the i40e fix, ice_set_vf_trust() unconditionally calls ice_reset_vf() when the trust setting changes. While the delay is smaller than i40e, this reset is still unnecessary in most cases.

When granting trust, no reset is needed - we can just set the capability flag to allow privileged operations.

When revoking trust, we only need to reset (conservative approach) if the VF has actually configured advanced features that require cleanup (MAC LLDP filters, promiscuous mode). For VFs in a clean state, we can safely change the trust setting without the disruptive reset.

When we do reset, we maintain the original ice pattern that has been reliable in
production: cleanup LLDP filters first, then set vf->trusted, then reset. This ensures the privilege capability bit is handled correctly during reset rebuild.

When we don't reset, we manually handle the capability flag via helper function, eliminating the delay.

---
v7: Rebase on current net tree (no code changes from v6)
v6: https://lore.kernel.org/all/[email protected]/

 drivers/net/ethernet/intel/ice/ice_sriov.c | 33 +++++++++++++++++++---
 1 file changed, 29 insertions(+), 4 deletions(-)
drivers/net/ethernet/intel/ice/ice_sriov.c +0 -0
index 7e00e091756d..XXXXXXXXXXXXXXXX 100644
@@ -1364,6 +1364,23 @@ int ice_set_vf_mac(struct net_device *netdev, int