From: Saeed Mahameed <saeed@kernel.org>
To: "David S. Miller" <davem@davemloft.net>,
Jakub Kicinski <kuba@kernel.org>
Cc: netdev@vger.kernel.org, Paul Blakey <paulb@nvidia.com>,
Saeed Mahameed <saeedm@nvidia.com>, Oz Shlomo <ozsh@nvidia.com>,
Roi Dayan <roid@nvidia.com>
Subject: [net-next v0 05/15] net/mlx5: CT: Allow static allocation of mod headers
Date: Tue, 16 Nov 2021 20:33:47 -0800 [thread overview]
Message-ID: <20211117043357.345072-6-saeed@kernel.org> (raw)
In-Reply-To: <20211117043357.345072-1-saeed@kernel.org>
From: Paul Blakey <paulb@nvidia.com>
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>
---
.../ethernet/mellanox/mlx5/core/en/mod_hdr.c | 17 ++++++++++++++---
.../ethernet/mellanox/mlx5/core/en/mod_hdr.h | 13 +++++++++++++
.../net/ethernet/mellanox/mlx5/core/en/tc_ct.c | 9 ++++++++-
3 files changed, 35 insertions(+), 4 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 @@ mlx5e_mod_hdr_alloc(struct mlx5_core_dev *mdev, int namespace,
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;
diff --git a/drivers/net/ethernet/mellanox/mlx5/core/en/mod_hdr.h b/drivers/net/ethernet/mellanox/mlx5/core/en/mod_hdr.h
index b8cd1a7a31be..b8dac418d0a5 100644
--- a/drivers/net/ethernet/mellanox/mlx5/core/en/mod_hdr.h
+++ b/drivers/net/ethernet/mellanox/mlx5/core/en/mod_hdr.h
@@ -7,14 +7,27 @@
#include <linux/hashtable.h>
#include <linux/mlx5/fs.h>
+#define MLX5_MH_ACT_SZ MLX5_UN_SZ_BYTES(set_add_copy_action_in_auto)
+
struct mlx5e_mod_hdr_handle;
struct mlx5e_tc_mod_hdr_acts {
int num_actions;
int max_actions;
+ bool is_static;
void *actions;
};
+#define DECLARE_MOD_HDR_ACTS_ACTIONS(name, len) \
+ u8 name[len][MLX5_MH_ACT_SZ] = {}
+
+#define DECLARE_MOD_HDR_ACTS(name, acts_arr) \
+ struct mlx5e_tc_mod_hdr_acts name = { \
+ .max_actions = ARRAY_SIZE(acts_arr), \
+ .is_static = true, \
+ .actions = acts_arr, \
+ }
+
char *mlx5e_mod_hdr_alloc(struct mlx5_core_dev *mdev, int namespace,
struct mlx5e_tc_mod_hdr_acts *mod_hdr_acts);
void mlx5e_mod_hdr_dealloc(struct mlx5e_tc_mod_hdr_acts *mod_hdr_acts);
diff --git a/drivers/net/ethernet/mellanox/mlx5/core/en/tc_ct.c b/drivers/net/ethernet/mellanox/mlx5/core/en/tc_ct.c
index 89065fac7590..f89a4c7a4f71 100644
--- a/drivers/net/ethernet/mellanox/mlx5/core/en/tc_ct.c
+++ b/drivers/net/ethernet/mellanox/mlx5/core/en/tc_ct.c
@@ -36,6 +36,12 @@
#define MLX5_CT_LABELS_BITS (mlx5e_tc_attr_to_reg_mappings[LABELS_TO_REG].mlen)
#define MLX5_CT_LABELS_MASK GENMASK(MLX5_CT_LABELS_BITS - 1, 0)
+/* Statically allocate modify actions for
+ * ipv6 and port nat (5) + tuple fields (4) + nic mode zone restore (1) = 10.
+ * This will be increased dynamically if needed (for the ipv6 snat + dnat).
+ */
+#define MLX5_CT_MIN_MOD_ACTS 10
+
#define ct_dbg(fmt, args...)\
netdev_dbg(ct_priv->netdev, "ct_debug: " fmt "\n", ##args)
@@ -645,7 +651,8 @@ mlx5_tc_ct_entry_create_mod_hdr(struct mlx5_tc_ct_priv *ct_priv,
struct mlx5e_mod_hdr_handle **mh,
u8 zone_restore_id, bool nat)
{
- struct mlx5e_tc_mod_hdr_acts mod_acts = {};
+ DECLARE_MOD_HDR_ACTS_ACTIONS(actions_arr, MLX5_CT_MIN_MOD_ACTS);
+ DECLARE_MOD_HDR_ACTS(mod_acts, actions_arr);
struct flow_action_entry *meta;
u16 ct_state = 0;
int err;
--
2.31.1
next prev parent reply other threads:[~2021-11-17 4:34 UTC|newest]
Thread overview: 17+ messages / expand[flat|nested] mbox.gz Atom feed top
2021-11-17 4:33 [pull request][net-next v0 00/15] mlx5 updates 2021-11-16 Saeed Mahameed
2021-11-17 4:33 ` [net-next v0 01/15] net/mlx5e: Support ethtool cq mode Saeed Mahameed
2021-11-17 11:10 ` patchwork-bot+netdevbpf
2021-11-17 4:33 ` [net-next v0 02/15] net/mlx5: Fix format-security build warnings Saeed Mahameed
2021-11-17 4:33 ` [net-next v0 03/15] net/mlx5: Avoid printing health buffer when firmware is unavailable Saeed Mahameed
2021-11-17 4:33 ` [net-next v0 04/15] net/mlx5e: Refactor mod header management API Saeed Mahameed
2021-11-17 4:33 ` Saeed Mahameed [this message]
2021-11-17 4:33 ` [net-next v0 06/15] net/mlx5: TC, using swap() instead of tmp variable Saeed Mahameed
2021-11-17 4:33 ` [net-next v0 07/15] net/mlx5e: TC, Destroy nic flow counter if exists Saeed Mahameed
2021-11-17 4:33 ` [net-next v0 08/15] net/mlx5e: TC, Move kfree() calls after destroying all resources Saeed Mahameed
2021-11-17 4:33 ` [net-next v0 09/15] net/mlx5e: TC, Move comment about mod header flag to correct place Saeed Mahameed
2021-11-17 4:33 ` [net-next v0 10/15] net/mlx5e: Specify out ifindex when looking up decap route Saeed Mahameed
2021-11-17 4:33 ` [net-next v0 11/15] net/mlx5: E-switch, Remove vport enabled check Saeed Mahameed
2021-11-17 4:33 ` [net-next v0 12/15] net/mlx5: E-switch, Reuse mlx5_eswitch_set_vport_mac Saeed Mahameed
2021-11-17 4:33 ` [net-next v0 13/15] net/mlx5: E-switch, move offloads mode callbacks to offloads file Saeed Mahameed
2021-11-17 4:33 ` [net-next v0 14/15] net/mlx5: E-switch, Enable vport QoS on demand Saeed Mahameed
2021-11-17 4:33 ` [net-next v0 15/15] net/mlx5: E-switch, Create " Saeed Mahameed
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20211117043357.345072-6-saeed@kernel.org \
--to=saeed@kernel.org \
--cc=davem@davemloft.net \
--cc=kuba@kernel.org \
--cc=netdev@vger.kernel.org \
--cc=ozsh@nvidia.com \
--cc=paulb@nvidia.com \
--cc=roid@nvidia.com \
--cc=saeedm@nvidia.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
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).