netdev.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH net-next 0/5] mlxsw: Offload TC action skbedit priority
@ 2020-03-19 13:47 Ido Schimmel
  2020-03-19 13:47 ` [PATCH net-next 1/5] net: tc_skbedit: Factor a helper out of is_tcf_skbedit_{mark, ptype}() Ido Schimmel
                   ` (6 more replies)
  0 siblings, 7 replies; 8+ messages in thread
From: Ido Schimmel @ 2020-03-19 13:47 UTC (permalink / raw)
  To: netdev; +Cc: davem, kuba, jiri, jhs, xiyou.wangcong, petrm, mlxsw, Ido Schimmel

From: Ido Schimmel <idosch@mellanox.com>

Petr says:

The TC action "skbedit priority P" has the effect of assigning skbprio of P
to SKBs that it's applied on. In HW datapath of a switch, the corresponding
action is assignment of internal switch priority. Spectrum switches allow
setting of packet priority based on an ACL action, which is good match for
the skbedit priority gadget. This patchset therefore implements offloading
of this action to the Spectrum ACL engine.

After a bit of refactoring in patch #1, patch #2 extends the skbedit action
to support offloading of "priority" subcommand.

On mlxsw side, in patch #3, the QOS_ACTION flexible action is added, with
fields necessary for priority adjustment. In patch #4, "skbedit priority"
is connected to that action.

Patch #5 implements a new forwarding selftest, suitable for both SW- and
HW-datapath testing.

Petr Machata (5):
  net: tc_skbedit: Factor a helper out of is_tcf_skbedit_{mark, ptype}()
  net: tc_skbedit: Make the skbedit priority offloadable
  mlxsw: core: Add QOS_ACTION
  mlxsw: spectrum_flower: Offload FLOW_ACTION_PRIORITY
  selftests: forwarding: Add an skbedit priority selftest

 .../mellanox/mlxsw/core_acl_flex_actions.c    |  53 ++++++
 .../mellanox/mlxsw/core_acl_flex_actions.h    |   3 +
 .../net/ethernet/mellanox/mlxsw/spectrum.h    |   3 +
 .../ethernet/mellanox/mlxsw/spectrum_acl.c    |  17 ++
 .../ethernet/mellanox/mlxsw/spectrum_flower.c |   4 +
 include/net/flow_offload.h                    |   2 +
 include/net/tc_act/tc_skbedit.h               |  41 +++--
 net/sched/cls_api.c                           |   3 +
 .../net/forwarding/skbedit_priority.sh        | 163 ++++++++++++++++++
 9 files changed, 275 insertions(+), 14 deletions(-)
 create mode 100755 tools/testing/selftests/net/forwarding/skbedit_priority.sh

-- 
2.24.1


^ permalink raw reply	[flat|nested] 8+ messages in thread

* [PATCH net-next 1/5] net: tc_skbedit: Factor a helper out of is_tcf_skbedit_{mark, ptype}()
  2020-03-19 13:47 [PATCH net-next 0/5] mlxsw: Offload TC action skbedit priority Ido Schimmel
