Skip to contentSkip to conversation

net_sched: act_mirred: add helper inlines to access tcf_mirred info

PATCH New Sridhar Samudrala 3 participants 7 messages Apr 5, 2016 – May 2, 2016

Subsystems (4)
lore
Share & tools
lore
#0 lore raw

PATCH 1/2 net_sched: act_mirred: add helper inlines to access tcf_mirred info

---
 include/net/tc_act/tc_mirred.h | 15 +++++++++++++++
 1 file changed, 15 insertions(+)
include/net/tc_act/tc_mirred.h +15 -0
index dae96ba..e891835 100644
@@ -2,6 +2,7 @@
 #define __NET_TC_MIR_H
 
 #include <net/act_api.h>
+#include <linux/tc_act/tc_mirred.h>
 
 struct tcf_mirred {
 	struct tcf_common	common;
@@ -14,4 +15,18 @@ struct tcf_mirred {
 #define to_mirred(a) \
 	container_of(a->priv, struct tcf_mirred, common)
 
+static inline bool is_tcf_mirred_redirect(const struct tc_action *a)
+{
+#ifdef CONFIG_NET_CLS_ACT
+	if (a->ops && a->ops->type == TCA_ACT_MIRRED)
+		return to_mirred(a)->tcfm_eaction == TCA_EGRESS_REDIR;
+#endif
+	return false;
+}
+
+static inline int tcf_mirred_ifindex(const struct tc_action *a)
+{
+	return to_mirred(a)->tcfm_ifindex;
+}
+
 #endif /* __NET_TC_MIR_H */
Signature · 1 line
2.1.0
#1 lore raw

PATCH 2/2 ixgbe: Add support for redirect action to cls_u32 offloads.

From: Sridhar Samudrala <[email protected]>

This patch enables 'redirect' to a SRIOV VF or a offloaded macvlan device queue via tc 'mirred' action.

Verified with the following script that creates SRIOV VFs, offloaded macvlan and adds tc u32 filters with redirect action to the associated netdevs.

 # add ingress qdisc.
 tc qdisc add dev p4p1 ingress
 # enable hw tc offload.
 ethtool -K p4p1 hw-tc-offload on
 # create 4 sriov VFs and bring up the first one.
 echo 4 > /sys/class/net/p4p1/device/sriov_numvfs
 sleep 1
 ip link set p4p1 up
 ip link set p4p1_0 up
 # create a offloaded macvlan device and bring it up.
 ethtool -K p4p1 l2-fwd-offload on
 ip link add link p4p1 name mvlan_1 type macvlan
 ip link set mvlan_1 up
 # add u32 filter with action to redirect to VF netdev
 tc filter add dev p4p1 parent ffff: protocol ip prio 99 \
    handle 800:0:1 u32 ht 800: \
    match ip src 192.168.1.3/32 \
    action mirred egress redirect dev p4p1_0
 # add u32 filter with action to redirect to macvlan netdev
 tc filter add dev p4p1 parent ffff: protocol ip prio 99 \
    handle 800:0:2 u32 ht 800: \
    match ip src 192.168.2.3/32 \
    action mirred egress redirect dev mvlan_1
---
 drivers/net/ethernet/intel/ixgbe/ixgbe_main.c | 96 +++++++++++++++++++++++----
 1 file changed, 83 insertions(+), 13 deletions(-)
drivers/net/ethernet/intel/ixgbe/ixgbe_main.c +83 -13
index 19bf386..df7b10a 100644
@@ -53,6 +53,7 @@
 #include <net/vxlan.h>
 #include <net/pkt_cls.h>
 #include <net/tc_act/tc_gact.h>
+#include <net/tc_act/tc_mirred.h>
 
 #include "ixgbe.h"
 #include "ixgbe_common.h"
@@ -8222,6 +8223,85 @@ static int ixgbe_configure_clsu32_del_hnode(struct ixgbe_adapter *adapter,
 	return 0;
 }
 
+#ifdef CONFIG_NET_CLS_ACT
+static int handle_redirect_action(struct ixgbe_adapter *adapter, int ifindex,
+				  u8 *queue, u64 *action)
+{
+	unsigned int num_vfs = adapter->num_vfs, vf;
+	struct net_device *upper;
+	struct list_head *iter;
+
+	/* redirect to a SRIOV VF */
+	for (vf = 0; vf < num_vfs; ++vf) {
+		upper = pci_get_drvdata(adapter->vfinfo[vf].vfdev);
+		if (upper->ifindex == ifindex) {
+			if (adapter->num_rx_pools > 1)
+				*queue = vf * 2;
+			else
+				*queue = vf * adapter->num_rx_queues_per_pool;
+
+			*action = vf+1;
+			*action <<= ETHTOOL_RX_FLOW_SPEC_RING_VF_OFF;
+			return 0;
+		}
+	}
+
+	/* redirect to a offloaded macvlan netdev */
+	netdev_for_each_all_upper_dev_rcu(adapter->netdev, upper, iter) {
+		if (netif_is_macvlan(upper)) {
+			struct macvlan_dev *dfwd = netdev_priv(upper);
+			struct ixgbe_fwd_adapter *vadapter = dfwd->fwd_priv;
+
+			if (vadapter && vadapter->netdev->ifindex == ifindex) {
+				*queue = adapter->rx_ring[vadapter->rx_base_queue]->reg_idx;
+				*action = *queue;
+				return 0;
+			}
+		}
+	}
+
+	return -EINVAL;
+}
+
+static int parse_tc_actions(struct ixgbe_adapter *adapter,
+			    struct tcf_exts *exts, u64 *action, u8 *queue)
+{
+	const struct tc_action *a;
+	int err;
+
+	if (tc_no_actions(exts))
+		return -EINVAL;
+
+	tc_for_each_action(a, exts) {
+
+		/* Drop action */
+		if (is_tcf_gact_shot(a)) {
+			*action = IXGBE_FDIR_DROP_QUEUE;
+			*queue = IXGBE_FDIR_DROP_QUEUE;
+			return 0;
+		}
+
+		/* Redirect to a VF or a offloaded macvlan */
+		if (is_tcf_mirred_redirect(a)) {
+			int ifindex = tcf_mirred_ifindex(a);
+
+			err = handle_redirect_action(adapter, ifindex, queue,
+						     action);
+			if (err == 0)
+				return err;
+		}
+	}
+
+	return -EINVAL;
+}
+#else
+static int parse_tc_actions(struct ixgbe_adapter *adapter,
+			    struct tcf_exts *exts, u64 *action, u8 *queue)
+{
+	return -EINVAL;
+}
+#endif /* CONFIG_NET_CLS_ACT */
+
 static int ixgbe_configure_clsu32(struct ixgbe_adapter *adapter,
 				  __be16 protocol,
 				  struct tc_cls_u32_offload *cls)
@@ -8231,9 +8311,6 @@ static int ixgbe_configure_clsu32(struct ixgbe_adapter *adapter,
 	struct ixgbe_mat_field *field_ptr;
 	struct ixgbe_fdir_filter *input;
 	union ixgbe_atr_input mask;
-#ifdef CONFIG_NET_CLS_ACT
-	const struct tc_action *a;
-#endif
 	int i, err = 0;
 	u8 queue;
 	u32 uhtid, link_uhtid;
@@ -8335,18 +8412,11 @@ static int ixgbe_configure_clsu32(struct ixgbe_adapter *adapter,
 	if (input->filter.formatted.flow_type == IXGBE_ATR_FLOW_TYPE_IPV4)
 		mask.formatted.flow_type &= IXGBE_ATR_L4TYPE_IPV6_MASK;
 
-#ifdef CONFIG_NET_CLS_ACT
-	if (list_empty(&cls->knode.exts->actions))
+	err = parse_tc_actions(adapter, cls->knode.exts, &input->action,
+			       &queue);
+	if (err < 0)
 		goto err_out;
 
-	list_for_each_entry(a, &cls->knode.exts->actions, list) {
-		if (!is_tcf_gact_shot(a))
-			goto err_out;
-	}
-#endif
-
-	input->action = IXGBE_FDIR_DROP_QUEUE;
-	queue = IXGBE_FDIR_DROP_QUEUE;
 	input->sw_idx = loc;
 
 	spin_lock(&adapter->fdir_perfect_lock);
Signature · 1 line
2.1.0
#2 lore raw

[Intel-wired-lan] [PATCH net-next 2/2] ixgbe: Add support for redirect action to cls_u32 offloads.

reproduce: wget https://git.kernel.org/cgit/linux/kernel/git/wfg/lkp-tests.git/plain/sbin/make.cross -O ~/bin/make.cross chmod +x ~/bin/make.cross # save the attached .config to linux build tree…

Hi Sridhar,

[auto build test WARNING on net-next/master]

url:    https://github.com/0day-ci/linux/commits/Sridhar-Samudrala/net_sched-act_mirred-add-helper-inlines-to-access-tcf_mirred-info/20160406-014537
config: xtensa-allyesconfig (attached as .config)

reproduce:
wget https://git.kernel.org/cgit/linux/kernel/git/wfg/lkp-tests.git/plain/sbin/make.cross -O ~/bin/make.cross chmod +x ~/bin/make.cross
# save the attached .config to linux build tree
make.cross ARCH=xtensa

All warnings (new ones prefixed by >>):

drivers/net/ethernet/intel/ixgbe/ixgbe_main.c: In function 'ixgbe_configure_clsu32':

>> drivers/net/ethernet/intel/ixgbe/ixgbe_main.c:8415:8: warning: passing argument 3 of 'parse_tc_actions' from incompatible pointer type
     err = parse_tc_actions(adapter, cls->knode.exts, &input->action,
           ^

drivers/net/ethernet/intel/ixgbe/ixgbe_main.c:8266:12: note: expected 'u64 *' but argument is of type 'u16 *'
static int parse_tc_actions(struct ixgbe_adapter *adapter,
^

vim +/parse_tc_actions +8415 drivers/net/ethernet/intel/ixgbe/ixgbe_main.c

8399 field_ptr[j].type;
8400 found_entry = true;
8401 break;
8402 }
8403 }
8404
8405 if (!found_entry)
8406 goto err_out;
8407 }
8408
8409 mask.formatted.flow_type = IXGBE_ATR_L4TYPE_IPV6_MASK |
8410 IXGBE_ATR_L4TYPE_MASK;
8411
8412 if (input->filter.formatted.flow_type == IXGBE_ATR_FLOW_TYPE_IPV4)
8413 mask.formatted.flow_type &= IXGBE_ATR_L4TYPE_IPV6_MASK;
8414

> 8415		err = parse_tc_actions(adapter, cls->knode.exts, &input->action,

8416 &queue);
8417 if (err < 0)
8418 goto err_out;
8419
8420 input->sw_idx = loc;
8421
8422 spin_lock(&adapter->fdir_perfect_lock);
8423

---
0-DAY kernel test infrastructure Open Source Technology Center
https://lists.01.org/pipermail/kbuild-all Intel Corporation
-------------- next part --------------
A non-text attachment was scrubbed...
Name: .config.gz
Type: application/octet-stream
Size: 44880 bytes
Desc: not available
URL: <http://lists.osuosl.org/pipermail/intel-wired-lan/attachments/20160406/1939c85b/attachment-0001.obj>

#3 lore raw

[Intel-wired-lan] [PATCH net-next 2/2] ixgbe: Add support for redirect action to cls_u32 offloads.

In reply to Sridhar Samudrala
reproduce:

Hi Sridhar,

[auto build test ERROR on net-next/master]

url:    https://github.com/0day-ci/linux/commits/Sridhar-Samudrala/net_sched-act_mirred-add-helper-inlines-to-access-tcf_mirred-info/20160406-014537
config: x86_64-randconfig-x010-201614 (attached as .config)
reproduce:
        # save the attached .config to linux build tree
        make ARCH=x86_64 

All errors (new ones prefixed by >>):

drivers/net/ethernet/intel/ixgbe/ixgbe_main.c: In function 'ixgbe_configure_clsu32':

>> drivers/net/ethernet/intel/ixgbe/ixgbe_main.c:8415:51: error: passing argument 3 of 'parse_tc_actions' from incompatible pointer type [-Werror=incompatible-pointer-types]
     err = parse_tc_actions(adapter, cls->knode.exts, &input->action,
                                                      ^

drivers/net/ethernet/intel/ixgbe/ixgbe_main.c:8298:12: note: expected 'u64 * {aka long long unsigned int *}' but argument is of type 'u16 * {aka short unsigned int *}'
static int parse_tc_actions(struct ixgbe_adapter *adapter,
^
cc1: some warnings being treated as errors

vim +/parse_tc_actions +8415 drivers/net/ethernet/intel/ixgbe/ixgbe_main.c

8409 mask.formatted.flow_type = IXGBE_ATR_L4TYPE_IPV6_MASK |
8410 IXGBE_ATR_L4TYPE_MASK;
8411
8412 if (input->filter.formatted.flow_type == IXGBE_ATR_FLOW_TYPE_IPV4)
8413 mask.formatted.flow_type &= IXGBE_ATR_L4TYPE_IPV6_MASK;
8414

> 8415		err = parse_tc_actions(adapter, cls->knode.exts, &input->action,

8416 &queue);
8417 if (err < 0)
8418 goto err_out;

---
0-DAY kernel test infrastructure Open Source Technology Center
https://lists.01.org/pipermail/kbuild-all Intel Corporation
-------------- next part --------------
A non-text attachment was scrubbed...
Name: .config.gz
Type: application/octet-stream
Size: 32342 bytes
Desc: not available
URL: <http://lists.osuosl.org/pipermail/intel-wired-lan/attachments/20160406/ab4c355d/attachment-0001.obj>

#4 lore raw

PATCH 2/2 ixgbe: Add support for redirect action to cls_u32 offloads.

In reply to Sridhar Samudrala
Quoted 4 lines · Sridhar Samudrala

From: Sridhar Samudrala <[email protected]>

This patch enables 'redirect' to a SRIOV VF or a offloaded macvlan device queue via tc 'mirred' action.

Jeff,
This patch has a dependency on this patch
https://git.kernel.org/cgit/linux/kernel/git/jkirsher/next-queue.git/commit/?h=dev-queue&id=aff19cd6dd891364ba440ee0e02fe8a83a110f7c
which is in your dev_queue branch.

Thanks
Sridhar

Quoted 169 lines

Verified with the following script that creates SRIOV VFs, offloaded macvlan and adds tc u32 filters with redirect action to the associated netdevs.

  # add ingress qdisc.
  tc qdisc add dev p4p1 ingress
  # enable hw tc offload.
  ethtool -K p4p1 hw-tc-offload on
  # create 4 sriov VFs and bring up the first one.
  echo 4 > /sys/class/net/p4p1/device/sriov_numvfs
  sleep 1
  ip link set p4p1 up
  ip link set p4p1_0 up
  # create a offloaded macvlan device and bring it up.
  ethtool -K p4p1 l2-fwd-offload on
  ip link add link p4p1 name mvlan_1 type macvlan
  ip link set mvlan_1 up
  # add u32 filter with action to redirect to VF netdev
  tc filter add dev p4p1 parent ffff: protocol ip prio 99 \
     handle 800:0:1 u32 ht 800: \
     match ip src 192.168.1.3/32 \
     action mirred egress redirect dev p4p1_0
  # add u32 filter with action to redirect to macvlan netdev
  tc filter add dev p4p1 parent ffff: protocol ip prio 99 \
     handle 800:0:2 u32 ht 800: \
     match ip src 192.168.2.3/32 \
     action mirred egress redirect dev mvlan_1
---
  drivers/net/ethernet/intel/ixgbe/ixgbe_main.c | 96 +++++++++++++++++++++++----
  1 file changed, 83 insertions(+), 13 deletions(-)
drivers/net/ethernet/intel/ixgbe/ixgbe_main.c +83 -13
index 19bf386..df7b10a 100644
@@ -53,6 +53,7 @@
  #include <net/vxlan.h>
  #include <net/pkt_cls.h>
  #include <net/tc_act/tc_gact.h>
+#include <net/tc_act/tc_mirred.h>
 
  #include "ixgbe.h"
  #include "ixgbe_common.h"
@@ -8222,6 +8223,85 @@ static int ixgbe_configure_clsu32_del_hnode(struct ixgbe_adapter *adapter,
  	return 0;
  }
 
+#ifdef CONFIG_NET_CLS_ACT
+static int handle_redirect_action(struct ixgbe_adapter *adapter, int ifindex,
+				  u8 *queue, u64 *action)
+{
+	unsigned int num_vfs = adapter->num_vfs, vf;
+	struct net_device *upper;
+	struct list_head *iter;
+
+	/* redirect to a SRIOV VF */
+	for (vf = 0; vf < num_vfs; ++vf) {
+		upper = pci_get_drvdata(adapter->vfinfo[vf].vfdev);
+		if (upper->ifindex == ifindex) {
+			if (adapter->num_rx_pools > 1)
+				*queue = vf * 2;
+			else
+				*queue = vf * adapter->num_rx_queues_per_pool;
+
+			*action = vf+1;
+			*action <<= ETHTOOL_RX_FLOW_SPEC_RING_VF_OFF;
+			return 0;
+		}
+	}
+
+	/* redirect to a offloaded macvlan netdev */
+	netdev_for_each_all_upper_dev_rcu(adapter->netdev, upper, iter) {
+		if (netif_is_macvlan(upper)) {
+			struct macvlan_dev *dfwd = netdev_priv(upper);
+			struct ixgbe_fwd_adapter *vadapter = dfwd->fwd_priv;
+
+			if (vadapter && vadapter->netdev->ifindex == ifindex) {
+				*queue = adapter->rx_ring[vadapter->rx_base_queue]->reg_idx;
+				*action = *queue;
+				return 0;
+			}
+		}
+	}
+
+	return -EINVAL;
+}
+
+static int parse_tc_actions(struct ixgbe_adapter *adapter,
+			    struct tcf_exts *exts, u64 *action, u8 *queue)
+{
+	const struct tc_action *a;
+	int err;
+
+	if (tc_no_actions(exts))
+		return -EINVAL;
+
+	tc_for_each_action(a, exts) {
+
+		/* Drop action */
+		if (is_tcf_gact_shot(a)) {
+			*action = IXGBE_FDIR_DROP_QUEUE;
+			*queue = IXGBE_FDIR_DROP_QUEUE;
+			return 0;
+		}
+
+		/* Redirect to a VF or a offloaded macvlan */
+		if (is_tcf_mirred_redirect(a)) {
+			int ifindex = tcf_mirred_ifindex(a);
+
+			err = handle_redirect_action(adapter, ifindex, queue,
+						     action);
+			if (err == 0)
+				return err;
+		}
+	}
+
+	return -EINVAL;
+}
+#else
+static int parse_tc_actions(struct ixgbe_adapter *adapter,
+			    struct tcf_exts *exts, u64 *action, u8 *queue)
+{
+	return -EINVAL;
+}
+#endif /* CONFIG_NET_CLS_ACT */
+
  static int ixgbe_configure_clsu32(struct ixgbe_adapter *adapter,
  				  __be16 protocol,
  				  struct tc_cls_u32_offload *cls)
@@ -8231,9 +8311,6 @@ static int ixgbe_configure_clsu32(struct ixgbe_adapter *adapter,
  	struct ixgbe_mat_field *field_ptr;
  	struct ixgbe_fdir_filter *input;
  	union ixgbe_atr_input mask;
-#ifdef CONFIG_NET_CLS_ACT
-	const struct tc_action *a;
-#endif
  	int i, err = 0;
  	u8 queue;
  	u32 uhtid, link_uhtid;
@@ -8335,18 +8412,11 @@ static int ixgbe_configure_clsu32(struct ixgbe_adapter *adapter,
  	if (input->filter.formatted.flow_type == IXGBE_ATR_FLOW_TYPE_IPV4)
  		mask.formatted.flow_type &= IXGBE_ATR_L4TYPE_IPV6_MASK;
 
-#ifdef CONFIG_NET_CLS_ACT
-	if (list_empty(&cls->knode.exts->actions))
+	err = parse_tc_actions(adapter, cls->knode.exts, &input->action,
+			       &queue);
+	if (err < 0)
  		goto err_out;
 
-	list_for_each_entry(a, &cls->knode.exts->actions, list) {
-		if (!is_tcf_gact_shot(a))
-			goto err_out;
-	}
-#endif
-
-	input->action = IXGBE_FDIR_DROP_QUEUE;
-	queue = IXGBE_FDIR_DROP_QUEUE;
  	input->sw_idx = loc;
 
  	spin_lock(&adapter->fdir_perfect_lock);
#5 lore raw

PATCH 2/2 ixgbe: Add support for redirect action to cls_u32 offloads.

Quoted 60 lines

-----Original Message-----
From: Intel-wired-lan [mailto:intel-wired-lan-bounces at lists.osuosl.org] On Behalf Of Samudrala, Sridhar
Sent: Tuesday, April 05, 2016 11:16 AM
To: intel-wired-lan at lists.osuosl.org; Kirsher, Jeffrey T <[email protected]>; Fastabend, John R <[email protected]>
Subject: Re: [Intel-wired-lan] [PATCH net-next 2/2] ixgbe: Add support for redirect action to cls_u32 offloads.

Quoted 4 lines · Sridhar Samudrala

From: Sridhar Samudrala <[email protected]>

This patch enables 'redirect' to a SRIOV VF or a offloaded macvlan device queue via tc 'mirred' action.

Jeff,
This patch has a dependency on this patch
https://git.kernel.org/cgit/linux/kernel/git/jkirsher/next-
queue.git/commit/?h=dev-
queue&id=aff19cd6dd891364ba440ee0e02fe8a83a110f7c
which is in your dev_queue branch.

Thanks
Sridhar

Quoted 34 lines

Verified with the following script that creates SRIOV VFs, offloaded macvlan and adds tc u32 filters with redirect action to the associated netdevs.

  # add ingress qdisc.
  tc qdisc add dev p4p1 ingress
  # enable hw tc offload.
  ethtool -K p4p1 hw-tc-offload on
  # create 4 sriov VFs and bring up the first one.
  echo 4 > /sys/class/net/p4p1/device/sriov_numvfs
  sleep 1
  ip link set p4p1 up
  ip link set p4p1_0 up
  # create a offloaded macvlan device and bring it up.
  ethtool -K p4p1 l2-fwd-offload on
  ip link add link p4p1 name mvlan_1 type macvlan
  ip link set mvlan_1 up
  # add u32 filter with action to redirect to VF netdev
  tc filter add dev p4p1 parent ffff: protocol ip prio 99 \
     handle 800:0:1 u32 ht 800: \
     match ip src 192.168.1.3/32 \
     action mirred egress redirect dev p4p1_0
  # add u32 filter with action to redirect to macvlan netdev
  tc filter add dev p4p1 parent ffff: protocol ip prio 99 \
     handle 800:0:2 u32 ht 800: \
     match ip src 192.168.2.3/32 \
     action mirred egress redirect dev mvlan_1
Quoted 5 lines
Quoted 3 lines
---
  drivers/net/ethernet/intel/ixgbe/ixgbe_main.c | 96

+++++++++++++++++++++++----

Quoted 1 line
  1 file changed, 83 insertions(+), 13 deletions(-)

Filters added successfully

#6 lore raw

PATCH 1/2 net_sched: act_mirred: add helper inlines to access tcf_mirred info

In reply to Sridhar Samudrala
Quoted 10 lines

-----Original Message-----
From: Intel-wired-lan [mailto:intel-wired-lan-bounces at lists.osuosl.org] On Behalf Of Sridhar Samudrala
Sent: Tuesday, April 05, 2016 10:39 AM
To: intel-wired-lan at lists.osuosl.org; Kirsher, Jeffrey T <[email protected]>; Fastabend, John R <[email protected]>
Subject: [Intel-wired-lan] [PATCH net-next 1/2] net_sched: act_mirred: add helper inlines to access tcf_mirred info

Quoted 4 lines
---
 include/net/tc_act/tc_mirred.h | 15 +++++++++++++++
 1 file changed, 15 insertions(+)