aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/net/ethernet/mellanox/mlx5/core/en/mod_hdr.c
diff options
context:
space:
mode:
authorPaul Blakey <paulb@nvidia.com>2021-08-25 16:46:41 +0300
committerSaeed Mahameed <saeedm@nvidia.com>2021-11-16 20:31:48 -0800
commit1cfd3490f2780edb3f1b2f3f64c5c80c67c64075 (patch)
tree32117ad6096c74cdb884f5cf5976584ee69b1931 /drivers/net/ethernet/mellanox/mlx5/core/en/mod_hdr.c
parentnet/mlx5e: Refactor mod header management API (diff)
downloadlinux-dev-1cfd3490f2780edb3f1b2f3f64c5c80c67c64075.tar.xz
linux-dev-1cfd3490f2780edb3f1b2f3f64c5c80c67c64075.zip
net/mlx5: CT: Allow static allocation of mod headers
As each CT rule uses at least 4 modify header actions, each rule causes at least 3 reallocations by the mod header actions api. Allow initial static allocation of the mod acts array, and use it for CT rules. If the static allocation is exceeded go back to dynamic allocation. Signed-off-by: Saeed Mahameed <saeedm@nvidia.com> Signed-off-by: Paul Blakey <paulb@nvidia.com> Reviewed-by: Oz Shlomo <ozsh@nvidia.com> Reviewed-by: Roi Dayan <roid@nvidia.com>
Diffstat (limited to 'drivers/net/ethernet/mellanox/mlx5/core/en/mod_hdr.c')
-rw-r--r--drivers/net/ethernet/mellanox/mlx5/core/en/mod_hdr.c17
1 files changed, 14 insertions, 3 deletions
diff --git a/drivers/net/ethernet/mellanox/mlx5/core/en/mod_hdr.c b/drivers/net/ethernet/mellanox/mlx5/core/en/mod_hdr.c
index 19d05fb4aab2..17325c5d6516 100644
--- a/drivers/net/ethernet/mellanox/mlx5/core/en/mod_hdr.c
+++ b/drivers/net/ethernet/mellanox/mlx5/core/en/mod_hdr.c
@@ -176,11 +176,20 @@ mlx5e_mod_hdr_alloc(struct mlx5_core_dev *mdev, int namespace,
new_sz = MLX5_MH_ACT_SZ * new_num_actions;
old_sz = mod_hdr_acts->max_actions * MLX5_MH_ACT_SZ;
- ret = krealloc(mod_hdr_acts->actions, new_sz, GFP_KERNEL);
+ if (mod_hdr_acts->is_static) {
+ ret = kzalloc(new_sz, GFP_KERNEL);
+ if (ret) {
+ memcpy(ret, mod_hdr_acts->actions, old_sz);
+ mod_hdr_acts->is_static = false;
+ }
+ } else {
+ ret = krealloc(mod_hdr_acts->actions, new_sz, GFP_KERNEL);
+ if (ret)
+ memset(ret + old_sz, 0, new_sz - old_sz);
+ }
if (!ret)
return ERR_PTR(-ENOMEM);
- memset(ret + old_sz, 0, new_sz - old_sz);
mod_hdr_acts->actions = ret;
mod_hdr_acts->max_actions = new_num_actions;
@@ -191,7 +200,9 @@ out:
void
mlx5e_mod_hdr_dealloc(struct mlx5e_tc_mod_hdr_acts *mod_hdr_acts)
{
- kfree(mod_hdr_acts->actions);
+ if (!mod_hdr_acts->is_static)
+ kfree(mod_hdr_acts->actions);
+
mod_hdr_acts->actions = NULL;
mod_hdr_acts->num_actions = 0;
mod_hdr_acts->max_actions = 0;