@ 2020-03-19 13:47 ` Ido Schimmel
  2020-03-19 13:47 ` [PATCH net-next 2/5] net: tc_skbedit: Make the skbedit priority offloadable Ido Schimmel
                   ` (5 subsequent siblings)
  6 siblings, 0 replies; 8+ messages in thread
From: Ido Schimmel @ 2020-03-19 13:47 UTC (permalink / raw)
  To: netdev; +Cc: davem, kuba, jiri, jhs, xiyou.wangcong, petrm, mlxsw, Ido Schimmel

From: Petr Machata <petrm@mellanox.com>

The two functions is_tcf_skbedit_mark() and is_tcf_skbedit_ptype() have a
very similar structure. A follow-up patch will add one more such function.
Instead of more cut'n'pasting, extract a helper function that checks
whether a TC action is an skbedit with the required flag. Convert the two
existing functions into thin wrappers around the helper.

Signed-off-by: Petr Machata <petrm@mellanox.com>
Reviewed-by: Jiri Pirko <jiri@mellanox.com>
Signed-off-by: Ido Schimmel <idosch@mellanox.com>
---
 include/net/tc_act/tc_skbedit.h | 24 ++++++++++--------------
 1 file changed, 10 insertions(+), 14 deletions(-)

diff --git a/include/net/tc_act/tc_skbedit.h b/include/net/tc_act/tc_skbedit.h
index b22a1f641f02..ac8ff60143fe 100644
--- a/include/net/tc_act/tc_skbedit.h
+++ b/include/net/tc_act/tc_skbedit.h
@@ -27,8 +27,8 @@ struct tcf_skbedit {
 };
 #define to_skbedit(a) ((struct tcf_skbedit *)a)
 
-/* Return true iff action is mark */
-static inline bool is_tcf_skbedit_mark(const struct tc_action *a)
+/* Return true iff action is the one identified by FLAG. */
+static inline bool is_tcf_skbedit_with_flag(const struct tc_action *a, u32 flag)
 {
 #ifdef CONFIG_NET_CLS_ACT
 	u32 flags;
@@ -37,12 +37,18 @@ static inline bool is_tcf_skbedit_mark(const struct tc_action *a)
 		rcu_read_lock();
 		flags = rcu_dereference(to_skbedit(a)->params)->flags;
 		rcu_read_unlock();
-		return flags == SKBEDIT_F_MARK;
+		return flags == flag;
 	}
 #endif
 	return false;
 }
 
+/* Return true iff action is mark */
+static inline bool is_tcf_skbedit_mark(const struct tc_action *a)
+{
+	return is_tcf_skbedit_with_flag(a, SKBEDIT_F_MARK);
+}
+
 static inline u32 tcf_skbedit_mark(const struct tc_action *a)
 {
 	u32 mark;
@@ -57,17 +63,7 @@ static inline u32 tcf_skbedit_mark(const struct tc_action *a)
 /* Return true iff action is ptype */
 static inline bool is_tcf_skbedit_ptype(const struct tc_action *a)
 {
-#ifdef CONFIG_NET_CLS_ACT
-	u32 flags;
-
-	if (a->ops && a->ops->id == TCA_ID_SKBEDIT) {
-		rcu_read_lock();
-		flags = rcu_dereference(to_skbedit(a)->params)->flags;
-		rcu_read_unlock();
-		return flags == SKBEDIT_F_PTYPE;
-	}
-#endif
-	return false;
+	return is_tcf_skbedit_with_flag(a, SKBEDIT_F_PTYPE);
 }
 
 static inline u32 tcf_skbedit_ptype(const struct tc_action *a)
-- 
2.24.1


^ permalink raw reply related	[flat|nested] 8+ messages in thread

* [PATCH net-next 2/5] net: tc_skbedit: Make the skbedit priority offloadable
  2020-03-19 13:47 [PATCH net-next 0/5] mlxsw: Offload TC action skbedit priority Ido Schimmel
  2020-03-19 13:47 ` [PATCH net-next 1/5] net: tc_skbedit: Factor a helper out of is_tcf_skbedit_{mark, ptype}() Ido Schimmel
