Blame SOURCES/0245-netdrv-net-mlx5e-CT-Handle-misses-after-executing-CT.patch

d8f823
From 14ce1ac023ad7ab9a3db5f1a1158f5c341a26361 Mon Sep 17 00:00:00 2001
d8f823
From: Alaa Hleihel <ahleihel@redhat.com>
d8f823
Date: Tue, 19 May 2020 07:49:07 -0400
d8f823
Subject: [PATCH 245/312] [netdrv] net/mlx5e: CT: Handle misses after executing
d8f823
 CT action
d8f823
d8f823
Message-id: <20200519074934.6303-37-ahleihel@redhat.com>
d8f823
Patchwork-id: 310556
d8f823
Patchwork-instance: patchwork
d8f823
O-Subject: [RHEL8.3 BZ 1663246 36/63] net/mlx5e: CT: Handle misses after executing CT action
d8f823
Bugzilla: 1790219 1663246
d8f823
RH-Acked-by: Marcelo Leitner <mleitner@redhat.com>
d8f823
RH-Acked-by: Jarod Wilson <jarod@redhat.com>
d8f823
RH-Acked-by: John Linville <linville@redhat.com>
d8f823
RH-Acked-by: Ivan Vecera <ivecera@redhat.com>
d8f823
RH-Acked-by: Tony Camuso <tcamuso@redhat.com>
d8f823
RH-Acked-by: Kamal Heib <kheib@redhat.com>
d8f823
d8f823
Bugzilla: http://bugzilla.redhat.com/1663246
d8f823
Bugzilla: http://bugzilla.redhat.com/1790219
d8f823
Upstream: v5.7-rc1
d8f823
d8f823
commit 5c6b9460474464c37c2d56df9e4c7044a042888b
d8f823
Author: Paul Blakey <paulb@mellanox.com>
d8f823
Date:   Thu Mar 12 12:23:16 2020 +0200
d8f823
d8f823
    net/mlx5e: CT: Handle misses after executing CT action
d8f823
d8f823
    Mark packets with a unique tupleid, and on miss use that id to get
d8f823
    the act ct restore_cookie. Using that restore cookie, we ask CT to
d8f823
    restore the relevant info on the SKB.
d8f823
d8f823
    Signed-off-by: Paul Blakey <paulb@mellanox.com>
d8f823
    Reviewed-by: Oz Shlomo <ozsh@mellanox.com>
d8f823
    Reviewed-by: Roi Dayan <roid@mellanox.com>
d8f823
    Signed-off-by: David S. Miller <davem@davemloft.net>
d8f823
d8f823
Signed-off-by: Alaa Hleihel <ahleihel@redhat.com>
d8f823
Signed-off-by: Frantisek Hrbata <fhrbata@redhat.com>
d8f823
---
d8f823
 drivers/net/ethernet/mellanox/mlx5/core/en/tc_ct.c | 59 ++++++++++++++++++++--
d8f823
 drivers/net/ethernet/mellanox/mlx5/core/en/tc_ct.h | 25 +++++++++
d8f823
 drivers/net/ethernet/mellanox/mlx5/core/en_tc.c    | 12 ++++-
d8f823
 drivers/net/ethernet/mellanox/mlx5/core/en_tc.h    |  1 +
d8f823
 4 files changed, 92 insertions(+), 5 deletions(-)
