Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

iavf: remove current MAC address filter on VF reset

Currently MAC filters are not altered during a VF reset event. This may
lead to a stale filter when an administratively set MAC is forced by the
PF.

For an administratively set MAC the PF driver deletes the VFs filters,
overwrites the VFs MAC address and triggers a VF reset. However
the VF driver itself is not aware of the filter removal, which is what
the VF reset is for.
The VF reset queues all filters present in the VF driver to be re-added
to the PF filter list (including the filter for the now stale VF MAC
address) and triggers a VIRTCHNL_OP_GET_VF_RESOURCES event, which
provides the new MAC address to the VF.

When this happens i40e will complain and reject the stale MAC filter,
at least in the untrusted VF case.
i40e 0000:08:00.0: Setting MAC 3c:fa:fa:fa:fa:01 on VF 0
iavf 0000:08:02.0: Reset warning received from the PF
iavf 0000:08:02.0: Scheduling reset task
i40e 0000:08:00.0: Bring down and up the VF interface to make this change effective.
i40e 0000:08:00.0: VF attempting to override administratively set MAC address, bring down and up the VF interface to resume normal operation
i40e 0000:08:00.0: VF 0 failed opcode 10, retval: -1
iavf 0000:08:02.0: Failed to add MAC filter, error IAVF_ERR_NVM

To avoid re-adding the stale MAC filter it needs to be removed from the
VF driver's filter list before queuing the existing filters. Then during
the VIRTCHNL_OP_GET_VF_RESOURCES event the correct filter needs to be
added again, at which point the MAC address has been updated.

As a bonus this change makes bringing the VF down and up again
superfluous for the administratively set MAC case.

Signed-off-by: Stefan Assmann <sassmann@kpanic.de>
Tested-by: Andrew Bowers <andrewx.bowers@intel.com>
Signed-off-by: Jeff Kirsher <jeffrey.t.kirsher@intel.com>

authored by

Stefan Assmann and committed by
Jeff Kirsher
9e052291 5365ec1a

+18 -4
+2
drivers/net/ethernet/intel/iavf/iavf.h
··· 415 415 void iavf_disable_channels(struct iavf_adapter *adapter); 416 416 void iavf_add_cloud_filter(struct iavf_adapter *adapter); 417 417 void iavf_del_cloud_filter(struct iavf_adapter *adapter); 418 + struct iavf_mac_filter *iavf_add_filter(struct iavf_adapter *adapter, 419 + const u8 *macaddr); 418 420 #endif /* _IAVF_H_ */
+13 -4
drivers/net/ethernet/intel/iavf/iavf_main.c
··· 743 743 * 744 744 * Returns ptr to the filter object or NULL when no memory available. 745 745 **/ 746 - static struct 747 - iavf_mac_filter *iavf_add_filter(struct iavf_adapter *adapter, 748 - const u8 *macaddr) 746 + struct iavf_mac_filter *iavf_add_filter(struct iavf_adapter *adapter, 747 + const u8 *macaddr) 749 748 { 750 749 struct iavf_mac_filter *f; 751 750 ··· 2064 2065 struct virtchnl_vf_resource *vfres = adapter->vf_res; 2065 2066 struct net_device *netdev = adapter->netdev; 2066 2067 struct iavf_hw *hw = &adapter->hw; 2068 + struct iavf_mac_filter *f, *ftmp; 2067 2069 struct iavf_vlan_filter *vlf; 2068 2070 struct iavf_cloud_filter *cf; 2069 - struct iavf_mac_filter *f; 2070 2071 u32 reg_val; 2071 2072 int i = 0, err; 2072 2073 bool running; ··· 2180 2181 2181 2182 spin_lock_bh(&adapter->mac_vlan_list_lock); 2182 2183 2184 + /* Delete filter for the current MAC address, it could have 2185 + * been changed by the PF via administratively set MAC. 2186 + * Will be re-added via VIRTCHNL_OP_GET_VF_RESOURCES. 2187 + */ 2188 + list_for_each_entry_safe(f, ftmp, &adapter->mac_filter_list, list) { 2189 + if (ether_addr_equal(f->macaddr, adapter->hw.mac.addr)) { 2190 + list_del(&f->list); 2191 + kfree(f); 2192 + } 2193 + } 2183 2194 /* re-add all MAC filters */ 2184 2195 list_for_each_entry(f, &adapter->mac_filter_list, list) { 2185 2196 f->add = true;
+3
drivers/net/ethernet/intel/iavf/iavf_virtchnl.c
··· 1359 1359 ether_addr_copy(netdev->perm_addr, 1360 1360 adapter->hw.mac.addr); 1361 1361 } 1362 + spin_lock_bh(&adapter->mac_vlan_list_lock); 1363 + iavf_add_filter(adapter, adapter->hw.mac.addr); 1364 + spin_unlock_bh(&adapter->mac_vlan_list_lock); 1362 1365 iavf_process_config(adapter); 1363 1366 } 1364 1367 break;