@ 2020-03-19 13:47 ` Ido Schimmel
  2020-03-19 13:47 ` [PATCH net-next 3/5] mlxsw: core: Add QOS_ACTION Ido Schimmel
                   ` (4 subsequent siblings)
  6 siblings, 0 replies; 8+ messages in thread
From: Ido Schimmel @ 2020-03-19 13:47 UTC (permalink / raw)
  To: netdev; +Cc: davem, kuba, jiri, jhs, xiyou.wangcong, petrm, mlxsw, Ido Schimmel

From: Petr Machata <petrm@mellanox.com>

The skbedit action "priority" is used for adjusting SKB priority. Allow
drivers to offload the action by introducing two new skbedit getters and a
new flow action, and initializing appropriately in tc_setup_flow_action().

Signed-off-by: Petr Machata <petrm@mellanox.com>
Reviewed-by: Jiri Pirko <jiri@mellanox.com>
Signed-off-by: Ido Schimmel <idosch@mellanox.com>
---
 include/net/flow_offload.h      |  2 ++
 include/net/tc_act/tc_skbedit.h | 17 +++++++++++++++++
 net/sched/cls_api.c             |  3 +++
 3 files changed, 22 insertions(+)

diff --git a/include/net/flow_offload.h b/include/net/flow_offload.h
index 1e30b0d44b61..51b9893d4ccb 100644
--- a/include/net/flow_offload.h
+++ b/include/net/flow_offload.h
@@ -137,6 +137,7 @@ enum flow_action_id {
 	FLOW_ACTION_CSUM,
 	FLOW_ACTION_MARK,
 	FLOW_ACTION_PTYPE,
+	FLOW_ACTION_PRIORITY,
 	FLOW_ACTION_WAKE,
 	FLOW_ACTION_QUEUE,
 	FLOW_ACTION_SAMPLE,
@@ -211,6 +212,7 @@ struct flow_action_entry {
 		u32			csum_flags;	/* FLOW_ACTION_CSUM */
 		u32			mark;		/* FLOW_ACTION_MARK */
 		u16                     ptype;          /* FLOW_ACTION_PTYPE */
+		u32			priority;	/* FLOW_ACTION_PRIORITY */
 		struct {				/* FLOW_ACTION_QUEUE */
 			u32		ctx;
 			u32		index;
diff --git a/include/net/tc_act/tc_skbedit.h b/include/net/tc_act/tc_skbedit.h
index ac8ff60143fe..00bfee70609e 100644
--- a/include/net/tc_act/tc_skbedit.h
+++ b/include/net/tc_act/tc_skbedit.h
@@ -77,4 +77,21 @@ static inline u32 tcf_skbedit_ptype(const struct tc_action *a)
 	return ptype;
 }
 
+/* Return true iff action is priority */
+static inline bool is_tcf_skbedit_priority(const struct tc_action *a)
+{
+	return is_tcf_skbedit_with_flag(a, SKBEDIT_F_PRIORITY);
+}
+
+static inline u32 tcf_skbedit_priority(const struct tc_action *a)
+{
+	u32 priority;
+
+	rcu_read_lock();
+	priority = rcu_dereference(to_skbedit(a)->params)->priority;
+	rcu_read_unlock();
+
+	return priority;
+}
+
 #endif /* __NET_TC_SKBEDIT_H */
diff --git a/net/sched/cls_api.c b/net/sched/cls_api.c
index eefacb3176e3..fb6c3660fb9a 100644
--- a/net/sched/cls_api.c
+++ b/net/sched/cls_api.c
@@ -3665,6 +3665,9 @@ int tc_setup_flow_action(struct flow_action *flow_action,
 		} else if (is_tcf_skbedit_ptype(act)) {
 			entry->id = FLOW_ACTION_PTYPE;
 			entry->ptype = tcf_skbedit_ptype(act);
+		} else if (is_tcf_skbedit_priority(act)) {
+			entry->id = FLOW_ACTION_PRIORITY;
+			entry->priority = tcf_skbedit_priority(act);
 		} else {
 			err = -EOPNOTSUPP;
 			goto err_out_locked;
-- 
2.24.1


^ permalink raw reply related	[flat|nested] 8+ messages in thread

* [PATCH net-next 3/5] mlxsw: core: Add QOS_ACTION
  2020-03-19 13:47 [PATCH net-next 0/5] mlxsw: Offload TC action skbedit priority Ido Schimmel
  2020-03-19 13:47 ` [PATCH net-next 1/5] net: tc_skbedit: Factor a helper out of is_tcf_skbedit_{mark, ptype}() Ido Schimmel
  2020-03-19 13:47 ` [PATCH net-next 2/5] net: tc_skbedit: Make the skbedit priority offloadable Ido Schimmel
@ 2020-03-19 13:47 ` Ido Schimmel
  2020-03-19 13:47 ` [PATCH net-next 4/5] mlxsw: spectrum_flower: Offload FLOW_ACTION_PRIORITY Ido Schimmel
                   ` (3 subsequent siblings)
  6 siblings, 0 replies; 8+ messages in thread
From: Ido Schimmel @ 2020-03-19 13:47 UTC (permalink / raw)
  To: netdev; +Cc: davem, kuba, jiri, jhs, xiyou.wangcong, petrm, mlxsw, Ido Schimmel

From: Petr Machata <petrm@mellanox.com>

The QOS_ACTION is used for manipulating the QoS attributes of a packet.
Add the corresponding defines and helpers, in particular for the
switch_priority override.

Signed-off-by: Petr Machata <petrm@mellanox.com>
Reviewed-by: Jiri Pirko <jiri@mellanox.com>
Signed-off-by: Ido Schimmel <idosch@mellanox.com>
---
 .../mellanox/mlxsw/core_acl_flex_actions.c    | 35 +++++++++++++++++++
 1 file changed, 35 insertions(+)