d8f823
d8f823
diff --git a/drivers/net/ethernet/mellanox/mlx5/core/en/tc_ct.c b/drivers/net/ethernet/mellanox/mlx5/core/en/tc_ct.c
d8f823
index e9826e379aca..c75dc97fd3a7 100644
d8f823
--- a/drivers/net/ethernet/mellanox/mlx5/core/en/tc_ct.c
d8f823
+++ b/drivers/net/ethernet/mellanox/mlx5/core/en/tc_ct.c
d8f823
@@ -35,6 +35,7 @@ struct mlx5_tc_ct_priv {
d8f823
 	struct mlx5_eswitch *esw;
d8f823
 	const struct net_device *netdev;
d8f823
 	struct idr fte_ids;
d8f823
+	struct idr tuple_ids;
d8f823
 	struct rhashtable zone_ht;
d8f823
 	struct mlx5_flow_table *ct;
d8f823
 	struct mlx5_flow_table *ct_nat;
d8f823
@@ -55,6 +56,7 @@ struct mlx5_ct_flow {
d8f823
 struct mlx5_ct_zone_rule {
d8f823
 	struct mlx5_flow_handle *rule;
d8f823
 	struct mlx5_esw_flow_attr attr;
d8f823
+	int tupleid;
d8f823
 	bool nat;
d8f823
 };
d8f823
 
d8f823
@@ -76,6 +78,7 @@ struct mlx5_ct_entry {
d8f823
 	struct mlx5_fc *counter;
d8f823
 	unsigned long lastuse;
d8f823
 	unsigned long cookie;
d8f823
+	unsigned long restore_cookie;
d8f823
 	struct mlx5_ct_zone_rule zone_rules[2];
d8f823
 };
d8f823
 
d8f823
@@ -237,6 +240,7 @@ mlx5_tc_ct_entry_del_rule(struct mlx5_tc_ct_priv *ct_priv,
d8f823
 
d8f823
 	mlx5_eswitch_del_offloaded_rule(esw, zone_rule->rule, attr);
d8f823
 	mlx5_modify_header_dealloc(esw->dev, attr->modify_hdr);
d8f823
+	idr_remove(&ct_priv->tuple_ids, zone_rule->tupleid);
d8f823
 }
d8f823
 
d8f823
 static void
d8f823
@@ -269,7 +273,8 @@ mlx5_tc_ct_entry_set_registers(struct mlx5_tc_ct_priv *ct_priv,
d8f823
 			       struct mlx5e_tc_mod_hdr_acts *mod_acts,
d8f823
 			       u8 ct_state,
d8f823
 			       u32 mark,
d8f823
-			       u32 label)
d8f823
+			       u32 label,
d8f823
+			       u32 tupleid)
d8f823
 {
d8f823
 	struct mlx5_eswitch *esw = ct_priv->esw;
d8f823
 	int err;
d8f823
@@ -289,6 +294,11 @@ mlx5_tc_ct_entry_set_registers(struct mlx5_tc_ct_priv *ct_priv,
d8f823
 	if (err)
d8f823
 		return err;
d8f823
 
d8f823
+	err = mlx5e_tc_match_to_reg_set(esw->dev, mod_acts,
d8f823
+					TUPLEID_TO_REG, tupleid);
d8f823
+	if (err)
d8f823
+		return err;
d8f823
+
d8f823
 	return 0;
d8f823
 }
d8f823
 
d8f823
@@ -412,6 +422,7 @@ static int
d8f823
 mlx5_tc_ct_entry_create_mod_hdr(struct mlx5_tc_ct_priv *ct_priv,
d8f823
 				struct mlx5_esw_flow_attr *attr,
d8f823
 				struct flow_rule *flow_rule,
d8f823
+				u32 tupleid,
d8f823
 				bool nat)
d8f823
 {
d8f823
 	struct mlx5e_tc_mod_hdr_acts mod_acts = {};
d8f823
@@ -442,7 +453,8 @@ mlx5_tc_ct_entry_create_mod_hdr(struct mlx5_tc_ct_priv *ct_priv,
d8f823
 					     (MLX5_CT_STATE_ESTABLISHED_BIT |
d8f823
 					      MLX5_CT_STATE_TRK_BIT),
d8f823
 					     meta->ct_metadata.mark,
d8f823
-					     meta->ct_metadata.labels[0]);
d8f823
+					     meta->ct_metadata.labels[0],
d8f823
+					     tupleid);
d8f823
 	if (err)
d8f823
 		goto err_mapping;
d8f823
 
d8f823
@@ -473,15 +485,27 @@ mlx5_tc_ct_entry_add_rule(struct mlx5_tc_ct_priv *ct_priv,
d8f823
 	struct mlx5_esw_flow_attr *attr = &zone_rule->attr;
d8f823
 	struct mlx5_eswitch *esw = ct_priv->esw;
d8f823
 	struct mlx5_flow_spec spec = {};
d8f823
+	u32 tupleid = 1;
d8f823
 	int err;
d8f823
 
d8f823
 	zone_rule->nat = nat;
d8f823
 
d8f823
-	err = mlx5_tc_ct_entry_create_mod_hdr(ct_priv, attr, flow_rule, nat);
d8f823
+	/* Get tuple unique id */
d8f823
+	err = idr_alloc_u32(&ct_priv->tuple_ids, zone_rule, &tupleid,
d8f823
+			    TUPLE_ID_MAX, GFP_KERNEL);
d8f823
 	if (err) {
d8f823
-		ct_dbg("Failed to create ct entry mod hdr");
d8f823
+		netdev_warn(ct_priv->netdev,
d8f823
+			    "Failed to allocate tuple id, err: %d\n", err);
d8f823
 		return err;
d8f823
 	}
d8f823
+	zone_rule->tupleid = tupleid;
d8f823
+
d8f823
+	err = mlx5_tc_ct_entry_create_mod_hdr(ct_priv, attr, flow_rule,
d8f823
+					      tupleid, nat);
d8f823
+	if (err) {
d8f823
+		ct_dbg("Failed to create ct entry mod hdr");
d8f823
+		goto err_mod_hdr;
d8f823
+	}
d8f823
 
d8f823
 	attr->action = MLX5_FLOW_CONTEXT_ACTION_MOD_HDR |
d8f823
 		       MLX5_FLOW_CONTEXT_ACTION_FWD_DEST |
d8f823
@@ -511,6 +535,8 @@ mlx5_tc_ct_entry_add_rule(struct mlx5_tc_ct_priv *ct_priv,
d8f823
 
d8f823
 err_rule:
d8f823
 	mlx5_modify_header_dealloc(esw->dev, attr->modify_hdr);
d8f823
+err_mod_hdr:
d8f823
+	idr_remove(&ct_priv->tuple_ids, zone_rule->tupleid);
d8f823
 	return err;
d8f823
 }
d8f823
 
d8f823
@@ -573,6 +599,7 @@ mlx5_tc_ct_block_flow_offload_add(struct mlx5_ct_ft *ft,
d8f823
 	entry->zone = ft->zone;
d8f823
 	entry->flow_rule = flow_rule;
d8f823
 	entry->cookie = flow->cookie;
d8f823
+	entry->restore_cookie = meta_action->ct_metadata.cookie;
d8f823
 
d8f823
 	err = mlx5_tc_ct_entry_add_rules(ct_priv, flow_rule, entry);
d8f823
 	if (err)
d8f823
@@ -1188,6 +1215,7 @@ mlx5_tc_ct_init(struct mlx5_rep_uplink_priv *uplink_priv)
d8f823
 	}
d8f823
 
d8f823
 	idr_init(&ct_priv->fte_ids);
d8f823
+	idr_init(&ct_priv->tuple_ids);
d8f823
 	mutex_init(&ct_priv->control_lock);
d8f823
 	rhashtable_init(&ct_priv->zone_ht, &zone_params);
d8f823
 
d8f823
@@ -1222,8 +1250,31 @@ mlx5_tc_ct_clean(struct mlx5_rep_uplink_priv *uplink_priv)
d8f823
 
d8f823
 	rhashtable_destroy(&ct_priv->zone_ht);
d8f823
 	mutex_destroy(&ct_priv->control_lock);
d8f823
+	idr_destroy(&ct_priv->tuple_ids);
d8f823
 	idr_destroy(&ct_priv->fte_ids);
d8f823
 	kfree(ct_priv);
d8f823
 
d8f823
 	uplink_priv->ct_priv = NULL;
d8f823
 }
d8f823
+
d8f823
+bool
d8f823
+mlx5e_tc_ct_restore_flow(struct mlx5_rep_uplink_priv *uplink_priv,
d8f823
+			 struct sk_buff *skb, u32 tupleid)
d8f823
+{
d8f823
+	struct mlx5_tc_ct_priv *ct_priv = uplink_priv->ct_priv;
d8f823
+	struct mlx5_ct_zone_rule *zone_rule;
d8f823
+	struct mlx5_ct_entry *entry;
d8f823
+
d8f823
+	if (!ct_priv || !tupleid)
d8f823
+		return true;
d8f823
+
d8f823
+	zone_rule = idr_find(&ct_priv->tuple_ids, tupleid);
d8f823
+	if (!zone_rule)
d8f823
+		return false;
d8f823
+
d8f823
+	entry = container_of(zone_rule, struct mlx5_ct_entry,
d8f823
+			     zone_rules[zone_rule->nat]);
d8f823
+	tcf_ct_flow_table_restore_skb(skb, entry->restore_cookie);
d8f823
+
d8f823
+	return true;
d8f823
+}
d8f823
diff --git a/drivers/net/ethernet/mellanox/mlx5/core/en/tc_ct.h b/drivers/net/ethernet/mellanox/mlx5/core/en/tc_ct.h
d8f823
index f4bfda77f01a..464c86595309 100644
d8f823
--- a/drivers/net/ethernet/mellanox/mlx5/core/en/tc_ct.h
d8f823
+++ b/drivers/net/ethernet/mellanox/mlx5/core/en/tc_ct.h
d8f823
@@ -64,6 +64,17 @@ struct mlx5_ct_attr {
d8f823
 				 misc_parameters_2.metadata_reg_c_5),\
d8f823
 }
d8f823
 
d8f823
+#define tupleid_to_reg_ct {\
d8f823
+	.mfield = MLX5_ACTION_IN_FIELD_METADATA_REG_C_1,\
d8f823
+	.moffset = 0,\
d8f823
+	.mlen = 3,\
d8f823
+	.soffset = MLX5_BYTE_OFF(fte_match_param,\
d8f823
+				 misc_parameters_2.metadata_reg_c_1),\
d8f823
+}
d8f823
+
d8f823
+#define TUPLE_ID_BITS (mlx5e_tc_attr_to_reg_mappings[TUPLEID_TO_REG].mlen * 8)
d8f823
+#define TUPLE_ID_MAX GENMASK(TUPLE_ID_BITS - 1, 0)
d8f823
+
d8f823
 #if IS_ENABLED(CONFIG_MLX5_TC_CT)
