Skip to contentSkip to conversation

iavf: cleanup procedure for changing interface's MAC address

PATCH Superseded Piotr Gardocki 1 participant 3 messages May 17, 2023

Subsystems (2)

v3 of 4 Superseded Latest is v4 →

lore
Share & tools
lore
#0 lore raw

v3 cover iavf: cleanup procedure for changing interface's MAC address

This patchset cleanups .ndo_set_mac_address callback in iavf.

The second patch addresses potential issue with iavf_add_filter function failing to add a new MAC filter to the list. However, it does make an assumption that the new MAC address is different than the current one. The first patch protects from this issue by skipping the entire procedure if the MAC address doesn't actually change.

Without these two patches iavf is sending two AdminQ commands to PF driver:
VIRTCHNL_OP_ADD_ETH_ADDR to add new MAC filter and VIRTCHNL_OP_DEL_ETH_ADDR to remove the old one. Even though it does not seem to cause issues, it is very error prone. Skipping these callbacks is more reliable.

v2: added missing Signed-off-by and comma in second patch
v3: fixed malformed second patch

Piotr Gardocki (1):
iavf: add check for current MAC address in set_mac callback

Przemek Kitszel (1):
iavf: fix err handling for MAC replace

 drivers/net/ethernet/intel/iavf/iavf_main.c | 48 +++++++++++----------
 1 file changed, 25 insertions(+), 23 deletions(-)
Signature · 6 lines
2.34.1

_______________________________________________
Intel-wired-lan mailing list
[email protected]
https://lists.osuosl.org/mailman/listinfo/intel-wired-lan
#1 lore raw

PATCH v3 1/2 iavf: add check for current MAC address in set_mac callback

In some cases it is possible for kernel to come with request to change primary MAC address to the address that is actually already set on the given interface.

If the old and new MAC addresses are equal there is no need for going through entire routine, including AdminQ and waitqueue.

This patch adds proper check to return fast from the function in these cases. The same check can also be found in i40e and ice drivers.

An example of such case is adding an interface to bonding channel in balance-alb mode:
modprobe bonding mode=balance-alb miimon=100 max_bonds=1 ip link set bond0 up
ifenslave bond0 <eth>

---
 drivers/net/ethernet/intel/iavf/iavf_main.c | 6 ++++++
 1 file changed, 6 insertions(+)
drivers/net/ethernet/intel/iavf/iavf_main.c +6 -0
index e18d7cacf99c..888d063478a1 100644
@@ -1085,6 +1085,12 @@ static int iavf_set_mac(struct net_device *netdev, void *p)
 	if (!is_valid_ether_addr(addr->sa_data))
 		return -EADDRNOTAVAIL;
 
+	if (ether_addr_equal(netdev->dev_addr, addr->sa_data)) {
+		netdev_dbg(netdev, "already using mac address %pM\n",
+			   addr->sa_data);
+		return 0;
+	}
+
 	ret = iavf_replace_primary_mac(adapter, addr->sa_data);
 
 	if (ret)
Signature · 6 lines
2.34.1

_______________________________________________
Intel-wired-lan mailing list
[email protected]
https://lists.osuosl.org/mailman/listinfo/intel-wired-lan
#2 lore raw

PATCH v3 2/2 iavf: fix err handling for MAC replace

In reply to Piotr Gardocki

From: Przemek Kitszel <[email protected]>

Defer removal of current primary MAC until a replacement is successfully added. Previous implementation would left filter list with no primary MAC. This was found while reading the code.

The patch takes advantage of the fact that there can only be a single primary MAC filter at any time.

---
 drivers/net/ethernet/intel/iavf/iavf_main.c | 42 ++++++++++-----------
 1 file changed, 19 insertions(+), 23 deletions(-)
drivers/net/ethernet/intel/iavf/iavf_main.c +19 -23
index 888d063478a1..68aa680f7fec 100644
@@ -1007,40 +1007,36 @@ int iavf_replace_primary_mac(struct iavf_adapter *adapter,
 			     const u8 *new_mac)
 {
 	struct iavf_hw *hw = &adapter->hw;
-	struct iavf_mac_filter *f;
+	struct iavf_mac_filter *new_f;
+	struct iavf_mac_filter *old_f;
 
 	spin_lock_bh(&adapter->mac_vlan_list_lock);
 
-	list_for_each_entry(f, &adapter->mac_filter_list, list) {
-		f->is_primary = false;
+	new_f = iavf_add_filter(adapter, new_mac);
+	if (!new_f) {
+		spin_unlock_bh(&adapter->mac_vlan_list_lock);
+		return -ENOMEM;
 	}
 
-	f = iavf_find_filter(adapter, hw->mac.addr);
-	if (f) {
-		f->remove = true;
+	old_f = iavf_find_filter(adapter, hw->mac.addr);
+	if (old_f) {
+		old_f->is_primary = false;
+		old_f->remove = true;
 		adapter->aq_required |= IAVF_FLAG_AQ_DEL_MAC_FILTER;
 	}
-
-	f = iavf_add_filter(adapter, new_mac);
-
-	if (f) {
-		/* Always send the request to add if changing primary MAC
-		 * even if filter is already present on the list
-		 */
-		f->is_primary = true;
-		f->add = true;
-		adapter->aq_required |= IAVF_FLAG_AQ_ADD_MAC_FILTER;
-		ether_addr_copy(hw->mac.addr, new_mac);
-	}
+	/* Always send the request to add if changing primary MAC,
+	 * even if filter is already present on the list
+	 */
+	new_f->is_primary = true;
+	new_f->add = true;
+	adapter->aq_required |= IAVF_FLAG_AQ_ADD_MAC_FILTER;
+	ether_addr_copy(hw->mac.addr, new_mac);
 
 	spin_unlock_bh(&adapter->mac_vlan_list_lock);
 
 	/* schedule the watchdog task to immediately process the request */
-	if (f) {
-		mod_delayed_work(adapter->wq, &adapter->watchdog_task, 0);
-		return 0;
-	}
-	return -ENOMEM;
+	mod_delayed_work(adapter->wq, &adapter->watchdog_task, 0);
+	return 0;
 }
 
 /**
Signature · 6 lines
2.34.1

_______________________________________________
Intel-wired-lan mailing list
[email protected]
https://lists.osuosl.org/mailman/listinfo/intel-wired-lan