diff --git a/drivers/net/ethernet/mellanox/mlxsw/core_acl_flex_actions.c b/drivers/net/ethernet/mellanox/mlxsw/core_acl_flex_actions.c
index 1f2e6db743e1..fbb76377adf8 100644
--- a/drivers/net/ethernet/mellanox/mlxsw/core_acl_flex_actions.c
+++ b/drivers/net/ethernet/mellanox/mlxsw/core_acl_flex_actions.c
@@ -1238,6 +1238,41 @@ mlxsw_afa_block_append_mirror(struct mlxsw_afa_block *block, u8 local_in_port,
 }
 EXPORT_SYMBOL(mlxsw_afa_block_append_mirror);
 
+/* QoS Action
+ * ----------
+ * The QOS_ACTION is used for manipulating the QoS attributes of a packet. It
+ * can be used to change the DCSP, ECN, Color and Switch Priority of the packet.
+ * Note that PCP field can be changed using the VLAN action.
+ */
+
+#define MLXSW_AFA_QOS_CODE 0x06
+#define MLXSW_AFA_QOS_SIZE 1
+
+enum mlxsw_afa_qos_cmd {
+	/* Do nothing */
+	MLXSW_AFA_QOS_CMD_NOP,
+	/* Set a field */
+	MLXSW_AFA_QOS_CMD_SET,
+};
+
+/* afa_qos_switch_prio_cmd
+ * Switch Priority command as per mlxsw_afa_qos_cmd.
+ */
+MLXSW_ITEM32(afa, qos, switch_prio_cmd, 0x08, 14, 2);
+
+/* afa_qos_switch_prio
+ * Switch Priority.
+ */
+MLXSW_ITEM32(afa, qos, switch_prio, 0x08, 0, 4);
+
+static inline void
+mlxsw_afa_qos_switch_prio_pack(char *payload,
+			       enum mlxsw_afa_qos_cmd prio_cmd, u8 prio)
+{
+	mlxsw_afa_qos_switch_prio_cmd_set(payload, prio_cmd);
+	mlxsw_afa_qos_switch_prio_set(payload, prio);
+}
+
 /* Forwarding Action
  * -----------------
  * Forwarding Action can be used to implement Policy Based Switching (PBS)
-- 
2.24.1


^ permalink raw reply related	[flat|nested] 8+ messages in thread

* [PATCH net-next 4/5] mlxsw: spectrum_flower: Offload FLOW_ACTION_PRIORITY
  2020-03-19 13:47 [PATCH net-next 0/5] mlxsw: Offload TC action skbedit priority Ido Schimmel
                   ` (2 preceding siblings ...)
  2020-03-19 13:47 ` [PATCH net-next 3/5] mlxsw: core: Add QOS_ACTION Ido Schimmel
@ 2020-03-19 13:47 ` Ido Schimmel
  2020-03-19 13:47 ` [PATCH net-next 5/5] selftests: forwarding: Add an skbedit priority selftest Ido Schimmel
                   ` (2 subsequent siblings)
  6 siblings, 0 replies; 8+ messages in thread
From: Ido Schimmel @ 2020-03-19 13:47 UTC (permalink / raw)
  To: netdev; +Cc: davem, kuba, jiri, jhs, xiyou.wangcong, petrm, mlxsw, Ido Schimmel

From: Petr Machata <petrm@mellanox.com>

Offload action skbedit priority when keyed to a flower classifier. The
skb->priority field in Linux is very generic, so only allow setting the
bottom 8 priorities and bounce anything else.

Signed-off-by: Petr Machata <petrm@mellanox.com>
Reviewed-by: Jiri Pirko <jiri@mellanox.com>
Signed-off-by: Ido Schimmel <idosch@mellanox.com>
---
 .../mellanox/mlxsw/core_acl_flex_actions.c     | 18 ++++++++++++++++++
 .../mellanox/mlxsw/core_acl_flex_actions.h     |  3 +++
 drivers/net/ethernet/mellanox/mlxsw/spectrum.h |  3 +++
 .../net/ethernet/mellanox/mlxsw/spectrum_acl.c | 17 +++++++++++++++++
 .../ethernet/mellanox/mlxsw/spectrum_flower.c  |  4 ++++
 5 files changed, 45 insertions(+)

diff --git a/drivers/net/ethernet/mellanox/mlxsw/core_acl_flex_actions.c b/drivers/net/ethernet/mellanox/mlxsw/core_acl_flex_actions.c
index fbb76377adf8..c713bc22da7d 100644
--- a/drivers/net/ethernet/mellanox/mlxsw/core_acl_flex_actions.c
+++ b/drivers/net/ethernet/mellanox/mlxsw/core_acl_flex_actions.c
@@ -1273,6 +1273,24 @@ mlxsw_afa_qos_switch_prio_pack(char *payload,
 	mlxsw_afa_qos_switch_prio_set(payload, prio);
 }
 
+int mlxsw_afa_block_append_qos_switch_prio(struct mlxsw_afa_block *block,
+					   u8 prio,
+					   struct netlink_ext_ack *extack)
+{
+	char *act = mlxsw_afa_block_append_action(block,
+						  MLXSW_AFA_QOS_CODE,
+						  MLXSW_AFA_QOS_SIZE);
+
+	if (IS_ERR(act)) {
+		NL_SET_ERR_MSG_MOD(extack, "Cannot append QOS action");
+		return PTR_ERR(act);
+	}
+	mlxsw_afa_qos_switch_prio_pack(act, MLXSW_AFA_QOS_CMD_SET,
+				       prio);
+	return 0;
+}
+EXPORT_SYMBOL(mlxsw_afa_block_append_qos_switch_prio);
+
 /* Forwarding Action
  * -----------------
  * Forwarding Action can be used to implement Policy Based Switching (PBS)
diff --git a/drivers/net/ethernet/mellanox/mlxsw/core_acl_flex_actions.h b/drivers/net/ethernet/mellanox/mlxsw/core_acl_flex_actions.h
index 5f4c1e505136..2125d7d6bcb0 100644
--- a/drivers/net/ethernet/mellanox/mlxsw/core_acl_flex_actions.h
+++ b/drivers/net/ethernet/mellanox/mlxsw/core_acl_flex_actions.h
@@ -62,6 +62,9 @@ int mlxsw_afa_block_append_fwd(struct mlxsw_afa_block *block,
 int mlxsw_afa_block_append_vlan_modify(struct mlxsw_afa_block *block,
 				       u16 vid, u8 pcp, u8 et,
 				       struct netlink_ext_ack *extack);
+int mlxsw_afa_block_append_qos_switch_prio(struct mlxsw_afa_block *block,
+					   u8 prio,
+					   struct netlink_ext_ack *extack);
 int mlxsw_afa_block_append_allocated_counter(struct mlxsw_afa_block *block,
 					     u32 counter_index);
 int mlxsw_afa_block_append_counter(struct mlxsw_afa_block *block,
diff --git a/drivers/net/ethernet/mellanox/mlxsw/spectrum.h b/drivers/net/ethernet/mellanox/mlxsw/spectrum.h
index 57d8c95e4f9f..bbd8bec8fee4 100644
--- a/drivers/net/ethernet/mellanox/mlxsw/spectrum.h
+++ b/drivers/net/ethernet/mellanox/mlxsw/spectrum.h
@@ -746,6 +746,9 @@ int mlxsw_sp_acl_rulei_act_vlan(struct mlxsw_sp *mlxsw_sp,
 				struct mlxsw_sp_acl_rule_info *rulei,
 				u32 action, u16 vid, u16 proto, u8 prio,
 				struct netlink_ext_ack *extack);
+int mlxsw_sp_acl_rulei_act_priority(struct mlxsw_sp *mlxsw_sp,
+				    struct mlxsw_sp_acl_rule_info *rulei,
+				    u32 prio, struct netlink_ext_ack *extack);
 int mlxsw_sp_acl_rulei_act_count(struct mlxsw_sp *mlxsw_sp,
 				 struct mlxsw_sp_acl_rule_info *rulei,
 				 struct netlink_ext_ack *extack);
diff --git a/drivers/net/ethernet/mellanox/mlxsw/spectrum_acl.c b/drivers/net/ethernet/mellanox/mlxsw/spectrum_acl.c
index 6f8d5005ff36..01324d002680 100644
--- a/drivers/net/ethernet/mellanox/mlxsw/spectrum_acl.c
+++ b/drivers/net/ethernet/mellanox/mlxsw/spectrum_acl.c
@@ -638,6 +638,23 @@ int mlxsw_sp_acl_rulei_act_vlan(struct mlxsw_sp *mlxsw_sp,
 	}
 }
 
+int mlxsw_sp_acl_rulei_act_priority(struct mlxsw_sp *mlxsw_sp,
+				    struct mlxsw_sp_acl_rule_info *rulei,
+				    u32 prio, struct netlink_ext_ack *extack)
+{
+	/* Even though both Linux and Spectrum switches support 16 priorities,
+	 * spectrum_qdisc only processes the first eight priomap elements, and
+	 * the DCB and PFC features are tied to 8 priorities as well. Therefore
+	 * bounce attempts to prioritize packets to higher priorities.
+	 */
+	if (prio >= IEEE_8021QAZ_MAX_TCS) {
+		NL_SET_ERR_MSG_MOD(extack, "Only priorities 0..7 are supported");
+		return -EINVAL;
+	}
+	return mlxsw_afa_block_append_qos_switch_prio(rulei->act_block, prio,
+						      extack);
+}
+
 int mlxsw_sp_acl_rulei_act_count(struct mlxsw_sp *mlxsw_sp,
 				 struct mlxsw_sp_acl_rule_info *rulei,
 				 struct netlink_ext_ack *extack)
