Skip to contentSkip to conversation

i40e: Add VF VLAN pruning

PATCH Superseded Mateusz Palczewski 1 participant 1 message Sep 2, 2021

Subsystems (2)

v2 of 3 Superseded Latest is v3 →

lore
Share & tools
lore
#0 lore raw

PATCH v2 1/1 i40e: Add VF VLAN pruning

From: Sylwester Dziedziuch <[email protected]>

VFs were able to see all tagged traffic regardless of trust and VLAN filters configured. Change the default VLAN filters settings for an untrusted VF so it is able to receive only untagged traffic or traffic with VLAN tags it has created interfaces for.

Add new private flag vf-vlan-prune-disable that allows disabling
of VF vlan pruning for all VF types. The flag is off by default
and can only be changed if there are no VFs spawned on the PF.
This flag will only be effective when no PVID is set on VF and VF is not trusted. Add new function that computes the correct VLAN ID for VF VLAN filters based on trust, PVID, vf-vlan-prune-disable flag and current VLAN ID.

Testing hits:
scenario 1: spawn 1 VF
bring VF up
turn on packet capturing on a VF
send untagged packet to VF
VF should receive untagged packet
send tagged packet to VF
VF should not see the tagged packet
scenario 2: set vf-vlan-prune-disable flag to off
spawn 1 VF
turn on packet capturing on a VF
send untagged packet to VF
VF should receive untagged packet
send tagged packet to VF
VF should receive tagged packet

---
v2: Fixed commit message

---
 drivers/net/ethernet/intel/i40e/i40e.h        |   1 +
 .../net/ethernet/intel/i40e/i40e_ethtool.c    |   9 ++
 drivers/net/ethernet/intel/i40e/i40e_main.c   | 138 +++++++++++++++++-
 .../ethernet/intel/i40e/i40e_virtchnl_pf.c    |  12 +-
 4 files changed, 151 insertions(+), 9 deletions(-)
drivers/net/ethernet/intel/i40e/i40e.h +1 -0
index b10bc59..5fda78b 100644
@@ -565,6 +565,7 @@ struct i40e_pf {
 #define I40E_FLAG_DISABLE_FW_LLDP		BIT(24)
 #define I40E_FLAG_RS_FEC			BIT(25)
 #define I40E_FLAG_BASE_R_FEC			BIT(26)
+#define I40E_FLAG_VF_VLAN_PRUNE_DISABLE		BIT(27)
 /* TOTAL_PORT_SHUTDOWN
  * Allows to physically disable the link on the NIC's port.
  * If enabled, (after link down request from the OS)
drivers/net/ethernet/intel/i40e/i40e_ethtool.c +9 -0
index 2c9e4ee..d47832b 100644
@@ -451,6 +451,8 @@ static const struct i40e_priv_flags i40e_gstrings_priv_flags[] = {
 	I40E_PRIV_FLAG("disable-fw-lldp", I40E_FLAG_DISABLE_FW_LLDP, 0),
 	I40E_PRIV_FLAG("rs-fec", I40E_FLAG_RS_FEC, 0),
 	I40E_PRIV_FLAG("base-r-fec", I40E_FLAG_BASE_R_FEC, 0),
+	I40E_PRIV_FLAG("vf-vlan-prune-disable",
+		       I40E_FLAG_VF_VLAN_PRUNE_DISABLE, 0),
 };
 
 #define I40E_PRIV_FLAGS_STR_LEN ARRAY_SIZE(i40e_gstrings_priv_flags)
@@ -5273,6 +5275,13 @@ flags_complete:
 		dev_warn(&pf->pdev->dev,
 			 "Turning on link-down-on-close flag may affect other partitions\n");
 
+	if ((changed_flags & I40E_FLAG_VF_VLAN_PRUNE_DISABLE) &&
+	    pf->num_alloc_vfs) {
+		dev_warn(&pf->pdev->dev,
+			 "Changing vf-vlan-prune-disable flag while VF(s) are active is not supported");
+		return -EOPNOTSUPP;
+	}
+
 	if (changed_flags & I40E_FLAG_DISABLE_FW_LLDP) {
 		if (new_flags & I40E_FLAG_DISABLE_FW_LLDP) {
 #ifdef CONFIG_I40E_DCB
drivers/net/ethernet/intel/i40e/i40e_main.c +132 -6

163 lines not on this page · raw message

drivers/net/ethernet/intel/i40e/i40e_virtchnl_pf.c +9 -3
index c007fba..23a708f 100644
@@ -4295,6 +4295,7 @@ int i40e_ndo_set_vf_port_vlan(struct net_device *netdev, int vf_id,
 		/* duplicate request, so just return success */
 		goto error_pvid;
 
+	i40e_vlan_stripping_enable(vsi);
 	i40e_vc_reset_vf(vf, true);
 	/* During reset the VF got a new VSI, so refresh a pointer. */
 	vsi = pf->vsi[vf->lan_vsi_idx];
@@ -4310,9 +4311,9 @@ int i40e_ndo_set_vf_port_vlan(struct net_device *netdev, int vf_id,
 	 * MAC addresses deleted.
 	 */
 	if ((!(vlan_id || qos) ||
-	    vlanprio != le16_to_cpu(vsi->info.pvid)) &&
+	     vlanprio != le16_to_cpu(vsi->info.pvid)) &&
 	    vsi->info.pvid) {
-		ret = i40e_add_vlan_all_mac(vsi, I40E_VLAN_ANY);
+		ret = i40e_add_vlan_all_mac(vsi, 0);
 		if (ret) {
 			dev_info(&vsi->back->pdev->dev,
 				 "add VF VLAN failed, ret=%d aq_err=%d\n", ret,
@@ -4359,7 +4360,7 @@ int i40e_ndo_set_vf_port_vlan(struct net_device *netdev, int vf_id,
 		}
 
 		/* remove the previously added non-VLAN MAC filters */
-		i40e_rm_vlan_all_mac(vsi, I40E_VLAN_ANY);
+		i40e_rm_vlan_all_mac(vsi, 0);
 	}
 
 	spin_unlock_bh(&vsi->mac_filter_hash_lock);
@@ -4673,6 +4674,11 @@ int i40e_ndo_set_vf_trust(struct net_device *netdev, int vf_id, bool setting)
 		goto out;
 
 	vf->trusted = setting;
+
+	/* request PF to sync mac/vlan filters for the VF */
+	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);
 	dev_info(&pf->pdev->dev, "VF %u is now %strusted\n",
 		 vf_id, setting ? "" : "un");
Signature · 1 line
2.27.0