Skip to content

Commit b99dd77

Browse files
lczapnikanguy11
authored andcommitted
i40e: improve VF MAC filters accounting
When adding new VM MAC, driver checks only *active* filters in vsi->mac_filter_hash. Each MAC, even in non-active state is using resources. To determine number of MACs VM uses, count VSI filters in *any* state. Add i40e_count_all_filters() to simply count all filters, and rename i40e_count_filters() to i40e_count_active_filters() to avoid ambiguity. Fixes: cfb1d57 ("i40e: Add ensurance of MacVlan resources for every trusted VF") Cc: [email protected] Signed-off-by: Lukasz Czapnik <[email protected]> Reviewed-by: Aleksandr Loktionov <[email protected]> Signed-off-by: Przemek Kitszel <[email protected]> Reviewed-by: Simon Horman <[email protected]> Tested-by: Rafal Romanowski <[email protected]> Signed-off-by: Tony Nguyen <[email protected]>
1 parent eac0442 commit b99dd77

File tree

3 files changed

+50
-44
lines changed

3 files changed

+50
-44
lines changed

drivers/net/ethernet/intel/i40e/i40e.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1278,7 +1278,8 @@ struct i40e_mac_filter *i40e_add_mac_filter(struct i40e_vsi *vsi,
12781278
const u8 *macaddr);
12791279
int i40e_del_mac_filter(struct i40e_vsi *vsi, const u8 *macaddr);
12801280
bool i40e_is_vsi_in_vlan(struct i40e_vsi *vsi);
1281-
int i40e_count_filters(struct i40e_vsi *vsi);
1281+
int i40e_count_all_filters(struct i40e_vsi *vsi);
1282+
int i40e_count_active_filters(struct i40e_vsi *vsi);
12821283
struct i40e_mac_filter *i40e_find_mac(struct i40e_vsi *vsi, const u8 *macaddr);
12831284
void i40e_vlan_stripping_enable(struct i40e_vsi *vsi);
12841285
static inline bool i40e_is_sw_dcb(struct i40e_pf *pf)

drivers/net/ethernet/intel/i40e/i40e_main.c

Lines changed: 22 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1243,12 +1243,30 @@ void i40e_update_stats(struct i40e_vsi *vsi)
12431243
}
12441244

12451245
/**
1246-
* i40e_count_filters - counts VSI mac filters
1246+
* i40e_count_all_filters - counts VSI MAC filters
12471247
* @vsi: the VSI to be searched
12481248
*
1249-
* Returns count of mac filters
1250-
**/
1251-
int i40e_count_filters(struct i40e_vsi *vsi)
1249+
* Return: count of MAC filters in any state.
1250+
*/
1251+
int i40e_count_all_filters(struct i40e_vsi *vsi)
1252+
{
1253+
struct i40e_mac_filter *f;
1254+
struct hlist_node *h;
1255+
int bkt, cnt = 0;
1256+
1257+
hash_for_each_safe(vsi->mac_filter_hash, bkt, h, f, hlist)
1258+
cnt++;
1259+
1260+
return cnt;
1261+
}
1262+
1263+
/**
1264+
* i40e_count_active_filters - counts VSI MAC filters
1265+
* @vsi: the VSI to be searched
1266+
*
1267+
* Return: count of active MAC filters.
1268+
*/
1269+
int i40e_count_active_filters(struct i40e_vsi *vsi)
12521270
{
12531271
struct i40e_mac_filter *f;
12541272
struct hlist_node *h;

drivers/net/ethernet/intel/i40e/i40e_virtchnl_pf.c

Lines changed: 26 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -2862,24 +2862,6 @@ static int i40e_vc_get_stats_msg(struct i40e_vf *vf, u8 *msg)
28622862
(u8 *)&stats, sizeof(stats));
28632863
}
28642864