diff --git a/drivers/net/ethernet/mellanox/mlxsw/spectrum_flower.c b/drivers/net/ethernet/mellanox/mlxsw/spectrum_flower.c
index 21c4b10d106c..1cb023955d8f 100644
--- a/drivers/net/ethernet/mellanox/mlxsw/spectrum_flower.c
+++ b/drivers/net/ethernet/mellanox/mlxsw/spectrum_flower.c
@@ -154,6 +154,10 @@ static int mlxsw_sp_flower_parse_actions(struct mlxsw_sp *mlxsw_sp,
 							   act->id, vid,
 							   proto, prio, extack);
 			}
+		case FLOW_ACTION_PRIORITY:
+			return mlxsw_sp_acl_rulei_act_priority(mlxsw_sp, rulei,
+							       act->priority,
+							       extack);
 		default:
 			NL_SET_ERR_MSG_MOD(extack, "Unsupported action");
 			dev_err(mlxsw_sp->bus_info->dev, "Unsupported action\n");
-- 
2.24.1


^ permalink raw reply related	[flat|nested] 8+ messages in thread

* [PATCH net-next 5/5] selftests: forwarding: Add an skbedit priority selftest
  2020-03-19 13:47 [PATCH net-next 0/5] mlxsw: Offload TC action skbedit priority Ido Schimmel
                   ` (3 preceding siblings ...)
  2020-03-19 13:47 ` [PATCH net-next 4/5] mlxsw: spectrum_flower: Offload FLOW_ACTION_PRIORITY Ido Schimmel
