Skip to content

Commit 47ebc7b

Browse files
bcreeley13Jeff Kirsher
authored andcommitted
ice: Check if unicast MAC exists before setting VF MAC
Currently if a unicast MAC is set via ndo_set_vf_mac, the PF driver will set the VF's dflt_lan_addr.addr once some basic checks have passed. The VF is then reset. During reset the PF driver will attempt to program the VF's MAC from the dflt_lan_addr.addr field. This fails when the MAC already exists on the PF's switch. This is causing the VF to be completely disabled until removing/enabling any VFs via sysfs. Fix this by checking if the unicast MAC exists before triggering a VF reset directly in ndo_set_vf_mac. Also, add a check if the unicast MAC is set to the same value as before and return 0 if that is the case. Signed-off-by: Brett Creeley <[email protected]> Tested-by: Andrew Bowers <[email protected]> Signed-off-by: Jeff Kirsher <[email protected]>
1 parent 4dc926d commit 47ebc7b

File tree

1 file changed

+43
-0
lines changed

1 file changed

+43
-0
lines changed

drivers/net/ethernet/intel/ice/ice_virtchnl_pf.c

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3640,6 +3640,39 @@ ice_get_vf_cfg(struct net_device *netdev, int vf_id, struct ifla_vf_info *ivi)
36403640
return 0;
36413641
}
36423642

3643+
/**
3644+
* ice_unicast_mac_exists - check if the unicast MAC exists on the PF's switch
3645+
* @pf: PF used to reference the switch's rules
3646+
* @umac: unicast MAC to compare against existing switch rules
3647+
*
3648+
* Return true on the first/any match, else return false
3649+
*/
3650+
static bool ice_unicast_mac_exists(struct ice_pf *pf, u8 *umac)
3651+
{
3652+
struct ice_sw_recipe *mac_recipe_list =
3653+
&pf->hw.switch_info->recp_list[ICE_SW_LKUP_MAC];
3654+
struct ice_fltr_mgmt_list_entry *list_itr;
3655+
struct list_head *rule_head;
3656+
struct mutex *rule_lock; /* protect MAC filter list access */
3657+
3658+
rule_head = &mac_recipe_list->filt_rules;
3659+
rule_lock = &mac_recipe_list->filt_rule_lock;
3660+
3661+
mutex_lock(rule_lock);
3662+
list_for_each_entry(list_itr, rule_head, list_entry) {
3663+
u8 *existing_mac = &list_itr->fltr_info.l_data.mac.mac_addr[0];
3664+
3665+
if (ether_addr_equal(existing_mac, umac)) {
3666+
mutex_unlock(rule_lock);
3667+
return true;
3668+
}
3669+
}
3670+
3671+
mutex_unlock(rule_lock);
3672+
3673+
return false;
3674+
}
3675+
36433676
/**
36443677
* ice_set_vf_mac
36453678
* @netdev: network interface device structure
@@ -3663,10 +3696,20 @@ int ice_set_vf_mac(struct net_device *netdev, int vf_id, u8 *mac)
36633696
}
36643697

36653698
vf = &pf->vf[vf_id];
3699+
/* nothing left to do, unicast MAC already set */
3700+
if (ether_addr_equal(vf->dflt_lan_addr.addr, mac))
3701+
return 0;
3702+
36663703
ret = ice_check_vf_ready_for_cfg(vf);
36673704
if (ret)
36683705
return ret;
36693706

3707+
if (ice_unicast_mac_exists(pf, mac)) {
3708+
netdev_err(netdev, "Unicast MAC %pM already exists on this PF. Preventing setting VF %u unicast MAC address to %pM\n",
3709+
mac, vf_id, mac);
3710+
return -EINVAL;
3711+
}
3712+
36703713
/* copy MAC into dflt_lan_addr and trigger a VF reset. The reset
36713714
* flow will use the updated dflt_lan_addr and add a MAC filter
36723715
* using ice_add_mac. Also set pf_set_mac to indicate that the PF has

0 commit comments

Comments
 (0)