2865-
/**
2866-
* i40e_can_vf_change_mac
2867-
* @vf: pointer to the VF info
2868-
*
2869-
* Return true if the VF is allowed to change its MAC filters, false otherwise
2870-
*/
2871-
static bool i40e_can_vf_change_mac(struct i40e_vf *vf)
2872-
{
2873-
/* If the VF MAC address has been set administratively (via the
2874-
* ndo_set_vf_mac command), then deny permission to the VF to
2875-
* add/delete unicast MAC addresses, unless the VF is trusted
2876-
*/
2877-
if (vf->pf_set_mac && !vf->trusted)
2878-
return false;
2879-
2880-
return true;
2881-
}
2882-
28832865
#define I40E_MAX_MACVLAN_PER_HW 3072
28842866
#define I40E_MAX_MACVLAN_PER_PF(num_ports) (I40E_MAX_MACVLAN_PER_HW / \
28852867
(num_ports))
@@ -2918,8 +2900,10 @@ static inline int i40e_check_vf_permission(struct i40e_vf *vf,
29182900
struct i40e_pf *pf = vf->pf;
29192901
struct i40e_vsi *vsi = pf->vsi[vf->lan_vsi_idx];
29202902
struct i40e_hw *hw = &pf->hw;
2921-
int mac2add_cnt = 0;
2922-
int i;
2903+
int i, mac_add_max, mac_add_cnt = 0;
2904+
bool vf_trusted;
2905+
2906+
vf_trusted = test_bit(I40E_VIRTCHNL_VF_CAP_PRIVILEGE, &vf->vf_caps);
29232907

29242908
for (i = 0; i < al->num_elements; i++) {
29252909
struct i40e_mac_filter *f;
@@ -2939,9 +2923,8 @@ static inline int i40e_check_vf_permission(struct i40e_vf *vf,
29392923
* The VF may request to set the MAC address filter already
29402924
* assigned to it so do not return an error in that case.
29412925
*/
2942-
if (!i40e_can_vf_change_mac(vf) &&
2943-
!is_multicast_ether_addr(addr) &&
2944-
!ether_addr_equal(addr, vf->default_lan_addr.addr)) {
2926+
if (!vf_trusted && !is_multicast_ether_addr(addr) &&
2927+
vf->pf_set_mac && !ether_addr_equal(addr, vf->default_lan_addr.addr)) {
29452928
dev_err(&pf->pdev->dev,
29462929
"VF attempting to override administratively set MAC address, bring down and up the VF interface to resume normal operation\n");
29472930
return -EPERM;
@@ -2950,29 +2933,33 @@ static inline int i40e_check_vf_permission(struct i40e_vf *vf,
29502933
/*count filters that really will be added*/
29512934
f = i40e_find_mac(vsi, addr);
29522935
if (!f)
2953-
++mac2add_cnt;
2936+
++mac_add_cnt;
29542937
}
29552938

29562939
/* If this VF is not privileged, then we can't add more than a limited
2957-
* number of addresses. Check to make sure that the additions do not
2958-
* push us over the limit.
2959-
*/
2960-
if (!test_bit(I40E_VIRTCHNL_VF_CAP_PRIVILEGE, &vf->vf_caps)) {
2961-
if ((i40e_count_filters(vsi) + mac2add_cnt) >
2962-
I40E_VC_MAX_MAC_ADDR_PER_VF) {
2963-
dev_err(&pf->pdev->dev,
2964-
"Cannot add more MAC addresses, VF is not trusted, switch the VF to trusted to add more functionality\n");
2965-
return -EPERM;
2966-
}
2967-
/* If this VF is trusted, it can use more resources than untrusted.
2940+
* number of addresses.
2941+
*
2942+
* If this VF is trusted, it can use more resources than untrusted.
29682943
* However to ensure that every trusted VF has appropriate number of
29692944
* resources, divide whole pool of resources per port and then across
29702945
* all VFs.
29712946
*/
2972-
} else {
2973-
if ((i40e_count_filters(vsi) + mac2add_cnt) >
2974-
I40E_VC_MAX_MACVLAN_PER_TRUSTED_VF(pf->num_alloc_vfs,
2975-
hw->num_ports)) {
2947+
if (!vf_trusted)
2948+
mac_add_max = I40E_VC_MAX_MAC_ADDR_PER_VF;
2949+
else
2950+
mac_add_max = I40E_VC_MAX_MACVLAN_PER_TRUSTED_VF(pf->num_alloc_vfs, hw->num_ports);
2951+
2952+
/* VF can replace all its filters in one step, in this case mac_add_max
2953+
* will be added as active and another mac_add_max will be in
2954+
* a to-be-removed state. Account for that.
2955+
*/
2956+
if ((i40e_count_active_filters(vsi) + mac_add_cnt) > mac_add_max ||
2957+
(i40e_count_all_filters(vsi) + mac_add_cnt) > 2 * mac_add_max) {
2958+
if (!vf_trusted) {
2959+
dev_err(&pf->pdev->dev,
2960+
"Cannot add more MAC addresses, VF is not trusted, switch the VF to trusted to add more functionality\n");
2961+
return -EPERM;
2962+
} else {
29762963
dev_err(&pf->pdev->dev,
29772964
"Cannot add more MAC addresses, trusted VF exhausted it's resources\n");
29782965
return -EPERM;

0 commit comments

Comments
 (0)