@ 2020-03-19 13:47 ` Ido Schimmel
  2020-03-19 22:24 ` [PATCH net-next 0/5] mlxsw: Offload TC action skbedit priority Jakub Kicinski
  2020-03-20  4:09 ` David Miller
  6 siblings, 0 replies; 8+ messages in thread
From: Ido Schimmel @ 2020-03-19 13:47 UTC (permalink / raw)
  To: netdev; +Cc: davem, kuba, jiri, jhs, xiyou.wangcong, petrm, mlxsw, Ido Schimmel

From: Petr Machata <petrm@mellanox.com>

Add a test that runs traffic through a port such that skbedit priority
action acts on it during forwarding. Test that at egress, it is classified
correctly according to the new priority at a PRIO qdisc.

Signed-off-by: Petr Machata <petrm@mellanox.com>
Signed-off-by: Ido Schimmel <idosch@mellanox.com>
---
 .../net/forwarding/skbedit_priority.sh        | 163 ++++++++++++++++++
 1 file changed, 163 insertions(+)
 create mode 100755 tools/testing/selftests/net/forwarding/skbedit_priority.sh

diff --git a/tools/testing/selftests/net/forwarding/skbedit_priority.sh b/tools/testing/selftests/net/forwarding/skbedit_priority.sh
new file mode 100755
index 000000000000..0e7693297765
--- /dev/null
+++ b/tools/testing/selftests/net/forwarding/skbedit_priority.sh
@@ -0,0 +1,163 @@
+#!/bin/bash
+# SPDX-License-Identifier: GPL-2.0
+
+# This test sends traffic from H1 to H2. Either on ingress of $swp1, or on
+# egress of $swp2, the traffic is acted upon by an action skbedit priority. The
+# new priority should be taken into account when classifying traffic on the PRIO
+# qdisc at $swp2. The test verifies that for different priority values, the
+# traffic ends up in expected PRIO band.
+#
+# +----------------------+                             +----------------------+
+# | H1                   |                             |                   H2 |
+# |    + $h1             |                             |            $h2 +     |
+# |    | 192.0.2.1/28    |                             |   192.0.2.2/28 |     |
+# +----|-----------------+                             +----------------|-----+
+#      |                                                                |
+# +----|----------------------------------------------------------------|-----+
+# | SW |                                                                |     |
+# |  +-|----------------------------------------------------------------|-+   |
+# |  | + $swp1                       BR                           $swp2 + |   |
+# |  |                                                             PRIO   |   |
+# |  +--------------------------------------------------------------------+   |
+# +---------------------------------------------------------------------------+
+
+ALL_TESTS="
+	ping_ipv4
+	test_ingress
+	test_egress
+"
+
+NUM_NETIFS=4
+source lib.sh
+
+: ${HIT_TIMEOUT:=2000} # ms
+
+h1_create()
+{
+	simple_if_init $h1 192.0.2.1/28
+}
+
+h1_destroy()
+{
+	simple_if_fini $h1 192.0.2.1/28
+}
+
+h2_create()
+{
+	simple_if_init $h2 192.0.2.2/28
+}
+
+h2_destroy()
+{
+	simple_if_fini $h2 192.0.2.2/28
+}
+
+switch_create()
+{
+	ip link add name br1 up type bridge vlan_filtering 1
+	ip link set dev $swp1 master br1
+	ip link set dev $swp1 up
+	ip link set dev $swp2 master br1
+	ip link set dev $swp2 up
+
+	tc qdisc add dev $swp1 clsact
+	tc qdisc add dev $swp2 clsact
+	tc qdisc add dev $swp2 root handle 10: \
+	   prio bands 8 priomap 7 6 5 4 3 2 1 0
+}
+
+switch_destroy()
+{
+	tc qdisc del dev $swp2 root
+	tc qdisc del dev $swp2 clsact
+	tc qdisc del dev $swp1 clsact
+
+	ip link set dev $swp2 nomaster
+	ip link set dev $swp1 nomaster
+	ip link del dev br1
+}
+
+setup_prepare()
+{
+	h1=${NETIFS[p1]}
+	swp1=${NETIFS[p2]}
+
+	swp2=${NETIFS[p3]}
+	h2=${NETIFS[p4]}
+
+	h2mac=$(mac_get $h2)
+
+	vrf_prepare
+	h1_create
+	h2_create
+	switch_create
+}
+
+cleanup()
+{
+	pre_cleanup
+
+	switch_destroy
+	h2_destroy
+	h1_destroy
+	vrf_cleanup
+}
+
+ping_ipv4()
+{
+	ping_test $h1 192.0.2.2
+}
+
+test_skbedit_priority_one()
+{
+	local locus=$1; shift
+	local prio=$1; shift
+	local classid=$1; shift
+
+	RET=0
+
+	tc filter add $locus handle 101 pref 1 \
+	   flower action skbedit priority $prio
+
+	local pkt0=$(qdisc_parent_stats_get $swp2 $classid .packets)
+	$MZ $h1 -t udp "sp=54321,dp=12345" -c 10 -d 20msec -p 100 \
+	    -a own -b $h2mac -A 192.0.2.1 -B 192.0.2.2 -q
+	local pkt1
+	pkt1=$(busywait "$HIT_TIMEOUT" until_counter_is ">= $((pkt0 + 10))" \
+			qdisc_parent_stats_get $swp2 $classid .packets)
+
+	check_err $? "Expected to get 10 packets on class $classid, but got
+$((pkt1 - pkt0))."
+	log_test "$locus skbedit priority $prio -> classid $classid"
+
+	tc filter del $locus pref 1
+}
+
+test_ingress()
+{
+	local prio
+
+	for prio in {0..7}; do
+		test_skbedit_priority_one "dev $swp1 ingress" \
+					  $prio 10:$((8 - prio))
+	done
+}
+
+test_egress()
+{
+	local prio
+
+	for prio in {0..7}; do
+		test_skbedit_priority_one "dev $swp2 egress" \
+					  $prio 10:$((8 - prio))
+	done
+}
+
+trap cleanup EXIT
+
+setup_prepare
+setup_wait
+
+tests_run
+
+exit $EXIT_STATUS
-- 
2.24.1


^ permalink raw reply related	[flat|nested] 8+ messages in thread

* Re: [PATCH net-next 0/5] mlxsw: Offload TC action skbedit priority
  2020-03-19 13:47 [PATCH net-next 0/5] mlxsw: Offload TC action skbedit priority Ido Schimmel
                   ` (4 preceding siblings ...)
  2020-03-19 13:47 ` [PATCH net-next 5/5] selftests: forwarding: Add an skbedit priority selftest Ido Schimmel
@ 2020-03-19 22:24 ` Jakub Kicinski
  2020-03-20  4:09 ` David Miller
  6 siblings, 0 replies; 8+ messages in thread
From: Jakub Kicinski @ 2020-03-19 22:24 UTC (permalink / raw)
  To: Ido Schimmel
  Cc: netdev, davem, jiri, jhs, xiyou.wangcong, petrm, mlxsw, Ido Schimmel

On Thu, 19 Mar 2020 15:47:19 +0200 Ido Schimmel wrote:
> From: Ido Schimmel <idosch@mellanox.com>
> 
> Petr says:
> 
> The TC action "skbedit priority P" has the effect of assigning skbprio of P
> to SKBs that it's applied on. In HW datapath of a switch, the corresponding
> action is assignment of internal switch priority. Spectrum switches allow
> setting of packet priority based on an ACL action, which is good match for
> the skbedit priority gadget. This patchset therefore implements offloading
> of this action to the Spectrum ACL engine.
> 
> After a bit of refactoring in patch #1, patch #2 extends the skbedit action
> to support offloading of "priority" subcommand.
> 
> On mlxsw side, in patch #3, the QOS_ACTION flexible action is added, with
> fields necessary for priority adjustment. In patch #4, "skbedit priority"
> is connected to that action.
> 
> Patch #5 implements a new forwarding selftest, suitable for both SW- and
> HW-datapath testing.

FWIW:

Reviewed-by: Jakub Kicinski <kuba@kernel.org>

^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: [PATCH net-next 0/5] mlxsw: Offload TC action skbedit priority
  2020-03-19 13:47 [PATCH net-next 0/5] mlxsw: Offload TC action skbedit priority Ido Schimmel
                   ` (5 preceding siblings ...)
  2020-03-19 22:24 ` [PATCH net-next 0/5] mlxsw: Offload TC action skbedit priority Jakub Kicinski
@ 2020-03-20  4:09 ` David Miller
  6 siblings, 0 replies; 8+ messages in thread
