Blame SOURCES/0144-netdrv-net-mlx5-Allow-creating-autogroups-with-reser.patch

d8f823
From be97eb6496043414729200bb083deda814c7d33d Mon Sep 17 00:00:00 2001
d8f823
From: Alaa Hleihel <ahleihel@redhat.com>
d8f823
Date: Tue, 12 May 2020 10:54:04 -0400
d8f823
Subject: [PATCH 144/312] [netdrv] net/mlx5: Allow creating autogroups with
d8f823
 reserved entries
d8f823
d8f823
Message-id: <20200512105530.4207-39-ahleihel@redhat.com>
d8f823
Patchwork-id: 306911
d8f823
Patchwork-instance: patchwork
d8f823
O-Subject: [RHEL8.3 BZ 1789382 038/124] net/mlx5: Allow creating autogroups with reserved entries
d8f823
Bugzilla: 1789382
d8f823
RH-Acked-by: Tony Camuso <tcamuso@redhat.com>
d8f823
RH-Acked-by: Kamal Heib <kheib@redhat.com>
d8f823
RH-Acked-by: Jarod Wilson <jarod@redhat.com>
d8f823
d8f823
Bugzilla: http://bugzilla.redhat.com/1789382
d8f823
Upstream: v5.6-rc1
d8f823
d8f823
commit 79cdb0aaea8b5478db34afa1d4d5ecc808689a67
d8f823
Author: Paul Blakey <paulb@mellanox.com>
d8f823
Date:   Thu Nov 14 17:02:59 2019 +0200
d8f823
d8f823
    net/mlx5: Allow creating autogroups with reserved entries
d8f823
d8f823
    Exclude the last n entries for an autogrouped flow table.
d8f823
d8f823
    Reserving entries at the end of the FT will ensure that this FG will be
d8f823
    the last to be evaluated. This will be used in the next patch to create
d8f823
    a miss group enabling custom actions on FT miss.
d8f823
d8f823
    Signed-off-by: Paul Blakey <paulb@mellanox.com>
d8f823
    Reviewed-by: Roi Dayan <roid@mellanox.com>
d8f823
    Reviewed-by: Oz Shlomo <ozsh@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/fs_core.c | 26 +++++++++++++++--------
d8f823
 drivers/net/ethernet/mellanox/mlx5/core/fs_core.h |  3 +++
d8f823
 include/linux/mlx5/fs.h                           |  3 +++
d8f823
 3 files changed, 23 insertions(+), 9 deletions(-)
d8f823
d8f823
diff --git a/drivers/net/ethernet/mellanox/mlx5/core/fs_core.c b/drivers/net/ethernet/mellanox/mlx5/core/fs_core.c
d8f823
index 2f6c8890f25e..4c7c707f9e2d 100644
d8f823
--- a/drivers/net/ethernet/mellanox/mlx5/core/fs_core.c
d8f823
+++ b/drivers/net/ethernet/mellanox/mlx5/core/fs_core.c
d8f823
@@ -579,7 +579,9 @@ static void del_sw_flow_group(struct fs_node *node)
d8f823
 
d8f823
 	rhashtable_destroy(&fg->ftes_hash);
d8f823
 	ida_destroy(&fg->fte_allocator);
d8f823
-	if (ft->autogroup.active && fg->max_ftes == ft->autogroup.group_size)
d8f823
+	if (ft->autogroup.active &&
d8f823
+	    fg->max_ftes == ft->autogroup.group_size &&
d8f823
+	    fg->start_index < ft->autogroup.max_fte)
d8f823
 		ft->autogroup.num_groups--;
