i40e: Add VF VLAN pruning
Subsystems (2)
PATCH 1/1 i40e: Add VF VLAN pruning
From: Sylwester Dziedziuch <[email protected]>
VFs by default are able to see all tagged traffic regardless of trust and VLAN filters configured.
Add new private flag vf-vlan-pruning that allows changing of default VF behavior for tagged traffic. When the flag is turned on untrusted VF will only be able to receive untagged traffic or traffic with VLAN tags it has created interfaces for
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 Hints:
Test 1: vf-vlan-pruning == off
==============================
1. Set the private flag
Quoted 1 line
ethtool --set-priv-flag eth0 vf-vlan-pruning off (default setting)
2. Use scapy to send any VLAN tagged traffic and make sure the VF receives all VLAN tagged traffic that matches its destination MAC filters (unicast, multicast, and broadcast).
Test 2: vf-vlan-pruning == on
==============================
1. Set the private flag
Quoted 1 line
ethtool --set-priv-flag eth0 vf-vlan-pruning on
2. Use scapy to send any VLAN tagged traffic and make sure the VF does not receive any VLAN tagged traffic that matches its destination MAC filters (unicast, multicast, and broadcast).
3. Add a VLAN filter on the VF netdev
Quoted 1 line
ip link add link eth0v0 name vlan10 type vlan id 10
4. Bring the VLAN netdev up
Quoted 1 line
ip link set vlan10 up
4. Use scapy to send traffic with VLAN 10, VLAN 11 (anything not VLAN 10), and untagged traffic. Make sure the VF only receives VLAN 10 and untagged traffic when the link partner is sending.
Test 3: vf-vlan-pruning == off && VF is in a port VLAN
==============================
1. Set the private flag
Quoted 1 line
ethtool --set-priv-flag eth0 vf-vlan-pruning off (default setting)
2. Create a VF
Quoted 1 line
echo 1 >
sriov_numvfs
3. Put the VF in a port VLAN
Quoted 1 line
ip link set eth0 vf 0 vlan 10
4. Use scapy to send traffic with VLAN 10 and VLAN 11 (anything not VLAN
10) and make sure the VF only receives untagged traffic when the link partner is sending VLAN 10 tagged traffic as the VLAN tag is expected to be stripped by HW for port VLANs and not visible to the VF.
Test 4: Change vf-vlan-pruning while VFs are created
==============================
echo 0 > sriov_numvfs
ethtool --set-priv-flag eth0 vf-vlan-pruning off
echo 1 > sriov_numvfs
ethtool --set-priv-flag eth0 vf-vlan-pruning on (expect failure)
--- drivers/net/ethernet/intel/i40e/i40e.h | 1 + .../net/ethernet/intel/i40e/i40e_ethtool.c | 10 ++ drivers/net/ethernet/intel/i40e/i40e_main.c | 136 +++++++++++++++++- .../ethernet/intel/i40e/i40e_virtchnl_pf.c | 8 +- 4 files changed, 149 insertions(+), 6 deletions(-)
drivers/net/ethernet/intel/i40e/i40e.h +1 -0
@@ -564,6 +564,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_PRUNING 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 +10 -0
@@ -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-pruning" , + I40E_FLAG_VF_VLAN_PRUNING, 0), };#define I40E_PRIV_FLAGS_STR_LEN ARRAY_SIZE(i40e_gstrings_priv_flags)
@@ -5275,6 +5277,14 @@ flags_complete:return -EOPNOTSUPP ; } +if ((changed_flags &I40E_FLAG_VF_VLAN_PRUNING ) && + pf->num_alloc_vfs) { +dev_warn (&pf->pdev->dev, +"Changing vf-vlan-pruning flag while VF(s) are active is not supported\n" ); +return -EOPNOTSUPP ; + } + +if ((changed_flags & new_flags &I40E_FLAG_LINK_DOWN_ON_CLOSE_ENABLED ) && (new_flags &I40E_FLAG_MFP_ENABLED ))
drivers/net/ethernet/intel/i40e/i40e_main.c +131 -5
155 lines not on this page · raw message
drivers/net/ethernet/intel/i40e/i40e_virtchnl_pf.c +7 -1
@@ -4354,6 +4354,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];
@@ -4369,7 +4370,7 @@ 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 );if (ret) {
@@ -4732,6 +4733,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
Nguyen
PATCH 1/1 i40e: Add VF VLAN pruning
Quoted 64 lines · Mateusz Palczewski
From: Sylwester Dziedziuch <[email protected]>
VFs by default are able to see all tagged traffic regardless of trust and VLAN filters configured.
Add new private flag vf-vlan-pruning that allows changing of default VF behavior for tagged traffic. When the flag is turned on untrusted VF will only be able to receive untagged traffic or traffic with VLAN tags it has created interfaces for
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 Hints:
Test 1: vf-vlan-pruning == off
==============================
1. Set the private flagQuoted 1 line
ethtool --set-priv-flag eth0 vf-vlan-pruning off (default setting)
2. Use scapy to send any VLAN tagged traffic and make sure the VF receives all VLAN tagged traffic that matches its destination MAC filters (unicast, multicast, and broadcast).
Test 2: vf-vlan-pruning == on
==============================
1. Set the private flagQuoted 1 line
ethtool --set-priv-flag eth0 vf-vlan-pruning on
2. Use scapy to send any VLAN tagged traffic and make sure the VF does
not receive any VLAN tagged traffic that matches its destination MAC filters (unicast, multicast, and broadcast).
3. Add a VLAN filter on the VF netdevQuoted 1 line
ip link add link eth0v0 name vlan10 type vlan id 10
4. Bring the VLAN netdev up
Quoted 1 line
ip link set vlan10 up
4. Use scapy to send traffic with VLAN 10, VLAN 11 (anything not VLAN 10), and untagged traffic. Make sure the VF only receives VLAN 10 and untagged traffic when the link partner is sending.
Test 3: vf-vlan-pruning == off && VF is in a port VLAN
==============================
1. Set the private flagQuoted 1 line
ethtool --set-priv-flag eth0 vf-vlan-pruning off (default setting)
2. Create a VF
Quoted 1 line
echo 1 >
sriov_numvfs3. Put the VF in a port VLAN
Quoted 1 line
ip link set eth0 vf 0 vlan 10
4. Use scapy to send traffic with VLAN 10 and VLAN 11 (anything not VLAN
10) and make sure the VF only receives untagged traffic when the link partner is sending VLAN 10 tagged traffic as the VLAN tag is expected to be stripped by HW for port VLANs and not visible to the VF.Test 4: Change vf-vlan-pruning while VFs are created
==============================
echo 0 >sriov_numvfs
ethtool --set-priv-flag eth0 vf-vlan-pruning off
echo 1 >sriov_numvfs
ethtool --set-priv-flag eth0 vf-vlan-pruning on (expect failure)
Quoted 4 lines
Signed-off-by Sylwester Dziedziuch <[email protected]>Signed-off-by Przemyslaw PatynowskiSigned-off-by Mateusz Palczewski <[email protected]>
This has checkpatch issues, please fix.
CHECK: Alignment should match open parenthesis
#108: FILE: drivers/net/ethernet/intel/i40e/i40e_ethtool.c:5283:
+ dev_warn(&pf->pdev->dev,
+ "Changing vf-vlan-pruning flag while VF(s) are
active is not supported\n");
CHECK: Please don't use multiple blank lines
#112: FILE: drivers/net/ethernet/intel/i40e/i40e_ethtool.c:5287:
+
+