cxgb4: add mirror action support for TC-MATCHALL
Subsystems (3)
cover cxgb4: add mirror action support for TC-MATCHALL
This series of patches add support to mirror all ingress traffic for TC-MATCHALL ingress offload.
Patch 1 adds support to dynamically create a mirror Virtual Interface (VI) that accepts all mirror ingress traffic when mirror action is set in TC-MATCHALL offload.
Patch 2 adds support to allocate mirror Rxqs and setup RSS for the mirror VI.
Patch 3 adds support to replicate all the main VI configuration to mirror VI. This includes replicating MTU, promiscuous mode, all-multicast mode, and enabled netdev Rx feature offloads.
Thanks,
Rahul
Rahul Lakkireddy (3):
cxgb4: add mirror action to TC-MATCHALL offload
cxgb4: add support for mirror Rxqs
cxgb4: add main VI to mirror VI config replication
drivers/net/ethernet/chelsio/cxgb4/cxgb4.h | 21 + .../ethernet/chelsio/cxgb4/cxgb4_debugfs.c | 69 ++- .../net/ethernet/chelsio/cxgb4/cxgb4_main.c | 487 ++++++++++++++++-- .../ethernet/chelsio/cxgb4/cxgb4_tc_flower.c | 16 +- .../ethernet/chelsio/cxgb4/cxgb4_tc_flower.h | 3 +- .../chelsio/cxgb4/cxgb4_tc_matchall.c | 57 +- .../chelsio/cxgb4/cxgb4_tc_matchall.h | 1 + drivers/net/ethernet/chelsio/cxgb4/t4_hw.c | 16 + 8 files changed, 626 insertions(+), 44 deletions(-)
Signature · 1 line
2.24.0
PATCH 1/3 cxgb4: add mirror action to TC-MATCHALL offload
Add mirror Virtual Interface (VI) support to receive all ingress mirror traffic from the underlying device. The mirror VI is created dynamically, if the TC-MATCHALL rule has a corresponding mirror action. Also request MSI-X vectors needed for the mirror VI Rxqs. If no vectors are available, then disable mirror VI support.
--- drivers/net/ethernet/chelsio/cxgb4/cxgb4.h | 10 ++ .../net/ethernet/chelsio/cxgb4/cxgb4_main.c | 94 ++++++++++++++++++- .../ethernet/chelsio/cxgb4/cxgb4_tc_flower.c | 16 +++- .../ethernet/chelsio/cxgb4/cxgb4_tc_flower.h | 3 +- .../chelsio/cxgb4/cxgb4_tc_matchall.c | 57 ++++++++++- .../chelsio/cxgb4/cxgb4_tc_matchall.h | 1 + drivers/net/ethernet/chelsio/cxgb4/t4_hw.c | 16 ++++ 7 files changed, 187 insertions(+), 10 deletions(-)
drivers/net/ethernet/chelsio/cxgb4/cxgb4.h +10 -0
@@ -679,6 +679,11 @@ struct port_info {u8 rx_cchan;bool tc_block_shared; + +/* Mirror VI information */ +u16 viid_mirror; +refcount_t vi_mirror_refcnt; +u16 nmirrorqsets; };struct dentry ;
@@ -960,6 +965,7 @@ struct sge {u16 ofldqsets;/* # of active ofld queue sets */ u16 nqs_per_uld;/* # of Rx queues per ULD */ u16 eoqsets;/* # of ETHOFLD queues */ +u16 mirrorqsets;/* # of Mirror queues */ u16 timer_val[SGE_NTIMERS ];u8 counter_val[SGE_NCOUNTERS ];
@@ -1857,6 +1863,8 @@ int t4_init_rss_mode(struct adapter *adap, int mbox);int t4_init_portinfo (struct port_info *pi,int mbox,int port,int pf,int vf,u8 mac[]);int t4_port_init (struct adapter *adap,int mbox,int pf,int vf); +int t4_init_port_mirror (struct port_info *pi,u8 mbox,u8 port,u8 pf,u8 vf, +u16 *mirror_viid);void t4_fatal_err (struct adapter *adapter);unsigned int t4_chip_rss_size (struct adapter *adapter); int t4_config_rss_range(struct adapter *adapter, int mbox, unsigned int viid,
@@ -2141,6 +2149,8 @@ int cxgb_open(struct net_device *dev);int cxgb_close (struct net_device *dev);void cxgb4_enable_rx (struct adapter *adap,struct sge_rspq *q);void cxgb4_quiesce_rx (struct sge_rspq *q); +int cxgb4_port_mirror_alloc (struct net_device *dev); +void cxgb4_port_mirror_free (struct net_device *dev);#ifdef CONFIG_CHELSIO_TLS_DEVICE int cxgb4_set_ktls_feature (struct adapter *adap,bool enable);#endif
drivers/net/ethernet/chelsio/cxgb4/cxgb4_main.c +90 -4
156 lines not on this page · raw message
drivers/net/ethernet/chelsio/cxgb4/cxgb4_tc_flower.c +13 -3
@@ -382,6 +382,7 @@ void cxgb4_process_flow_actions(struct net_device *in,case FLOW_ACTION_DROP : fs->action =FILTER_DROP ;break ; +case FLOW_ACTION_MIRRED :case FLOW_ACTION_REDIRECT : {struct net_device *out = act->dev;struct port_info *pi =netdev_priv (out);
@@ -539,7 +540,8 @@ static bool valid_pedit_action(struct net_device *dev,int cxgb4_validate_flow_actions (struct net_device *dev,struct flow_action *actions, -struct netlink_ext_ack *extack) +struct netlink_ext_ack *extack, +u8 matchall_filter) {struct flow_action_entry *act;bool act_redir = false;
@@ -556,11 +558,19 @@ int cxgb4_validate_flow_actions(struct net_device *dev,case FLOW_ACTION_DROP :/* Do nothing */ break ; +case FLOW_ACTION_MIRRED :case FLOW_ACTION_REDIRECT : {struct adapter *adap =netdev2adap (dev);struct net_device *n_dev, *target_dev; -unsigned int i;bool found = false; +unsigned int i; + +if (act->id ==FLOW_ACTION_MIRRED && + !matchall_filter) { +NL_SET_ERR_MSG_MOD (extack, +"Egress mirror action is only supported for tc-matchall" ); +return -EOPNOTSUPP ; + } target_dev = act->dev;for_each_port (adap, i) {
@@ -699,7 +709,7 @@ int cxgb4_flow_rule_replace(struct net_device *dev, struct flow_rule *rule,u8 inet_family;int fidx, ret; -if (cxgb4_validate_flow_actions (dev, &rule->action, extack)) +if (cxgb4_validate_flow_actions (dev, &rule->action, extack,0 ))return -EOPNOTSUPP ;if (cxgb4_validate_flow_match (dev, rule))
drivers/net/ethernet/chelsio/cxgb4/cxgb4_tc_flower.h +2 -1
@@ -113,7 +113,8 @@ void cxgb4_process_flow_actions(struct net_device *in, struct ch_filter_specification *fs);int cxgb4_validate_flow_actions (struct net_device *dev,struct flow_action *actions, -struct netlink_ext_ack *extack); +struct netlink_ext_ack *extack, +u8 matchall_filter);int cxgb4_tc_flower_replace (struct net_device *dev,struct flow_cls_offload *cls);
drivers/net/ethernet/chelsio/cxgb4/cxgb4_tc_matchall.c +55 -2
91 lines not on this page · raw message
drivers/net/ethernet/chelsio/cxgb4/cxgb4_tc_matchall.h +1 -0
@@ -21,6 +21,7 @@ struct cxgb4_matchall_ingress_entry {enum cxgb4_matchall_state state;/* Current MATCHALL offload state */ u32 tid;/* Index to hardware filter entry */ struct ch_filter_specification fs;/* Filter entry */ +u16 viid_mirror;/* Identifier for allocated Mirror VI */ u64 bytes;/* # of bytes hitting the filter */ u64 packets;/* # of packets hitting the filter */ u64 last_used;/* Last updated jiffies time */
drivers/net/ethernet/chelsio/cxgb4/t4_hw.c +16 -0
@@ -9712,6 +9712,22 @@ int t4_port_init(struct adapter *adap, int mbox, int pf, int vf)return 0 ; } +int t4_init_port_mirror (struct port_info *pi,u8 mbox,u8 port,u8 pf,u8 vf, +u16 *mirror_viid) +{ +int ret; + + ret =t4_alloc_vi (pi->adapter, mbox, port, pf, vf,1 ,NULL ,NULL , +NULL ,NULL ); +if (ret <0 ) +return ret; + +if (mirror_viid) + *mirror_viid = ret; + +return 0 ; +} +/** * t4_read_cimq_cfg - read CIM queue configuration * @adap: the adapter
Signature · 1 line
2.24.0
Jakub Kicinski
maintainerRe: [PATCH net-next 1/3] cxgb4: add mirror action to TC-MATCHALL offload
drivers/net/ethernet/chelsio/cxgb4/cxgb4_main.c static int setup_debugfs(struct adapter *adap) · line 1322
Quoted 4 lines · On Thu, 25 Jun 2020 17:28:41 +0530 Rahul Lakkireddy wrote:
drivers/net/ethernet/chelsio/cxgb4/cxgb4_main.c +4
-0+if (refcount_read (&pi->vi_mirror_refcnt) >1 ) { +refcount_dec (&pi->vi_mirror_refcnt); +return ; + }
FWIW this looks very dodgy. If you know nothing changes the count between the read and the dec here, you probably don't need atomic refcounts at all..
Re: [PATCH net-next 1/3] cxgb4: add mirror action to TC-MATCHALL offload
Quoted 9 lines · Jakub Kicinski
drivers/net/ethernet/chelsio/cxgb4/cxgb4_main.c static int setup_debugfs(struct adapter *adap) · line 1322
Quoted 4 lines · On Thu, 25 Jun 2020 17:28:41 +0530 Rahul Lakkireddy wrote:
drivers/net/ethernet/chelsio/cxgb4/cxgb4_main.c +4
-0+if (refcount_read (&pi->vi_mirror_refcnt) >1 ) { +refcount_dec (&pi->vi_mirror_refcnt); +return ; + }FWIW this looks very dodgy. If you know nothing changes the count between the read and the dec here, you probably don't need atomic refcounts at all..
Currently, all the callers accessing this refcount and its related data is having the RTNL lock held by the stack. Perhaps this is a false sense of security, especially if the stack API may change in the future.
I'll add a proper lock to protect this data in v2 to be on the safer side.
Thanks,
Rahul
PATCH 2/3 cxgb4: add support for mirror Rxqs
In reply to Rahul LakkireddyWhen mirror VI is enabled, allocate the mirror Rxqs and setup the mirror VI RSS table. The mirror Rxqs are allocated/freed when the mirror VI is created/destroyed or when underlying port is brought up/down, respectively.
--- drivers/net/ethernet/chelsio/cxgb4/cxgb4.h | 11 + .../ethernet/chelsio/cxgb4/cxgb4_debugfs.c | 69 ++++- .../net/ethernet/chelsio/cxgb4/cxgb4_main.c | 238 ++++++++++++++++-- 3 files changed, 296 insertions(+), 22 deletions(-)
drivers/net/ethernet/chelsio/cxgb4/cxgb4.h +11 -0
@@ -710,6 +710,13 @@ enum { ULP_CRYPTO_KTLS_INLINE = 1 << 3, }; +#define CXGB4_MIRROR_RXQ_DEFAULT_DESC_NUM 1024 +#define CXGB4_MIRROR_RXQ_DEFAULT_DESC_SIZE 64 +#define CXGB4_MIRROR_RXQ_DEFAULT_INTR_USEC 5 +#define CXGB4_MIRROR_RXQ_DEFAULT_PKT_CNT 8 + +#define CXGB4_MIRROR_FLQ_DEFAULT_DESC_NUM 72 +struct rx_sw_desc ;struct sge_fl {/* SGE free-buffer queue state */
@@ -959,6 +966,8 @@ struct sge {struct sge_eohw_txq *eohw_txq;struct sge_ofld_rxq *eohw_rxq; +struct sge_eth_rxq *mirror_rxq[NCHAN ]; +u16 max_ethqsets;/* # of available Ethernet queue sets */ u16 ethqsets;/* # of active Ethernet queue sets */ u16 ethtxq_rover;/* Tx queue to clean up next */
@@ -992,6 +1001,8 @@ struct sge {int fwevtq_msix_idx;/* Index to firmware event queue MSI-X info */ int nd_msix_idx;/* Index to non-data interrupts MSI-X info */ + +struct mutex queue_mutex;/* Sync access to dynamic queue info */ };#define for_each_ethrxq (sge, i) for (i = 0; i < (sge)->ethqsets; i++)
drivers/net/ethernet/chelsio/cxgb4/cxgb4_debugfs.c +67 -2
95 lines not on this page · raw message
drivers/net/ethernet/chelsio/cxgb4/cxgb4_main.c +218 -20
302 lines not on this page · raw message
Signature · 1 line
2.24.0
PATCH 3/3 cxgb4: add main VI to mirror VI config replication
In reply to Rahul LakkireddyWhen mirror VI is enabled, replicate various VI config params enabled on main VI to mirror VI. These include replicating MTU, promiscuous mode, all-multicast mode, and enabled netdev Rx feature offloads.
--- .../net/ethernet/chelsio/cxgb4/cxgb4_main.c | 155 ++++++++++++++++-- 1 file changed, 143 insertions(+), 12 deletions(-)
drivers/net/ethernet/chelsio/cxgb4/cxgb4_main.c +143 -12
@@ -431,14 +431,32 @@ static int set_rxmode(struct net_device *dev, int mtu, bool sleep_ok) {struct port_info *pi =netdev_priv (dev);struct adapter *adapter = pi->adapter; +int ret;__dev_uc_sync (dev, cxgb4_mac_sync, cxgb4_mac_unsync);__dev_mc_sync (dev, cxgb4_mac_sync, cxgb4_mac_unsync); -return t4_set_rxmode (adapter, adapter->mbox, pi->viid, mtu, - (dev->flags &IFF_PROMISC ) ?1 :0 , - (dev->flags &IFF_ALLMULTI ) ?1 :0 ,1 ,-1 , - sleep_ok); + ret =t4_set_rxmode (adapter, adapter->mbox, pi->viid, mtu, + (dev->flags &IFF_PROMISC ) ?1 :0 , + (dev->flags &IFF_ALLMULTI ) ?1 :0 ,1 ,-1 , + sleep_ok); +if (ret) +return ret; + +if (refcount_read (&pi->vi_mirror_refcnt)) { + ret =t4_set_rxmode (adapter, adapter->mbox, pi->viid_mirror, + mtu, (dev->flags &IFF_PROMISC ) ?1 :0 , + (dev->flags &IFF_ALLMULTI ) ?1 :0 ,1 ,-1 , + sleep_ok); +if (ret) { +dev_err (adapter->pdev_dev, +"Failed setting Rx Mode for Mirror VI 0x%x, ret: %d\n" , + pi->viid_mirror, ret); +return ret; + } + } + +return ret; }/**
@@ -1270,18 +1288,36 @@ int cxgb4_set_rspq_intr_params(struct sge_rspq *q,static int cxgb_set_features (struct net_device *dev,netdev_features_t features) { -const struct port_info *pi =netdev_priv (dev);netdev_features_t changed = dev->features ^ features; +const struct port_info *pi =netdev2pinfo (dev); +struct adapter *adap =netdev2adap (dev);int err;if (!(changed &NETIF_F_HW_VLAN_CTAG_RX ))return 0 ; - err =t4_set_rxmode (pi->adapter, pi->adapter->pf, pi->viid,-1 , --1 ,-1 ,-1 , + err =t4_set_rxmode (adap, adap->mbox, pi->viid,-1 ,-1 ,-1 ,-1 , !!(features &NETIF_F_HW_VLAN_CTAG_RX ), true); -if (unlikely (err)) +if (err) + goto out; + +if (refcount_read (&pi->vi_mirror_refcnt)) { + err =t4_set_rxmode (adap, adap->mbox, pi->viid_mirror, +-1 ,-1 ,-1 ,-1 , + !!(features &NETIF_F_HW_VLAN_CTAG_RX ), + true); +if (err) { +dev_err (adap->pdev_dev, +"Failed setting VLAN Rx mode for Mirror VI 0x%x, ret: %d\n" , + pi->viid_mirror, err); + goto out; + } + } + +out: +if (err) dev->features = features ^NETIF_F_HW_VLAN_CTAG_RX ; +return err; }
@@ -1452,6 +1488,74 @@ static void cxgb4_port_mirror_free_queues(struct net_device *dev)mutex_unlock (&s->queue_mutex); } +static int cxgb4_port_mirror_start (struct net_device *dev) +{ +struct port_info *pi =netdev2pinfo (dev); +struct adapter *adap =netdev2adap (dev); +int ret, idx =-1 ; + +if (!refcount_read (&pi->vi_mirror_refcnt)) +return 0 ; + +/* Mirror VIs can be created dynamically after stack had +* already setup Rx modes like MTU, promisc, allmulti, etc. +* on main VI. So, parse what the stack had setup on the +* main VI and update the same on the mirror VI. +*/ + ret =t4_set_rxmode (adap, adap->mbox, pi->viid_mirror, dev->mtu, + (dev->flags &IFF_PROMISC ) ?1 :0 , + (dev->flags &IFF_ALLMULTI ) ?1 :0 ,1 , + !!(dev->features &NETIF_F_HW_VLAN_CTAG_RX ), true); +if (ret) { +dev_err (adap->pdev_dev, +"Failed start up Rx mode for Mirror VI 0x%x, ret: %d\n" , + pi->viid_mirror, ret); +return ret; + } + +/* Enable replication bit for the device's MAC address +* in MPS TCAM, so that the packets for the main VI are +* replicated to mirror VI. +*/ + ret =cxgb4_update_mac_filt (pi, pi->viid_mirror, &idx, + dev->dev_addr, true,NULL ); +if (ret) { +dev_err (adap->pdev_dev, +"Failed updating MAC filter for Mirror VI 0x%x, ret: %d\n" , + pi->viid_mirror, ret); +return ret; + } + +/* Enabling a Virtual Interface can result in an interrupt +* during the processing of the VI Enable command and, in some +* paths, result in an attempt to issue another command in the +* interrupt context. Thus, we disable interrupts during the +* course of the VI Enable command ... +*/ +local_bh_disable (); + ret =t4_enable_vi_params (adap, adap->mbox, pi->viid_mirror, true, true, + false); +local_bh_enable (); +if (ret) +dev_err (adap->pdev_dev, +"Failed starting Mirror VI 0x%x, ret: %d\n" , + pi->viid_mirror, ret); + +return ret; +} + +static void cxgb4_port_mirror_stop (struct net_device *dev) +{ +struct port_info *pi =netdev2pinfo (dev); +struct adapter *adap =netdev2adap (dev); + +if (!refcount_read (&pi->vi_mirror_refcnt)) +return ; + +t4_enable_vi_params (adap, adap->mbox, pi->viid_mirror, false, false, + false); +} +int cxgb4_port_mirror_alloc (struct net_device *dev) {struct port_info *pi =netdev2pinfo (dev);
@@ -1477,10 +1581,17 @@ int cxgb4_port_mirror_alloc(struct net_device *dev) ret =cxgb4_port_mirror_alloc_queues (dev);if (ret <0 ) goto out_free_vi; + + ret =cxgb4_port_mirror_start (dev); +if (ret <0 ) + goto out_free_queues; }return 0 ; +out_free_queues: +cxgb4_port_mirror_free_queues (dev); + out_free_vi:refcount_set (&pi->vi_mirror_refcnt,0 );t4_free_vi (adap, adap->mbox, adap->pf,0 , pi->viid_mirror);
@@ -1501,6 +1612,7 @@ void cxgb4_port_mirror_free(struct net_device *dev)return ; } +cxgb4_port_mirror_stop (dev);cxgb4_port_mirror_free_queues (dev);refcount_set (&pi->vi_mirror_refcnt,0 );
@@ -2786,6 +2898,10 @@ int cxgb_open(struct net_device *dev)if (err) goto out_free; + err =cxgb4_port_mirror_start (dev); +if (err) + goto out_free; +netif_tx_start_all_queues (dev);return err;
@@ -2811,6 +2927,7 @@ int cxgb_close(struct net_device *dev)if (ret)return ret; +cxgb4_port_mirror_stop (dev);cxgb4_port_mirror_free_queues (dev);return ret; }
@@ -3078,13 +3195,27 @@ static void cxgb_set_rxmode(struct net_device *dev)static int cxgb_change_mtu (struct net_device *dev,int new_mtu) { +struct port_info *pi =netdev2pinfo (dev); +struct adapter *adap =netdev2adap (dev);int ret; -struct port_info *pi =netdev_priv (dev); - ret =t4_set_rxmode (pi->adapter, pi->adapter->pf, pi->viid, new_mtu,-1 , + ret =t4_set_rxmode (adap, adap->mbox, pi->viid, new_mtu,-1 ,-1 ,-1 ,-1 , true); -if (!ret) - dev->mtu = new_mtu; +if (ret) +return ret; + +if (refcount_read (&pi->vi_mirror_refcnt)) { + ret =t4_set_rxmode (adap, adap->mbox, pi->viid_mirror, + new_mtu,-1 ,-1 ,-1 ,-1 , true); +if (ret) { +dev_err (adap->pdev_dev, +"MTU change for Mirror VI 0x%x error: %d\n" , + pi->viid_mirror, ret); +return ret; + } + } + + dev->mtu = new_mtu;return ret; }
Signature · 1 line
2.24.0
Jakub Kicinski
maintainerQuoted 7 lines · On Thu, 25 Jun 2020 17:28:40 +0530 Rahul Lakkireddy wrote:
This series of patches add support to mirror all ingress traffic for TC-MATCHALL ingress offload.
Patch 1 adds support to dynamically create a mirror Virtual Interface (VI) that accepts all mirror ingress traffic when mirror action is set in TC-MATCHALL offload.
Quoted 6 lines
Patch 2 adds support to allocate mirror Rxqs and setup RSS for the mirror VI.
Patch 3 adds support to replicate all the main VI configuration to mirror VI. This includes replicating MTU, promiscuous mode, all-multicast mode, and enabled netdev Rx feature offloads.
Could you say more about this mirror VI? Is this an internal object within the NIC or something visible to the user?
Also looking at the implementation of redirect:
case FLOW_ACTION_REDIRECT: {
struct net_device *out = act->dev;
struct port_info *pi = netdev_priv(out);
fs->action = FILTER_SWITCH;
fs->eport = pi->port_id;
}How do you know the output interface is controlled by your driver, and therefore it's sage to cast netdev_priv() to port_info?
Quoted 11 lines · Jakub Kicinski
Quoted 10 lines · On Thu, 25 Jun 2020 17:28:40 +0530 Rahul Lakkireddy wrote:
This series of patches add support to mirror all ingress traffic for TC-MATCHALL ingress offload.
Patch 1 adds support to dynamically create a mirror Virtual Interface (VI) that accepts all mirror ingress traffic when mirror action is set in TC-MATCHALL offload.
Patch 2 adds support to allocate mirror Rxqs and setup RSS for the mirror VI.
Quoted 7 lines
Quoted 3 lines
Patch 3 adds support to replicate all the main VI configuration to mirror VI. This includes replicating MTU, promiscuous mode, all-multicast mode, and enabled netdev Rx feature offloads.
Could you say more about this mirror VI? Is this an internal object within the NIC or something visible to the user?
The Virtual Interface (VI) is an internal object managed by firmware and Multi Port Switch (MPS) module in hardware. Each VI can be programmed with a unique MAC address in the MPS TCAM. So, 1 physical port can have multiple VIs, each with their own MAC address. It's also possible for VIs to share the same MAC address, which would result in MPS setting the replication mode for that entry in the TCAM. In this case, the incoming packet would get replicated and sent to all the VIs sharing the MAC address. When MPS is able to classify the destination MAC in the incoming packet with an entry in the MPS TCAM, it forwards the packet to the corresponding VI(s).
In case of Mirror VI, we program the same MAC as the existing main VI. This will result in MPS setting the replication mode for that existing entry in the MPS TCAM. So, the MPS would replicate the incoming packet and send it to both the main VI and mirror VI. Note that for the main VI, we also programmed the flow Lookup Engine (LE) module to switch the packet back out on one of the underlying ports. So, when this rule hits in the LE, the main VI's packet would get switched back out in hardware to one of the underlying ports and will not reach driver. The mirror VI's packet will not hit any rule in the LE and will be received by the driver and will be sent up to Linux networking stack.
Quoted 10 lines
Also looking at the implementation of redirect:
case FLOW_ACTION_REDIRECT: { struct net_device *out = act->dev; struct port_info *pi = netdev_priv(out); fs->action = FILTER_SWITCH; fs->eport = pi->port_id; }
Quoted 2 lines
How do you know the output interface is controlled by your driver, and therefore it's sage to cast
netdev_priv()toport_info?
We're validating it earlier in cxgb4_validate_flow_actions(). Here's the code snippet. We're saving the netdevice pointer returned by alloc_etherdev_mq() during PCI probe in cxgb4_main.c::init_one() and using it to compare the netdevice given by redirect action. If the redirect action's netdevice doesn't match any of our underlying ports, then we fail offloading this rule.
case FLOW_ACTION_REDIRECT: {
struct adapter *adap = netdev2adap(dev);
struct net_device *n_dev, *target_dev;
unsigned int i;
bool found = false;
target_dev = act->dev;
for_each_port(adap, i) {
n_dev = adap->port[i];
if (target_dev == n_dev) {
found = true;
break;
}
}
/* If interface doesn't belong to our hw, then
* the provided output port is not valid
*/
if (!found) {
netdev_err(dev, "%s: Out port invalid\n",
__func__);
return -EINVAL;
}
act_redir = true;
}
break;Thanks,
Rahul
Jakub Kicinski
maintainerQuoted 31 lines · On Fri, 26 Jun 2020 15:36:15 +0530 Rahul Lakkireddy wrote:
Quoted 11 lines · Jakub Kicinski
Quoted 10 lines · On Thu, 25 Jun 2020 17:28:40 +0530 Rahul Lakkireddy wrote:
This series of patches add support to mirror all ingress traffic for TC-MATCHALL ingress offload.
Patch 1 adds support to dynamically create a mirror Virtual Interface (VI) that accepts all mirror ingress traffic when mirror action is set in TC-MATCHALL offload.
Patch 2 adds support to allocate mirror Rxqs and setup RSS for the mirror VI.
Quoted 7 lines
Quoted 3 lines
Patch 3 adds support to replicate all the main VI configuration to mirror VI. This includes replicating MTU, promiscuous mode, all-multicast mode, and enabled netdev Rx feature offloads.
Could you say more about this mirror VI? Is this an internal object within the NIC or something visible to the user?
The Virtual Interface (VI) is an internal object managed by firmware and Multi Port Switch (MPS) module in hardware. Each VI can be programmed with a unique MAC address in the MPS TCAM. So, 1 physical port can have multiple VIs, each with their own MAC address. It's also possible for VIs to share the same MAC address, which would result in MPS setting the replication mode for that entry in the TCAM. In this case, the incoming packet would get replicated and sent to all the VIs sharing the MAC address. When MPS is able to classify the destination MAC in the incoming packet with an entry in the MPS TCAM, it forwards the packet to the corresponding VI(s).
Quoted 4 lines
In case of Mirror VI, we program the same MAC as the existing main VI. This will result in MPS setting the replication mode for that existing entry in the MPS TCAM. So, the MPS would replicate the incoming packet and send it to both the main VI and mirror VI.
So far sounds good.
Quoted 7 lines
Note that for the main VI, we also programmed the flow Lookup Engine (LE) module to switch the packet back out on one of the underlying ports. So, when this rule hits in the LE, the main VI's packet would get switched back out in hardware to one of the underlying ports and will not reach driver. The mirror VI's packet will not hit any rule in the LE and will be received by the driver and will be sent up to Linux networking stack.
This I'm not sure I'm following. Are you saying that if there is another (flower, not matchall) rule programmed it will be ignored as far as the matchall filter is concerned? I assume you ensure the matchall rule is at higher prio in that case?
Quoted 38 lines
Quoted 10 lines
Also looking at the implementation of redirect:
case FLOW_ACTION_REDIRECT: { struct net_device *out = act->dev; struct port_info *pi = netdev_priv(out); fs->action = FILTER_SWITCH; fs->eport = pi->port_id; }Quoted 2 lines
How do you know the output interface is controlled by your driver, and therefore it's sage to cast
netdev_priv()toport_info?We're validating it earlier in
cxgb4_validate_flow_actions(). Here's the code snippet. We're saving the netdevice pointer returned byalloc_etherdev_mq()during PCI probe incxgb4_main.c::init_one()and using it to compare the netdevice given by redirect action. If the redirect action's netdevice doesn't match any of our underlying ports, then we fail offloading this rule.case FLOW_ACTION_REDIRECT: { struct adapter *adap = netdev2adap(dev); struct net_device *n_dev, *target_dev; unsigned int i; bool found = false; target_dev = act->dev; for_each_port(adap, i) { n_dev = adap->port[i]; if (target_dev == n_dev) { found = true; break; } } /* If interface doesn't belong to our hw, then * the provided output port is not valid */
Quoted 8 lines
if (!found) {
netdev_err(dev, "%s: Out port invalid\n",
__func__);
return -EINVAL;
}
act_redir = true;
}
break;Thanks, FWIW this is what netdev_port_same_parent_id() is for.
Quoted 47 lines · Jakub Kicinski
Quoted 31 lines · On Fri, 26 Jun 2020 15:36:15 +0530 Rahul Lakkireddy wrote:
Quoted 11 lines · Jakub Kicinski
Quoted 10 lines · On Thu, 25 Jun 2020 17:28:40 +0530 Rahul Lakkireddy wrote:
This series of patches add support to mirror all ingress traffic for TC-MATCHALL ingress offload.
Patch 1 adds support to dynamically create a mirror Virtual Interface (VI) that accepts all mirror ingress traffic when mirror action is set in TC-MATCHALL offload.
Patch 2 adds support to allocate mirror Rxqs and setup RSS for the mirror VI.
Quoted 7 lines
Quoted 3 lines
Patch 3 adds support to replicate all the main VI configuration to mirror VI. This includes replicating MTU, promiscuous mode, all-multicast mode, and enabled netdev Rx feature offloads.
Could you say more about this mirror VI? Is this an internal object within the NIC or something visible to the user?
The Virtual Interface (VI) is an internal object managed by firmware and Multi Port Switch (MPS) module in hardware. Each VI can be programmed with a unique MAC address in the MPS TCAM. So, 1 physical port can have multiple VIs, each with their own MAC address. It's also possible for VIs to share the same MAC address, which would result in MPS setting the replication mode for that entry in the TCAM. In this case, the incoming packet would get replicated and sent to all the VIs sharing the MAC address. When MPS is able to classify the destination MAC in the incoming packet with an entry in the MPS TCAM, it forwards the packet to the corresponding VI(s).
Quoted 4 lines
In case of Mirror VI, we program the same MAC as the existing main VI. This will result in MPS setting the replication mode for that existing entry in the MPS TCAM. So, the MPS would replicate the incoming packet and send it to both the main VI and mirror VI.
So far sounds good.
Quoted 7 lines
Note that for the main VI, we also programmed the flow Lookup Engine (LE) module to switch the packet back out on one of the underlying ports. So, when this rule hits in the LE, the main VI's packet would get switched back out in hardware to one of the underlying ports and will not reach driver. The mirror VI's packet will not hit any rule in the LE and will be received by the driver and will be sent up to Linux networking stack.
Quoted 5 lines
This I'm not sure I'm following. Are you saying that if there is another (flower, not matchall) rule programmed it will be ignored as far as the matchall filter is concerned? I assume you ensure the matchall rule is at higher prio in that case?
The order is still maintained. If there's a higher priority flower rule, then that rule will be considered first before considering the matchall rule.
For example, let's say we have 2 rules like below:
# tc filter add dev enp2s0f4 ingress protocol ip pref 1 \ flower skip_sw src_ip 10.1.3.3 action drop
# tc filter add dev enp2s0f4 ingress pref 100 \ matchall skip_sw action mirred egress mirror dev enp2s0f4d1
If we're receiving a packet with src_ip 10.1.3.3, then rule prio 1 will hit first and the lower prio 100 matchall rule will never hit for that packet. For all other packets, the matchall rule prio 100 will always hit.
I had tried to explain that some special care must be taken to make sure that the redirect action of the mirror rule must only be performed for the main VI's packet, so that it gets switched out to enp2s0f4d1 and _must not_ reach the driver. The same redirect action must not be performed for the mirror VI's replicated packet and the packet _must_ reach the driver. We're ensuring this by explicitly programming the main VI's index for the filter entry in hardware. This way the hardware will redirect out only the main VI's packet to enp2s0f4d1. It will not perform redirect on the replicated packet coming from mirror VI. If no VI index is programmed, then hardware will redirect out both the main and mirror VI packets to enp2s0f4d1 and none of the replicated packets will reach the driver, which is unexpected.
I hope I'm making sense... :)
Quoted 47 lines
Quoted 38 lines
Quoted 10 lines
Also looking at the implementation of redirect:
case FLOW_ACTION_REDIRECT: { struct net_device *out = act->dev; struct port_info *pi = netdev_priv(out); fs->action = FILTER_SWITCH; fs->eport = pi->port_id; }Quoted 2 lines
How do you know the output interface is controlled by your driver, and therefore it's sage to cast
netdev_priv()toport_info?We're validating it earlier in
cxgb4_validate_flow_actions(). Here's the code snippet. We're saving the netdevice pointer returned byalloc_etherdev_mq()during PCI probe incxgb4_main.c::init_one()and using it to compare the netdevice given by redirect action. If the redirect action's netdevice doesn't match any of our underlying ports, then we fail offloading this rule.case FLOW_ACTION_REDIRECT: { struct adapter *adap = netdev2adap(dev); struct net_device *n_dev, *target_dev; unsigned int i; bool found = false; target_dev = act->dev; for_each_port(adap, i) { n_dev = adap->port[i]; if (target_dev == n_dev) { found = true; break; } } /* If interface doesn't belong to our hw, then * the provided output port is not valid */Quoted 8 lines
if (!found) { netdev_err(dev, "%s: Out port invalid\n", __func__); return -EINVAL; } act_redir = true; } break;
Quoted 1 line
Thanks, FWIW this is what
netdev_port_same_parent_id()is for.
Looks like I need to add ndo_get_port_parent_id() support in the driver for this to work. I'll look into adding this support in follow up patches.
Thanks,
Rahul
Jakub Kicinski
maintainerQuoted 85 lines · On Sat, 27 Jun 2020 02:20:12 +0530 Rahul Lakkireddy wrote:
Quoted 47 lines · Jakub Kicinski
Quoted 31 lines · On Fri, 26 Jun 2020 15:36:15 +0530 Rahul Lakkireddy wrote:
Quoted 11 lines · Jakub Kicinski
Quoted 10 lines · On Thu, 25 Jun 2020 17:28:40 +0530 Rahul Lakkireddy wrote:
This series of patches add support to mirror all ingress traffic for TC-MATCHALL ingress offload.
Patch 1 adds support to dynamically create a mirror Virtual Interface (VI) that accepts all mirror ingress traffic when mirror action is set in TC-MATCHALL offload.
Patch 2 adds support to allocate mirror Rxqs and setup RSS for the mirror VI.
Quoted 7 lines
Quoted 3 lines
Patch 3 adds support to replicate all the main VI configuration to mirror VI. This includes replicating MTU, promiscuous mode, all-multicast mode, and enabled netdev Rx feature offloads.
Could you say more about this mirror VI? Is this an internal object within the NIC or something visible to the user?
The Virtual Interface (VI) is an internal object managed by firmware and Multi Port Switch (MPS) module in hardware. Each VI can be programmed with a unique MAC address in the MPS TCAM. So, 1 physical port can have multiple VIs, each with their own MAC address. It's also possible for VIs to share the same MAC address, which would result in MPS setting the replication mode for that entry in the TCAM. In this case, the incoming packet would get replicated and sent to all the VIs sharing the MAC address. When MPS is able to classify the destination MAC in the incoming packet with an entry in the MPS TCAM, it forwards the packet to the corresponding VI(s).
Quoted 4 lines
In case of Mirror VI, we program the same MAC as the existing main VI. This will result in MPS setting the replication mode for that existing entry in the MPS TCAM. So, the MPS would replicate the incoming packet and send it to both the main VI and mirror VI.
So far sounds good.
Quoted 7 lines
Note that for the main VI, we also programmed the flow Lookup Engine (LE) module to switch the packet back out on one of the underlying ports. So, when this rule hits in the LE, the main VI's packet would get switched back out in hardware to one of the underlying ports and will not reach driver. The mirror VI's packet will not hit any rule in the LE and will be received by the driver and will be sent up to Linux networking stack.
Quoted 5 lines
This I'm not sure I'm following. Are you saying that if there is another (flower, not matchall) rule programmed it will be ignored as far as the matchall filter is concerned? I assume you ensure the matchall rule is at higher prio in that case?
The order is still maintained. If there's a higher priority flower rule, then that rule will be considered first before considering the matchall rule.
For example, let's say we have 2 rules like below:
# tc filter add dev enp2s0f4 ingress protocol ip pref 1 \ flower skip_sw src_ip 10.1.3.3 action drop# tc filter add dev enp2s0f4 ingress pref 100 \ matchall skip_sw action mirred egress mirror dev enp2s0f4d1If we're receiving a packet with
src_ip10.1.3.3, then rule prio 1 will hit first and the lower prio 100 matchall rule will never hit for that packet. For all other packets, the matchall rule prio 100 will always hit.I had tried to explain that some special care must be taken to make sure that the redirect action of the mirror rule must only be performed for the main VI's packet, so that it gets switched out to enp2s0f4d1 and
_mustnot_reach the driver. The same redirect action must not be performed for the mirror VI's replicated packet and the packet _must_ reach the driver. We're ensuring this by explicitly programming the main VI's index for the filter entry in hardware. This way the hardware will redirect out only the main VI's packet to enp2s0f4d1. It will not perform redirect on the replicated packet coming from mirror VI. If no VI index is programmed, then hardware will redirect out both the main and mirror VI packets to enp2s0f4d1 and none of the replicated packets will reach the driver, which is unexpected.
Quoted 1 line
I hope I'm making sense... :)
What's the main use case for this feature? It appears that you're allocating queues in patch 2. At the same time I don't see SWITCHDEV mode / representors in this driver. So the use case is to redirect a packet out to another port while still receiving a copy?
Quoted 86 lines · Jakub Kicinski
Quoted 85 lines · On Sat, 27 Jun 2020 02:20:12 +0530 Rahul Lakkireddy wrote:
Quoted 47 lines · Jakub Kicinski
Quoted 31 lines · On Fri, 26 Jun 2020 15:36:15 +0530 Rahul Lakkireddy wrote:
Quoted 11 lines · Jakub Kicinski
Quoted 10 lines · On Thu, 25 Jun 2020 17:28:40 +0530 Rahul Lakkireddy wrote:
This series of patches add support to mirror all ingress traffic for TC-MATCHALL ingress offload.
Patch 1 adds support to dynamically create a mirror Virtual Interface (VI) that accepts all mirror ingress traffic when mirror action is set in TC-MATCHALL offload.
Patch 2 adds support to allocate mirror Rxqs and setup RSS for the mirror VI.
Quoted 7 lines
Quoted 3 lines
Patch 3 adds support to replicate all the main VI configuration to mirror VI. This includes replicating MTU, promiscuous mode, all-multicast mode, and enabled netdev Rx feature offloads.
Could you say more about this mirror VI? Is this an internal object within the NIC or something visible to the user?
The Virtual Interface (VI) is an internal object managed by firmware and Multi Port Switch (MPS) module in hardware. Each VI can be programmed with a unique MAC address in the MPS TCAM. So, 1 physical port can have multiple VIs, each with their own MAC address. It's also possible for VIs to share the same MAC address, which would result in MPS setting the replication mode for that entry in the TCAM. In this case, the incoming packet would get replicated and sent to all the VIs sharing the MAC address. When MPS is able to classify the destination MAC in the incoming packet with an entry in the MPS TCAM, it forwards the packet to the corresponding VI(s).
Quoted 4 lines
In case of Mirror VI, we program the same MAC as the existing main VI. This will result in MPS setting the replication mode for that existing entry in the MPS TCAM. So, the MPS would replicate the incoming packet and send it to both the main VI and mirror VI.
So far sounds good.
Quoted 7 lines
Note that for the main VI, we also programmed the flow Lookup Engine (LE) module to switch the packet back out on one of the underlying ports. So, when this rule hits in the LE, the main VI's packet would get switched back out in hardware to one of the underlying ports and will not reach driver. The mirror VI's packet will not hit any rule in the LE and will be received by the driver and will be sent up to Linux networking stack.
Quoted 5 lines
This I'm not sure I'm following. Are you saying that if there is another (flower, not matchall) rule programmed it will be ignored as far as the matchall filter is concerned? I assume you ensure the matchall rule is at higher prio in that case?
The order is still maintained. If there's a higher priority flower rule, then that rule will be considered first before considering the matchall rule.
For example, let's say we have 2 rules like below:
# tc filter add dev enp2s0f4 ingress protocol ip pref 1 \ flower skip_sw src_ip 10.1.3.3 action drop# tc filter add dev enp2s0f4 ingress pref 100 \ matchall skip_sw action mirred egress mirror dev enp2s0f4d1If we're receiving a packet with
src_ip10.1.3.3, then rule prio 1 will hit first and the lower prio 100 matchall rule will never hit for that packet. For all other packets, the matchall rule prio 100 will always hit.I had tried to explain that some special care must be taken to make sure that the redirect action of the mirror rule must only be performed for the main VI's packet, so that it gets switched out to enp2s0f4d1 and
_mustnot_reach the driver. The same redirect action must not be performed for the mirror VI's replicated packet and the packet _must_ reach the driver. We're ensuring this by explicitly programming the main VI's index for the filter entry in hardware. This way the hardware will redirect out only the main VI's packet to enp2s0f4d1. It will not perform redirect on the replicated packet coming from mirror VI. If no VI index is programmed, then hardware will redirect out both the main and mirror VI packets to enp2s0f4d1 and none of the replicated packets will reach the driver, which is unexpected.
Quoted 6 lines
Quoted 1 line
I hope I'm making sense... :)
What's the main use case for this feature? It appears that you're allocating queues in patch 2. At the same time I don't see SWITCHDEV mode / representors in this driver. So the use case is to redirect a packet out to another port while still receiving a copy?
The main use case is to sniff packets that are being switched out by hardware. The requirement is that there would be higher priority flower rules that will accept specific traffic and all the other traffic will be switched out on one of the underlying ports. Occasionally, we want to sniff the packets that are being switched out by replacing the redirect action with mirror action.
The reason for allocating queues is that the VIs are isolated from each other and can't access each other's queues. So, separate queues must be allocated for mirror VI.
Thanks,
Rahul
Jakub Kicinski
maintainerQuoted 12 lines · On Sat, 27 Jun 2020 12:14:07 +0530 Rahul Lakkireddy wrote:
Quoted 4 lines
What's the main use case for this feature? It appears that you're allocating queues in patch 2. At the same time I don't see SWITCHDEV mode / representors in this driver. So the use case is to redirect a packet out to another port while still receiving a copy?
The main use case is to sniff packets that are being switched out by hardware. The requirement is that there would be higher priority flower rules that will accept specific traffic and all the other traffic will be switched out on one of the underlying ports. Occasionally, we want to sniff the packets that are being switched out by replacing the redirect action with mirror action.
Quoted 3 lines
The reason for allocating queues is that the VIs are isolated from each other and can't access each other's queues. So, separate queues must be allocated for mirror VI.
Sounds reasonable, please fix the use of refcount_t (perhaps just use a normal integer since structures are protected), and repost.