d8f823
 	err = rhltable_remove(&ft->fgs_hash,
d8f823
 			      &fg->hash,
d8f823
@@ -1121,9 +1123,14 @@ struct mlx5_flow_table*
d8f823
 mlx5_create_auto_grouped_flow_table_attr_(struct mlx5_flow_namespace *ns,
d8f823
 					  struct mlx5_flow_table_attr *ft_attr)
d8f823
 {
d8f823
+	int num_reserved_entries = ft_attr->autogroup.num_reserved_entries;
d8f823
+	int autogroups_max_fte = ft_attr->max_fte - num_reserved_entries;
d8f823
+	int max_num_groups = ft_attr->autogroup.max_num_groups;
d8f823
 	struct mlx5_flow_table *ft;
d8f823
 
d8f823
-	if (ft_attr->autogroup.max_num_groups > ft_attr->max_fte)
d8f823
+	if (max_num_groups > autogroups_max_fte)
d8f823
+		return ERR_PTR(-EINVAL);
d8f823
+	if (num_reserved_entries > ft_attr->max_fte)
d8f823
 		return ERR_PTR(-EINVAL);
d8f823
 
d8f823
 	ft = mlx5_create_flow_table(ns, ft_attr);
d8f823
@@ -1131,10 +1138,10 @@ mlx5_create_auto_grouped_flow_table_attr_(struct mlx5_flow_namespace *ns,
d8f823
 		return ft;
d8f823
 
d8f823
 	ft->autogroup.active = true;
d8f823
-	ft->autogroup.required_groups = ft_attr->autogroup.max_num_groups;
d8f823
+	ft->autogroup.required_groups = max_num_groups;
d8f823
+	ft->autogroup.max_fte = autogroups_max_fte;
d8f823
 	/* We save place for flow groups in addition to max types */
d8f823
-	ft->autogroup.group_size = ft->max_fte /
d8f823
-				   (ft->autogroup.required_groups + 1);
d8f823
+	ft->autogroup.group_size = autogroups_max_fte / (max_num_groups + 1);
d8f823
 
d8f823
 	return ft;
d8f823
 }
d8f823
@@ -1175,7 +1182,7 @@ struct mlx5_flow_group *mlx5_create_flow_group(struct mlx5_flow_table *ft,
d8f823
 	struct mlx5_flow_group *fg;
d8f823
 	int err;
d8f823
 
d8f823
-	if (ft->autogroup.active)
d8f823
+	if (ft->autogroup.active && start_index < ft->autogroup.max_fte)
d8f823
 		return ERR_PTR(-EPERM);
d8f823
 
d8f823
 	down_write_ref_node(&ft->node, false);
d8f823
@@ -1348,9 +1355,10 @@ static struct mlx5_flow_group *alloc_auto_flow_group(struct mlx5_flow_table  *ft
d8f823
 						     const struct mlx5_flow_spec *spec)
d8f823
 {
d8f823
 	struct list_head *prev = &ft->node.children;
d8f823
-	struct mlx5_flow_group *fg;
d8f823
+	u32 max_fte = ft->autogroup.max_fte;
d8f823
 	unsigned int candidate_index = 0;
d8f823
 	unsigned int group_size = 0;
d8f823
+	struct mlx5_flow_group *fg;
d8f823
 
d8f823
 	if (!ft->autogroup.active)
d8f823
 		return ERR_PTR(-ENOENT);
d8f823
@@ -1358,7 +1366,7 @@ static struct mlx5_flow_group *alloc_auto_flow_group(struct mlx5_flow_table  *ft
d8f823
 	if (ft->autogroup.num_groups < ft->autogroup.required_groups)
d8f823
 		group_size = ft->autogroup.group_size;
d8f823
 
d8f823
-	/*  ft->max_fte == ft->autogroup.max_types */
d8f823
+	/*  max_fte == ft->autogroup.max_types */
d8f823
 	if (group_size == 0)
d8f823
 		group_size = 1;
d8f823
 
d8f823
@@ -1371,7 +1379,7 @@ static struct mlx5_flow_group *alloc_auto_flow_group(struct mlx5_flow_table  *ft
d8f823
 		prev = &fg->node.list;
d8f823
 	}
d8f823
 
d8f823
-	if (candidate_index + group_size > ft->max_fte)
d8f823
+	if (candidate_index + group_size > max_fte)
d8f823
 		return ERR_PTR(-ENOSPC);
d8f823
 
d8f823
 	fg = alloc_insert_flow_group(ft,
d8f823
diff --git a/drivers/net/ethernet/mellanox/mlx5/core/fs_core.h b/drivers/net/ethernet/mellanox/mlx5/core/fs_core.h
d8f823
index c6221ccbdddf..20f54e53dd01 100644
d8f823
--- a/drivers/net/ethernet/mellanox/mlx5/core/fs_core.h
d8f823
+++ b/drivers/net/ethernet/mellanox/mlx5/core/fs_core.h
d8f823
@@ -164,6 +164,9 @@ struct mlx5_flow_table {
d8f823
 		unsigned int		required_groups;
d8f823
 		unsigned int		group_size;
d8f823
 		unsigned int		num_groups;
d8f823
+#ifndef __GENKSYMS__
d8f823
+		unsigned int		max_fte;
d8f823
+#endif
d8f823
 	} autogroup;
d8f823
 	/* Protect fwd_rules */
d8f823
 	struct mutex			lock;
d8f823
diff --git a/include/linux/mlx5/fs.h b/include/linux/mlx5/fs.h
d8f823
index 5649a8a70c2e..b918d9724fc2 100644
d8f823
--- a/include/linux/mlx5/fs.h
d8f823
+++ b/include/linux/mlx5/fs.h
d8f823
@@ -165,6 +165,9 @@ struct mlx5_flow_table_attr {
d8f823
 
d8f823
 	struct {
d8f823
 		int max_num_groups;
d8f823
+#ifndef __GENKSYMS__
d8f823
+		int num_reserved_entries;
d8f823
+#endif
d8f823
 	} autogroup;
d8f823
 };
d8f823
 
d8f823
-- 
d8f823
2.13.6
d8f823