From: David Miller @ 2020-03-20  4:09 UTC (permalink / raw)
  To: idosch; +Cc: netdev, kuba, jiri, jhs, xiyou.wangcong, petrm, mlxsw, idosch

From: Ido Schimmel <idosch@idosch.org>
Date: Thu, 19 Mar 2020 15:47:19 +0200

> From: Ido Schimmel <idosch@mellanox.com>
> 
> Petr says:
> 
> The TC action "skbedit priority P" has the effect of assigning skbprio of P
> to SKBs that it's applied on. In HW datapath of a switch, the corresponding
> action is assignment of internal switch priority. Spectrum switches allow
> setting of packet priority based on an ACL action, which is good match for
> the skbedit priority gadget. This patchset therefore implements offloading
> of this action to the Spectrum ACL engine.
> 
> After a bit of refactoring in patch #1, patch #2 extends the skbedit action
> to support offloading of "priority" subcommand.
> 
> On mlxsw side, in patch #3, the QOS_ACTION flexible action is added, with
> fields necessary for priority adjustment. In patch #4, "skbedit priority"
> is connected to that action.
> 
> Patch #5 implements a new forwarding selftest, suitable for both SW- and
> HW-datapath testing.

Looks quite straightforward, applied, thanks.

^ permalink raw reply	[flat|nested] 8+ messages in thread

end of thread, other threads:[~2020-03-20  4:09 UTC | newest]

Thread overview: 8+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-03-19 13:47 [PATCH net-next 0/5] mlxsw: Offload TC action skbedit priority Ido Schimmel
2020-03-19 13:47 ` [PATCH net-next 1/5] net: tc_skbedit: Factor a helper out of is_tcf_skbedit_{mark, ptype}() Ido Schimmel
2020-03-19 13:47 ` [PATCH net-next 2/5] net: tc_skbedit: Make the skbedit priority offloadable Ido Schimmel
2020-03-19 13:47 ` [PATCH net-next 3/5] mlxsw: core: Add QOS_ACTION Ido Schimmel
2020-03-19 13:47 ` [PATCH net-next 4/5] mlxsw: spectrum_flower: Offload FLOW_ACTION_PRIORITY Ido Schimmel
2020-03-19 13:47 ` [PATCH net-next 5/5] selftests: forwarding: Add an skbedit priority selftest Ido Schimmel
2020-03-19 22:24 ` [PATCH net-next 0/5] mlxsw: Offload TC action skbedit priority Jakub Kicinski
2020-03-20  4:09 ` David Miller

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).