d8f823
 
d8f823
 int
d8f823
@@ -92,6 +103,10 @@ mlx5_tc_ct_delete_flow(struct mlx5e_priv *priv,
d8f823
 		       struct mlx5e_tc_flow *flow,
d8f823
 		       struct mlx5_esw_flow_attr *attr);
d8f823
 
d8f823
+bool
d8f823
+mlx5e_tc_ct_restore_flow(struct mlx5_rep_uplink_priv *uplink_priv,
d8f823
+			 struct sk_buff *skb, u32 tupleid);
d8f823
+
d8f823
 #else /* CONFIG_MLX5_TC_CT */
d8f823
 
d8f823
 static inline int
d8f823
@@ -139,5 +154,15 @@ mlx5_tc_ct_delete_flow(struct mlx5e_priv *priv,
d8f823
 {
d8f823
 }
d8f823
 
d8f823
+static inline bool
d8f823
+mlx5e_tc_ct_restore_flow(struct mlx5_rep_uplink_priv *uplink_priv,
d8f823
+			 struct sk_buff *skb, u32 tupleid)
d8f823
+{
d8f823
+	if  (!tupleid)
d8f823
+		return  true;
d8f823
+
d8f823
+	return false;
d8f823
+}
d8f823
+
d8f823
 #endif /* !IS_ENABLED(CONFIG_MLX5_TC_CT) */
d8f823
 #endif /* __MLX5_EN_TC_CT_H__ */
d8f823
diff --git a/drivers/net/ethernet/mellanox/mlx5/core/en_tc.c b/drivers/net/ethernet/mellanox/mlx5/core/en_tc.c
d8f823
index 3e15cb4992a6..f88b199487d2 100644
d8f823
--- a/drivers/net/ethernet/mellanox/mlx5/core/en_tc.c
d8f823
+++ b/drivers/net/ethernet/mellanox/mlx5/core/en_tc.c
d8f823
@@ -200,6 +200,7 @@ struct mlx5e_tc_attr_to_reg_mapping mlx5e_tc_attr_to_reg_mappings[] = {
d8f823
 	[MARK_TO_REG] = mark_to_reg_ct,
d8f823
 	[LABELS_TO_REG] = labels_to_reg_ct,
d8f823
 	[FTEID_TO_REG] = fteid_to_reg_ct,
d8f823
+	[TUPLEID_TO_REG] = tupleid_to_reg_ct,
d8f823
 };
d8f823
 
d8f823
 static void mlx5e_put_flow_tunnel_id(struct mlx5e_tc_flow *flow);
d8f823
@@ -4846,7 +4847,9 @@ bool mlx5e_tc_rep_update_skb(struct mlx5_cqe64 *cqe,
d8f823
 			     struct mlx5e_tc_update_priv *tc_priv)
d8f823
 {
d8f823
 #if IS_ENABLED(CONFIG_NET_TC_SKB_EXT)
d8f823
-	u32 chain = 0, reg_c0, reg_c1, tunnel_id;
d8f823
+	u32 chain = 0, reg_c0, reg_c1, tunnel_id, tuple_id;
d8f823
+	struct mlx5_rep_uplink_priv *uplink_priv;
d8f823
+	struct mlx5e_rep_priv *uplink_rpriv;
d8f823
 	struct tc_skb_ext *tc_skb_ext;
d8f823
 	struct mlx5_eswitch *esw;
d8f823
 	struct mlx5e_priv *priv;
d8f823
@@ -4880,6 +4883,13 @@ bool mlx5e_tc_rep_update_skb(struct mlx5_cqe64 *cqe,
d8f823
 		}
d8f823
 
d8f823
 		tc_skb_ext->chain = chain;
d8f823
+
d8f823
+		tuple_id = reg_c1 & TUPLE_ID_MAX;
d8f823
+
d8f823
+		uplink_rpriv = mlx5_eswitch_get_uplink_priv(esw, REP_ETH);
d8f823
+		uplink_priv = &uplink_rpriv->uplink_priv;
d8f823
+		if (!mlx5e_tc_ct_restore_flow(uplink_priv, skb, tuple_id))
d8f823
+			return false;
d8f823
 	}
d8f823
 
d8f823
 	tunnel_moffset = mlx5e_tc_attr_to_reg_mappings[TUNNEL_TO_REG].moffset;
d8f823
diff --git a/drivers/net/ethernet/mellanox/mlx5/core/en_tc.h b/drivers/net/ethernet/mellanox/mlx5/core/en_tc.h
d8f823
index 31c9e81b9287..abdcfa4c4e0e 100644
d8f823
--- a/drivers/net/ethernet/mellanox/mlx5/core/en_tc.h
d8f823
+++ b/drivers/net/ethernet/mellanox/mlx5/core/en_tc.h
d8f823
@@ -99,6 +99,7 @@ enum mlx5e_tc_attr_to_reg {
d8f823
 	MARK_TO_REG,
d8f823
 	LABELS_TO_REG,
d8f823
 	FTEID_TO_REG,
d8f823
+	TUPLEID_TO_REG,
d8f823
 };
d8f823
 
d8f823
 struct mlx5e_tc_attr_to_reg_mapping {
d8f823
-- 
d8f823
2.13.6
d8f823