Blame SOURCES/0213-netdrv-net-mlx5-ft-Check-prio-and-chain-sanity-for-f.patch

d8f823
From 54d02b39369e78ccdc913277f36d16b337d08437 Mon Sep 17 00:00:00 2001
d8f823
From: Alaa Hleihel <ahleihel@redhat.com>
d8f823
Date: Tue, 19 May 2020 07:48:34 -0400
d8f823
Subject: [PATCH 213/312] [netdrv] net/mlx5: ft: Check prio and chain sanity
d8f823
 for ft offload
d8f823
d8f823
Message-id: <20200519074934.6303-4-ahleihel@redhat.com>
d8f823
Patchwork-id: 310509
d8f823
Patchwork-instance: patchwork
d8f823
O-Subject: [RHEL8.3 BZ 1663246 03/63] net/mlx5: ft: Check prio and chain sanity for ft offload
d8f823
Bugzilla: 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
Upstream: v5.6-rc1
d8f823
d8f823
commit 82270e12544ee76ea9a3117a769a6d466a2e646b
d8f823
Author: Paul Blakey <paulb@mellanox.com>
d8f823
Date:   Tue Nov 26 14:15:00 2019 +0200
d8f823
d8f823
    net/mlx5: ft: Check prio and chain sanity for ft offload
d8f823
d8f823
    Before changing the chain from original chain to ft offload chain,
d8f823
    make sure user doesn't actually use chains.
d8f823
d8f823
    While here, normalize the prio range to that which we support.
d8f823
d8f823
    Signed-off-by: Paul Blakey <paulb@mellanox.com>
d8f823
    Reviewed-by: Roi Dayan <roid@mellanox.com>
d8f823
    Reviewed-by: Mark Bloch <markb@mellanox.com>
d8f823
    Signed-off-by: Saeed Mahameed <saeedm@mellanox.com>
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_rep.c | 27 ++++++++++++++++++------
d8f823
 1 file changed, 20 insertions(+), 7 deletions(-)
d8f823
d8f823
diff --git a/drivers/net/ethernet/mellanox/mlx5/core/en_rep.c b/drivers/net/ethernet/mellanox/mlx5/core/en_rep.c
d8f823
index 406fb642f2d4..bde634ca85d0 100644
d8f823
--- a/drivers/net/ethernet/mellanox/mlx5/core/en_rep.c
d8f823
+++ b/drivers/net/ethernet/mellanox/mlx5/core/en_rep.c
d8f823
@@ -1223,8 +1223,7 @@ static int mlx5e_rep_setup_tc_cb(enum tc_setup_type type, void *type_data,
d8f823
 static int mlx5e_rep_setup_ft_cb(enum tc_setup_type type, void *type_data,
d8f823
 				 void *cb_priv)
d8f823
 {
d8f823
-	struct flow_cls_offload *f = type_data;
d8f823
-	struct flow_cls_offload cls_flower;
d8f823
+	struct flow_cls_offload tmp, *f = type_data;
d8f823
 	struct mlx5e_priv *priv = cb_priv;
d8f823
 	struct mlx5_eswitch *esw;
d8f823
 	unsigned long flags;
d8f823
@@ -1237,16 +1236,30 @@ static int mlx5e_rep_setup_ft_cb(enum tc_setup_type type, void *type_data,
d8f823
 
d8f823
 	switch (type) {
d8f823
 	case TC_SETUP_CLSFLOWER:
d8f823
-		if (!mlx5_eswitch_prios_supported(esw) || f->common.chain_index)
d8f823
+		memcpy(&tmp, f, sizeof(*f));
d8f823
+
d8f823
+		if (!mlx5_eswitch_prios_supported(esw) ||
d8f823
+		    tmp.common.chain_index)
d8f823
 			return -EOPNOTSUPP;
d8f823
 
d8f823
 		/* Re-use tc offload path by moving the ft flow to the
d8f823
 		 * reserved ft chain.
d8f823
+		 *
d8f823
+		 * FT offload can use prio range [0, INT_MAX], so we
d8f823
+		 * normalize it to range [1, mlx5_eswitch_get_prio_range(esw)]
d8f823
+		 * as with tc, where prio 0 isn't supported.
d8f823
+		 *
d8f823
+		 * We only support chain 0 of FT offload.
d8f823
 		 */
d8f823
-		memcpy(&cls_flower, f, sizeof(*f));
d8f823
-		cls_flower.common.chain_index = mlx5_eswitch_get_ft_chain(esw);
d8f823
-		err = mlx5e_rep_setup_tc_cls_flower(priv, &cls_flower, flags);
d8f823
-		memcpy(&f->stats, &cls_flower.stats, sizeof(f->stats));
d8f823
+		if (tmp.common.prio >= mlx5_eswitch_get_prio_range(esw))
d8f823
+			return -EOPNOTSUPP;
d8f823
+		if (tmp.common.chain_index != 0)
d8f823
+			return -EOPNOTSUPP;
d8f823
+
d8f823
+		tmp.common.chain_index = mlx5_eswitch_get_ft_chain(esw);
d8f823
+		tmp.common.prio++;
d8f823
+		err = mlx5e_rep_setup_tc_cls_flower(priv, &tmp, flags);
d8f823
+		memcpy(&f->stats, &tmp.stats, sizeof(f->stats));
d8f823
 		return err;
d8f823
 	default:
d8f823
 		return -EOPNOTSUPP;
d8f823
-- 
d8f823
2.13.6
d8f823